def login(): print(get_locale()) print(request.user_agent.platform) print(request.user_agent.language) print(request.user_agent.browser) print(request.user_agent.version) print(request.headers.get('User-Agent')) print(request.accept_languages.best_match(['en', 'fr'])) print("============") fform = LoginForm(request.form) if request.method == 'POST' and fform.validate(): with app.db.session_scope(): if app.db.authenticate(request.form["user"], request.form["passwd"]): user = app.db.get_user_account_by_login(request.form["user"]) if user.is_admin: login_user(user) flash(gettext("Login successfull"), "success") return redirect('/') else: flash(gettext("This user is not an admin"), "warning") else: flash(gettext("Combination of username and password wrong"), "warning") return render_template('login.html', form=fform, nonav = True)
def network_nodes(client_id, network_id): detail = get_client_detail(client_id) abort = False if detail["status"] not in ["alive", "starting"] : abort = True openzwaveInfo = get_openzwave_info(abort) if openzwaveInfo['error'] == 'Plugin timeout response.': abort = True managerState = get_manager_state(abort) if managerState['error'] == 'Plugin timeout response.': abort = True networkState = get_controller_state(network_id, abort) if networkState['error'] == 'Plugin timeout response.': abort = True nodesState = get_controller_nodes(network_id, abort) try: return render_template('plugin_ozwave_nodes.html', clientid = client_id, client_detail = detail, mactive="clients", active = 'advanced', network_active = network_id, networkmenu_active = 'nodes', openzwaveInfo = openzwaveInfo, managerState = managerState, network_state = networkState, nodes_state = nodesState['nodes']) except TemplateNotFound: abort(404)
def client_devices_edit(client_id, did): detail = get_client_detail(client_id) with app.db.session_scope(): device = app.db.get_device_sql(did) MyForm = model_form(Device, \ base_class=Form, \ db_session=app.db.get_session(), exclude=['params', 'commands', 'sensors', 'address', \ 'xpl_commands', 'xpl_stats', 'device_type_id', \ 'client_id', 'client_version']) form = MyForm(request.form, device) if request.method == 'POST' and form.validate(): # save it app.db.update_device(did, \ d_name=request.form['name'], \ d_description=request.form['description'], \ d_reference=request.form['reference']) # message the suer flash(gettext("Device saved"), 'success') # redirect return redirect("/client/{0}/dmg_devices/known".format(client_id)) else: return render_template( 'client_device_edit.html', form=form, clientid=client_id, mactive="clients", active='devices', client_detail=detail, )
def persons_edit(person_id): with app.db.session_scope(): if person_id > 0: person = app.db.get_person(person_id) else: personn = None MyForm = model_form(Person, \ base_class=Form, \ db_session=app.db.get_session(), exclude=['user_accounts']) form = MyForm(request.form, person) if request.method == 'POST' and form.validate(): if int(person_id) > 0: app.db.update_person(person_id, \ p_first_name=request.form['first_name'], \ p_last_name=request.form['last_name'], \ p_birthdate=request.form['birthdate']) else: app.db.add_person(\ p_first_name=request.form['first_name'], \ p_last_name=request.form['last_name'], \ p_birthdate=request.form['birthdate']) flash(gettext("Changes saved"), "success") return redirect("/persons") pass elif request.method == 'POST' and not form.validate(): flash(gettext("Invalid input"), "error") return render_template( 'person_edit.html', form=form, personid=person_id, mactve="auth", )
def client_doc_static(client_id, path): pkg = client_id.split(".")[0].replace("-", "_") root_path = os.path.join(get_packages_directory(), pkg) root_path = os.path.join(root_path, "_build_doc/html/") if not os.path.isfile(os.path.join(root_path, path)): return render_template('client_no_doc.html') return send_from_directory(root_path, path)
def network_nodes(client_id, network_id): detail = get_client_detail(client_id) abort = False if detail["status"] not in ["alive", "starting"]: abort = True openzwaveInfo = get_openzwave_info(abort) if openzwaveInfo['error'] == 'Plugin timeout response.': abort = True managerState = get_manager_state(abort) if managerState['error'] == 'Plugin timeout response.': abort = True networkState = get_controller_state(network_id, abort) if networkState['error'] == 'Plugin timeout response.': abort = True nodesState = get_controller_nodes(network_id, abort) try: return render_template('plugin_ozwave_nodes.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', network_active=network_id, networkmenu_active='nodes', openzwaveInfo=openzwaveInfo, managerState=managerState, network_state=networkState, nodes_state=nodesState['nodes']) except TemplateNotFound: abort(404)
def client_devices_new(client_id): detail = get_client_detail(client_id) data = detail['data'] device_types_keys = sorted(data["device_types"]) device_types_list = OrderedDict() for key in device_types_keys: device_types_list[key] = data["device_types"][key] products = {} products_per_type = OrderedDict() if "products" in data: products_list = data["products"] products_list = sorted(products_list, key=itemgetter("name")) for prod in products_list: product_label = data['device_types'][prod["type"]]['name'] products[prod["name"]] = prod["type"] #if not products_per_type.has_key(prod["type"]): if product_label not in products_per_type: products_per_type[product_label] = OrderedDict() products_per_type[product_label][prod['name']] = prod["type"] # TODO : include products icons return render_template( 'client_device_new.html', device_types=device_types_list, products=products, products_per_type=products_per_type, clientid=client_id, mactive="clients", active='devices', client_detail=detail, )
def client_devices_known(client_id): detail = get_client_detail(client_id) if app.datatypes == {}: cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('datatype.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: app.datatypes = res.get_data()['datatypes'] else: app.datatypes = {} # todo : grab from MQ ? with app.db.session_scope(): devices = app.db.list_devices_by_plugin(client_id) # sort clients per device type devices_by_device_type_id = {} for dev in devices: if devices_by_device_type_id.has_key(dev['device_type_id']): devices_by_device_type_id[dev['device_type_id']].append(dev) else: devices_by_device_type_id[dev['device_type_id']] = [dev] return render_template('client_devices.html', datatypes = app.datatypes, devices = devices, devices_by_device_type_id = devices_by_device_type_id, clientid = client_id, mactive="clients", active = 'devices', rest_url = get_rest_url(), client_detail = detail )
def client_sensor_edit(client_id, sensor_id): with app.db.session_scope(): sensor = app.db.get_sensor(sensor_id) MyForm = model_form(Sensor, \ base_class=Form, \ db_session=app.db.get_session(), exclude=['core_device', 'name', 'reference', 'incremental', 'data_type', 'conversion', 'last_value', 'last_received', 'history_duplicate','value_min','value_max']) #MyForm.history_duplicate.kwargs['validators'] = [] MyForm.history_store.kwargs['validators'] = [] form = MyForm(request.form, sensor) if request.method == 'POST' and form.validate(): if request.form['history_store'] == 'y': store = 1 else: store = 0 app.db.update_sensor(sensor_id, \ history_round=request.form['history_round'], \ history_store=store, \ history_max=request.form['history_max'], \ history_expire=request.form['history_expire'], timeout=request.form['timeout'], formula=request.form['formula']) flash(gettext("Changes saved"), "success") return redirect("/client/{0}/dmg_devices/known".format(client_id)) pass else: return render_template('client_sensor.html', form = form, clientid = client_id, mactive="clients", active = 'devices', sensor = sensor )
def client_devices_new(client_id): detail = get_client_detail(client_id) data = detail['data'] device_types_keys = sorted(data["device_types"]) device_types_list = OrderedDict() for key in device_types_keys: device_types_list[key] = data["device_types"][key] products = {} products_per_type = OrderedDict() if "products" in data: products_list = data["products"] products_list = sorted(products_list, key=itemgetter("name")) for prod in products_list: product_label = data['device_types'][prod["type"]]['name'] products[prod["name"]] = prod["type"] #if not products_per_type.has_key(prod["type"]): if not products_per_type.has_key(product_label): products_per_type[product_label] = OrderedDict() products_per_type[product_label][prod['name']] = prod["type"] # TODO : include products icons return render_template('client_device_new.html', device_types = device_types_list, products = products, products_per_type = products_per_type, clientid = client_id, mactive="clients", active = 'devices', client_detail = detail, )
def clients(): cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('client.list.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: client_list = res.get_data() else: client_list = {} client_list_per_host_per_type = OrderedDict() for client in client_list: cli_type = client_list[client]['type'] cli_host = client_list[client]['host'] if not client_list_per_host_per_type.has_key(cli_host): client_list_per_host_per_type[cli_host] = {} if not client_list_per_host_per_type[cli_host].has_key(cli_type): client_list_per_host_per_type[cli_host][cli_type] = {} client_list_per_host_per_type[cli_host][cli_type][client] = client_list[client] return render_template('clients.html', mactive="clients", overview_state="collapse", clients=client_list, client_list_per_host_per_type=client_list_per_host_per_type )
def index(client_id): detail = get_client_detail(client_id) form = CodeForm() product_id = str(detail['data']['configuration'][1]['value']) product_secret = str(detail['data']['configuration'][2]['value']) if request.method == "POST": generate_token_file(form.code.data, product_id, product_secret, access_token_cache_file) try: return render_template( 'plugin_nestdevice.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', get_token_url=get_token_link(product_id, product_secret, access_token_cache_file), form=form, device_list=get_device_list(product_id, product_secret, access_token_cache_file), devices=get_device(product_id, product_secret, access_token_cache_file), errorlog=get_info_from_log(geterrorlogcmd)) except TemplateNotFound: abort(404)
def login(): print(get_locale()) print(request.user_agent.platform) print(request.user_agent.language) print(request.user_agent.browser) print(request.user_agent.version) print(request.headers.get('User-Agent')) print(request.accept_languages.best_match(['en', 'fr'])) print("============") fform = LoginForm(request.form) if request.method == 'POST' and fform.validate(): with app.db.session_scope(): if app.db.authenticate(request.form["user"], request.form["passwd"]): user = app.db.get_user_account_by_login(request.form["user"]) if user.is_admin: login_user(user) # as we see the page after the login, there is no need to tell this is a success ;) #flash(gettext("Login successfull"), "success") return redirect('/') else: flash(gettext("This user is not an admin"), "warning") else: flash(gettext("Combination of username and password wrong"), "warning") return render_template('login.html', form=fform, nonav = True)
def client_devices_edit(client_id, did): detail = get_client_detail(client_id) with app.db.session_scope(): device = app.db.get_device_sql(did) MyForm = model_form(Device, \ base_class=Form, \ db_session=app.db.get_session(), exclude=['params', 'commands', 'sensors', 'address', 'xpl_commands', 'xpl_stats', 'device_type_id', 'client_id', 'client_version']) form = MyForm(request.form, device) if request.method == 'POST' and form.validate(): # save it app.db.update_device(did, \ d_name=request.form['name'], \ d_description=request.form['description'], \ d_reference=request.form['reference']) # message the suer flash(gettext("Device saved"), 'success') # redirect return redirect("/client/{0}/dmg_devices/known".format(client_id)) else: return render_template('client_device_edit.html', form = form, clientid = client_id, mactive="clients", active = 'devices', client_detail = detail, )
def index(client_id): detail = get_client_detail(client_id) form = CodeForm() withing_client_id = str(detail['data']['configuration'][1]['value']) withing_client_secret = str(detail['data']['configuration'][2]['value']) if request.method == "POST": generate_token_file(form.verifier.data) with open(withing_temp_file, 'r') as withing_auth_file: auth = pickle.load(withing_auth_file) else : try: auth = get_auth(withing_client_id, withing_client_secret) except: flash(gettext(u"Plugin not configured."), "error") abort(404) try: return render_template('plugin_withingdevice.html', clientid = client_id, client_detail = detail, mactive = "clients", active = 'advanced', get_token_url= get_authorize_url(auth), form = form, # car_id = get_car_list(withing_client_id,withing_client_secret), # current_token = show_current_token(), errorlog = get_info_from_log(geterrorlogcmd)) except TemplateNotFound: abort(404)
def persons_edit(person_id): with app.db.session_scope(): if person_id > 0: person = app.db.get_person(person_id) else: personn = None MyForm = model_form(Person, \ base_class=Form, \ db_session=app.db.get_session(), exclude=['user_accounts']) form = MyForm(request.form, person) if request.method == 'POST' and form.validate(): if int(person_id) > 0: app.db.update_person(person_id, \ p_first_name=request.form['first_name'], \ p_last_name=request.form['last_name'], \ p_birthdate=request.form['birthdate']) else: app.db.add_person(\ p_first_name=request.form['first_name'], \ p_last_name=request.form['last_name'], \ p_birthdate=request.form['birthdate']) flash(gettext("Changes saved"), "success") return redirect("/persons") pass elif request.method == 'POST' and not form.validate(): flash(gettext("Invalid input"), "error") return render_template('person_edit.html', form = form, personid = person_id, mactve="auth", )
def accounts(): with app.db.session_scope(): accounts = [] for acc in app.db.list_user_accounts(): accounts.append(acc.__dict__) return render_template('accounts.html', accounts=accounts, mactive='auth')
def core_butler_not_understood(client_id): brain = get_brain_content("not_understood") return render_template('core_butler_not_understood.html', loop={'index': 1}, clientid=client_id, brain=brain, mactive="clients", active='not_understood')
def core_butler_learned(client_id): brain = get_brain_content("learn") return render_template('core_butler_learned.html', loop={'index': 1}, clientid=client_id, brain=brain, mactive="clients", active='learn')
def client_detail(client_id): detail = get_client_detail(client_id) return render_template('client.html', loop = {'index': 1}, clientid = client_id, client_detail = detail, mactive="clients", active = 'home')
def core_butler_learned(client_id): brain = get_brain_content("learn") return render_template('core_butler_learned.html', loop = {'index': 1}, clientid = client_id, brain = brain, mactive="clients", active = 'learn' )
def client_detail(client_id): detail = get_client_detail(client_id) return render_template('client.html', loop={'index': 1}, clientid=client_id, client_detail=detail, mactive="clients", active='home')
def persons(): with app.db.session_scope(): persons = [] for per in app.db.list_persons(): persons.append(per.__dict__) return render_template('persons.html', persons=persons, mactive='auth' )
def core_butler_not_understood(client_id): brain = get_brain_content("not_understood") return render_template('core_butler_not_understood.html', loop = {'index': 1}, clientid = client_id, brain = brain, mactive="clients", active = 'not_understood' )
def accounts(): with app.db.session_scope(): accounts = [] for acc in app.db.list_user_accounts(): accounts.append(acc.__dict__) return render_template('accounts.html', accounts=accounts, mactive='auth' )
def client_global_edit(client_id, dev_id): with app.db.session_scope(): dev = app.db.get_device(dev_id) known_items = {} class F(Form): pass for item in dev["parameters"]: item = dev["parameters"][item] default = item["value"] arguments = [Required()] # keep track of the known fields known_items[item["key"]] = { u"id": item["id"], u"type": item["type"] } # build the field if item["type"] == "boolean": if default == 'y' or default == 1 or default == True: # in db value stored in lowcase default = True else: default = False field = BooleanField( item["key"], [validators.optional()], default=default ) # set to optional field due to WTForm BooleanField return no data for false value (HTML checkbox) elif item["type"] == "integer": field = IntegerField(item["key"], arguments, default=default) elif item["type"] == "float": field = DateTimeField(item["key"], arguments, default=default) else: # time, email, ipv4, ipv6, url field = TextField(item["key"], arguments, default=default) # add the field setattr(F, "{0}-{1}".format(item["id"], item["key"]), field) form = F() if request.method == 'POST' and form.validate(): for key, item in known_items.iteritems(): val = getattr(form, "{0}-{1}".format(item["id"], key)).data if item["type"] == "boolean": if val == False: val = 'n' # in db value stored in lowcase else: val = 'y' # in db value stored in lowcase app.db.udpate_device_param(item["id"], value=val) return redirect("/client/{0}/dmg_devices/known".format(client_id)) pass else: return render_template('client_global.html', form=form, clientid=client_id, client_detail=get_client_detail(client_id), mactive="clients", active='devices', device=dev)
def client_devices_known(client_id): detail = get_client_detail(client_id) if app.datatypes == {}: cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('datatype.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: app.datatypes = res.get_data()['datatypes'] else: app.datatypes = {} # todo : grab from MQ ? with app.db.session_scope(): try: devices = app.db.list_devices_by_plugin(client_id) error = None except: error = "Error while retrieving the devices list. Error is : {0}".format(traceback.format_exc()) devices = [] # first sort by device name devices = sorted(devices, key=itemgetter("name")) # device_types_list[key] = data["device_types"][key] # group clients per device type devices_by_device_type_id = {} for dev in devices: try: device_type_name = detail['data']['device_types'][dev['device_type_id']]['name'] except KeyError: print(u"Warning : the device type '{0}' does not exist anymore in the installed package release. Device type name set as the existing id in database".format(dev['device_type_id'])) device_type_name = dev['device_type_id'] if device_type_name in devices_by_device_type_id: devices_by_device_type_id[device_type_name].append(dev) else: devices_by_device_type_id[device_type_name] = [dev] # sorting # disabled as this breaks because of storing other objects then normal strings devices_by_device_type_id = json.dumps(devices_by_device_type_id, sort_keys=True) devices_by_device_type_id = json.loads(devices_by_device_type_id, object_pairs_hook=OrderedDict) return render_template('client_devices.html', datatypes = app.datatypes, devices = devices, devices_by_device_type_id = devices_by_device_type_id, clientid = client_id, mactive="clients", active = 'devices', #rest_url = get_rest_url(), rest_url = request.url_root + "rest", client_detail = detail, error = error)
def index(client_id): detail = get_client_detail(client_id) try: return render_template('plugin_mysensors.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', errorlog=get_errorlog(geterrorlogcmd, logfile)) except TemplateNotFound: abort(404)
def clients(): #cli = MQSyncReq(app.zmq_context) #msg = MQMessage() #msg.set_action('client.list.get') #res = cli.request('manager', msg.get(), timeout=10) #if res is not None: # client_list = res.get_data() #else: # client_list = {} client_list = get_clients_list() client_list_per_host_per_type = OrderedDict() num_core = 0 num_core_dead = 0 for client in client_list: cli_type = client_list[client]['type'] cli_host = client_list[client]['host'] if cli_type == "core": num_core += 1 if client_list[client]['status'] == STATUS_DEAD: num_core_dead += 1 if cli_host not in client_list_per_host_per_type: client_list_per_host_per_type[cli_host] = {} if cli_type not in client_list_per_host_per_type[cli_host]: client_list_per_host_per_type[cli_host][cli_type] = {} client_list_per_host_per_type[cli_host][cli_type][ client] = client_list[client] # sorting client_list_per_host_per_type = json.dumps(client_list_per_host_per_type, sort_keys=True) client_list_per_host_per_type = json.loads(client_list_per_host_per_type, object_pairs_hook=OrderedDict) # if all the core clients are dead, there is an issue with MQ pub/sub (forwarder) # so display a message if num_core > 0 and num_core == num_core_dead: msg_core_dead = "Ooups, it seems that you have an issue with your current configuration!<br>" msg_core_dead += "The message queue is not working for PUB/SUB messages.<br>" msg_core_dead += "This is related to the component MQ forwarder.<br>" msg_core_dead += "The related configuration file is : /etc/domogik/domogik-mq.cfg.<br>" else: msg_core_dead = None return render_template( 'clients.html', mactive="clients", overview_state="collapse", clients=client_list, client_list_per_host_per_type=client_list_per_host_per_type, msg_core_dead=msg_core_dead)
def index(client_id): detail = get_client_detail(client_id) try: return render_template('plugin_callerid.html', clientid = client_id, client_detail = detail, mactive="clients", active = 'advanced') except TemplateNotFound: abort(404)
def client_brain(client_id): detail = get_client_detail(client_id) brain = get_brain_content(client_id) return render_template('client_brain.html', loop={'index': 1}, clientid=client_id, client_detail=detail, brain=brain, mactive="clients", active='brain')
def index(client_id): detail = get_client_detail(client_id) try: return render_template('client_nothing_adm.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced') except TemplateNotFound: abort(404)
def core(client_id): tmp = client_id.split(".") name = tmp[0].split("-")[1] if name == "butler": brain = get_brain_content("learn") history = get_butler_history() client_list = get_clients_list() return render_template('core_butler.html', loop={'index': 1}, clientid=client_id, client_list=client_list, history=map(json.dumps, history), brain=brain, mactive="clients", active='home') else: return render_template('core.html', loop={'index': 1}, clientid=client_id, mactive="clients", active='home')
def index(client_id): detail = get_client_detail(client_id) try: return render_template('plugin_onewired.html', clientid = client_id, client_detail = detail, mactive="clients", active = 'advanced', informations = get_informations()) except TemplateNotFound: abort(404)
def index(client_id): detail = get_client_detail(client_id) try: return render_template('plugin_bluez.html', clientid = client_id, client_detail = detail, mactive="clients", active = 'advanced', bt = list_bt_devices()) except TemplateNotFound: abort(404)
def client_brain(client_id): detail = get_client_detail(client_id) brain = get_brain_content(client_id) return render_template('client_brain.html', loop = {'index': 1}, clientid = client_id, client_detail = detail, brain = brain, mactive="clients", active = 'brain' )
def scenario(): scenarios = [] cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action("scenario.list") res = cli.request("scenario", msg.get(), timeout=10) if res is not None: res = res.get_data() if "result" in res: res = res["result"] for scen in res: scenarios.append(scen) return render_template("scenario.html", scenarios=scenarios, mactive=u"scenario")
def index(client_id): detail = get_client_detail(client_id) try: return render_template( 'plugin_hue.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', hue=list_lights(detail['data']['configuration'][1]['value'])) except TemplateNotFound: abort(404)
def client_timeline(client_id): from domogik.admin.views.timeline import timeline_generic temp = timeline_generic(the_client_id=client_id, asDict=True) detail = get_client_detail(client_id) return render_template('client_timeline.html', timeline=temp['timeline'], datatypes=temp['datatypes'], client_detail=detail, clientid=client_id, device_name=client_id, mactive="clients", active='timeline')
def client_timeline(client_id): from domogik.admin.views.timeline import timeline_generic temp = timeline_generic(the_client_id = client_id, asDict = True) detail = get_client_detail(client_id) return render_template('client_timeline.html', timeline = temp['timeline'], datatypes = temp['datatypes'], client_detail = detail, clientid = client_id, device_name = client_id, mactive="clients", active = 'timeline')
def clients(): #cli = MQSyncReq(app.zmq_context) #msg = MQMessage() #msg.set_action('client.list.get') #res = cli.request('manager', msg.get(), timeout=10) #if res is not None: # client_list = res.get_data() #else: # client_list = {} client_list = get_clients_list() client_list_per_host_per_type = OrderedDict() num_core = 0 num_core_dead = 0 for client in client_list: cli_type = client_list[client]['type'] cli_host = client_list[client]['host'] if cli_type == "core": num_core += 1 if client_list[client]['status'] == STATUS_DEAD: num_core_dead += 1 if cli_host not in client_list_per_host_per_type: client_list_per_host_per_type[cli_host] = {} if cli_type not in client_list_per_host_per_type[cli_host]: client_list_per_host_per_type[cli_host][cli_type] = {} client_list_per_host_per_type[cli_host][cli_type][client] = client_list[client] # sorting client_list_per_host_per_type = json.dumps(client_list_per_host_per_type, sort_keys=True) client_list_per_host_per_type = json.loads(client_list_per_host_per_type, object_pairs_hook=OrderedDict) # if all the core clients are dead, there is an issue with MQ pub/sub (forwarder) # so display a message if num_core > 0 and num_core == num_core_dead: msg_core_dead = "Ooups, it seems that you have an issue with your current configuration!<br>" msg_core_dead += "The message queue is not working for PUB/SUB messages.<br>" msg_core_dead += "This is related to the component MQ forwarder.<br>" msg_core_dead += "The related configuration file is : /etc/domogik/domogik-mq.cfg.<br>" else: msg_core_dead = None return render_template('clients.html', mactive="clients", overview_state="collapse", clients=client_list, client_list_per_host_per_type=client_list_per_host_per_type, msg_core_dead = msg_core_dead)
def index(client_id): detail = get_client_detail(client_id) device = str(detail['data']['configuration'][1]['value']) try: return render_template('plugin_onewired.html', clientid = client_id, client_detail = detail, mactive="clients", active = 'advanced', informations = get_informations(device), errorlog = get_errorlog(geterrorlogcmd)) except TemplateNotFound: abort(404)
def core(client_id): tmp = client_id.split(".") name = tmp[0].split("-")[1] if name == "butler": brain = get_brain_content("learn") history = get_butler_history() client_list = get_clients_list() return render_template('core_butler.html', loop = {'index': 1}, clientid = client_id, client_list = client_list, history = map(json.dumps, history), brain = brain, mactive="clients", active = 'home' ) else: return render_template('core.html', loop = {'index': 1}, clientid = client_id, mactive="clients", active = 'home' )
def log(client_id): detail = get_client_detail(client_id) with open(logfile, 'r') as contentLogFile: content_log = contentLogFile.read() try: return render_template('plugin_vigilightning_log.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', logfile=logfile, contentLog=content_log) except TemplateNotFound: abort(404)
def scenario(): scenarios = [] cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('scenario.list') res = cli.request('scenario', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'result' in res: res = res['result'] for scen in res: scenarios.append(scen) return render_template('scenario.html', scenarios=scenarios, mactive=u"scenario")
def client_global_edit(client_id, dev_id): with app.db.session_scope(): dev = app.db.get_device(dev_id) known_items = {} class F(Form): pass for item in dev["parameters"]: item = dev["parameters"][item] default = item["value"] arguments = [Required()] # keep track of the known fields known_items[item["key"]] = {u"id": item["id"], u"type": item["type"]} # build the field if item["type"] == "boolean": if default == 'y' or default == 1 or default == True: # in db value stored in lowcase default = True else: default = False field = BooleanField(item["key"], [validators.optional()], default=default) # set to optional field due to WTForm BooleanField return no data for false value (HTML checkbox) elif item["type"] == "integer": field = IntegerField(item["key"], arguments, default=default) elif item["type"] == "float": field = DateTimeField(item["key"], arguments, default=default) else: # time, email, ipv4, ipv6, url field = TextField(item["key"], arguments, default=default) # add the field setattr(F, "{0}-{1}".format(item["id"], item["key"]), field) form = F() if request.method == 'POST' and form.validate(): for key, item in known_items.iteritems(): val = getattr(form, "{0}-{1}".format(item["id"], key)).data if item["type"] == "boolean": if val == False: val = 'n' # in db value stored in lowcase else: val = 'y' # in db value stored in lowcase app.db.udpate_device_param(item["id"], value=val) return redirect("/client/{0}/dmg_devices/known".format(client_id)) pass else: return render_template('client_global.html', form = form, clientid = client_id, client_detail = get_client_detail(client_id), mactive="clients", active = 'devices', device = dev)
def index(): mqConfig = mqLoader('mq').load()[0] butlerConfig = dict(dmgLoader('butler').load()[1]) qrCode = dict() qrCode["admin_url"] = str(request.url) qrCode["rest_port"] = int(app.port) qrCode["rest_path"] = "/rest" qrCode["rest_auth"] = bool(app.rest_auth) qrCode["mq_ip"] = str(mqConfig['ip']) qrCode["mq_port_pubsub"] = int(mqConfig['sub_port']) qrCode["mq_port_req_rep"] = int(mqConfig['req_rep_port']) qrCode["butler_name"] = ucode(butlerConfig['name']) qrCode["butler_sex"] = str(butlerConfig['sex']) qrCode["butler_lang"] = str(butlerConfig['lang']) return render_template('index.html', qrdata=qrCode)
def index(): mqConfig = mqLoader('mq').load()[0] butlerConfig = dict(dmgLoader('butler').load()[1]) qrCode = dict() qrCode["admin_url"] = str(request.url) qrCode["rest_port"] = int(app.port) qrCode["rest_path"] = "/rest" qrCode["rest_auth"] = bool(app.rest_auth) qrCode["mq_ip"] = str(mqConfig['ip']) qrCode["mq_port_pubsub"] = int( mqConfig['sub_port']) qrCode["mq_port_req_rep"] = int(mqConfig['req_rep_port']) qrCode["butler_name"] = ucode(butlerConfig['name']) qrCode["butler_sex"] = str(butlerConfig['sex']) qrCode["butler_lang"] = str(butlerConfig['lang']) return render_template('index.html', qrdata=qrCode)
def index(client_id): detail = get_client_detail(client_id) # vigiallergen plugin configuration devices = get_client_devices(client_id) # vigiallergen plugin devices list #print("Admin vigiallergen devices\n %s" % format(devices)) print("Departements list: %s" % format(get_informations(devices))) try: return render_template('plugin_vigiallergen.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', departementslist=get_informations(devices), logfile=logfile, errorlog=get_errorlog(geterrorlogcmd, logfile)) except TemplateNotFound: abort(404)
def index(client_id): detail = get_client_detail(client_id) ebusd_device = str(detail['data']['configuration'][1]['value']) information = '' try: return render_template('plugin_ebusd.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', sensor_list=list_sensors(ebusd_device), errorlog=get_info_from_log(geterrorlogcmd), information=information) except TemplateNotFound: abort(404)
def graph(client_id, sensor_id, device, stype): flash(gettext(u"Loading data"), "info") clientid = client_id detail = get_client_detail(client_id) if sensor_id == '0': flash(gettext(u"No data to graph"), "error") abort(404) tsfrom = int(datetime.now().strftime("%s")) - 2678400 # now - 32d datahistory = [] cli = MQSyncReq(zmq.Context()) msg = MQMessage() msg.set_action('sensor_history.get') msg.add_data('sensor_id', sensor_id) msg.add_data('mode', 'period') msg.add_data('from', tsfrom) sensor_history = cli.request('admin', msg.get(), timeout=15).get() if 'sensor_history.result' in sensor_history: historyvalues = json.loads(sensor_history[1]) if historyvalues["status"]: for value in historyvalues["values"]: datahistory.append([value["timestamp"] * 1000, value["value_num"]]) try: stypeunit = datatypeslist["DT_" + stype]['unit'] except KeyError: stypeunit = "" try: return render_template('plugin_mqtt_graph.html', clientid = client_id, client_detail = detail, mactive = "clients", active = 'advanced', device = device, stype = stype, unit = stypeunit, data = datahistory) except TemplateNotFound: abort(404)
def login(): fform = LoginForm(request.form) if request.method == 'POST' and fform.validate(): with app.db.session_scope(): if app.db.authenticate(request.form["user"], request.form["passwd"]): user = app.db.get_user_account_by_login(request.form["user"]) if user.is_admin: login_user(user) # as we see the page after the login, there is no need to tell this is a success ;) #flash(gettext("Login successfull"), "success") return redirect('/') else: flash(gettext("This user is not an admin"), "warning") else: flash(gettext("Combination of username and password wrong"), "warning") return render_template('login.html', form=fform, nonav = True)
def blacklist(client_id): detail = get_client_detail(client_id) form = BlacklistForm() if request.method == "POST": save_blacklist(form.blacklist.data) else: form.blacklist.data = read_blacklist() try: return render_template('plugin_callerid_blacklist.html', clientid = client_id, client_detail = detail, mactive="clients", active = 'advanced', blacklist = read_blacklist(), form = form) except TemplateNotFound: abort(404)
def client_devices_detected(client_id): detail = get_client_detail(client_id) cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('device.new.get') res = cli.request(str(client_id), msg.get(), timeout=10) if res is not None: data = res.get_data() devices = data['devices'] else: devices = {} return render_template('client_detected.html', devices=devices, clientid=client_id, mactive="clients", active='devices', client_detail=detail)
def login(): fform = LoginForm(request.form) if request.method == 'POST' and fform.validate(): with app.db.session_scope(): if app.db.authenticate(request.form["user"], request.form["passwd"]): user = app.db.get_user_account_by_login(request.form["user"]) if user.is_admin: login_user(user) # as we see the page after the login, there is no need to tell this is a success ;) #flash(gettext("Login successfull"), "success") return redirect('/') else: flash(gettext("This user is not an admin"), "warning") else: flash(gettext("Combination of username and password wrong"), "warning") return render_template('login.html', form=fform, nonav=True)
def client_devices_detected(client_id): detail = get_client_detail(client_id) cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('device.new.get') res = cli.request(str(client_id), msg.get(), timeout=10) if res is not None: data = res.get_data() devices = data['devices'] else: devices = {} return render_template('client_detected.html', devices = devices, clientid = client_id, mactive="clients", active = 'devices', client_detail = detail)
def contacts(client_id): detail = get_client_detail(client_id) form = ContactsForm() if request.method == "POST": save_contacts(form.contacts.data) else: form.contacts.data = read_contacts() try: return render_template('plugin_callerid_contacts.html', clientid = client_id, client_detail = detail, mactive="clients", active = 'advanced', contacts = read_contacts(), form = form) except TemplateNotFound: abort(404)
def index(client_id): detail = get_client_detail(client_id) # vigilightning plugin configuration devices = get_client_devices( client_id) # vigilightning plugin devices list deviceInfos = get_informations(devices) print("Locations list: %s" % format(deviceInfos)) try: return render_template('plugin_vigilightning.html', clientid=client_id, client_detail=detail, mactive="clients", active='advanced', locationsList=deviceInfos, logfile=logfile, errorlog=get_errorlog(geterrorlogcmd, logfile)) except TemplateNotFound: abort(404)
def battery(): # datatypes datatypes = {} used_datatypes = [] cli = MQSyncReq(app.zmq_context) msg = MQMessage() msg.set_action('datatype.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: res = res.get_data() if 'datatypes' in res: datatypes = res['datatypes'] else: print("Error : no datatypes found!") datatypes = {} # TODO : improve by getting directly all devices instead of all sensors ? with app.db.session_scope(): sensors = [] data = app.db.get_all_sensor() for item in data: if item.data_type == "DT_Battery": dev = app.db.get_device(item.device_id) try: last_value = int(item.last_value) except: last_value = None sensors.append({"name" : item.name, "last_value" : last_value, "last_received" : item.last_received, "device_id" : item.device_id, "device_name" : dev['name'], "client_id" : dev['client_id'], "id" : item.id }) sensors = sorted(sensors, key=itemgetter("last_value", "device_name")) return render_template('battery.html', mactive="battery", sensors=sensors )