def start(update, context, first_run=True): # prevent someone from sending new requests while current one is still processed while pbot.has_request(): context.bot.send_chat_action(chat_id=update.effective_message.chat_id, action=ChatAction.TYPING) log.info("[Personal bot] Waiting for request to be processed...") sleep(5) msg = 'Чим я можу допомогти?' if first_run else 'Може ще щось?' header_buttons = InlineKeyboardButton(mm_buttons.BALANCE, callback_data=mm_buttons.BALANCE) button_list = [ InlineKeyboardButton(mm_buttons.REBOOT_CONFIRM, callback_data=mm_buttons.REBOOT_CONFIRM), InlineKeyboardButton(mm_buttons.FIX_CONFIRM, callback_data=mm_buttons.FIX_CONFIRM), InlineKeyboardButton(mm_buttons.SMS_NUM, callback_data=mm_buttons.SMS_NUM), InlineKeyboardButton(mm_buttons.USSD_NUM, callback_data=mm_buttons.USSD_NUM) ] reply_markup = InlineKeyboardMarkup( build_menu(button_list, n_cols=2, header_buttons=header_buttons)) send_bot_msg(update, context, msg=msg, reply_markup=reply_markup, noedit=True)
def reset_config(self): log.info("[Reset config] Re-setting") # as GoIP's SMPP is not started after configuration is reset SmsWrapper.kill() BrowserWrapper.b.go_relative_url("reset_config.html") sleep(20) # login with default password self.init_browser(pwd=DEFAULT_GOIP_PWD)
def monitor(self): log.info("[CallMonitor] Started monitor") BrowserWrapper.b.open_menu("Status") waiting_from = None while True: if pbot.has_request(): skip_processing = False request = pbot.request log.info("[CallMonitor] Has personal bot request: %s" % request) # reboot and reset/restore are still possible while in the call # as we have a confirmation message before running each of them if self.call_or_dialing_started(): if isinstance(request, BalanceRequest)\ or isinstance(request, SendSmsRequest)\ or isinstance(request, SendUssdRequest): log.info( "[CallMonitor] Could not process the request while in a call. Waiting..." ) skip_processing = True if isinstance(request, RebootRequest) or isinstance( request, ResetRestoreRequest): waiting_from = None if not skip_processing: log.info("[CallMonitor] Processing personal bot request") pbot.process_request(self.goip) log.info("[CallMonitor] Processed personal bot request") BrowserWrapper.b.open_menu("Status") # send daily status every day once at 23:XX when no-one is using GoIP caller if current_time().hour == 23 and not self.call_or_dialing_started() and\ (not self.daily_status_sent_at or self.daily_status_sent_at.date() != current_date().date()): self.daily_status_sent_at = current_time( ) # using in-memory var to decrease amt of calls to DB vs.set_daily_status_sent(self.daily_status_sent_at) bot.send(daily_status()) # this should be checked every time, so no var defined above sleep_for_sec = 2 if self.call_or_dialing_started( ) else LAST_CALL_SLEEP_SECONDS # if not authorised for < 5 minutes - just wait for this issue to get fixed (with reset/restore?) if not BrowserWrapper.b.is_authorized( ) and not passed_more_that_sec(waiting_from, 5 * 60): log.warning( "[CallMonitor] Browser is not ok - session is not authorised" ) if waiting_from is None: waiting_from = current_time() sleep(sleep_for_sec) continue waiting_from = None # this is the way to get up-to-day info from the page BrowserWrapper.b.driver.refresh() if self.goip.goip_monitor(): # if all is fine with GoIP self.call_monitor() # run call monitor logic else: log.info("[CallMonitor] GoIP monitor is not ok") sleep(sleep_for_sec, print_log=False)
def reboot(self): log.info("[Reboot] Rebooting caller") SmsWrapper.kill() bot.send("Перезавантажую дзвонилку.") BrowserWrapper.b.go_relative_url("reboot.html") sleep(30) self.init_browser() self.init_sms(notify=True) log.info("[Reboot] Finished reboot") bot.send("Перезавантажено дзвонилку.")
def close(self, force=False): if not self._all_processes: return log.info("[Close] Disconnecting the SMPP client") try: self.client.disconnect() except Exception as e: log.error(e) if not force: sleep(2) log.info("[Close] Terminating processes for SMS monitoring") for process in self._all_processes: process.terminate()
def restore_config(self): log.info("[Restore config] Restoring") b = BrowserWrapper.b b.open_menu("Configurations") b.set_text(b.by_id("time_zone"), "GMT+2") b.set_text(b.by_id("ntp_server"), "0.ua.pool.ntp.org") b.by_id("auto_reboot_disable").click() b.by_id("ivr_enable_disable").click() b.by_id("smpp_enable_enable").click() b.set_text(b.by_id("smpp_id"), SMPP_USER) b.set_text(b.by_id("smpp_key"), SMPP_SECRET) b.set_text(b.by_id("dtmf_min_gap"), "200") b.save() b.open_menu("Network") b.set_select("pc_port_select", "Bridge mode") b.save() b.open_menu("Basic VoIP") b.set_text(b.by_id("sip_auth_id"), self.sip) b.set_text(b.by_id("sip_auth_passwd"), self.spwd) b.set_text(b.by_id("sip_registrar"), "sip.zadarma.com") b.set_text(b.by_id("sip_phone_number"), self.sip) b.set_text(b.by_id("sip_display_name"), self.sip) b.save() b.open_menu("Advance VoIP") b.set_select("sip_local_port_mode_select", "Fixed") b.set_select("sip_183_select", "SIP 180") # maybe change 'Signaling SIP Port' == 5060 => 5065 b.save() b.open_menu("Media") b.expand_items("Audio Codec Preference") b.disable_codec("g729a") b.disable_codec("g729ab") b.disable_codec("g7231") b.move_up_codec("g729", 2) b.save() b.open_menu("Call Out") b.set_text(b.by_id("gsm_outc_noans_t"), "60") b.save() b.open_menu("Call Out Auth") b.set_select("line1_fw2pstn_auth_mode_select", "Whitelist") b.expand_items("Whitelist/Blacklist") b.set_text(b.by_id("l1_voip_trust_num1"), "419522") b.set_text(b.by_id("l1_voip_trust_num2"), "549950") b.set_text(b.by_id("l1_voip_trust_num3"), "685171") b.set_text(b.by_id("l1_voip_trust_num4"), "752227") b.save() b.open_menu("Call In") b.by_id("line1_fw_to_voip_disable").click() b.save() b.open_menu("SIM") b.by_id("gprs_disable").click() b.by_id("expiry_m_enable").click() b.set_text(b.by_id("line1_gsm_num"), SENDER_PHONE) b.set_text(b.by_id("line1_gsm_pin2"), "9819") b.by_id("line1_exp_drop_disable").click() b.save() b.open_menu("Tools") b.open_menu("User Management") parent = "//table[//td[text()='Administration Level']]//form[@name='form2']//" xpath = parent + "input[@name='%s']" b.set_text(b.by_xpath(xpath % "passwd"), self.pwd) b.set_text(b.by_xpath(xpath % "confirm_passwd"), self.pwd) b.by_xpath(parent + "input[@type='submit' and @value='Change']").click() sleep(10) self.init_browser() self.init_sms() vs.increase_daily_fixed_times(1)