Пример #1
0
 def __init__(self):
     self.project = ProjectModule()
     self.setting = SettingModule()
     self.option_func = OptionsFunction()
     self.common_func = CommonFunction()
     self.thread_func = ThreadFunction()
     self.jenkins_server = jenkins.Jenkins(url=jenkins_url,
                                           username=jenkins_user,
                                           password=jenkins_password,
                                           timeout=5)
Пример #2
0
 def prepare(self):
     self.user = UserModule()
     self.project = ProjectModule()
     self.setting = SettingModule()
     self.option = OptionModule()
     self.msg = MessagesModule()
     self.statistics = StatisticsModule()
     self.common_func = CommonFunction()
     self.option_func = OptionsFunction()
     self.thread_func = ThreadFunction()
Пример #3
0
 def prepare(self):
     self.common_func = CommonFunction()
     self.user = UserModule()
     self.project = ProjectModule()
     self.setting = SettingModule()
     self.option = OptionModule()
     self.option_func = OptionsFunction()
     self.company = yield self.option_func.get_option_by_name(name='company')
     self.limit = yield self.option_func.get_option_by_name(name='page_limit')
     self.company = self.company or '开源接口测试平台'
     self.argv = dict(company=self.company)
Пример #4
0
 def __init__(self, pid=0, jid=0):
     self.default_headers = {
         'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
         'User-Agent':
         'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
         'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4',
         'Cookie': ''
     }
     self.headers = dict()
     self.setting = SettingModule()
     self.common_func = CommonFunction()
     self.option_func = OptionsFunction()
     self.pid = pid
     self.jid = jid
Пример #5
0
 def __init__(self):
     self.common_func = CommonFunction()
Пример #6
0
 def __get_links(self, url, user_agent='', cookie='', check_all=False):
     response = yield self.__request_url(url, user_agent, cookie)
     common_func = CommonFunction()
     url_split = common_func.url_split(url)
     host = url_split.host
     scheme = url_split.scheme
     netloc = '{}://{}'.format(scheme, url_split.netloc)
     links = []
     if response and response.body:
         body = response.body if not isinstance(
             response.body, bytes) else response.body.decode(
                 'utf8', errors='ignore')
         body = body if isinstance(body, str) else str(body)
         link_a = re.findall(
             r'<a.*?href=[\'"](.*?)[\'"].*?title=[\'"](.*?)[\'"].*?>(.*?)</a>',
             body)
         link_b = re.findall(
             r'<a.*?title=[\'"](.*?)[\'"].*?href=[\'"](.*?)[\'"].*?>(.*?)</a>',
             body)
         link_c = re.findall(r'<a.*?href=[\'"](.*?)[\'"].*?>(.*?)</a>',
                             body)
         link_d = re.findall(r'data-href=[\'"](.*?)[\'"]', body)
         link_e = re.findall(r'data-url=[\'"](.*?)[\'"]', body)
         for link in link_a:
             href = link[0].strip()
             if re.match(r'^(http|https):', href) is not None:
                 pass
             elif re.match(r'^//', href) is not None:
                 href = scheme + href
             elif re.match(r'^/', href) is not None:
                 href = netloc + href
             elif re.match(r'^(javascript|#)', href.lower()) is not None:
                 continue
             else:
                 href = '{}/{}'.format(url, href)
             title = link[1]
             text = link[2] if link[2] != '' else link[1]
             log.info('获取到链接: {} {}'.format(text, href))
             link = dict(href=href, title=title, text=text)
             if link not in links:
                 links.append(link)
         for link in link_b:
             href = link[1].strip()
             if re.match(r'^(http|https):', href) is not None:
                 pass
             elif re.match(r'^//', href) is not None:
                 href = scheme + href
             elif re.match(r'^/', href) is not None:
                 href = netloc + href
             elif re.match(r'^(javascript|#)', href.lower()) is not None:
                 continue
             else:
                 href = '{}/{}'.format(url, href)
             title = link[0]
             text = link[2] if link[2] != '' else link[0]
             log.info('获取到链接: {} {}'.format(text, href))
             link = dict(href=href, title=title, text=text)
             if link not in links:
                 links.append(link)
         for link in link_c:
             href = link[0].strip()
             if re.match(r'^(http|https):', href) is not None:
                 pass
             elif re.match(r'^//', href) is not None:
                 href = scheme + href
             elif re.match(r'^/', href) is not None:
                 href = netloc + href
             elif re.match(r'^(javascript|#)', href.lower()) is not None:
                 continue
             else:
                 href = '{}/{}'.format(url, href)
             title = ''
             text = link[1]
             log.info('获取到链接: {} {}'.format(text, href))
             link = dict(href=href, title=title, text=text)
             if link not in links:
                 links.append(link)
         for link in link_d + link_e:
             href = link[0].strip()
             if re.match(r'^(http|https):', href) is not None:
                 pass
             elif re.match(r'^//', href) is not None:
                 href = scheme + href
             elif re.match(r'^/', href) is not None:
                 href = netloc + href
             elif re.match(r'^(javascript|#)', href.lower()) is not None:
                 continue
             else:
                 href = '{}/{}'.format(url, href)
             title = ''
             text = ''
             log.info('获取到链接: {} {}'.format(text, href))
             link = dict(href=href, title=title, text=text)
             if link not in links:
                 links.append(link)
     next_links = []
     if check_all:
         for link in links:
             cur_host = common_func.url_split(link['href']).host
             if cur_host == host and link['href'] not in next_links:
                 next_links.append(link['href'])
     return links, next_links, response
