Compare commits
No commits in common. "af75b864df450cd949215f3a042f8e4889e05698" and "06c4d75f277217b6026d49ce8da180954ecefd8d" have entirely different histories.
af75b864df
...
06c4d75f27
1 changed files with 19 additions and 68 deletions
|
@ -19,7 +19,7 @@ try:
|
|||
import threading
|
||||
from time import time, localtime, strftime, sleep
|
||||
import configparser
|
||||
except Exception as e:
|
||||
except ImportException as e:
|
||||
print('Import error: {}'.format(e))
|
||||
|
||||
|
||||
|
@ -117,28 +117,14 @@ def display_peercert(cert):
|
|||
elif len(cert) == 0:
|
||||
logging.debug('Peer certificate was not valid')
|
||||
else:
|
||||
logging.debug('--- Peer cert ---')
|
||||
for key in cert.keys():
|
||||
if key in ('subject', 'serialNumber', 'notBefore', 'notAfter'):
|
||||
if key == 'subject':
|
||||
logging.debug(f'Subject: {cert[key]}')
|
||||
for i in cert[key]:
|
||||
logging.debug(f'{i[0][0]}: {i[0][1]}')
|
||||
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)
|
||||
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']))
|
||||
|
||||
def receive_buffer_is_valid(raw_data):
|
||||
'''
|
||||
|
@ -186,7 +172,7 @@ def read_api(api):
|
|||
return False
|
||||
return api_json_data
|
||||
|
||||
def change_status(status, timestamp, api_template, filename):
|
||||
def change_status(status, timestamp, filename):
|
||||
'''
|
||||
Write the new status together with a timestamp into the Space API JSON.
|
||||
param 1: byte object
|
||||
|
@ -194,15 +180,19 @@ def change_status(status, timestamp, api_template, filename):
|
|||
return: boolean
|
||||
'''
|
||||
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):
|
||||
logging.debug('API file is writable')
|
||||
with open(filename, 'w') as api_file:
|
||||
logging.debug('API file successfull writable opened')
|
||||
api_template["state"]["open"] = status
|
||||
api_template["state"]["lastchange"] = timestamp
|
||||
data["state"]["open"] = status
|
||||
data["state"]["lastchange"] = timestamp
|
||||
try:
|
||||
# json.dump(data, api_file, indent=4)
|
||||
json.dump(api_template, api_file, indent=4)
|
||||
json.dump(data, api_file, indent=4)
|
||||
except Exception as e:
|
||||
logging.error('Failed to change API file')
|
||||
logging.error('{}'.format(e))
|
||||
|
@ -345,45 +335,6 @@ def main():
|
|||
'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')
|
||||
configfile = './apistatusd.conf'
|
||||
config = configparser.ConfigParser()
|
||||
|
@ -451,7 +402,7 @@ def main():
|
|||
raw_data = Connection.recv(1)
|
||||
if receive_buffer_is_valid(raw_data) is True:
|
||||
status, timestamp = get_status_and_time(raw_data)
|
||||
if change_status(status, timestamp, api_template, config['api']['api']) is True:
|
||||
if change_status(status, timestamp, config['api']['api']) is True:
|
||||
answer = raw_data
|
||||
if config['mastodon']['send'].lower() == 'true':
|
||||
logging.debug('Toot is set to true')
|
||||
|
|
Loading…
Reference in a new issue