Compare commits
2 commits
06c4d75f27
...
af75b864df
Author | SHA1 | Date | |
---|---|---|---|
af75b864df | |||
4b19063b66 |
1 changed files with 68 additions and 19 deletions
|
@ -19,7 +19,7 @@ try:
|
||||||
import threading
|
import threading
|
||||||
from time import time, localtime, strftime, sleep
|
from time import time, localtime, strftime, sleep
|
||||||
import configparser
|
import configparser
|
||||||
except ImportException as e:
|
except Exception as e:
|
||||||
print('Import error: {}'.format(e))
|
print('Import error: {}'.format(e))
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,14 +117,28 @@ def display_peercert(cert):
|
||||||
elif len(cert) == 0:
|
elif len(cert) == 0:
|
||||||
logging.debug('Peer certificate was not valid')
|
logging.debug('Peer certificate was not valid')
|
||||||
else:
|
else:
|
||||||
logging.debug('Peer certificate commonName: {}'.format(
|
logging.debug('--- Peer cert ---')
|
||||||
cert['subject'][5][0][1]))
|
for key in cert.keys():
|
||||||
logging.debug('Peer certificate serialNumber: {}'.format(
|
if key in ('subject', 'serialNumber', 'notBefore', 'notAfter'):
|
||||||
cert['serialNumber']))
|
if key == 'subject':
|
||||||
logging.debug('Peer certificate notBefore: {}'.format(
|
logging.debug(f'Subject: {cert[key]}')
|
||||||
cert['notBefore']))
|
for i in cert[key]:
|
||||||
logging.debug('Peer certificate notAfter: {}'.format(
|
logging.debug(f'{i[0][0]}: {i[0][1]}')
|
||||||
cert['notAfter']))
|
else:
|
||||||
|
logging.debug(f'{key}: {cert[key]}')
|
||||||
|
logging.debug('-----------------')
|
||||||
|
try:
|
||||||
|
logging.debug('Peer certificate commonName: {}'.format(
|
||||||
|
cert['subject'][5][0][1]))
|
||||||
|
logging.debug('Peer certificate serialNumber: {}'.format(
|
||||||
|
cert['serialNumber']))
|
||||||
|
logging.debug('Peer certificate notBefore: {}'.format(
|
||||||
|
cert['notBefore']))
|
||||||
|
logging.debug('Peer certificate notAfter: {}'.format(
|
||||||
|
cert['notAfter']))
|
||||||
|
except Exception as error:
|
||||||
|
logging.debug('Cert display failed')
|
||||||
|
logging.debug(error)
|
||||||
|
|
||||||
def receive_buffer_is_valid(raw_data):
|
def receive_buffer_is_valid(raw_data):
|
||||||
'''
|
'''
|
||||||
|
@ -172,7 +186,7 @@ def read_api(api):
|
||||||
return False
|
return False
|
||||||
return api_json_data
|
return api_json_data
|
||||||
|
|
||||||
def change_status(status, timestamp, filename):
|
def change_status(status, timestamp, api_template, filename):
|
||||||
'''
|
'''
|
||||||
Write the new status together with a timestamp into the Space API JSON.
|
Write the new status together with a timestamp into the Space API JSON.
|
||||||
param 1: byte object
|
param 1: byte object
|
||||||
|
@ -180,19 +194,15 @@ def change_status(status, timestamp, filename):
|
||||||
return: boolean
|
return: boolean
|
||||||
'''
|
'''
|
||||||
logging.debug('Change status API')
|
logging.debug('Change status API')
|
||||||
# todo: use walrus operator := when migrating to python >= 3.8
|
|
||||||
data = read_api(filename)
|
|
||||||
if data is False:
|
|
||||||
return False
|
|
||||||
|
|
||||||
if os.access(filename, os.W_OK):
|
if os.access(filename, os.W_OK):
|
||||||
logging.debug('API file is writable')
|
logging.debug('API file is writable')
|
||||||
with open(filename, 'w') as api_file:
|
with open(filename, 'w') as api_file:
|
||||||
logging.debug('API file successfull writable opened')
|
logging.debug('API file successfull writable opened')
|
||||||
data["state"]["open"] = status
|
api_template["state"]["open"] = status
|
||||||
data["state"]["lastchange"] = timestamp
|
api_template["state"]["lastchange"] = timestamp
|
||||||
try:
|
try:
|
||||||
json.dump(data, api_file, indent=4)
|
# json.dump(data, api_file, indent=4)
|
||||||
|
json.dump(api_template, api_file, indent=4)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error('Failed to change API file')
|
logging.error('Failed to change API file')
|
||||||
logging.error('{}'.format(e))
|
logging.error('{}'.format(e))
|
||||||
|
@ -335,6 +345,45 @@ def main():
|
||||||
'token': 'aaaaa-bbbbb-ccccc-ddddd-eeeee'
|
'token': 'aaaaa-bbbbb-ccccc-ddddd-eeeee'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api_template = {
|
||||||
|
"api": "0.13",
|
||||||
|
"space": "Krautspace",
|
||||||
|
"url": "https://kraut.space",
|
||||||
|
"logo": "https://status.krautspace.de/images/krautspace_pixelbanner.png",
|
||||||
|
"location": {
|
||||||
|
"address": "Hackspace Jena e. V., Krautgasse 26, 07743 Jena, Germany",
|
||||||
|
"lat": 50.9292,
|
||||||
|
"lon": 11.5826
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"open": False,
|
||||||
|
"lastchange": 1563499131,
|
||||||
|
"icon": {
|
||||||
|
"open":"https://status.krautspace.de/images/status-open.png",
|
||||||
|
"closed":"https://status.krautspace.de/images/status-closed.png"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"feeds": {
|
||||||
|
"calendar": {
|
||||||
|
"type": "ical",
|
||||||
|
"url": "https://cloud.kraut.space/remote.php/dav/public-calendars/2EkPGt3PF6WwYsA3?export"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"contact": {
|
||||||
|
"mastodon": "@krautspace@chaos.social",
|
||||||
|
"matrix": "#krautchan:matrix.kraut.space",
|
||||||
|
"email": "office@krautspace.de"
|
||||||
|
},
|
||||||
|
"issue_report_channels": [
|
||||||
|
"matrix",
|
||||||
|
"email"
|
||||||
|
],
|
||||||
|
"projects": [
|
||||||
|
"https://git.kraut.space/Krautspace"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
logging.info('Try to read config file')
|
logging.info('Try to read config file')
|
||||||
configfile = './apistatusd.conf'
|
configfile = './apistatusd.conf'
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -402,7 +451,7 @@ def main():
|
||||||
raw_data = Connection.recv(1)
|
raw_data = Connection.recv(1)
|
||||||
if receive_buffer_is_valid(raw_data) is True:
|
if receive_buffer_is_valid(raw_data) is True:
|
||||||
status, timestamp = get_status_and_time(raw_data)
|
status, timestamp = get_status_and_time(raw_data)
|
||||||
if change_status(status, timestamp, config['api']['api']) is True:
|
if change_status(status, timestamp, api_template, config['api']['api']) is True:
|
||||||
answer = raw_data
|
answer = raw_data
|
||||||
if config['mastodon']['send'].lower() == 'true':
|
if config['mastodon']['send'].lower() == 'true':
|
||||||
logging.debug('Toot is set to true')
|
logging.debug('Toot is set to true')
|
||||||
|
|
Loading…
Reference in a new issue