def stop(process_name=None): if process_name and __get_process(process_name) is not None: process = __get_process(process_name) pids = find_pid(process.get('token')) if not pids: ApiLogging.warning(process_name + ' is not running!', True) else: for pid in pids: ApiLogging.info(process_name + ' stopped successful!', True) proc = psutil.Process(pid) if proc.is_running(): proc.kill() else: for process in constants.APP_PROCESSES: pids = find_pid(process.get('token')) if not pids: ApiLogging.warning( process.get('name') + ' is not running!', True) else: for pid in pids: ApiLogging.info( process.get('name') + ' stopped successful!', True) proc = psutil.Process(pid) if proc.is_running(): proc.kill() try: __cleanup() except Exception as e: # print("cleanup exception: ", e) pass
def decode(hash_type,hash_code): if login(): hash_field = robot.find_by_css('#ctl00_ContentPlaceHolder1_TextBoxInput') if hash_field is not None: type_field = robot.find_by_css('#ctl00_ContentPlaceHolder1_InputHashType') ApiLogging.info('hash: ' + str(hash) +' type: ' + str(type) + ' hashcode: '+ hash_code ) return None hash_field.set_value(hash) type_field.set_value(type) fill_captcha_if_needed() submit_button = robot.find_by_css("#ctl00_ContentPlaceHolder1_Button1") submit_button.click() result = robot.find_by_css('#ctl00_ContentPlaceHolder1_LabelAnswer') ApiLogging.info ("result: %s"%result.get_text().split('\n')[0]) if result.get_text() == 'Verify code error!': decode(hash_type,hash_code) elif 'payment' in result.get_text(): pr = robot.find_by_contain_text('a', 'Purchase') if pr: pr.click() result = robot.find_by_css('#ctl00_ContentPlaceHolder1_LabelAnswer') ApiLogging.info("result: %s" % result.get_text().split('\n')[0]) elif 'Not Found' in result.get_text(): ApiLogging.warning('Not Found') else: log(result.get_text().split('\n')[0]) else: ApiLogging.warning ('login fail')
def send_signal(): pids = [] for process_name in constants.APP_PROCESSES: if process_name.get('name') == 'process_sync.py': pids = find_pid(process_name.get('token')) if len(pids) > 1: ApiLogging.warning('Too many sync process running') elif len(pids) == 1: p = psutil.Process(pids[0]) p.send_signal(signal.SIGUSR1)
def send_signal(process_names): try: for name in process_names: pids = [] for process_name in constants.APP_PROCESSES: if process_name.get('name') == name: pids = find_pid(process_name.get('token')) if len(pids) > 1: ApiLogging.warning('Too many ' + str(name) + ' process running') elif len(pids) == 1: p = psutil.Process(pids[0]) ApiLogging.info('process name: ' + str(pids[0])) p.send_signal(signal.SIGUSR1) except Exception as e: ApiLogging.critical('broadcast signal exception: ' + str(e))
def start(process_name=None): requirements = check_requirements() if requirements is not True: for requirement in requirements: ApiLogging.critical(requirement, True) return if process_name and __get_process(process_name) is not None: process = __get_process(process_name) pids = find_pid(process.get('token')) if pids: ApiLogging.warning(str(len(pids)) + ' instance(s) of this process already running!', True) else: __run(process_name, 'start') else: for process in constants.APP_PROCESSES: if find_pid(process.get('token')): ApiLogging.warning(process.get('name') + ' is already running!', True) else: __run(process.get('name'), 'start')
def fill_captcha_if_needed(self): captcha_field = self.robot.find_by_css( '#ctl00_ContentPlaceHolder1_TextBoxCode') if captcha_field is not None: ApiLogging.warning('captcha needed') self.robot.set_viewport_size(1280, 800) img = self.robot.find_by_css("#Image1") rect = img.get_position() box = (int(rect['left']), int(rect['top']), int(rect['right']), int(rect['bottom'])) filename = tempfile.mktemp('.png') self.robot.save_as_png(filename, 1280, 800) image = Image.open(filename) os.unlink(filename) captcha_image = image.crop(box) captcha_image.save('%s.png' % self.unique_time, 'png') captcha_field.set_value( self.resolve_captcha('%s.png' % self.unique_time)) os.remove('%s.png' % self.unique_time)
def validate_email(email, check_mx=False, verify=False, debug=False, smtp_timeout=10, sending_email=''): regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$' # Syntax check match = re.match(regex, email) if match == None: ApiLogging.warning('Bad Syntax') return False if check_mx: hostname = email[email.find('@') + 1:] mx_hosts = get_mx_ip(hostname) if mx_hosts is None: return False for key in mx_hosts: try: server = smtplib.SMTP() server.set_debuglevel(0) # SMTP Conversation if mx_hosts[key] is None: return False server.connect(mx_hosts[key]) server.helo(server.local_hostname) server.mail(sending_email) code, message = server.rcpt(email) server.quit() if code == 250: return True else: return False except: return False
def decode(self, hash_type, hash_code): if self.login(): hash_field = self.robot.find_by_css( '#ctl00_ContentPlaceHolder1_TextBoxInput') if hash_field is not None: type_field = self.robot.find_by_css( '#ctl00_ContentPlaceHolder1_InputHashType') hash_field.set_value(hash_code) type_field.set_value(hash_type) self.fill_captcha_if_needed() submit_button = self.robot.find_by_css( "#ctl00_ContentPlaceHolder1_Button1") submit_button.click() result = self.robot.find_by_css( '#ctl00_ContentPlaceHolder1_LabelAnswer') ApiLogging.info("result in hash: %s" % result.get_text()) ApiLogging.info('type: ' + str(hash_type) + ' code: ' + str(hash_code)) chk_result = self.check_result(result) if chk_result == VERIFY: self.decode(hash_type, hash_code) elif chk_result == PAYMENT: pr = self.robot.find_by_contain_text('a', 'Purchase') ApiLogging.info('click payment' + str(pr.get_text())) if pr: pr.click() result = self.robot.find_by_css( '#ctl00_ContentPlaceHolder1_LabelAnswer') chk_result = self.check_result(result) if chk_result is None: return result.get_text() elif chk_result == NOT_FOUND: return None else: return result.get_text().split('\n')[0] else: ApiLogging.warning('login fail')