working on it

api
Simon 2 years ago
parent 448c853760
commit 4ca991f98b

@ -0,0 +1,62 @@
from xmlrpc.client import Fault
from twisted.web import xmlrpc
from hashlib import blake2b
class FD_API_HELPERS():
def __init__(self,CONFIG,APIQUEUE):
self._CONFIG = CONFIG
self._APIQUEUE = APIQUEUE
def connected(self,_id):
for system in self._CONFIG['SYSTEMS']:
for peerid in self._CONFIG['SYSTEMS'][self._system]['PEERS']:
if peerid == _id:
return(system)
return(False)
def validateHMAC(_hmac,_system):
self._config = self._CONFIG['SYSTEMS'][_system]
_h = blake2b(key=self._config['_opt_key'], digest_size=16)
_h.update('validate')
_hash = _h.digest()
if _hash == _hmac:
return(True)
else:
return(False)
class FD_API(xmlrpc.XMLRPC(allow_none=True)):
def __init__(self,CONFIG,APIQUEUE):
self._CONFIG = CONFIG
self._APIQUEUE = APIQUEUE
self.helpers = FD_API_HELPERS(self._CONFIG,self._APIQUEUE)
def reset(self,_id,_hmac):
return('<xml></xml>')
system = self.helpers.connected(_id)
if result:
if self.helpers.validateHMAC(_hmac,_system):
self._CONFIG['SYSTEMS'][system]['_reset'] = True
else:
return Fault(2, "Authentication failed")
else:
return Fault(1, "ID not connected to this server")
return('Z')
def main():
from twisted.internet import reactor
from twisted.web import server
r = FD_API({},{})
reactor.listenTCP(7080, server.Site(r))
reactor.run()
if __name__ == "__main__":
main()

@ -0,0 +1,23 @@
from twisted.internet import reactor
from twisted.web.xmlrpc import Proxy
def printValue(value):
print(repr(value))
reactor.stop()
def printError(error):
print("error", error)
reactor.stop()
def capitalize(value):
print(value)
proxy = Proxy(b"http://localhost:7080/xmlrpc")
# The callRemote method accepts a method name and an argument list.
proxy.callRemote("FD_API.reset", '2', '55555').addCallbacks(capitalize, printError)
reactor.run()

@ -50,6 +50,7 @@ from hashlib import blake2b
from twisted.internet.protocol import Factory, Protocol from twisted.internet.protocol import Factory, Protocol
from twisted.protocols.basic import NetstringReceiver from twisted.protocols.basic import NetstringReceiver
from twisted.internet import reactor, task from twisted.internet import reactor, task
from twisted.web import server
# Things we import from the main hblink module # Things we import from the main hblink module
from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, mk_aliases, acl_check from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, mk_aliases, acl_check
@ -80,6 +81,7 @@ import re
from binascii import b2a_hex as ahex from binascii import b2a_hex as ahex
from AMI import AMI from AMI import AMI
from API import FD_API
# Does anybody read this stuff? There's a PEP somewhere that says I should do this. # Does anybody read this stuff? There's a PEP somewhere that says I should do this.
@ -134,6 +136,14 @@ def config_reports(_config, _factory):
return report_server return report_server
# Start API server
def config_API(_config, _apiqueue):
r = FD_API(_config,_apiqueue)
reactor.listenTCP(7080, server.Site(r))
return r
# Import Bridging rules # Import Bridging rules
# Note: A stanza *must* exist for any MASTER or CLIENT configured in the main # Note: A stanza *must* exist for any MASTER or CLIENT configured in the main
@ -844,9 +854,6 @@ def options_config():
else: else:
logger.debug('(OPTIONS) %s, _opt_key not set and no key sent. Generate random key',_system) logger.debug('(OPTIONS) %s, _opt_key not set and no key sent. Generate random key',_system)
CONFIG['SYSTEMS'][_system]['_opt_key'] = randint(0,65535) CONFIG['SYSTEMS'][_system]['_opt_key'] = randint(0,65535)
if 'DIAL' in _options: if 'DIAL' in _options:
_options['DEFAULT_REFLECTOR'] = _options.pop('DIAL') _options['DEFAULT_REFLECTOR'] = _options.pop('DIAL')
@ -2611,6 +2618,7 @@ if __name__ == '__main__':
ID_MAX = 16776415 ID_MAX = 16776415
#Set process title early #Set process title early
setproctitle(__file__) setproctitle(__file__)
@ -2845,6 +2853,15 @@ if __name__ == '__main__':
logger.error('(GLOBAL) STOPPING REACTOR TO AVOID MEMORY LEAK: Unhandled error in timed loop.\n %s', failure) logger.error('(GLOBAL) STOPPING REACTOR TO AVOID MEMORY LEAK: Unhandled error in timed loop.\n %s', failure)
reactor.stop() reactor.stop()
#Initialize API
APIQUEUE = {}
api = config_API(CONFIG,APIQUEUE)
if api:
logger.info('(API) API running')
else:
logger.info('(API) API not started')
# Initialize the rule timer -- this if for user activated stuff # Initialize the rule timer -- this if for user activated stuff
rule_timer_task = task.LoopingCall(rule_timer_loop) rule_timer_task = task.LoopingCall(rule_timer_loop)
rule_timer = rule_timer_task.start(52) rule_timer = rule_timer_task.start(52)

@ -76,7 +76,7 @@ logging.trace = partial(logging.log, logging.TRACE)
# Does anybody read this stuff? There's a PEP somewhere that says I should do this. # Does anybody read this stuff? There's a PEP somewhere that says I should do this.
__author__ = 'Cortney T. Buffington, N0MJS, Forked by Simon Adlem - G7RZU' __author__ = 'Cortney T. Buffington, N0MJS, Forked by Simon Adlem - G7RZU'
__copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group, Simon Adlem, G7RZU 2020,2021,2022' __copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group, Simon Adlem, G7RZU 2020,2021,2022,2023'
__credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT; Jon Lee, G4TSN; Norman Williams, M6NBP' __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT; Jon Lee, G4TSN; Norman Williams, M6NBP'
__license__ = 'GNU GPLv3' __license__ = 'GNU GPLv3'
__maintainer__ = 'Simon Adlem G7RZU' __maintainer__ = 'Simon Adlem G7RZU'

Loading…
Cancel
Save

Powered by TurnKey Linux.