checkLogin(); } public function run() { $this->view->set_tpl("manage/index"); $this->view->assign("title", "ShadowSocks5管理后台"); $this->view->display(); } public function showdata() { $logs = $this->getLogsDao(); $data = $logs->getAll(); $china = array( 'bj' => '北京', 'tj' => '天津', 'hb' => '河北', 'shanxi' => '山西', 'nmg' => '内蒙古', 'liaoning' => '辽宁', 'jiling' => '吉林', 'hlj' => '黑龙江', 'shanghai' => '上海', 'shandong' => '山东', 'ah1' => '安徽', 'js2' => '江苏', 'zj3' => '浙江', 'fj4' => '福建', 'jx5' => '江西', 'henan' => '河南', 'hb1' => '湖北', 'hunan' => '湖南', 'guangdong' => '广东', 'guangxi' => '广西', 'hainan' => '海南', 'sx2' => '陕西', 'gs6' => '甘肃', 'nx7' => '宁夏', 'qh8' => '青海', 'xj9' => '新疆', 'cq11' => '重庆', 'sc21' => '四川', 'gz21' => '贵州', 'yn22' => '云南', 'xz33' => '西藏', 'tw44' => '台湾', 'xg55' => '香港', 'am66' => '澳门' ); $keys = array_keys($china); $value = array(); foreach ($keys as $k => $v) { $value[$v] = 0; } foreach ($china as $k => $v) { foreach ($data as $k1 => $v1) { if (strpos($v1['location'], $v) !== false) { $value[$k] ++; } } } $this->view->assign("china", $china); $this->view->assign("value", $value); $this->view->set_tpl("index/map"); $this->view->display(); } /** * 节点管理 */ public function node() { $node = $this->getNodeDao(); $nodelist = $node->getAllNode(); $this->view->assign("node", $nodelist); $this->view->set_tpl("manage/node"); $this->view->display(); // 模板展示 } /** * 批量执行命令管理 */ public function ssh() { if ($this->controller->get_gp("do") == "exec") { // 提交更新 set_time_limit(0); ignore_user_abort(); $server = $this->getServer(); $data = $server->getAll(); echo "
";
            foreach ($data as $k => $v) {
                echo $v['server']." response:
"; $ssh = $this->getssh(); $cmd = $this->controller->get_gp("cmd"); $status = $ssh->login($v['server'], $v['port'], 'root', $v['passwd']); if (!$status) { echo $v['server'].' connect fail!'; continue; } $str = $ssh->exec($cmd); echo $str . "\r\n\r\n\r\n"; $ssh->close(); } echo "
"; die(); } $this->view->set_tpl("manage/ssh"); $this->view->display(); // 模板展示 } public function node_edit() { $node = $this->getNodeDao(); $id = $this->controller->get_gp("id"); if ($this->controller->get_gp("do") == "update") { // 提交更新 $data = $this->controller->get_gp(array( 'node_name', 'node_type', 'node_server', 'node_method', 'node_info', 'node_status', 'node_order', 'idc_server', 'idc_url', 'api_veid', 'api_key' )); foreach ($data as $k => $v) { if ($v == "") { unset($data[$k]); } } $node->update($id, $data); JsMessage("更新成功!", '/manage/node'); die(); } $nodeData = $node->getNodeById($id); $this->view->assign("data", $nodeData); $this->view->set_tpl("manage/node_edit"); $this->view->display(); } /** * 用户管理 */ public function user() { $userService = self::getUserService(); $all = $userService->getAllTran(); $all = round($all / (1027 * 1024 * 1024), 2); $pager = self::getPagerLibrary(); $page = $this->controller->get_gp("page") ? $page = $this->controller->get_gp("page") : 1; $pernum = 10; $count = $userService->getCount(); $start = $pernum * ($page - 1); $url = "/manage/user"; $page_html = $pager->pager($count, $pernum, $url, $page, true); // 最后一个参数为true则使用默认样式 $userData = $userService->getUsers($pernum, $start); $this->view->assign("allTran", $all); $this->view->assign("user", $userData); $this->view->assign("pager", $page_html); $this->view->set_tpl("manage/user"); $this->view->display('', false); // 模板展示 } public function del() { $uid = $this->controller->get_gp("id"); $userService = self::getUserService(); if ($userService->delUser($uid)) { JsMessage("删除成功!"); } else { JsMessage("删除失败!"); } } /** * 邀请管理 */ public function code() { $do = $this->controller->get_gp("do"); if ($do == 'add') { $num = $this->controller->get_gp("num"); $pre = $this->controller->get_gp("pre"); $platform = $this->controller->get_gp("platform"); $user = $this->getUserService(); $result = $user->add($pre, $num,$platform); if ($result) { echo $result; // JsMessage("添加成功!", "/manage/user"); } } $this->view->set_tpl("/manage/node"); $this->view->display(); } /** * 用户列表 */ public function userlist() { $adminService = InitPHP::getService("user"); $pager = $this->getLibrary('pager'); $page = $this->controller->get_gp("page") ? $page = $this->controller->get_gp("page") : 1; $pernum = 30; $count = $adminService->getCount(); $start = $pernum * ($page - 1); $url = "userlist"; $page_html = $pager->pager($count, $pernum, $url, $page, true); // 最后一个参数为true则使用默认样式 $adminData = $adminService->getUsers($pernum, $start); $this->view->set_tpl("manage/userlist"); $this->view->assign("data", $adminData); $this->view->assign("pager", $page_html); $this->view->display('', false); } public function left() { $session = $this->getUtil('session'); $adminname = $session->get('adminname'); $config = InitPHP::getConfig(); $leftmenu = $config['menu']; $this->view->assign("menu", $leftmenu); $this->view->assign('admin', $adminname); $this->view->set_tpl("manage/left"); $this->view->display(); } public function top() { $session = $this->getUtil('session'); $adminid = $session->get('adminid'); if (empty($adminid)) { $this->view->set_tpl("manage/login"); } else { $this->view->assign('softid', $session->get('softid')); $this->view->set_tpl("manage/top"); $this->view->display(); // 模板展示 } } /** * 登陆 */ public function login() { $info = $this->controller->get_gp(array( 'username', 'password', 'validcode' )); if ($info['username']) { $session = $this->getUtil('session'); $code = $session->get('user_vaildcode_key'); if (strtolower(trim($code)) !== strtolower(trim($info['validcode']))) { JsMessage('验证码错了!'); die(); } else { $password = md5($info['password']); $admin = InitPHP::getService("admin"); $result = $admin->getOne($info['username']); if ($result) { if ($result['pass'] === $password) { $session->set('adminid', intval($result['uid'])); $session->set('adminname', htmlspecialchars($info['username'])); $function = $this->getLibrary("function"); $function->goto_url("/manage"); } else { JsMessage("密码错误!"); } } else { JsMessage("用户名不存在!"); } } } else { $this->view->set_tpl("manage/login"); $this->view->assign("title", "ShadowSocks5管理后台"); $this->view->display(); } } /** * 检查登陆状态 */ public function checkLogin() { $list = array( "login", "validcode" ); $session = $this->getUtil('session'); $adminid = $session->get('adminid'); $a = $this->getA(); if (! in_array($a, $list)) { if (empty($adminid)) { $function = $this->getLibrary('function'); $function->goto_url('/manage/login'); die(); } } } /** * * @return userService */ private function getUserService() { return InitPHP::getService("user"); } /** * * @return nodeDao */ private function getNodeDao() { return InitPHP::getDao("node"); } /** * * @return pagerInit */ private function getPagerLibrary() { return InitPHP::getLibrarys("pager"); } /** * 获取验证码函数 */ public function validcode() { $captcha = self::getCaptcha(); $code = $captcha->CreateCheckCode(); $session = $this->getUtil('session'); $session->set('user_vaildcode_key', $code); $captcha->OutCheckImage(); } /** * * @return captchaInit */ private function getCaptcha() { return InitPHP::getLibrarys("captcha"); } /** * * @return sshInit */ private function getssh() { return InitPHP::getLibrarys("ssh"); } /** * * @return sshDao */ private function getServer() { return InitPHP::getDao("ssh"); } /** * 退出后台 删除session */ public function logout() { $session = $this->getUtil('session'); $function = $this->getLibrary('function'); $session->clear(); $function->goto_url('/manage/login'); } /** * * @return logsDao */ private function getLogsDao() { return InitPHP::getDao("logs"); } }