Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
70503a0f
Commit
70503a0f
authored
Oct 28, 2020
by
Vladislav Rykov
Browse files
gateway settings view added and tested
parent
11add1d1
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/app.log
View file @
70503a0f
...
@@ -13,3 +13,7 @@
...
@@ -13,3 +13,7 @@
[2020-10-07 22:22:21,007] INFO in views: Logged in superuser admin
[2020-10-07 22:22:21,007] INFO in views: Logged in superuser admin
[2020-10-27 11:05:02,900] INFO in views: Logged in superuser admin
[2020-10-27 11:05:02,900] INFO in views: Logged in superuser admin
[2020-10-27 11:05:37,214] INFO in views: Logged in superuser admin
[2020-10-27 11:05:37,214] INFO in views: Logged in superuser admin
[2020-10-28 17:55:40,659] ERROR in views_admin: Administrator admin failed to create new gateway - syntax error at or near "desc"
LINE 7: desc = 'sdasfasdf',
^
app/app/__pycache__/views_admin.cpython-37.pyc
View file @
70503a0f
No preview for this file type
app/app/dao/gateway/gateway.py
View file @
70503a0f
...
@@ -43,7 +43,7 @@ def update(cur, name, gwid, protocol, desc, telemetry_send_freq):
...
@@ -43,7 +43,7 @@ def update(cur, name, gwid, protocol, desc, telemetry_send_freq):
SET
SET
name = %s,
name = %s,
protocol = %s,
protocol = %s,
desc = %s,
desc
ription
= %s,
telemetry_send_freq = %s
telemetry_send_freq = %s
WHERE
WHERE
id = %s
id = %s
...
...
app/app/helpers/gateway_management.py
0 → 100644
View file @
70503a0f
PROTOCOLS
=
{
"liteiot"
:
"LiteIoT"
,
"mqtt"
:
"MQTT"
,
"httprest"
:
"HTTP REST"
}
app/app/helpers/maintainer.py
deleted
100644 → 0
View file @
11add1d1
from
apscheduler.schedulers.background
import
BackgroundScheduler
from
app
import
app
,
views
import
os
def
clean_data_folder
():
try
:
filelist
=
[
f
for
f
in
os
.
listdir
(
app
.
config
[
'DATA_DOWNLOAD_DIR_OS'
])]
for
f
in
filelist
:
os
.
remove
(
app
.
config
[
'DATA_DOWNLOAD_DIR_OS'
]
+
'/'
+
f
)
except
OSError
:
pass
def
maintainer
():
views
.
pend_delete_all_ack
()
clean_data_folder
()
def
fire_notifications
():
views
.
fire_notifications
(
app
)
scheduler
=
BackgroundScheduler
()
scheduler
.
add_job
(
maintainer
,
'interval'
,
minutes
=
app
.
config
[
'MAINTAINER_INTERVAL'
])
scheduler
.
add_job
(
fire_notifications
,
'interval'
,
minutes
=
app
.
config
[
'FIRE_NOTIFICATIONS_INTERVAL'
])
scheduler
.
start
()
app/app/helpers/maintainer.pyc
deleted
100644 → 0
View file @
11add1d1
File deleted
app/app/templates/views/admin/gateway-settings.html
0 → 100644
View file @
70503a0f
{% extends 'logged_layout.html' %}
{% block title %} Administration - Gateway - {{ gw['id'] }} - Settings - HPC
&
A IoT {% endblock %}
{% block location %}
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/administration"
>
Administration
</a>
<p
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
>
-
</p>
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/administration/gateway/{{ gw['id'] }}"
>
{{ gw['name'] }}
</a>
<p
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
>
-
</p>
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/administration/gateway/{{ gw['id'] }}/settings"
>
Settings
</a>
{% endblock %}
{% block body %}
<!-- Page content -->
<div
class=
"container-fluid mt--7"
>
<!-- Table -->
<div
class=
"row"
>
<div
class=
"col"
>
<div
class=
"card shadow"
>
<div
class=
"card-header bg-transparent"
>
<h3
class=
"mb-0"
>
Gateway Settings
</h3>
</div>
<div
class=
"card-body"
>
<form
action=
"/administration/gateway/{{ gw['id'] }}/settings"
method=
"post"
id=
"gwsettings"
>
<div
class=
"form-group"
>
<label>
Name:
</label><br>
<input
type=
"text"
maxlength=
"30"
class=
"form-control"
id=
"gwname"
name=
"gwname"
value=
"{{ gw['name'] }}"
required
><br>
</div>
<div
class=
"form-group"
>
<label>
ID:
</label><br>
<input
type=
"text"
maxlength=
"30"
class=
"form-control"
id=
"gwid"
name=
"gwid"
value=
"{{ gw['id'] }}"
required
><br>
</div>
<div
class=
"form-group"
>
<label>
Protocol:
</label><br>
<select
class=
"form-control"
id=
"gwprotocol"
name=
"gwprotocol"
>
{% for k,v in protocols.items() %}
<option
value=
"{{ k }}"
{%
if
k =
=
gw
['
protocol
']
%}
selected
{%
endif
%}
>
{{ v }}
</option>
{% endfor %}
</select>
</div>
<div
class=
"form-group"
>
<label>
Description:
</label><br>
<textarea
id=
"gwdesc"
maxlength=
"200"
class=
"form-control"
name=
"gwdesc"
rows=
"5"
></textarea>
</div>
<div
class=
"form-group"
>
<label>
Telemetry Send Frequency (seconds):
</label><br>
<input
type=
"number"
min=
"1"
class=
"form-control"
id=
"gwtelemetry"
name=
"gwtelemetry"
value=
"{{ gw['telemetry_send_freq'] }}"
required
><br>
</div>
<br>
<br>
</form>
<div
class=
"row"
style=
"margin-top: 30px;"
>
<div
class=
"col-lg-3"
>
<button
type=
"submit"
form=
"gwsettings"
class=
"btn btn-primary btn-block"
>
Save
</button>
</div>
<div
class=
"col-lg-3"
>
</div>
<div
class=
"col-lg-3"
>
</div>
<div
class=
"col-lg-3"
>
<button
type=
"button"
class=
"btn btn-danger btn-block"
data-toggle=
"modal"
data-target=
"#exampleModal"
>
Delete
</button>
<div
class=
"modal fade"
id=
"exampleModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"exampleModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<h5
class=
"modal-title"
id=
"exampleModalLabel"
>
Are you sure?
</h5>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
</div>
<div
class=
"modal-body"
>
This action will remove permanently the gateway.
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-dismiss=
"modal"
>
Close
</button>
<a
href=
"/administration/gateway/{{ gw['id'] }}/delete"
><button
type=
"button"
class=
"btn btn-danger"
>
Delete Gateway
</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script
type=
"text/javascript"
>
document
.
getElementById
(
"
gwdesc
"
).
value
=
"
{{ gw['description'] }}
"
;
</script>
{% endblock %}
app/app/templates/views/admin/gateway.html
View file @
70503a0f
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
<div
class=
"card"
style=
"margin-bottom : 15px;"
>
<div
class=
"card"
style=
"margin-bottom : 15px;"
>
<div
class=
"card-body"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
Protocol
</h5>
<h5
class=
"card-title"
>
Protocol
</h5>
<p
class=
"card-text"
>
{{ gw['protocol'] }}
</p>
<p
class=
"card-text"
>
{{
protocols[
gw['protocol']
]
}}
</p>
</div>
</div>
</div>
</div>
<div
class=
"card"
style=
"margin-bottom : 15px;"
>
<div
class=
"card"
style=
"margin-bottom : 15px;"
>
...
@@ -98,7 +98,7 @@
...
@@ -98,7 +98,7 @@
var
skey
=
document
.
getElementById
(
"
secure_key
"
).
innerHTML
;
var
skey
=
document
.
getElementById
(
"
secure_key
"
).
innerHTML
;
var
fskey
=
"
{
"
;
var
fskey
=
"
{
"
;
for
(
var
i
=
2
;
i
<
skey
.
length
-
2
;
i
+=
2
)
{
for
(
var
i
=
0
;
i
<
skey
.
length
-
2
;
i
+=
2
)
{
fskey
+=
"
0x
"
+
(
skey
[
i
]
+
skey
[
i
+
1
])
+
"
,
"
;
fskey
+=
"
0x
"
+
(
skey
[
i
]
+
skey
[
i
+
1
])
+
"
,
"
;
}
}
fskey
+=
"
0x
"
+
skey
[
skey
.
length
-
2
]
+
skey
[
skey
.
length
-
1
]
+
"
}
"
;
fskey
+=
"
0x
"
+
skey
[
skey
.
length
-
2
]
+
skey
[
skey
.
length
-
1
]
+
"
}
"
;
...
...
app/app/templates/views/admin/new-gateway.html
View file @
70503a0f
...
@@ -31,9 +31,9 @@
...
@@ -31,9 +31,9 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label>
Protocol:
</label><br>
<label>
Protocol:
</label><br>
<select
class=
"form-control"
id=
"gwprotocol"
name=
"gwprotocol"
>
<select
class=
"form-control"
id=
"gwprotocol"
name=
"gwprotocol"
>
<option
value=
"liteiot"
>
LightIoT
</option>
{% for k,v in protocols.items() %}
<option
value=
"
mqtt"
>
MQTT
</option>
<option
value=
"
{{ k }}"
>
{{ v }}
</option>
<option
value=
"rest"
>
HTTP REST
</option>
{% endfor %}
</select>
</select>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
...
...
app/app/views_admin.py
View file @
70503a0f
...
@@ -16,6 +16,7 @@ import app.dao.misc.misc as md
...
@@ -16,6 +16,7 @@ import app.dao.misc.misc as md
from
app.helpers.decorators
import
restricted
from
app.helpers.decorators
import
restricted
import
app.helpers.device_data_model
as
ddm
import
app.helpers.device_data_model
as
ddm
import
app.helpers.misc
as
misc
import
app.helpers.misc
as
misc
import
app.helpers.gateway_management
as
gwm
import
binascii
import
binascii
import
os
import
os
...
@@ -671,15 +672,16 @@ def administration_gateway(gwid):
...
@@ -671,15 +672,16 @@ def administration_gateway(gwid):
info
=
[
user_cnt
,
apps_cnt
,
devs_cnt
]
info
=
[
user_cnt
,
apps_cnt
,
devs_cnt
]
gw
=
gd
.
get
(
gwid
)[
1
]
gw
=
gd
.
get
(
gwid
)[
1
]
gw
[
'secure_key'
]
=
misc
.
skey_b64_to_hex
(
gw
[
'secure_key'
]).
decode
(
'UTF-8'
)
return
render_template
(
'views/admin/gateway.html'
,
utcnow
=
misc
.
get_utc
(),
info
=
info
,
gw
=
gw
)
return
render_template
(
'views/admin/gateway.html'
,
utcnow
=
misc
.
get_utc
(),
info
=
info
,
gw
=
gw
,
protocols
=
gwm
.
PROTOCOLS
)
@
app
.
route
(
'/administration/new-gateway'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/administration/new-gateway'
,
methods
=
[
'GET'
,
'POST'
])
@
restricted
(
'admin'
)
@
restricted
(
'admin'
)
def
administration_new_gateway
():
def
administration_new_gateway
():
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
return
render_template
(
'views/admin/new-gateway.html'
,
administration
=
"active"
)
return
render_template
(
'views/admin/new-gateway.html'
,
administration
=
"active"
,
protocols
=
gwm
.
PROTOCOLS
)
elif
request
.
method
==
'POST'
:
elif
request
.
method
==
'POST'
:
secure_key
=
misc
.
gen_skey_b64
(
16
)
secure_key
=
misc
.
gen_skey_b64
(
16
)
...
@@ -690,3 +692,21 @@ def administration_new_gateway():
...
@@ -690,3 +692,21 @@ def administration_new_gateway():
return
redirect
(
request
.
url
)
return
redirect
(
request
.
url
)
return
redirect
(
url_for
(
'administration_gateways'
))
return
redirect
(
url_for
(
'administration_gateways'
))
@
app
.
route
(
'/administration/gateway/<gwid>/settings'
,
methods
=
[
"GET"
,
"POST"
])
@
restricted
(
'admin'
)
def
administration_gateway_settings
(
gwid
):
if
request
.
method
==
"GET"
:
gw
=
gd
.
get
(
gwid
)[
1
]
gw
[
'secure_key'
]
=
misc
.
skey_b64_to_hex
(
gw
[
'secure_key'
]).
decode
(
'UTF-8'
)
return
render_template
(
'views/admin/gateway-settings.html'
,
utcnow
=
misc
.
get_utc
(),
gw
=
gw
,
protocols
=
gwm
.
PROTOCOLS
)
elif
request
.
method
==
"POST"
:
res
=
gd
.
update
(
request
.
form
[
'gwname'
],
request
.
form
[
'gwid'
],
request
.
form
[
'gwprotocol'
],
request
.
form
[
'gwdesc'
],
request
.
form
[
'gwtelemetry'
])
if
not
res
[
0
]:
app
.
logger
.
error
(
'Administrator %s failed to update new gateway - %s'
,
session
[
'name'
],
res
[
1
])
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
redirect
(
request
.
url
)
return
redirect
(
url_for
(
'administration_gateway'
,
gwid
=
gwid
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment