66#
77# Distributed under terms of the GNU GPLv3 license.
88
9- from bottle import abort , auth_basic , request , response , route , run , static_file , template , TEMPLATE_PATH , HTTPError
9+ import os
10+ from bottle import abort , request , response , route , run , static_file , template , TEMPLATE_PATH , HTTPError
1011from pam import pam
1112from socket import gethostname
13+ from datetime import datetime
1214from sysdweb .config import checkConfig
1315from sysdweb .systemd import systemdBus , Journal
14- from datetime import datetime
15-
16- import os
1716
1817# Search for template path
1918template_paths = [ os .path .join (os .path .abspath (os .path .dirname (__file__ )), 'templates' ),
@@ -30,10 +29,10 @@ def login(user, password):
3029 auth = config .get ('DEFAULT' , 'auth' , fallback = None )
3130
3231 if auth == 'basic' :
33- users = [tuple (user .strip ().split (':' )) for user in users .split (',' )]
34- return True if (user ,password ) in users else False
32+ userlist = [tuple (usr .strip ().split (':' )) for usr in users .split (',' )]
33+ return True if (user ,password ) in userlist else False
3534 elif auth == 'pam' :
36- if users and not user in users .split (',' ): return False
35+ if users and user not in users .split (',' ): return False
3736 return pam ().authenticate (user , password )
3837 elif auth == 'none' :
3938 return True
@@ -63,6 +62,11 @@ def wrapper(*a, **ka):
6362
6463 return decorator
6564
65+ @route ('/api/v1/services' )
66+ @if_auth (login )
67+ def get_service_list ():
68+ return {'services' : [service for service in config .sections () if service != 'DEFAULT' ]}
69+
6670@route ('/api/v1/<service>/<action>' )
6771@if_auth (login )
6872def get_service_action (service , action ):
0 commit comments