Пример #1
0

def _empty_cell():
    return '<td></td>'


def _is_service_controllable(service):
    if service != 'app_starter':
        return True
    else:
        return False


require_private_access()

output = html_output('monitor.html')
user_agent = os.environ.get('HTTP_USER_AGENT', 'test_agent')
if 'Android' in user_agent:
    output.add_parameter('stylesheet', 'mobile.css')
else:
    output.add_parameter('stylesheet', 'desktop.css')

is_monitor_online = ping(SERVICE_MONITOR).get_response()
if not is_monitor_online:
        table_data = _service_status_row(SERVICE_MONITOR, OFFLINE)
        table_data += _empty_cell()
        table_data += _empty_cell()
        #  status = '<td class="offline">offline</td>'
        #  status += _start_service_cell(SERVICE_MONITOR)
        html_data = '<tr><td>%s</td>%s</tr>' % (SERVICE_MONITOR, table_data)
else:
Пример #2
0
#!/usr/bin/env python

from myhouse.lib.cgi.session import require_private_access, html_output
from myhouse.lib.common.config import service_config
from myhouse.lib.common.network import send_event_to_port
from myhouse.lib.service.events import start_app
#  from myhouse.lib.tv import tv

require_private_access()

output = html_output('kodi.html')

service = service_config().find_service('app_starter')
if not service:
    text = 'Invalid service'
else:
    #  t = tv()
    #  t.power_on()
    #  t.switch_to_hdmi_input()

    send_event_to_port(start_app('kodi'), service['port'])

    text = 'kodi started'

output.add_parameter('data', text)
print output
Пример #3
0
#!/usr/bin/env python

#  import cgitb; cgitb.enable()
import cgi

from myhouse.lib.cgi.session import require_private_access, html_output
from myhouse.lib.common.config import service_config
from myhouse.lib.common.network import send_event_to_port
from myhouse.lib.service.events import debug_mode_off


require_private_access()

data = cgi.FieldStorage()
if data:
    output = html_output('service.html')

    service_name = data['service'].value

    config = service_config()
    service = config.find_service(service_name)
    if not service:
        text = "Invalid service"
    else:
        send_event_to_port(debug_mode_off(), service['port'])
        text = service + ' debug mode off'

    output.add_parameter('data', text)

    print output
Пример #4
0
#  import cgitb; cgitb.enable()
import cgi
import os
from time import sleep

from myhouse.lib.common.config import service_config
from myhouse.lib.common.network import send_event_to_port
from myhouse.lib.cgi.session import require_private_access, html_output
from myhouse.lib.service.events import stop_service
from myhouse.lib.service.service_requests import ping

require_private_access()

data = cgi.FieldStorage()
if data:
    output = html_output("service.html")
    service_name = data["service"].value
    config = service_config()

    service = config.find_service(service_name)
    if not service:
        text = "Invalid service"
    else:
        send_event_to_port(stop_service(), service["port"])

        text = service["name"] + " on port " + str(service["port"]) + " stopped"

    text += "<br/>"

    sleep(2)
Пример #5
0
from myhouse.lib.component.device import Device
from myhouse.lib.component.person import Person
from myhouse.lib.service.service_requests import presence_data_request


def _device_last_changed(last_change):
    return '<td>'+last_change+'</td>'


def _device_status_row(status):
    return '<td class="'+status+'">' + status + '</td>'


require_private_access()

output = html_output('status.html')
if 'Android' in os.environ['HTTP_USER_AGENT']:
    output.add_parameter('stylesheet', 'mobile.css')
else:
    output.add_parameter('stylesheet', 'desktop.css')

presence_data = json.loads(presence_data_request().get_response())
if not presence_data:
    html_data = '<p>Presence status is not available</p>'
else:
    html_data = ''
    for data in presence_data:
        if data['type'] == 'device':
            presence_item = Device.from_json_string(json.dumps(data['item']))
        elif data['type'] == 'person':
            presence_item = Person.from_json_string(json.dumps(data['item']))
Пример #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from myhouse.lib.cgi.session import require_private_access, html_output
from myhouse.lib.cgi.util import is_mobile_device
import re

require_private_access()

output = ''
if is_mobile_device():
    output = html_output('log_mobile.html')
else:
    output = html_output('log_desktop.html')

log_file = '/home/bacso/myhouse/log/banan.log'
content = ''
with open(log_file, 'r') as f:
    for line in reversed(f.readlines()):
        content += '<tr>'

        m = re.search('\[(.*)\]\[(.*)\](.*)', line)
        content += '<td>%s</td>' % (m.group(1))
        content += '<td>%s</td>' % (m.group(2))
        content += '<td>%s</td>' % (m.group(3))

        content += '</tr>'

output.add_parameter('content', content)

print output
Пример #7
0
from myhouse.lib.cgi.util import (public_session_file,
                                  private_session_file,
                                  is_public_logged_in,
                                  is_private_logged_in,
                                  is_on_local_network)

expire_time_in_hours = timedelta(hours=2)
hash_file = '/home/bacso/myhouse/hash/login'
USERNAME = '******'
PASSWORD = '******'
USERNAME_PUBLIC = 'public'
USERNAME_PRIVATE = 'private'

output = ''
if is_on_local_network():
    output = html_output('logged_in.html')
    output.add_parameter(
        'data',
        'No login needed, you are on the local network')
else:
    data = cgi.FieldStorage()
    if data:
        hashes = read_config(hash_file)
        username = data[USERNAME].value

        if username == USERNAME_PUBLIC or username == USERNAME_PRIVATE:
            m = hashlib.sha256()
            m.update(data[PASSWORD].value)
            if hashes[username] == m.hexdigest():
                expires = datetime.now() + expire_time_in_hours
                data = {os.environ['REMOTE_ADDR']: str(expires)}
Пример #8
0
from myhouse.lib.ncore import ncore_session, calculate_earliest_completion_time
from myhouse.lib.cgi.session import require_private_access, html_output
from myhouse.lib.cgi.util import is_mobile_device


def table_row(content, class_=''):
    return u'<tr class="'+class_+'"><td>' + content + u'</td></tr>'


require_private_access()

ncore = ncore_session()

data = cgi.FieldStorage()
if is_mobile_device():
    output = html_output('ncore_mobile.html')
else:
    output = html_output('ncore_desktop.html')

if data:
    search_phrase = data['search_phrase'].value
    output.add_parameter("previous_search", search_phrase)

    torrents = ncore.search_movie(search_phrase)
    content = ''
    for idx, torrent in enumerate(torrents):
        size_float = float(torrent['size'].split()[0])
        completion_time = calculate_earliest_completion_time(size_float)
        completion_time_str = '%02d:%02d' % (
            completion_time.hour,
            completion_time.minute)