Example #1
0
 public function act()
 {
     $history_id = (int) Request::get_param('historyid', 'post');
     $item_id = (int) Request::get_param('itemid', 'post');
     $case_id = (int) Request::get_param('caseid', 'post');
     echo json_encode(LF\M('Result')->get_by_case($history_id, $item_id, $case_id));
 }
Example #2
0
 public function act()
 {
     $history_id = (int) Request::get_param('id', 'post');
     $host = trim(Request::get_param('host', 'post'));
     $system_info = LF\M('System')->select()->fetch();
     $history_info = LF\M('History')->get_by_id($history_id);
     $pass_num = (int) $history_info['pass'];
     $fail_num = (int) $history_info['fail'];
     $title = '接口自动化测试报告 (' . date('Y-m-d h:i:s') . ')';
     $result = $fail_num === 0 ? '<span style="color:#629731">PASS</span>' : '<span style="color:#d0636e">FAIL</span>';
     $content = '<p style="font-size:20px;font-family:Microsoft Yahei, SimHei, Arial;font-weight:bold;">任务结果: ' . $result . '</p>';
     $content .= '<p style="font-size:16px;font-family:Microsoft Yahei, SimHei, Arial;">总共执行' . ($pass_num + $fail_num) . '个检查点,';
     $content .= '通过<span style="color:#629731;font-weight:bold;">' . $pass_num . '</span>,';
     $content .= '失败<span style="color:#d0636e;font-weight:bold;">' . $fail_num . '</span></p>';
     $content .= '<p style="font-size:16px;font-family:Microsoft Yahei, SimHei, Arial;font-weight:bold;"><a stype="color:#22aabe;" href="' . $host . '/report?id=' . $history_id . '" target="_blank">查看详细报告 >></a></p>';
     foreach (explode(',', $system_info['mail_list']) as $mail) {
         $mail = trim($mail);
         if (!$mail) {
             continue;
         }
         try {
             $smtp = new Extension_Smtp();
             $smtp->setServer($system_info['smtp_server'], $system_info['smtp_user'], $system_info['smtp_password'], $system_info['smtp_port'], $system_info['smtp_ssl'] ? TRUE : FALSE);
             $smtp->setFrom($system_info['smtp_user']);
             $smtp->setReceiver($mail);
             $smtp->setMail($title, $content);
             $smtp->sendMail();
         } catch (Exception $e) {
         }
     }
 }
Example #3
0
 public function act()
 {
     if (!$this->check_param('username, password, issave')) {
         LF\V('Json.Base')->init(Const_Code::LOGIN_PARAM_ERROR, '登录传递参数错误');
         return;
     }
     $username = trim(Request::get_param('username', 'post'));
     $password = trim(Request::get_param('password', 'post'));
     $is_save = (int) Request::get_param('issave', 'post');
     $time = time();
     $seckey = LF\lb_read_system('seckey');
     $user_id = (int) LF\M('User')->check_password($username, md5($username . $password));
     if (!$user_id) {
         LF\V('Json.Base')->init(Const_Code::LOGIN_FAIL, '帐号验证失败');
         return;
     }
     $user = LF\M('User')->get_by_id($user_id);
     $expire_time = $is_save ? 86400 * 30 : 0;
     Cookie::set_cookie('userid', $user_id, $expire_time);
     Cookie::set_cookie('username', $user['name'], $expire_time);
     Cookie::set_cookie('userrole', $user['role'], $expire_time);
     Cookie::set_cookie('time', $time, $expire_time);
     Cookie::set_cookie('secstr', md5($user_id . '$' . $user['name'] . '$' . $user['role'] . '$' . $time . '$' . $seckey), $expire_time);
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '帐号验证通过');
 }
