Commit b6822327 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

views purged from old front-end, not tested entirely

parent 385aadfd
...@@ -73,6 +73,13 @@ ...@@ -73,6 +73,13 @@
<div class="col-lg-3"> <div class="col-lg-3">
<button type="submit" form="administration" class="btn btn-primary btn-block">Save</button> <button type="submit" form="administration" class="btn btn-primary btn-block">Save</button>
</div> </div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
<a href="/administration/users"><button type="button" class="btn btn-primary btn-block">Users</button></a>
</div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -94,7 +94,7 @@ def login(): ...@@ -94,7 +94,7 @@ def login():
@app.route('/logout') @app.route('/logout')
def logout(): def logout():
session.clear() session.clear()
return redirect(url_for('index')) return redirect(url_for('login'))
@app.route('/applications') @app.route('/applications')
...@@ -339,154 +339,6 @@ def recent_activity(): ...@@ -339,154 +339,6 @@ def recent_activity():
return '', 401 return '', 401
@app.route('/new-app')
def new_app():
if 'name' in session:
return render_template('old/public/new-app.html')
else:
return redirect(url_for('index'))
@app.route('/app', methods=['GET', 'POST'])
def app_():
if 'name' in session:
if request.method == 'GET':
session['appkey'] = request.args.get('appkey')
ap = ad.get(session['appkey'])
devs = dd.get_list(ap[1][1])
session['appname'] = ap[1][0]
if session['role'] == 'admin' or session['name'] == ap[1][2]:
return render_template('old/public/app.html', app=ap[1], devs=devs[1])
else:
return redirect(url_for('index'))
else:
if request.form['appname'] == '':
error = 'Application name cannot be empty.'
return render_template('old/public/new-app.html', feedback=error)
else:
appkey = misc.rand_str(app.config['APPKEY_LENGTH']).decode('utf-8')
secure_key = misc.gen_skey_b64(16)
secure = False
if request.form.getlist('secure') and request.form.getlist('secure')[0] == 'true':
secure = True
res = ad.create(request.form['appname'], appkey, session['name'], request.form['appdesc'], secure, secure_key)
if not res[0]:
return render_template('old/public/new-app.html', feedback=res[1])
res = dd.create_table(appkey)
if not res[0]:
ad.delete(appkey)
return render_template('old/public/new-app.html', feedback=res[1])
return redirect(url_for('index'))
else:
return redirect(url_for('index'))
@app.route('/delete-app')
def delete_app():
if 'name' in session:
devs = dd.get_list(session['appkey'])
for dev in devs[1]:
data.delete_table(session['appkey'], dev[1])
dd.delete_table(session['appkey'])
res = ad.delete(session['appkey'])
if not res[0]:
return redirect(url_for('app_'))
else:
return redirect(url_for('index'))
else:
return redirect(url_for('index'))
@app.route('/add-dev')
def new_dev():
if 'name' in session:
dev_list = dd.get_list(session['appkey'])
if not dev_list[0]:
return render_template('old/public/add-dev.html', feedback=dev_list[1])
else:
return render_template('old/public/add-dev.html', free_ids=misc.prep_id_range(dev_list[1]))
else:
return redirect(url_for('index'))
@app.route('/dev', methods=['GET', 'POST'])
def dev():
if 'name' in session:
if request.method == 'GET':
ap = ad.get(session['appkey'])
if session['role'] == 'admin' or session['name'] == ap[1][2]:
dev = dd.get(session['appkey'], request.args.get('id'))
session['devid'] = int(dev[1][1])
session['devname'] = dev[1][0]
last = data.get_last_n(session['appkey'], session['devid'], 1)
ltup = 'Device has not sent data yet'
if last[0]:
ltup = last[1][0][1]
return render_template('old/public/dev.html', dev=dev[1], appkey=session['appkey'], ltup=ltup)
else:
return redirect(url_for('index'))
else:
res = dd.create(request.form['devname'], request.form['devid'], session['appkey'], request.form['devdesc'])
if not res[0]:
return render_template('old/public/add-dev.html', feedback=res[1])
else:
res = data.create_table(session['appkey'], request.form['devid'])
if not res[0]:
dd.delete(session['appkey'], request.form['devid'])
return render_template('old/public/add-dev.html', feedback=res[1])
else:
return redirect(url_for('app_', appkey=session['appkey']))
else:
return redirect(url_for('index'))
@app.route('/dev-conf', methods=['GET', 'POST'])
def dev_conf():
if 'name' in session and 'devid' in session:
if request.method == 'GET':
pend_msgs = pend.get_list(session['appkey'], session['devid'])
if pend_msgs[0]:
config_list = []
for pm in pend_msgs[1]:
cntt = binascii.a2b_base64(pm[2])
config_id = int(cntt[0])
config_args = cntt[2:(len(cntt)-1)].decode('utf-8')
ack = pm[3]
config_list.append((config_id, config_args, ack, pm[2]))
return render_template('old/public/dev-conf.html', devname=session['devname'], config_list=config_list)
else:
return render_template('old/public/dev-conf.html', devname=session['devname'])
else:
base64_args = pend_base64_encode(request.form['arg'], request.form['confid'])
pend.create(session['appkey'], session['devid'], base64_args)
return redirect(url_for('dev', id=session['devid']))
else:
return redirect(url_for('index'))
@app.route('/application/<appkey>/device/<devid>/remove-configuration') @app.route('/application/<appkey>/device/<devid>/remove-configuration')
def application_device_configuration_remove(appkey, devid): def application_device_configuration_remove(appkey, devid):
if 'name' in session: if 'name' in session:
...@@ -527,126 +379,6 @@ def delete_dev(): ...@@ -527,126 +379,6 @@ def delete_dev():
return redirect(utl_for('index')) return redirect(utl_for('index'))
@app.route('/dev-data')
def dev_data_pg():
if 'name' in session and 'devid' in session:
cur_pg = 1
if request.args.get('p'):
cur_pg = int(request.args.get('p'))
if cur_pg < 1:
cur_pg = 1
last = data.get_last_range(session['appkey'], session['devid'], [MAX_PG_ENTRIES_DATA, (cur_pg-1)*MAX_PG_ENTRIES_DATA])
ent_cnt = data.get_count(session['appkey'], session['devid'])
if ent_cnt[0]:
# range data
rd = misc.paging(cur_pg, ent_cnt[1][0], MAX_PG_ENTRIES_DATA, MAX_PG)
if ent_cnt[1][0] > 0:
return render_template('old/public/dev-data-t.html', data=last[1], total=ent_cnt[1][0], cp=cur_pg, np=rd[2], pp=rd[0], pr=rd[1], devname=session['devname'])
else:
return render_template('old/public/dev-data-t.html', devname=session['devname'])
else:
flash('Error: {}'.format(ent_cnt[1]), 'danger')
return render_template('old/public/dev-data-t.html', devname=session['devname'])
else:
return redirect(utl_for('index'))
@app.route('/dev-vars')
def dev_vars():
if 'name' in session:
last = data.get_last_n(session['appkey'], request.args.get('id'), 1)
if last[0]:
select = '<select class="form-control notifelem" id="varname" name="varname" onchange="onvar(event)" required>'
select += '<option value="-">Select Variable</option>'
for k in last[1][0][2]:
select += '<option>'+k+'</option>'
select += '</select>'
return select
else:
return redirect(url_for('index'))
@app.route('/data-csv')
def data_csv():
if 'name' in session and 'devid' in session:
dumpd = data.get_all(session['appkey'], session['devid'])
fn = session['appkey']+ '_' +str(session['devid'])+ '.csv'
with open(app.config['DATA_DOWNLOAD_DIR_OS']+'/'+fn, 'w+') as f:
f.write('utc,timestamp,')
for d in dumpd[1][0][2]:
f.write(d)
f.write(',')
f.write('\n')
for row in dumpd[1]:
f.write('{},{},'.format(row[0],row[1]))
for v in row[2]:
f.write(str(row[2][v]))
f.write(',')
f.write('\n')
return send_from_directory(app.config['DATA_DOWNLOAD_DIR'], fn, as_attachment=True)
else:
return redirect(utl_for('index'))
@app.route('/administration_old', methods=['GET', 'POST'])
def administration_old():
if 'role' in session and session['role'] == 'admin':
user_cnt = ud.get_count()
apps_cnt = ad.get_count()
devs_cnt = dd.get_count_all()
cur_pg = 1
if request.args.get('p'):
cur_pg = int(request.args.get('p'))
if cur_pg < 1:
cur_pg = 1
users = None
if request.method == 'POST':
session['users_filter'] = request.form['username']
if 'users_filter' in session:
users = ud.get_range_name(session['users_filter'], [MAX_PG_ENTRIES_USERS, (cur_pg-1)*MAX_PG_ENTRIES_USERS])
rd = misc.paging(cur_pg, len(users[1]), MAX_PG_ENTRIES_USERS, MAX_PG)
else:
users = ud.get_range([MAX_PG_ENTRIES_USERS, (cur_pg-1)*MAX_PG_ENTRIES_USERS])
rd = misc.paging(cur_pg, user_cnt[1][0], MAX_PG_ENTRIES_USERS, MAX_PG)
return render_template('old/admin/dashboard.html', users_cnt=user_cnt[1][0], apps_cnt=apps_cnt[1][0], dev_cnt=devs_cnt, users=users[1], pp=rd[0], pr=rd[1], np=rd[2], cp=cur_pg, usn=(cur_pg-1)*MAX_PG_ENTRIES_USERS+1)
else:
return redirect(url_for('index'))
@app.route('/dashboard-clean-search')
def dashboard_clean_search():
if 'users_filter' in session:
session.pop('users_filter', None)
return redirect(url_for('administration'))
@app.route('/user')
def user():
if 'role' in session and session['role'] == 'admin':
name = request.args.get('name')
apps = ad.get_list(name)
session.pop('appkey', None)
if apps[0]:
return render_template('old/admin/user.html', apps=apps[1], username=name)
else:
return render_template('old/admin/user.html', feedback=apps[1], username=name)
else:
return render_template('old/public/index.html')
@app.route('/delete-account') @app.route('/delete-account')
def delete_account(): def delete_account():
user = ud.get(request.args.get('name')) user = ud.get(request.args.get('name'))
...@@ -676,7 +408,7 @@ def delete_account(): ...@@ -676,7 +408,7 @@ def delete_account():
if not res[0]: if not res[0]:
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return render_template('old/admin/user.html', username=user[1][0]) return render_template('new/public/settings.html', user=session['name'])
else: else:
flash('User {} was successfully deleted'.format(request.args.get('name')), 'success') flash('User {} was successfully deleted'.format(request.args.get('name')), 'success')
return redirect(url_for('login')) return redirect(url_for('login'))
...@@ -905,131 +637,6 @@ def application_device_settings(appkey, devid): ...@@ -905,131 +637,6 @@ def application_device_settings(appkey, devid):
return redirect(url_for('login')) return redirect(url_for('login'))
@app.route('/alerts')
def alerts():
if 'name' in session:
alerts = nfs.get_alerts_list(session['appkey'])
return render_template('old/public/alerts.html', alert_list=alerts[1])
else:
return redirect(url_for('index'))
@app.route('/new-alert')
def new_alert():
if 'name' in session:
devs = dd.get_list(session['appkey'])
return render_template('old/public/new-alert.html', devs=devs[1])
else:
return redirect(url_for('index'))
@app.route('/alert', methods=['POST'])
def alert():
if 'name' in session:
if request.method == 'POST':
# create new notification
nid = misc.rand_str(app.config['NID_LENGTH']).decode('utf-8')
dev = dd.get(session['appkey'], request.form['devid'])
try:
desc = dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']+' '+request.form['avalue']
res = nfs.create(nid, session['appkey'], request.form['devid'], request.form['alertname'], desc, 'alert', request.form['alertemail'])
if res[0]:
# create new function and trigger
tr.create_function(session['appkey'], request.form['devid'], nid, [request.form['varname'],request.form['operation'],request.form['avalue']])
tr.create(session['appkey'], request.form['devid'], nid)
return redirect(url_for('alerts'))
else:
flash('Error creating new alert: {}'.format(res[1]), 'danger')
return redirect(url_for('alerts'))
except Exception as e:
flash('Error creating new alert: {}. Make sure you have filled all form fields.'.format(e), 'danger')
return redirect(url_for('new_alert'))
else:
return redirect(url_for('index'))
else:
return redirect(url_for('index'))
@app.route('/alert-rm')
def alarm_rm():
if 'name' in session:
nq.delete(session['appkey'], request.args.get('devid'), request.args.get('id'))
tr.delete(session['appkey'], request.args.get('devid'), request.args.get('id'))
tr.delete_function(session['appkey'], request.args.get('devid'), request.args.get('id'))
res = nfs.delete(session['appkey'], request.args.get('devid'), request.args.get('id'))
if res[0]:
flash('Alert removed', 'success')
return redirect(url_for('alerts'))
else:
flash('Alert cannot be removed : {}'.format(res[1]), 'danger')
return redirect(url_for('alerts'))
else:
return redirect(url_for('index'))
@app.route('/automation', methods=['GET','POST'])
def automation():
if 'name' in session:
if request.method == 'GET':
auto = nfs.get_automation_list(session['appkey'])
return render_template('old/public/automation.html', auto_list=auto[1])
elif request.method == 'POST':
# new automation
nid = misc.rand_str(app.config['NID_LENGTH']).decode('utf-8')
dev = dd.get(session['appkey'], request.form['devid'])
adev = dd.get(session['appkey'], request.form['adevid'])
try:
desc = 'IF '+dev[1][0]+'.'+request.form['varname']+' '+request.form['operation']+' '+request.form['avalue']+' THEN '+adev[1][0]+'.confID_'+request.form['confid']+' = '+request.form['arg']
# action format: '<devid>#<confid>#<arg>'
action = request.form['adevid']+'#'+request.form['confid']+'#'+request.form['arg']
res = nfs.create(nid, session['appkey'], request.form['devid'], request.form['automationname'], desc, 'automation', action)
if res[0]:
# create new function and trigger
tr.create_function(session['appkey'], request.form['devid'], nid, [request.form['varname'],request.form['operation'],request.form['avalue']])
tr.create(session['appkey'], request.form['devid'], nid)
return redirect(url_for('automation'))
else:
flash('Error creating new alert: {}'.format(res[1]), 'danger')
return redirect(url_for('automation'))
return redirect(url_for('autmation'))
except Exception as e:
flash('Error creating new automation: {}. Make sure you have filled all form fields correctly.'.format(e), 'danger')
return redirect(url_for('automation'))
else:
return redirect(url_for('index'))
@app.route('/new-automation')
def new_automation():
if 'name' in session:
devs = dd.get_list(session['appkey'])
return render_template('old/public/new-automation.html', devs=devs[1])
else:
return redirect(url_for('index'))
@app.route('/automation-rm')
def automation_rm():
if 'name' in session:
nq.delete(session['appkey'], request.args.get('devid'), request.args.get('id'))
tr.delete(session['appkey'], request.args.get('devid'), request.args.get('id'))
tr.delete_function(session['appkey'], request.args.get('devid'), request.args.get('id'))
res = nfs.delete(session['appkey'], request.args.get('devid'), request.args.get('id'))
if res[0]:
flash('Automation removed', 'success')
return redirect(url_for('alerts'))
else:
flash('Automation cannot be removed : {}'.format(res[1]), 'danger')
return redirect(url_for('alerts'))
else:
return redirect(url_for('index'))
def pend_delete_all_ack(): def pend_delete_all_ack():
pend.delete_all_ack() pend.delete_all_ack()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment