Skip to content

Commit cb1489e

Browse files
committed
added all ressources locally
1 parent 30a01be commit cb1489e

14 files changed

+9783
-16
lines changed

Diff for: sysdweb/server.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
import os
1616

1717
# Search for template path
18-
template_paths = [ os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates'),
19-
'/usr/share/sysdweb/templates']
18+
template_paths = [os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates'),
19+
'/usr/share/sysdweb/templates']
2020
template_path = [path for path in template_paths if os.access(path, os.R_OK)]
2121
if template_path == []:
2222
raise SystemExit('Templates are missing.')
2323
TEMPLATE_PATH.insert(0, os.path.join(template_path[0], 'views'))
2424
static_path = os.path.join(template_path[0], 'static')
2525

2626
# Define auth function
27+
28+
2729
def login(user, password):
2830
users = config.get('DEFAULT', 'users', fallback=None)
2931
if users and not user in users.split(','):
@@ -32,11 +34,13 @@ def login(user, password):
3234
# Validate user with password
3335
return pam().authenticate(user, password)
3436

37+
3538
@route('/api/v1/<service>/<action>')
3639
@auth_basic(login)
3740
def get_service_action(service, action):
3841
if service in config.sections():
39-
sdbus = systemdBus(True) if config.get('DEFAULT', 'scope', fallback='system') == 'user' else systemdBus()
42+
sdbus = systemdBus(True) if config.get(
43+
'DEFAULT', 'scope', fallback='system') == 'user' else systemdBus()
4044
unit = config.get(service, 'unit')
4145
if action == 'start':
4246
return {action: 'OK'} if sdbus.start_unit(unit) else {action: 'Fail'}
@@ -62,6 +66,7 @@ def get_service_action(service, action):
6266
response.status = 400
6367
return {'msg': 'Sorry, but \'{}\' is not defined in config.'.format(service)}
6468

69+
6570
@route('/api/v1/<service>/journal/<lines>')
6671
@auth_basic(login)
6772
def get_service_journal(service, lines):
@@ -80,6 +85,7 @@ def get_service_journal(service, lines):
8085
response.status = 400
8186
return {'msg': 'Sorry, but \'{}\' is not defined in config.'.format(service)}
8287

88+
8389
@route('/')
8490
@auth_basic(login)
8591
def get_main():
@@ -98,19 +104,21 @@ def get_main():
98104
disabled_stop = True if cls == 'active' or cls == 'danger' else False
99105
disabled_restart = True if cls == 'active' or cls == 'danger' else False
100106
services.append({'class': cls,
101-
'disabled_start': disabled_start,
102-
'disabled_stop': disabled_stop,
103-
'disabled_restart': disabled_restart,
104-
'title': config.get(service, 'title'),
105-
'service': service})
107+
'disabled_start': disabled_start,
108+
'disabled_stop': disabled_stop,
109+
'disabled_restart': disabled_restart,
110+
'title': config.get(service, 'title'),
111+
'service': service})
106112
return template('index', hostname=gethostname(), services=services)
107113

114+
108115
@route('/journal/<service>')
109116
@auth_basic(login)
110117
def get_service_journal_page(service):
111118
if service in config.sections():
112119
if get_service_action(service, 'status')['status'] == 'not-found':
113-
abort(400,'Sorry, but service \'{}\' unit not found in system.'.format(config.get(service, 'title')))
120+
abort(400, 'Sorry, but service \'{}\' unit not found in system.'.format(
121+
config.get(service, 'title')))
114122
journal_lines = get_service_journal(service, 100)
115123
return template('journal', hostname=gethostname(), service=config.get(service, 'title'), journal=journal_lines['journal'])
116124
else:
@@ -122,33 +130,40 @@ def get_service_journal_page(service):
122130
def get_favicon():
123131
return static_file('favicon.ico', root=os.path.join(static_path, 'img'))
124132

133+
125134
@route('/css/<file>')
126135
@auth_basic(login)
127136
def get_css(file):
128137
return static_file(file, root=os.path.join(static_path, 'css'))
129138

139+
130140
@route('/fonts/<file>')
131141
@auth_basic(login)
132142
def get_fonts(file):
133143
return static_file(file, root=os.path.join(static_path, 'fonts'))
134144

145+
135146
@route('/img/<file>')
136147
@auth_basic(login)
137148
def get_img(file):
138149
return static_file(file, root=os.path.join(static_path, 'img'))
139150

151+
140152
@route('/js/<file>')
141153
@auth_basic(login)
142154
def get_js(file):
143155
return static_file(file, root=os.path.join(static_path, 'js'))
144156

157+
145158
def start(config_file, host, port):
146159
# Check config
147160
global config
148161
config = checkConfig(config_file)
149162

150-
if host == None: host = config.get('DEFAULT', 'host', fallback='127.0.0.1')
151-
if port == None: port = config.get('DEFAULT', 'port', fallback='10080')
163+
if host == None:
164+
host = config.get('DEFAULT', 'host', fallback='127.0.0.1')
165+
if port == None:
166+
port = config.get('DEFAULT', 'port', fallback='10080')
152167

153168
# Run webserver
154169
run(host=host, port=port)

0 commit comments

Comments
 (0)