Example #4
0
 public function act()
 {
     if (!$this->check_param('taskid')) {
         LF\V('Json.Base')->init(Const_Code::JOB_PARAM_ERROR, '作业传递参数错误');
         return;
     }
     $task_id = (int) Request::get_param('taskid', 'post');
     if (LF\M('Job')->check_task_exists($task_id)) {
         LF\V('Json.Base')->init(Const_Code::ADD_JOB_EXISTS, '作业已在队列');
         return;
     }
     $task = LF\M('Task')->get_by_id($task_id);
     if (!$task) {
         LF\V('Json.Base')->init(Const_Code::ADD_JOB_FAIL, '作业添加失败');
         return;
     }
     LF\M('Job')->insert();
     $job = LF\M('Job')->get_by_task($task_id);
     $job_id = (int) $job['task_id'];
     if (!$job_id) {
         LF\V('Json.Base')->init(Const_Code::ADD_JOB_FAIL, '作业添加失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, $job_id);
 }
Example #5
0
 public function act()
 {
     if (!$this->check_param('configid, packageid, configtype, configkeyword')) {
         LF\V('Json.Base')->init(Const_Code::CONFIG_PARAM_ERROR, '配置传递参数错误');
         return;
     }
     $config_id = (int) Request::get_param('configid', 'post');
     $package_id = (int) Request::get_param('packageid', 'post');
     $config_type = trim(Request::get_param('configtype', 'post'));
     $config_keyword = trim(Request::get_param('configkeyword', 'post'));
     if (!preg_match('/^\\w+$/', $config_keyword)) {
         LF\V('Json.Base')->init(Const_Code::CONFIG_FORMAT_ERROR, '配置关键字格式错误');
         return;
     }
     if (LF\M('Conf')->check_keyword_update($config_id, $package_id, $config_type, $config_keyword)) {
         LF\V('Json.Base')->init(Const_Code::UPDATE_CONFIG_EXISTS, '配置关键字重复');
         return;
     }
     $result = LF\M('Conf')->where('id=' . $config_id)->update();
     if (is_null($result)) {
         LF\V('Json.Base')->init(Const_Code::UPDATE_CONFIG_FAIL, '配置更新失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '配置更新成功');
 }
Example #6
0
 public function act()
 {
     if (!$this->check_param('username, userrole')) {
         LF\V('Json.Base')->init(Const_Code::USER_PARAM_ERROR, '用户传递参数错误');
         return;
     }
     $user_name = trim(Request::get_param('username', 'post'));
     $user_password = trim(Request::get_param('userpassword', 'post'));
     if (!preg_match('/^\\w+$/', $user_name)) {
         LF\V('Json.Base')->init(Const_Code::USER_FORMAT_ERROR, '用户名称格式错误');
         return;
     }
     if (LF\M('User')->check_name_exists($user_name)) {
         LF\V('Json.Base')->init(Const_Code::ADD_USER_EXISTS, '用户名称重复');
         return;
     }
     $_POST['userpassword'] = $user_password ? md5($user_name . $user_password) : md5($user_name . '888888');
     LF\M('User')->insert();
     $user = LF\M('User')->get_by_name($user_name);
     $user_id = (int) $user['id'];
     if (!$user_id) {
         LF\V('Json.Base')->init(Const_Code::ADD_USER_FAIL, '用户添加失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, $user_id);
 }
Example #7
0
 public function act()
 {
     $id = (int) Request::get_param('reload', 'get');
     $view = LF\V('Html.Start.Index');
     $view->add_data('reload_id', $id);
     $view->init('Start.Index');
 }
Example #8
0
 public function act()
 {
     if (!$this->check_param('itemid, moduleid, spaceid, casename, sendtype, contenttype')) {
         LF\V('Json.Base')->init(Const_Code::CASE_PARAM_ERROR, '用例传递参数错误');
         return;
     }
     $item_id = (int) Request::get_param('itemid', 'post');
     $case_name = trim(Request::get_param('casename', 'post'));
     if (LF\M('Case')->check_name_exists($item_id, $case_name)) {
         LF\V('Json.Base')->init(Const_Code::ADD_CASE_EXISTS, '用例名称重复');
         return;
     }
     LF\M('Case')->insert();
     $case = LF\M('Case')->get_by_name($item_id, $case_name);
     $case_id = (int) $case['id'];
     if (!$case_id) {
         LF\V('Json.Base')->init(Const_Code::ADD_CASE_FAIL, '用例添加失败');
         return;
     }
     $item = LF\M('Item')->get_by_id($item_id);
     $_POST['caseid'] = $case_id;
     $_POST['stepname'] = '调用: ' . $item['name'] . '->' . $case_name;
     $_POST['steptype'] = '接口调用';
     $_POST['stepcommand'] = 'self';
     $_POST['stepvalue'] = $case_id;
     $_POST['stepsequence'] = 1;
     LF\M('Step')->insert();
     LF\V('Json.Base')->init(Const_Code::SUCCESS, $case_id);
 }
Example #9
0
 public function act()
 {
     if (!$this->check_param('userid, username, userrole')) {
         LF\V('Json.Base')->init(Const_Code::USER_PARAM_ERROR, '用户传递参数错误');
         return;
     }
     $user_id = (int) Request::get_param('userid', 'post');
     $user_name = trim(Request::get_param('username', 'post'));
     $user_password = trim(Request::get_param('userpassword', 'post'));
     if (!preg_match('/^\\w+$/', $user_name)) {
         LF\V('Json.Base')->init(Const_Code::USER_FORMAT_ERROR, '用户名称格式错误');
         return;
     }
     if (LF\M('User')->check_name_update($user_id, $user_name)) {
         LF\V('Json.Base')->init(Const_Code::UPDATE_USER_EXISTS, '用户名称重复');
         return;
     }
     if ($user_password) {
         $_POST['userpassword'] = md5($user_name . $user_password);
     } else {
         unset($_POST['userpassword']);
     }
     unset($_POST['username']);
     $result = LF\M('User')->where('id=' . $user_id)->update();
     if (is_null($result)) {
         LF\V('Json.Base')->init(Const_Code::UPDATE_USER_FAIL, '用户更新失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '用户更新成功');
 }
Example #10
0
 public function act()
 {
     if (!$this->check_param('packageid, configtype, configkeyword')) {
         LF\V('Json.Base')->init(Const_Code::CONFIG_PARAM_ERROR, '配置传递参数错误');
         return;
     }
     $package_id = (int) Request::get_param('packageid', 'post');
     $config_type = trim(Request::get_param('configtype', 'post'));
     $config_keyword = trim(Request::get_param('configkeyword', 'post'));
     if (!preg_match('/^\\w+$/', $config_keyword)) {
         LF\V('Json.Base')->init(Const_Code::CONFIG_FORMAT_ERROR, '配置关键字格式错误');
         return;
     }
     if (LF\M('Conf')->check_keyword_exists($package_id, $config_type, $config_keyword)) {
         LF\V('Json.Base')->init(Const_Code::ADD_CONFIG_EXISTS, '配置关键字重复');
         return;
     }
     LF\M('Conf')->insert();
     $config = LF\M('Conf')->get_by_keyword($package_id, $config_type, $config_keyword);
     $config_id = (int) $config['id'];
     if (!$config_id) {
         LF\V('Json.Base')->init(Const_Code::ADD_CONFIG_FAIL, '配置添加失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, $config_id);
 }
Example #11
0
 public function act()
 {
     $page = (int) Request::get_param('page', 'post');
     $size = (int) Request::get_param('size', 'post');
     $history_size = (int) Request::get_param('historysize', 'post');
     if ($page < 1) {
         $page = 1;
     }
     if ($size < 1) {
         $size = 20;
     }
     if ($history_size) {
         $history_size = 3;
     }
     $task_list = LF\M('Task')->get_all($page, $size, $history_size);
     foreach ($task_list as &$task) {
         $package = LF\M('Package')->get_by_id((int) $task['package_id']);
         $task['packagename'] = $package['name'];
         $space = LF\M('Space')->get_by_id((int) $task['space_id']);
         $task['spacename'] = $space['name'];
         $job = LF\M('Job')->get_by_task((int) $task['id']);
         $task['running'] = $job ? 1 : 0;
         $task['total'] = $job ? (int) $job['total'] : 0;
         $task['current'] = $job ? (int) $job['current'] : 0;
         $task['history'] = LF\M('History')->get_by_task((int) $task['id'], 1, $history_size);
     }
     echo json_encode($task_list);
 }
Example #12
0
 public function act()
 {
     if (!$this->check_param('oldpassword, newpassword')) {
         LF\V('Json.Base')->init(Const_Code::USER_PARAM_ERROR, '用户传递参数错误');
         return;
     }
     $old_password = trim(Request::get_param('oldpassword', 'post'));
     $new_password = trim(Request::get_param('newpassword', 'post'));
     $user_id = (int) $_COOKIE['userid'];
     $user_name = $_COOKIE['username'];
     $old_password = md5($user_name . $old_password);
     $new_password = md5($user_name . $new_password);
     $user = LF\M('User')->get_by_id($user_id);
     if ($old_password !== $user['passwd']) {
         LF\V('Json.Base')->init(Const_Code::USER_CHECK_ERROR, '用户密码校验失败');
         return;
     }
     $_POST['userpassword'] = $new_password;
     $result = LF\M('User')->where('id=' . $user_id)->update();
     if (is_null($result)) {
         LF\V('Json.Base')->init(Const_Code::UPDATE_USER_FAIL, '用户密码更新失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '用户密码更新成功');
 }
Example #13
0
 public function act()
 {
     if (!$this->check_param('guid')) {
         return;
     }
     $guid = trim(Request::get_param('guid', 'post'));
     LF\V('Xml.Base')->init('summary', LF\M('History')->get_by_guid($guid));
 }
Example #14
0
 protected function check_cookie()
 {
     $user_id = Util_Server_Request::get_cookie('userid');
     $user_name = Util_Server_Request::get_cookie('username');
     $user_role = Util_Server_Request::get_cookie('userrole');
     $time = Util_Server_Request::get_cookie('time');
     $secstr = Util_Server_Request::get_cookie('secstr');
     $seckey = LF\lb_read_system('seckey');
     return $secstr === md5($user_id . '$' . $user_name . '$' . $user_role . '$' . $time . '$' . $seckey);
 }
Example #15
0
 public function act()
 {
     $page = (int) Request::get_param('page', 'post');
     $size = (int) Request::get_param('size', 'post');
     if ($page < 1) {
         $page = 1;
     }
     if ($size < 1) {
         $size = 20;
     }
     echo json_encode(LF\M('User')->get_all($page, $size));
 }
Example #16
0
 public function act()
 {
     $space_id = (int) Request::get_param('spaceid', 'post');
     $module_list = LF\M('Module')->get_by_space($space_id);
     foreach ($module_list as &$module) {
         $item_num = LF\M('Item')->get_count_by_module((int) $module['id']);
         $case_num = LF\M('Case')->get_count_by_module((int) $module['id']);
         $module['item_num'] = (int) $item_num['count'];
         $module['case_num'] = (int) $case_num['count'];
     }
     echo json_encode($module_list);
 }
Example #17
0
 private function add_result($content, $addition)
 {
     $temp = (int) Request::get_param('temp', 'post');
     if ($temp) {
         return;
     }
     $_POST['stepid'] = 1;
     $_POST['steptype'] = '存储查询';
     $_POST['resultcontent'] = $content;
     $_POST['resultvalue1'] = $addition['query'];
     LF\M('Result')->insert();
 }
Example #18
0
 public function act()
 {
     $case_id = (int) Request::get_param('caseid', 'post');
     $case = LF\M('Case')->get_by_id($case_id);
     if (!$case) {
         LF\V('Xml.Base')->init('step', array());
         return;
     }
     $_POST['resultname'] = $case['name'];
     LF\M('Result')->insert();
     LF\V('Xml.Base')->init('step', LF\M('Step')->get_by_case($case_id));
 }
Example #19
0
 public function act()
 {
     $space_id = (int) Request::get_param('spaceid', 'post');
     $module_id = (int) Request::get_param('moduleid', 'post');
     if ($module_id) {
         $item_num = LF\M('Item')->get_count_by_module($module_id);
         $case_num = LF\M('Case')->get_count_by_module($module_id);
     } else {
         $item_num = LF\M('Item')->get_count_by_space($space_id);
         $case_num = LF\M('Case')->get_count_by_space($space_id);
     }
     echo json_encode(array('item_num' => $item_num, 'case_num' => $case_num));
 }
Example #20
0
 public function act()
 {
     $task_id = (int) Request::get_param('taskid', 'post');
     $space_id = (int) Request::get_param('spaceid', 'post');
     $module_id = (int) Request::get_param('moduleid', 'post');
     if ($module_id) {
         $item_list = LF\M('Item')->get_by_module($module_id, 0, 0);
     } else {
         $item_list = LF\M('Item')->get_by_space($space_id, 0, 0);
     }
     LF\M('Job')->set_total($task_id, count($item_list));
     LF\V('Xml.Base')->init('item', $item_list);
 }
Example #21
0
 public function act()
 {
     $package_id = (int) Request::get_param('packageid', 'post');
     $type = trim(Request::get_param('type', 'post'));
     $page = (int) Request::get_param('page', 'post');
     $size = (int) Request::get_param('size', 'post');
     if ($page < 1) {
         $page = 1;
     }
     if ($size < 1) {
         $size = 10;
     }
     echo json_encode(LF\M('Conf')->get_by_package($package_id, $type, $page, $size));
 }
Example #22
0
 public function act()
 {
     if (!$this->check_param('caseid, stepname, steptype, stepvalue, stepsequence')) {
         LF\V('Json.Base')->init(Const_Code::STEP_PARAM_ERROR, '步骤传递参数错误');
         return;
     }
     $case_id = (int) Request::get_param('caseid', 'post');
     $result = LF\M('Step')->insert();
     if (is_null($result)) {
         LF\V('Json.Base')->init(Const_Code::ADD_STEP_FAIL, '步骤添加失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '步骤添加成功');
 }
Example #23
0
 public function act()
 {
     if (!$this->check_param('taskid')) {
         LF\V('Json.Base')->init(Const_Code::TASK_PARAM_ERROR, '任务传递参数错误');
         return;
     }
     $task_id = (int) Request::get_param('taskid', 'post');
     LF\M('Task')->remove($task_id);
     $task = LF\M('Task')->get_by_id($task_id);
     if ($task) {
         LF\V('Json.Base')->init(Const_Code::DELETE_TASK_FAIL, '任务删除失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '任务删除成功');
 }
Example #24
0
 public function act()
 {
     if (!$this->check_param('taskid, taskhang')) {
         LF\V('Json.Base')->init(Const_Code::TASK_PARAM_ERROR, '任务传递参数错误');
         return;
     }
     $task_id = (int) Request::get_param('taskid', 'post');
     $task_hang = (int) Request::get_param('taskhang', 'post');
     $result = LF\M('Task')->set_hang($task_id, $task_hang);
     if (is_null($result)) {
         LF\V('Json.Base')->init(Const_Code::UPDATE_TASK_FAIL, '任务更新失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '任务更新成功');
 }
Example #25
0
 public function act()
 {
     if (!$this->check_param('taskid, guid')) {
         return;
     }
     $task_id = (int) Request::get_param('taskid', 'post');
     $guid = trim(Request::get_param('guid', 'post'));
     $_POST['historyruntime'] = date('Y-m-d H:i:s', time());
     LF\M('History')->insert();
     $history = LF\M('History')->get_by_guid($guid);
     if (!$history) {
         return;
     }
     echo (int) $history['id'];
 }
Example #26
0
 public function act()
 {
     if (!$this->check_param('configid')) {
         LF\V('Json.Base')->init(Const_Code::CONFIG_PARAM_ERROR, '配置传递参数错误');
         return;
     }
     $config_id = (int) Request::get_param('configid', 'post');
     LF\M('Conf')->remove($config_id);
     $config = LF\M('Conf')->get_by_id($config_id);
     if ($config) {
         LF\V('Json.Base')->init(Const_Code::DELETE_CONFIG_FAIL, '配置删除失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '配置删除成功');
 }
Example #27
0
 public function act()
 {
     $item_id = (int) Request::get_param('itemid', 'post');
     $task_id = (int) Request::get_param('taskid', 'post');
     $level = (int) Request::get_param('level', 'post');
     LF\M('Job')->increase_current($task_id);
     $item = LF\M('Item')->get_by_id($item_id);
     if (!$item) {
         LF\V('Xml.Base')->init('case', array());
         return;
     }
     $_POST['resultname'] = $item['name'];
     LF\M('Result')->insert();
     LF\V('Xml.Base')->init('case', LF\M('Case')->get_by_level($item_id, $level));
 }
Example #28
0
 public function act()
 {
     if (!$this->check_param('taskid')) {
         LF\V('Json.Base')->init(Const_Code::JOB_PARAM_ERROR, '作业传递参数错误');
         return;
     }
     $task_id = (int) Request::get_param('taskid', 'post');
     LF\M('Job')->remove_by_task($task_id);
     $job = LF\M('Job')->get_by_task($task_id);
     if ($job) {
         LF\V('Json.Base')->init(Const_Code::DELETE_JOB_FAIL, '作业删除失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '作业删除成功');
 }
Example #29
0
 public function act()
 {
     if (!$this->check_param('caseid')) {
         LF\V('Json.Base')->init(Const_Code::CASE_PARAM_ERROR, '用例传递参数错误');
         return;
     }
     $case_id = (int) Request::get_param('caseid', 'post');
     LF\M('Case')->remove($case_id);
     $case = LF\M('Case')->get_by_id($case_id);
     if ($case) {
         LF\V('Json.Base')->init(Const_Code::DELETE_CASE_FAIL, '用例删除失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '用例删除成功');
 }
Example #30
0
 public function act()
 {
     if (!$this->check_param('caseid')) {
         LF\V('Json.Base')->init(Const_Code::STEP_PARAM_ERROR, '步骤传递参数错误');
         return;
     }
     $case_id = (int) Request::get_param('caseid', 'post');
     LF\M('Step')->remove_by_case($case_id);
     $step = LF\M('Step')->get_by_case($case_id);
     if ($step) {
         LF\V('Json.Base')->init(Const_Code::DELETE_STEP_FAIL, '步骤删除失败');
         return;
     }
     LF\V('Json.Base')->init(Const_Code::SUCCESS, '步骤删除成功');
 }