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, '用户更新成功'); }
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); }
public function act() { $space_list = LF\M('Space')->get_all(); $view = LF\V('Html.Space.Index'); $view->add_data('space_list', $space_list); $view->init('Space.Index'); }
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) { } } }
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, '帐号验证通过'); }
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, '用户密码更新成功'); }
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); }
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); }
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)); }
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); }
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); }
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, '配置更新成功'); }
public function act() { $task_num = LF\M('Task')->get_count(); $view = LF\V('Html.Run.Index'); $view->add_data('page_num', ceil((int) $task_num['count'] / 10)); $view->init('Run.Index'); }
public function act() { $user_num = LF\M('User')->get_count(); $view = LF\V('Html.User.Index'); $view->add_data('page_num', ceil((int) $user_num['count'] / 10)); $view->init('User.Index'); }
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)); }
public function act() { $param_num = LF\M('Conf')->get_count_by_package(0, 'param'); $data_num = LF\M('Conf')->get_count_by_package(0, 'data'); $view = LF\V('Html.Conf.Index'); $view->add_data('param_num', (int) $param_num['count']); $view->add_data('data_num', (int) $data_num['count']); $view->add_data('page_num', ceil((int) $param_num['count'] / 10)); $view->init('Conf.Index'); }
public function set_system_param($subject, $package, $fliter) { preg_match_all('/\\$\\{param:(\\w+)\\}/', $subject, $matches); foreach (array_unique($matches[1]) as $match) { $config = LF\M('Conf')->get_by_keyword($package, 'param', $match); $config['value'] = isset($config['value']) ? $config['value'] : '[[ 配置不存在 ]]'; $replacement = $fliter ? str_replace('"', '\\"', $config['value']) : $config['value']; $subject = preg_replace('/\\$\\{param:' . $match . '\\}/', $replacement, $subject); } return $subject; }
public function act() { $package_list = LF\M('Package')->get_all(); foreach ($package_list as &$package) { $param_num = LF\M('Conf')->get_count_by_package((int) $package['id'], 'param'); $data_num = LF\M('Conf')->get_count_by_package((int) $package['id'], 'data'); $package['config_num']['param'] = (int) $param_num['count']; $package['config_num']['data'] = (int) $data_num['count']; } echo json_encode($package_list); }
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); }
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(); }
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)); }
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)); }
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); }
public function act() { if (!$this->check_param('smtpserver, smtpport')) { LF\V('Json.Base')->init(Const_Code::SYSTEM_PARAM_ERROR, '系统传递参数错误'); return; } $result = LF\M('System')->update(); if (is_null($result)) { LF\V('Json.Base')->init(Const_Code::UPDATE_SYSTEM_FAIL, '系统更新失败'); return; } LF\V('Json.Base')->init(Const_Code::SUCCESS, '系统更新成功'); }
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)); }
private function add_job($task_id) { if (LF\M('Job')->check_task_exists($task_id)) { return; } $_POST['taskid'] = $task_id; LF\M('Job')->insert(); $job = LF\M('Job')->get_by_task($task_id); if (!$job) { return; } LF\M('Task')->set_date($task_id); }
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, '步骤添加成功'); }
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)); }
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, '任务删除成功'); }
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']; }