Пример #7
0
 def post(self, op='option', do='save'):
     if self.current_user.role == 2:
         msg = dict(result=False, msg='请使用管理员登录后再进行操作!')
         yield self.return_json(msg)
         return
     if op == 'option':
         company = self.get_argument('company', default='')
         page_limit = self.get_argument('page_limit', default='')
         email_ext = self.get_argument('email_ext', default='')
         smtp_host = self.get_argument('smtp_host', default='')
         smtp_port = self.get_argument('smtp_port', default='')
         use_ssl = self.get_argument('use_ssl', default='off')
         smtp_user = self.get_argument('smtp_user', default='')
         smtp_password = self.get_argument('smtp_password', default='')
         mail_from = self.get_argument('mail_from', default='')
         report_url = self.get_argument('report_url', default='')
         mail_report = self.get_argument('mail_report', default='off')
         common_func = CommonFunction()
         if smtp_user != '' and not common_func.check_string(
                 smtp_user, 'email'):
             msg = dict(result=False, msg='【SMTP 登录用户】必须是Email格式')
             yield self.return_json(msg)
             return
         if mail_from != '' and not common_func.check_string(
                 mail_from, 'email'):
             msg = dict(result=False, msg='【发件人显示为】必须是Email格式')
             yield self.return_json(msg)
             return
         if do == 'test':
             send_to = self.get_argument('send_to', default='')
             if '' in (send_to, smtp_port, smtp_host, smtp_user,
                       smtp_password):
                 msg = dict(result=False, msg='所有配置不能为空, 请检查配置是否正确')
                 yield self.return_json(msg)
                 return
             if not common_func.check_string(send_to, 'email'):
                 msg = dict(result=False, msg='【配置测试】地址必须是Email格式')
                 yield self.return_json(msg)
                 return
             mail = Mail(smtp_server=smtp_host,
                         smtp_port=smtp_port,
                         use_ssl=use_ssl,
                         smtp_user=smtp_user,
                         smtp_password=smtp_password,
                         mail_from=mail_from)
             message = '<p>[{}]邮件配置测试, 收到此邮件说明配置正确。</p>'.format(
                 self.company)
             result, msg = yield mail.send_mail(
                 subject='[{}][系统测试邮件]'.format(self.company),
                 message=message,
                 to=[send_to])
             if result:
                 msg = dict(result=True, msg='邮件发送成功')
             else:
                 msg = dict(result=False, msg='邮件发送失败, {}'.format(msg))
         else:
             if page_limit == '':
                 page_limit = 0
             else:
                 page_limit = int(page_limit)
             if len(company) < 2 or len(company) > 60:
                 msg = dict(result=False, msg='【公司名称】格式不正确')
                 yield self.return_json(msg)
                 return
             if page_limit < 10 or page_limit > 100 or page_limit % 10 != 0:
                 msg = dict(result=False, msg='【分页数目】必须为10的倍数且是10与100之间的整数')
                 yield self.return_json(msg)
                 return
             if report_url != '' and not common_func.check_string(
                     report_url, 'url'):
                 msg = dict(result=False, msg='【邮件报告链接域名】格式不对, 请检查')
                 yield self.return_json(msg)
                 return
             edit_options = dict(company=company,
                                 page_limit=page_limit,
                                 email_ext=email_ext,
                                 report_url=report_url,
                                 smtp_host=smtp_host,
                                 smtp_port=smtp_port,
                                 smtp_user=smtp_user,
                                 mail_report=mail_report,
                                 smtp_password=smtp_password,
                                 use_ssl=use_ssl,
                                 mail_from=mail_from)
             options = yield self.option.get_options_list()
             flag = True
             msg = ''
             options_name = []
             for option in options:
                 options_name.append(option.name)
             if options_name:
                 for option in edit_options:
                     if option in options_name:
                         result, msg = yield self.option.edit_option(
                             name=option, value=edit_options[option])
                     else:
                         result, msg = yield self.option.add_option(
                             name=option, value=edit_options[option])
                     if not result:
                         flag = False
                         break
             else:
                 for option in edit_options:
                     result, msg = yield self.option.add_option(
                         name=option, value=edit_options[option])
                     if not result:
                         flag = False
                         break
             if flag:
                 msg = dict(result=True, msg='更新系统配置成功')
             else:
                 msg = dict(result=False, msg=msg)
         yield self.return_json(msg)
     elif op == 'users':
         if do == 'add':
             email = self.get_argument('email', default='')
             if self.common_func.check_string(email, 'email'):
                 user = yield self.user.get_user_info(email)
                 if user is None:
                     self.user.register_user(email, '123456')
             self.redirect('/admin/manage/users')
             return
         uid = self.get_argument('id', default='')
         user = yield self.user.get_users_info_by_ids(ids=[uid])
         if not user:
             msg = dict(result=False, msg='所编辑的用户不存在')
             yield self.return_json(msg)
             return
         if do == 'status':
             status = int(self.get_argument('status', default=0))
             result, msg = yield self.user.edit_user(email=user[0].email,
                                                     status=status)
             if result:
                 msg = dict(result=True, msg=msg)
             else:
                 msg = dict(result=False, msg=msg)
             yield self.return_json(msg)
             return
         elif do == 'role':
             role = int(self.get_argument('role', default=0))
             result, msg = yield self.user.edit_user(email=user[0].email,
                                                     role=role)
             if result:
                 msg = dict(result=True, msg=msg)
             else:
                 msg = dict(result=False, msg=msg)
             yield self.return_json(msg)
             return
         elif do == 'reset':
             result, msg = yield self.user.edit_user(email=user[0].email,
                                                     password='******')
             if result:
                 msg = dict(result=True,
                            msg='用户 {} 的密码已重置为 123456'.format(
                                user[0].email))
             else:
                 msg = dict(result=False, msg=msg)
             yield self.return_json(msg)
             return
     elif op == 'logs':
         yield self.setting.delete_settings_list(s_type='log')
         self.redirect('/admin/manage/logs')