def webapp_login(): global caller # logging in if request.method == 'POST': host_param = request.form['host'] try: if not Caller.check_up(host_param): return render_template("login.html", msg='host is down', host=host_param) private_key_df = request.form['private_key'] private_key_df_derived = Parser.derive(private_key_df) public_key_df = gen_public_key(private_key_df_derived) caller = Caller(host_param, public_key_df) return redirect(url_for('webapp.webapp_main', path='', dirname='')) except TypeError as te: return render_template("login.html", msg=str(te), host=host_param) elif request.method == 'GET': if caller is not None: if caller.get_session().status_code == 200: return redirect(url_for('webapp.webapp_main', path='', dirname='')) return render_template("login.html")
def __init__(self, usr='******', pwd='123456a@', host='localhost', port=5672, vhost='vh1'): self.vhost = vhost creds = pika.PlainCredentials(username=usr, password=pwd) params = pika.ConnectionParameters(host=host, port=port, virtual_host=vhost, credentials=creds) self.is_waiting = False self.c = Caller() try: self.conn = pika.BlockingConnection(parameters=params) self.ch = self.conn.channel() except pika.exceptions.ProbableAccessDeniedError: logging.info("[AppServer] Connection error. Check configuration.") return None except: return None # declare a queue to reply res = self.ch.queue_declare(exclusive=True, queue='reply') self.reply_queue = res.method.queue # get the queue name self.ch.basic_consume(queue=self.reply_queue, consumer_callback=self.on_feedback, no_ack=True) logging.info("[AppServer] Done init ...")
def call(namespace): caller = Caller(verbose=True) phone = namespace.phone if namespace.phone is not None else 9023618802 trunk = namespace.trunk if namespace.trunk is not None else '2' phone2 = namespace.phone2 if namespace.phone2 is not None else None trunk = decipher(trunk) if not trunk: print('указан несуществующий транк - ошибка') return muid = str(uuid.uuid4()) with TeleDB() as db: db << 'INSERT INTO `tele_material` (`intphone`, `region_id`, `extra`, `start_dial`,`trunk_dial`) \ VALUES (%s,33,2,NOW(),%s)' < (int(phone), muid) db << 'SELECT last_insert_id() as id' ids = [db.one()['id']] if phone2: db << 'INSERT INTO `tele_material` (`intphone`, `region_id`, `extra`, `start_dial`,`trunk_dial`) \ VALUES (%s,33,2,NOW(),%s)' < (int(phone2), muid) db << 'SELECT last_insert_id() as id' ids.append(db.one()['id']) #import pdb; pdb.set_trace() if not caller.produce(db, trunk, ids): db << 'UPDATE `tele_material` SET `trunk_dial`=NULL,`start_dial`=NULL WHERE `id` = %s' < muid
def pm(debug, host): """Connect to password manager""" logger = Logger(debug) logger.debug('debug mode on') caller = None p_key_derived = None try: if not Caller.check_up(host): logger.error('error creating session: host down') else: logger.debug('host up') key, p_key_derived = Input.get_public_key() logger.debug('creating a new session...') caller = Caller(host, key) logger.info(f'session created') except ConnectionError as ce: logger.error(f'error creating session: connection error - {str(ce)}') except TypeError as te: logger.error(f'error creating session: wrong input - {str(te)}') if caller is not None: InteractiveInput(caller, logger, p_key_derived).cmdloop()
def __init__(self, usr='******', pwd='123456a@', host='localhost', port=5672, vhost='vh1'): logging.info("BEGIN INIT THE [AppServer] ----------------------------->") self.vhost = vhost creds = pika.PlainCredentials(username=usr, password=pwd) params = pika.ConnectionParameters(host=host, port=port, virtual_host=vhost, credentials=creds) # is in waiting state self.is_waiting = False # is initiate successfully self.is_init = False self.c = Caller() try: self.conn = pika.BlockingConnection(parameters=params) self.ch = self.conn.channel() except pika.exceptions.ProbableAccessDeniedError: logging.critical("[AppServer] Connection error. Check configuration.") return None except: return None # declare a queue to reply try: res = self.ch.queue_declare(exclusive=True, queue='reply') self.reply_queue = res.method.queue # get the queue name self.ch.basic_consume(queue=self.reply_queue, consumer_callback=self.on_feedback, no_ack=True) except pika.exceptions.ChannelClosed as e: logging.critical("[AppServer] The pika channel is closed. Error message: {0}".format(e)) return None except Exception as e: logging.critical("[AppServer] Unknown error while init app: {0}".format(e)) return None self.is_init = True logging.info("[AppServer] Done init ...")
def __init__(self, vhost_data): Greenlet.__init__(self) self.vhost_data = vhost_data self.app1 = AppServer(usr=self.vhost_data['user'], pwd=self.vhost_data['password'], host=self.vhost_data['host'], port=self.vhost_data['port'], vhost=self.vhost_data['name']) self.c = Caller()
def trunk(namespace): #import pdb; pdb.set_trace() trunk = decipher(namespace.trunk) if not trunk: print('указан несуществующий транк - ошибка') return with TeleDB() as db: router = MaterialRouter(db) feedstock = router.feedstock(trunk) if feedstock and namespace.verbose: print('Запас ' + str(len(feedstock))) caller = Caller(verbose=namespace.verbose) if not caller.produce(db, trunk, feedstock): db << 'UPDATE `tele_material` SET `trunk_dial`=NULL,`start_dial`=NULL WHERE `trunk_dial` = %s' < router.uid
def do_refresh(self, arg): """ Get a fresh new session from server """ key = Input.get_public_key() current_host = self.caller.host try: self.caller = Caller(current_host, key) self.logger.info('session refreshed') except ConnectionError as ce: self.logger.error( f'error creating session: connection error - {str(ce)}') except TypeError as te: self.logger.error( f'error creating session: wrong input - {str(te)}')
async def _init_caller(self): self.caller = Caller(settings.TWILIO_FROM_NUMBER, settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_KEY)
def setUp(self): self.c = Caller('from', 'sid', 'authkey')
sys.path.append("./src") from caller import Caller if __name__ == '__main__': PARSER = argparse.ArgumentParser(description='Options to access micro service') PARSER.add_argument('--service', dest='service', help='service to access') PARSER.add_argument('--job', dest='job', help='job to report') PARSER.add_argument('--status', dest='status', help='job status to report') args = PARSER.parse_args() APP = Caller(verbose=1, serverip="localhost", port="8080") APP.set_verbose(1) APP.set_ip(serverip="localhost") APP.set_port(port="8080") if "create" in args.service: ROUTE = "create/" + str(args.job) APP.call(route=ROUTE, verb="POST", data=None) elif "delete" in args.service: ROUTE = "delete/" + str(args.job) APP.call(route=ROUTE, verb="DELETE", data=None) elif "search" in args.service: ROUTE = "search/" + str(args.job) APP.call(route=ROUTE, verb="GET", data=None)
def start(self, seq): ## self.db = adbapi.ConnectionPool('MySQLdb', host='localhost', ## user='******', passwd='HerrMeister', ## db='actor') # listen on all devices for t in seq.trunks: for i in range(t.lines): c = Caller(seq, self, t.name) self.devices.append(c) c.send(c, 'LSTN %s %s' % (t.name, 'any')) self.a_hackcenter = A_Hackcenter() self.a_haecksen = A_Haecksen(seq) self.b_se = B_SE() self.b_nw = B_NW() self.b_ne = B_NE() self.b_sw = B_SW() self.b_lounge = B_Lounge(seq) self.b_saal2 = B_Saal2(seq) self.b_saal3 = B_Saal3(seq) self.c_se = C_SE() self.c_nw = C_NW() self.c_ne = C_NE() self.c_sw = C_SW() self.c_office = C_Office() self.c_saal1 = C_Saal1(seq) self.entry = self.b_se # Floor A connect(self.a_hackcenter, self.a_haecksen, Door(), 'south') # Floor B connect(self.b_se, self.b_sw, Door(), 'west') connect(self.b_se, self.b_ne, Door(), 'north') connect(self.b_sw, self.b_nw, Door(), 'north') connect(self.b_ne, self.b_nw, Door(), 'west') connect(self.b_se, self.b_lounge, Door(), 'northwest') connect(self.b_sw, self.b_lounge, Door(), 'northeast') connect(self.b_nw, self.b_lounge, Door(), 'southeast') connect(self.b_ne, self.b_lounge, Door(), 'southwest') connect(self.b_sw, self.b_saal3, Door(), 'west') connect(self.b_nw, self.b_saal2, Door(), 'west') # Floor C connect(self.c_se, self.c_sw, Door(), 'west') connect(self.c_se, self.c_ne, Door(), 'north') connect(self.c_sw, self.c_nw, Door(), 'north') connect(self.c_ne, self.c_nw, Door(), 'west') connect(self.c_se, self.c_saal1, Door(), 'northwest') connect(self.c_sw, self.c_saal1, Door(), 'northeast') connect(self.c_nw, self.c_saal1, Door(), 'southeast') connect(self.c_ne, self.c_saal1, Door(), 'southwest') connect(self.c_sw, self.c_office, Door(), 'west') # Stairs connect(self.b_ne, self.a_hackcenter, Stairs(), 'northeast', 'northeast') connect(self.b_se, self.c_se, Stairs(), 'southeast', 'southeast') connect(self.b_sw, self.c_sw, Stairs(), 'southwest', 'southwest') connect(self.b_nw, self.c_nw, Stairs(), 'northwest', 'northwest') self.update_shortcuts()