| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- <?php
- class manageController extends Controller
- {
- public $initphp_list = array(
- 'top',
- 'left',
- 'login',
- 'logout',
- 'validcode',
- 'node',
- 'node_edit',
- 'user',
- 'ssh',
- 'code',
- 'del',
- 'showdata'
- );
- public function __construct()
- {
- parent::__construct();
- $this->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 "<pre>";
- foreach ($data as $k => $v) {
- echo $v['server']." response:<br>";
- $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 "</pre>";
- 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");
- }
- }
|