Example #1
0
 /**
  * 发送邮件
  * 
  * $emailsend 用于发送信件的邮箱地址
  * $emailtype 发送类型 mail sendmail smtp (推荐sendmail)
  * $smtpport SMTP 端口号
  * $smtphost SMTP 主机
  * $smtpuser SMTP 账号
  * $smtppassword SMTP 密码
  * $from 发送邮件
  * $fromname 发件人名
  * $to 收件人邮箱
  * $subject 标题
  * $body 内容
  * 
  * Enter description here ...
  */
 public function send_mail()
 {
     $email_queue = $this->mEmailQueue->getEmailQueueDetail('eq.id', 'ASC');
     if (empty($email_queue)) {
         $this->errorOutput('error');
     }
     $smtp = array('from' => $email_queue['emailsend'], 'fromname' => $email_queue['fromname']);
     $emailtype = $email_queue['emailtype'];
     if ($emailtype == 'smtp') {
         $smtp['smtpauth'] = $email_queue['smtpauth'];
         $smtp['usessl'] = $email_queue['usessl'];
         $smtp['smtpport'] = $email_queue['smtpport'];
         $smtp['smtphost'] = $email_queue['smtphost'];
         $smtp['smtpuser'] = $email_queue['smtpuser'];
         $smtp['smtppassword'] = hg_encript_str($email_queue['smtppassword'], false);
         $smtp['from'] = $email_queue['fromemail'];
     }
     $to = $email_queue['toemail'];
     $subject = htmlspecialchars_decode($email_queue['subject']);
     $body = htmlspecialchars_decode($email_queue['body']);
     //发送邮件
     $ret_send_mail = $this->mEmail->send_mail($smtp, $to, $subject, $body, $emailtype);
     //删除队列
     $ret_deleteEmailQueue = $this->mEmailQueue->deleteEmailQueue($email_queue['id']);
     //记录日志
     $ret_editEmailSendLog = $this->mEmailLog->editEmailSendLog($email_queue['id'], $ret_send_mail);
     $this->addItem($ret_editEmailSendLog);
     $this->output();
 }
Example #2
0
 function show()
 {
     $where = ' WHERE status < ' . (TRY_TIMES - 1);
     $orderby = ' ORDER BY create_time ASC';
     $limit = ' limit 0, ' . ERROR_LIMIT;
     $sql = 'SELECT * FROM ' . DB_PREFIX . 'ftplog_error ' . $where . $orderby . $limit;
     $query = $this->db->query($sql);
     $server_id = array();
     $server_info = array();
     $error = array();
     $sync_id = array();
     $sync_info = array();
     while ($row = $this->db->fetch_array($query)) {
         $server_id[] = $row['server_id'];
         $error[$row['sync_id']][$row['id']] = $row['sfile'];
         $sync_id[] = $row['sync_id'];
     }
     if ($server_id) {
         $server_id = array_unique($server_id);
         $sql = 'SELECT * FROM ' . DB_PREFIX . 'ftpserver WHERE id IN(' . implode(',', $server_id) . ')';
         $query = $this->db->query($sql);
         while ($r = $this->db->fetch_array($query)) {
             $server_info[$r['id']] = array('hostname' => $r['hostname'], 'username' => $r['user'], 'password' => hg_encript_str($r['pass'], false), 'port' => $r['port']);
         }
     }
     if ($sync_id) {
         $sql = 'SELECT id,server_dir,app_dir,app,server_id FROM ' . DB_PREFIX . 'ftpsync WHERE id IN(' . implode(',', $sync_id) . ')';
         $query = $this->db->query($sql);
         while ($row = $this->db->fetch_array($query)) {
             $sync_info[$row['id']] = $row;
         }
     }
     //print_r($sync_info);
     if (!$error) {
         return;
     }
     foreach ($error as $syncid => $errorfile) {
         $config = $server_info[$sync_info[$syncid]['server_id']];
         $app = $sync_info[$syncid]['app'];
         if (!$config || !$app || !$errorfile) {
             return;
         }
         //
         $config['app_dir'] = $sync_info[$syncid]['app_dir'];
         $config['server_dir'] = $sync_info[$syncid]['server_dir'];
         $responce = $this->upload_app_files($app, $errorfile, $config);
         foreach ($errorfile as $kid => $file) {
             if ($responce['error'] == 4 && $responce['message'][$file]) {
                 //上传失败
                 $this->db->query('UPDATE ' . DB_PREFIX . 'ftplog_error SET status=status+1 WHERE id=' . $kid);
             } else {
                 $logadta = array('server_id' => $sync_info[$syncid]['server_id'], 'sync_id' => $syncid, 'app' => $app, 'sfile' => $file, 'dfile' => '', 'status' => 0, 'message' => '上传成功');
                 //成功入日志库
                 $this->log->create($logadta);
                 $this->db->query('DELETE FROM ' . DB_PREFIX . 'ftplog_error WHERE id =' . $kid);
             }
         }
     }
 }
Example #3
0
 public function detail()
 {
     $id = intval($this->input['id']);
     $sql = 'SELECT * FROM ' . DB_PREFIX . 'ftplog WHERE id = ' . $id;
     $data = $this->db->query_first($sql);
     $data['pass'] = hg_encript_str($data['pass'], false);
     $this->addItem($data);
     $this->output();
 }
Example #4
0
 protected function initdata()
 {
     if ($this->input['a'] == 'update') {
         foreach ($this->filed as $field => $must) {
             if ($must && !$this->input[$field]) {
                 $this->errorOutput("请检查必填项是否都已全部正确输入!" . $field);
             }
             $this->data[$field] = $this->input[$field];
         }
         $this->data['pass'] = hg_encript_str($this->data['pass']);
         $this->autofill();
     }
 }
Example #5
0
 public function detail($id)
 {
     if (!$id) {
         $condition = ' ORDER BY id DESC LIMIT 1';
     } else {
         $condition = ' WHERE id IN (' . $id . ')';
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "email_settings " . $condition;
     $row = $this->db->query_first($sql);
     if (is_array($row) && $row) {
         $row['create_time'] = date('Y-m-d H:i:s', $row['create_time']);
         $row['smtppassword'] = hg_encript_str($row['smtppassword'], false);
         return $row;
     }
     return false;
 }
Example #6
0
 /**
  * 发送邮件
  *
  * $emailsend 用于发送信件的邮箱地址
  * $emailtype 发送类型 mail sendmail smtp (推荐sendmail)
  * $smtpport SMTP 端口号
  * $smtphost SMTP 主机
  * $smtpuser SMTP 账号
  * $smtppassword SMTP 密码
  * $from 发送邮件
  * $fromname 发件人名
  * $to 收件人邮箱
  * $subject 标题
  * $body 内容
  *
  * Enter description here ...
  */
 public function send_mail()
 {
     $email_queue = $this->mEmailQueue->getEmailQueueDetail('eq.id', 'ASC');
     if (empty($email_queue)) {
         return 'Queue does not exist';
     }
     if ($this->sendtempRecord($email_queue['id'], 'select')) {
         return 'Queue is running';
     } else {
         if (!$this->sendtempRecord($email_queue['id'], 'insert')) {
             return 'Queue failed to run';
         }
     }
     $smtp = array('from' => $email_queue['emailsend'], 'fromname' => $email_queue['fromname']);
     $emailtype = $email_queue['emailtype'];
     if ($emailtype == 'smtp') {
         $smtp['smtpauth'] = $email_queue['smtpauth'];
         $smtp['usessl'] = $email_queue['usessl'];
         $smtp['smtpport'] = $email_queue['smtpport'];
         $smtp['smtphost'] = $email_queue['smtphost'];
         $smtp['smtpuser'] = $email_queue['smtpuser'];
         $smtp['smtppassword'] = hg_encript_str($email_queue['smtppassword'], false);
         $smtp['from'] = $email_queue['fromemail'];
     }
     $to = $email_queue['toemail'];
     $subject = htmlspecialchars_decode($email_queue['subject']);
     $body = htmlspecialchars_decode($email_queue['body']);
     //发送邮件
     $ret_send_mail = $this->mEmail->send_mail($smtp, $to, $subject, $body, $emailtype);
     if ($ret_send_mail == 1 || $email_queue['ret_send_mail'] >= 5) {
         //删除队列
         $ret_deleteEmailQueue = $this->mEmailQueue->deleteEmailQueue($email_queue['id']);
     } else {
         $this->mEmailQueue->editEmailQueue($email_queue['id'], $email_queue['ret_send_mail']);
     }
     //记录日志
     $ret_editEmailSendLog = $this->mEmailLog->editEmailSendLog($email_queue['id'], $ret_send_mail);
     $this->sendtempRecord($email_queue['id'], 'delete');
     //队列运行结束
     //if(!$this->sendtempRecord(0, 'select','COUNT(*)'))//内存回收
     //{
     //$this->sendtempRecord(0, 'truncate');
     //}
     return $ret_send_mail;
 }
Example #7
0
 function syntable()
 {
     $id = $this->input['id'];
     $table = array_keys($this->table);
     $sql = 'SELECT id,host,port,user,pass,`database`,`charset`,`pconnect` FROM ' . DB_PREFIX . 'login_server WHERE id IN(' . $id . ') AND status=1';
     $query = $this->db->query($sql);
     $db = array();
     while ($row = $this->db->fetch_array($query)) {
         $row['pass'] = hg_encript_str($row['pass'], false);
         $dbserver[] = $row;
     }
     //$this->errorOutput(var_export($dbserver,1));
     $table_struct = array();
     $data = array();
     if (!$dbserver) {
         $this->errorOutput("没有可同步服务器");
     }
     foreach ($table as $name) {
         $t = $this->db->query_first('SHOW CREATE TABLE ' . $name);
         $table_struct[$name] = $t['Create Table'];
         if ($this->table[$name] == 2) {
             $table_struct[$name] = str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $table_struct[$name]);
         }
         if ($this->table[$name] == 1) {
             $sql = 'SELECT * FROM ' . $name;
             $query = $this->db->query($sql);
             $data[$name] = 'INSERT INTO ' . $name . ' VALUES ';
             while ($row = $this->db->fetch_array($query)) {
                 $data[$name] .= "('" . implode("','", $row) . "'),";
             }
             $data[$name] = trim($data[$name], ',');
         }
     }
     include_once ROOT_PATH . 'lib/db/db_mysql.class.php';
     $ServDB = new db();
     foreach ($dbserver as $server) {
         $ServDB->connect($server['host'], $server['user'], $server['pass'], $server['database'], $server['charset'], $server['pconnect']);
         foreach ($table_struct as $tn => $ts) {
             ////删除原表
             //$ServDB->query('DROP TABLE  IF EXISTS '.$tn.';');
             if ($this->table[$tn] == 3 || $this->table[$tn] == 1) {
                 $ServDB->query('DROP TABLE  IF EXISTS ' . $tn . ';');
             }
             //创建表
             $ServDB->query($ts);
             //插入数据
             if ($this->table[$tn] == 1) {
                 $ServDB->query($data[$tn]);
             }
         }
         $ServDB->close();
     }
     $this->addItem($dbserver);
     $this->output();
 }
Example #8
0
 public function add_dbserver()
 {
     $db = $_REQUEST['db'];
     $link = @mysql_connect($db['host'], $db['user'], $db['pass']);
     if (!$link) {
         $message = '此数据库服务器无法连接,请确认信息是否准确';
         $this->redirect($message, 0, 0, '', "hg_add_dbservererr_back('{$message}')");
     }
     $db['pass'] = hg_encript_str($db['pass']);
     $db_data = json_encode($db);
     $sql = 'INSERT INTO ' . DB_PREFIX . "server (name, brief, ip, outip, type, more_data,create_time) VALUES \r\n\t\t\t\t('{$db['name']}', '', '{$db['host']}', '', 'db', '{$db_data}', " . TIMENOW . ")";
     $this->db->query($sql);
     $id = $this->db->insert_id();
     $this->redirect('数据库服务器添加成功', 0, 0, '', "hg_add_dbserver_back({$id}, '{$db['name']}_{$db['host']}')");
 }
Example #9
0
function step7()
{
    $user_name = trim($_REQUEST['user_name']);
    $password = trim($_REQUEST['password']);
    $confirmpassword = trim($_REQUEST['confirmpassword']);
    if (!$user_name) {
        $message = '请设置用户名';
        step6($message);
    }
    if (!$password || $confirmpassword != $password) {
        $message = '未设置密码或两次密码不一致';
        step6($message);
    }
    $app = file_get_contents(CACHE_DIR . 'app.tmp');
    $app = json_decode($app, 1);
    $db = file_get_contents(CACHE_DIR . 'db.tmp');
    $db = json_decode($db, 1);
    $auth = @file_get_contents(CACHE_DIR . 'auth.tmp');
    $auth = json_decode($auth, 1);
    $socket = new hgSocket();
    $con = $socket->connect($app['ip'], $app['port']);
    if (!intval($con)) {
        step6('安装无法完成,服务器无法连接,请确认服务器ip是否正确或服务程序hogeMonitor.py是否监听在' . $app['ip'] . ':' . $app['port'] . '上');
    }
    $socket->close();
    $password = md5($password);
    $content = get_serv_file($app, $app['dir'] . 'conf/config.php');
    $string = "\$gGlobalConfig['admin_user'] = array(\n'{$user_name}'     => '{$password}',\n);";
    $content = preg_replace("/\\?>/is", "\n{$string}\n?>", $content);
    write_serv_file($app, $app['dir'] . 'conf/config.php', $content, 'utf8');
    hg_run_cmd($app, 'runcmd', 'chmod -Rf 777 ' . $app['dir'] . 'cache/ ' . $app['dir'] . 'conf/config.php');
    if ($db) {
        $pass = hg_encript_str($db['pass'], false, $auth['appkey']);
        $link = mysql_connect($db['host'], $db['user'], $pass);
        mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $link);
        mysql_select_db($db['database'], $link);
        $db_data = json_encode($db);
        $app_data = json_encode($app);
        $sql = 'INSERT INTO ' . $db['dbprefix'] . "server (name, brief, ip, outip, type, more_data,create_time) VALUES \n\t\t\t\t('app数据库服务器', '', '{$db['host']}', '', 'db', '{$db_data}', " . time() . ");\n\t\t\t\t";
        mysql_query($sql, $link);
        $sql = 'INSERT INTO ' . $db['dbprefix'] . "server (name, brief, ip, outip, type, more_data,create_time) VALUES \n\t\t\t\t('app服务器', '', '{$app['ip']}', '{$app['outip']}', 'app', '{$app_data}', " . time() . ");\n\t\t\t\t";
        mysql_query($sql, $link);
        $server_id = mysql_insert_id();
        $sql = 'INSERT INTO ' . $db['dbprefix'] . "server_domain (server_id, domain, dir, create_time) VALUES \n\t\t\t\t('{$server_id}', '{$app['domain']}', '{$app['dir']}', " . time() . ");\n\t\t\t\t";
        mysql_query($sql, $link);
    }
    $appstore = new curl('appstore.hogesoft.com:233', '');
    $appstore->mAutoInput = false;
    $appstore->setClient(CUSTOM_APPID, CUSTOM_APPKEY);
    $appstore->initPostData();
    $appstore->addRequestData('a', 'installed');
    $appstore->addRequestData('app', 'livworkbench');
    $appstore->request('index.php');
    header('Location:' . '?action=complete');
}
Example #10
0
 public function check_pgerp($server, $name)
 {
     $cmd = array('action' => 'pgrep', 'para' => $name, 'user' => $server['user'], 'pass' => hg_encript_str($server['password'], 0), 'charset' => 'utf8');
     $sock = new hgSocket();
     if (!($status = $sock->connect($server['ip'], $server['port']))) {
         $this->errorOutput('未连接上服务器,请检查python有没有启动');
     }
     $source = $sock->sendCmd($cmd);
     if (!$source) {
         $this->errorOutput('发送数据有问题');
     }
     $status = $sock->readall();
     return $status ? 1 : 2;
 }
Example #11
0
 public function access($cloud = array(), $get_user = false, $field = 'access_token')
 {
     $url = ltrim($cloud['authapi'], 'http://');
     $url = rtrim($cloud['authapi'], '/');
     $url = 'http://' . $url . '/' . 'get_access_token.php';
     //hg_pre(hg_encript_str($cloud['pwd'],false));exit;
     if (!$get_user) {
         $data = array('appid' => $cloud['appid'], 'appkey' => $cloud['appkey'], 'username' => $cloud['username'], 'password' => hg_encript_str($cloud['pwd'], false), 'a' => 'show');
     } else {
         $data = array('appid' => $cloud['appid'], 'appkey' => $cloud['appkey'], 'access_token' => $cloud['access_token'], 'a' => 'get_user_info');
     }
     $data_str = '';
     foreach ($data as $k => $v) {
         if (!$v) {
             continue;
         }
         $data_str .= $k . '=' . $v . '&';
     }
     $data_str = rtrim($data_str, '&');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str);
     $response = curl_exec($ch);
     curl_close($ch);
     //关闭
     $response = json_decode($response, 1);
     if ($response['ErrorCode']) {
         if ($response['ErrorCode'] == 'NO_ACCESS_TOKEN') {
             //防止循环
             $this->request_times++;
             if ($this->request_times > 3) {
                 $this->cloud_error('请求超出最大次数');
             }
             $response[0] = $this->access($cloud, false, $field);
         } else {
             $this->cloud_error($response['ErrorCode'] . $response['ErrorText']);
         }
     }
     $response = $response[0];
     if (!$get_user || $this->request_times) {
         $this->db->query('UPDATE ' . DB_PREFIX . 'cloud SET ' . $field . '="' . $response['token'] . '" WHERE cloud_id=' . intval($cloud['cloud_id']));
     }
     return $response;
 }
Example #12
0
 public function show()
 {
     $callback = urldecode(trim($this->input['verify_user_cb']));
     $time_expired = defined('TOKEN_EXPIRED') ? intval(TOKEN_EXPIRED + TIMENOW) : intval(3600 + TIMENOW);
     if (!$callback) {
         $this->db = hg_ConnectDB();
         $userinfo = $this->mcp_dologin();
         if (!$userinfo) {
             $userinfo = $this->member_dologin();
             if (!$userinfo) {
                 $this->errorOutput(USER_LOGIN_ERROR);
             }
             $group_type = 9999999999;
         } else {
             if ($userinfo['forced_change_pwd']) {
                 $this->addItem($userinfo);
                 $this->output();
             }
             //5游客
             $group_type = intval(min(explode(',', $userinfo['admin_role_id'])));
             if (!$group_type) {
                 $group_type = 9999999999;
             }
         }
         $appinfo = $this->verify_appkey($this->input['appid'], $this->input['appkey']);
         $accesstoken = $this->mk_access_token(0);
         //入user_login表数据
         $data = array('ip' => hg_getip(), 'user_name' => urldecode($userinfo['user_name']), 'user_id' => intval($userinfo['id']), 'login_time' => TIMENOW, 'token' => $accesstoken, 'appid' => intval($appinfo['appid']), 'group_type' => $group_type, 'display_name' => $appinfo['display_name'] ? $appinfo['display_name'] : $appinfo['custom_name'], 'visit_client' => $appinfo['mobile'], 'org_id' => $userinfo['org_id'], 'slave_group' => $userinfo['admin_role_id'], 'slave_org' => $userinfo['childs'], 'is_member' => $userinfo['is_member']);
         $sql = 'INSERT INTO ' . DB_PREFIX . 'user_login SET ';
         foreach ($data as $field => $value) {
             $sql .= "{$field} = '{$value}',";
         }
         $this->db->query(trim($sql, ','));
         //获取用户头像
         $avatar = unserialize($userinfo['avatar']) ? unserialize($userinfo['avatar']) : '';
         //登陆返回的数据 纪录session
         $reUserInfo = array('token' => $data['token'], 'appid' => $data['appid'], 'display_name' => $data['display_name'], 'app_expire_time' => $appinfo['expire_time'], 'user_name' => $userinfo['user_name'], 'group_type' => $group_type, 'password' => $userinfo['password'], 'id' => $userinfo['id'], 'verify_code' => $userinfo['verify_code'], 'visit_client' => $appinfo['mobile'], 'group_name' => $userinfo['role_name'], 'org_name' => $userinfo['org_name'], 'org_id' => $userinfo['org_id'], 'slave_org' => $userinfo['childs'], 'avatar' => $avatar, 'default_page' => $userinfo['index_page'], 'open_way' => $userinfo['open_way'], 'domain' => $userinfo['domain'], 'app_custom_menus' => $userinfo['app_unique'], 'cardid' => $userinfo['cardid'], 'prms_menus' => $userinfo['prms_menus'], 'expired_time' => $time_expired, 'is_member' => $data['is_member']);
         if ($reUserInfo['id'] > 0 && ($this->input['isextend'] || defined('IS_EXTEND') && IS_EXTEND)) {
             $reUserInfo['extend'] = $this->getUserExtendInfo($reUserInfo['id']);
         }
         $this->addItem($reUserInfo);
         //$token_expired = defined('TOKEN_EXPIRED') ? TOKEN_EXPIRED : 3600;
         $this->output();
     } else {
         $extend = urldecode($this->input['extend']);
         $user = array('user_name' => $this->input['user_name'], 'password' => $this->input['password']);
         $extend = explode('&', $extend);
         foreach ($extend as $v) {
             $v = explode('=', $v);
             if ($v[0]) {
                 $user[$v[0]] = $v[1];
             }
         }
         $userinfo = $this->post(urldecode($callback), $user);
         $userinfo = $userinfo[0];
         if (!$userinfo['user_id']) {
             $this->erroroutput(USER_VERIFY_FAIL);
         }
         $servers = hg_load_login_serv();
         if (!$servers) {
             $server_index = -1;
             $this->db = hg_ConnectDB();
         } else {
             include_once ROOT_PATH . 'lib/db/db_mysql.class.php';
             $server_index = $userinfo['user_id'] % count($servers);
             $server = $servers[$server_index];
             $server['pass'] = hg_encript_str($server['pass'], false);
             $this->db = new db();
             $conn = $this->db->connect($server['host'], $server['user'], $server['pass'], $server['database'], $server['charset'], $server['pconnect']);
             if (!$conn) {
                 $this->erroroutput(LOGIN_SERVER_ERROR);
             }
             $server['database'] = $server['database'] . '.';
         }
         $appinfo = $this->verify_appkey($this->input['appid'], $this->input['appkey']);
         $group_type = 999999999;
         $accesstoken = $this->mk_access_token($server_index + 1);
         $data = array('ip' => hg_getip(), 'user_name' => urldecode($userinfo['user_name']), 'user_id' => intval($userinfo['user_id']), 'login_time' => TIMENOW, 'token' => $accesstoken, 'appid' => intval($appinfo['appid']), 'group_type' => $group_type, 'display_name' => $appinfo['display_name'] ? $appinfo['display_name'] : $appinfo['custom_name'], 'visit_client' => $appinfo['mobile'], 'org_id' => $userinfo['org_id'], 'slave_group' => $userinfo['admin_role_id'], 'slave_org' => $userinfo['childs'], 'is_member' => 1);
         $sql = 'INSERT INTO ' . $server['database'] . DB_PREFIX . 'user_login SET ';
         foreach ($data as $field => $value) {
             $sql .= "{$field} = '{$value}',";
         }
         $this->db->query(trim($sql, ','));
         $userinfo['token'] = $accesstoken;
         $userinfo['appid'] = $data['appid'];
         $userinfo['display_name'] = $data['display_name'];
         $userinfo['visit_client'] = $data['visit_client'];
         $userinfo['login_time'] = $data['login_time'];
         $userinfo['expired_time'] = $time_expired;
         $userinfo['is_member'] = $data['is_member'];
         if ($userinfo['user_id'] > 0 && ($this->input['isextend'] || defined('IS_EXTEND') && IS_EXTEND)) {
             $userinfo['extend'] = $this->getUserExtendInfo($userinfo['user_id']);
         }
         $this->addItem($userinfo);
         $this->output();
     }
 }
Example #13
0
 public function show_opration()
 {
     if (!$this->input['id']) {
         $this->errorOutput(NOID);
     }
     $sql = " SELECT * FROM " . DB_PREFIX . "server WHERE id = '" . intval($this->input['id']) . "'";
     $server = $this->db->query_first($sql);
     $cmd = array('action' => 'top', 'user' => $server['user'], 'pass' => hg_encript_str($server['password'], 0), 'charset' => 'utf8');
     $sock = new hgSocket();
     if (!($status = $sock->connect($server['ip'], $server['port']))) {
         $this->errorOutput('未连接上服务器,请检查python有没有启动');
     }
     $sock->sendCmd($cmd);
     $configs = $sock->readall();
     if ($this->input['replace']) {
         $this->addItem($configs);
     } else {
         $cmd2 = array('action' => 'df', 'para' => '-h', 'user' => $server['user'], 'pass' => hg_encript_str($server['password'], 0), 'charset' => 'utf8');
         $sock2 = new hgSocket();
         if (!($status = $sock2->connect($server['ip'], $server['port']))) {
             $this->errorOutput('未连接上服务器,请检查python有没有启动');
         }
         $sock2->sendCmd($cmd2);
         $df = $sock2->readall();
         $this->addItem(array('config' => $configs, 'id' => intval($this->input['id']), 'df' => $df));
     }
     $this->output();
 }
Example #14
0
 function show()
 {
     $limit = ' LIMIT 0, 10';
     $sql = 'SELECT * FROM  ' . DB_PREFIX . 'ftpfile_del';
     $sql = $sql . $limit;
     $query = $this->db->query($sql);
     $files = array();
     while ($row = $this->db->fetch_array($query)) {
         $files[$row['app']][$row['id']] = array('fp' => $row['filepath'], 'pt' => $row['pathtype']);
     }
     if (!$files) {
         return;
     }
     $apps = @array_keys($files);
     if (!$apps) {
         return;
     }
     $sql = 'SELECT server_id,server_dir,app_dir,app FROM ' . DB_PREFIX . 'ftpsync WHERE app = "' . implode('","', $apps) . '"';
     $query = $this->db->query($sql);
     $server_id = array();
     $server_info = array();
     $sync_info = array();
     while ($row = $this->db->fetch_array($query)) {
         $server_id[] = $row['server_id'];
         $sync_info[$row['app']][] = $row;
     }
     if ($server_id) {
         $server_id = array_unique($server_id);
         $sql = 'SELECT * FROM ' . DB_PREFIX . 'ftpserver WHERE id IN(' . implode(',', $server_id) . ')';
         $query = $this->db->query($sql);
         while ($r = $this->db->fetch_array($query)) {
             $server_info[$r['id']] = array('hostname' => $r['hostname'], 'username' => $r['user'], 'password' => hg_encript_str($r['pass'], false), 'port' => $r['port']);
         }
     }
     foreach ($files as $app => $filepath) {
         if (!$filepath) {
             return;
         }
         if (empty($sync_info[$app])) {
             return;
         }
         foreach ($sync_info[$app] as $sinfo) {
             $config = $server_info[$sinfo['server_id']];
             if (!$config) {
                 continue;
             }
             //$config['server_dir'] = $sinfo['server_dir'];
             $this->ftp->connect($config);
             foreach ($filepath as $kid => $fl) {
                 $this->db->query('DELETE FROM  ' . DB_PREFIX . 'ftpfile_del WHERE id=' . $kid);
                 $server_dir = trim($sinfo['server_dir'], '/') . '/';
                 //绝对路径
                 if ($fl['pt']) {
                     $fl['fp'] = str_replace($sinfo['app_dir'], '', $fl['fp']);
                 }
                 if ($server_dir) {
                     $fl['fp'] = $server_dir . $fl['fp'];
                 }
                 $this->ftp->delete_file($fl['fp']);
             }
             $this->ftp->close();
         }
     }
 }
Example #15
0
 public function exec_cmd()
 {
     if (!$this->input['id']) {
         $this->errorOutput(NOID);
     }
     if (!$this->input['serverid']) {
         $this->errorOutput(NOID);
     }
     $cmd = array('stop', 'start', 'restart');
     $cmd_field = array('stop_cmd', 'start_cmd', 'restart_cmd');
     $sql = "SELECT * FROM " . DB_PREFIX . "services WHERE id = '" . intval($this->input['id']) . "'";
     $arr = $this->db->query_first($sql);
     $sql = " SELECT * FROM " . DB_PREFIX . "server WHERE id = '" . intval($this->input['serverid']) . "'";
     $server = $this->db->query_first($sql);
     $cmd = array('action' => $cmd[intval($this->input['cmd'])], 'para' => $arr[$cmd_field[$this->input['cmd']]], 'user' => $server['user'], 'pass' => hg_encript_str($server['password'], 0), 'charset' => 'utf8');
     $sock = new hgSocket();
     if (!($status = $sock->connect($server['ip'], $server['port']))) {
         $this->errorOutput('未连接上服务器,请检查python有没有启动');
     }
     $sock->sendCmd($cmd);
     $this->addItem('success');
     $this->output();
 }
Example #16
0
 public function update()
 {
     $id = $this->input['id'];
     if (!$id) {
         $this->ReportError('指定记录不存在或已删除!');
     }
     $name = trim($this->input['name']);
     if (!$name) {
         $this->form('请填写名称');
     }
     $data = array('name' => $name, 'custom_appkey' => trim(urldecode($this->input['custom_appkey'])), 'appid' => intval($this->input['appid']), 'appkey' => trim(urldecode($this->input['appkey'])), 'username' => trim(urldecode($this->input['username'])), 'pwd' => hg_encript_str(trim(urldecode($this->input['pwd'])), true, trim($this->input['custom_appkey'])), 'localusername' => trim(urldecode($this->input['localusername'])), 'localuserpwd' => hg_encript_str(trim(urldecode($this->input['localuserpwd']))), 'authapi' => trim(urldecode($this->input['authapi'])), 'is_close' => intval($this->input['is_close']));
     hg_fetch_query_sql($data, 'cloud_site', 'id=' . $id);
     $this->cache->recache('cloud_site');
     $this->redirect('更新成功', '?pp');
 }
Example #17
0
 public function update()
 {
     if ($this->mNeedCheckIn && !$this->prms['manage']) {
         $this->errorOutput(NO_OPRATION_PRIVILEGE);
     }
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('未传入ID');
     }
     $name = trim($this->input['name']);
     if (!$name) {
         $this->errorOutput('名称不能为空');
     }
     $appuniqueid = trim($this->input['appuniqueid']);
     if (!$appuniqueid) {
         $this->errorOutput('请选择应用标识');
     }
     if ($appuniqueid != trim($this->input['old_appuniqueid']) && $this->mEmailSettings->check_appuniqueid_exists($appuniqueid)) {
         $this->errorOutput($appuniqueid . ' 标识已被占用');
     }
     $emailsend = trim($this->input['emailsend']);
     if (!$emailsend) {
         $this->errorOutput('邮箱地址不能为空');
     }
     $emailwrapbracket = intval($this->input['emailwrapbracket']);
     $smtpauth = intval($this->input['smtpauth']);
     $smtphost = trim($this->input['smtphost']);
     $smtpport = intval($this->input['smtpport']);
     $fromname = trim($this->input['fromname']);
     $smtpuser = trim($this->input['smtpuser']);
     $smtppassword = trim($this->input['smtppassword']);
     if ($smtppassword) {
         $smtppassword = hg_encript_str($smtppassword);
     }
     $brief = trim($this->input['brief']) == '这里输入描述' ? '' : trim($this->input['brief']);
     $data = array('name' => $name, 'brief' => $brief, 'appuniqueid' => $appuniqueid, 'emailsend' => $emailsend, 'emailwrapbracket' => $emailwrapbracket, 'emailtype' => trim($this->input['emailtype']), 'usessl' => trim($this->input['usessl']), 'smtpauth' => $smtpauth, 'smtphost' => $smtphost, 'smtpport' => $smtpport ? $smtpport : 25, 'fromname' => $fromname ? $fromname : '管理员', 'smtpuser' => $smtpuser, 'smtppassword' => $smtppassword, 'email_footer' => $this->settings['email_settings']['email_footer']);
     $htmlheader = '';
     $htmlfooter = '';
     $is_head_foot = intval($this->input['is_head_foot']);
     if ($is_head_foot) {
         $header = trim($this->input['header']);
         $footer = trim($this->input['footer']);
         if (!$header || !$footer) {
             $this->errorOutput('邮件头尾不能为空');
         }
         if (get_magic_quotes_gpc()) {
             $htmlheader = stripslashes($header);
             $htmlfooter = stripslashes($footer);
         } else {
             $htmlheader = $header;
             $htmlfooter = $footer;
         }
     }
     $info = $this->mEmailSettings->update($id, $data, $is_head_foot, $htmlheader, $htmlfooter);
     $this->addItem($info);
     $this->output();
 }
Example #18
0
 public function update()
 {
     if (!$this->input['id']) {
         $this->errorOutput(NOID);
     }
     $fields = ' SET  ';
     if ($this->input['name']) {
         $sql = " SELECT count(*) as total FROM " . DB_PREFIX . "server WHERE name = '" . urldecode($this->input['name']) . "' AND id != '" . intval($this->input['id']) . "'";
         $arr = $this->db->query_first($sql);
         if (intval($arr['total']) >= 1) {
             $this->errorOutput('服务器已经存在');
         }
         $fields .= '  name = \'' . urldecode($this->input['name']) . '\',';
     } else {
         $this->errorOutput('服务器名称不能为空');
     }
     if ($this->input['uniqueid']) {
         $sql = " SELECT count(*) as total FROM " . DB_PREFIX . "server WHERE uniqueid = '" . urldecode($this->input['uniqueid']) . "' AND id != '" . intval($this->input['id']) . "'";
         $arr = $this->db->query_first($sql);
         if (intval($arr['total']) >= 1) {
             $this->errorOutput('标识已经存在');
         }
         $fields .= '  uniqueid = \'' . urldecode($this->input['uniqueid']) . '\',';
     } else {
         $this->errorOutput('标识不能为空');
     }
     if ($this->input['ip']) {
         if (!hg_checkip(urldecode($this->input['ip']))) {
             $this->errorOutput('ip有误');
         }
         $fields .= '  ip = \'' . urldecode($this->input['ip']) . '\',';
     }
     if ($this->input['outside_ip']) {
         if (!hg_checkip(urldecode($this->input['outside_ip']))) {
             $this->errorOutput('外网ip有误');
         }
         $fields .= '  outside_ip = \'' . urldecode($this->input['outside_ip']) . '\',';
     }
     if ($this->input['port']) {
         $fields .= '  port = \'' . intval($this->input['port']) . '\',';
     }
     if ($this->input['user']) {
         $fields .= '  user = \'' . urldecode($this->input['user']) . '\',';
     }
     if ($this->input['password']) {
         $fields .= '  password = \'' . hg_encript_str(urldecode($this->input['password'])) . '\',';
     }
     if ($this->input['iscur']) {
         $fields .= '  iscur = 1,';
     } else {
         $fields .= '  iscur = 0,';
     }
     $fields .= '  update_time = \'' . TIMENOW . '\'';
     $sql = "UPDATE " . DB_PREFIX . 'server ' . $fields . '  WHERE  id = ' . intval($this->input['id']);
     $this->db->query($sql);
     //返回数据
     $sql = "SELECT * FROM " . DB_PREFIX . "server WHERE id = '" . intval($this->input['id']) . "'";
     $ret = $this->db->query_first($sql);
     $ret['password'] = hg_encript_str($ret['password'], 0);
     $this->addItem($ret);
     $this->output();
 }
Example #19
0
 function show()
 {
     //从队列中读取需要同步的服务器信息
     $sql = 'SELECT fq.*,fse.hostname,fse.user,fse.pass,fse.port,fsy.max_number,fsy.server_id,fsy.allow_ftype,fsy.server_dir,fsy.app,fsy.app_dir,fsy.setinterval FROM ' . DB_PREFIX . 'ftpqueue fq LEFT JOIN ' . DB_PREFIX . 'ftpsync fsy ON fq.sync_id=fsy.id LEFT JOIN ' . DB_PREFIX . 'ftpserver fse ON fsy.server_id=fse.id';
     $where = ' WHERE fq.run_time = ' . floor(TIMENOW / 60) . ' AND fq.status > 0 AND is_stop = 0';
     $sql = $sql . $where;
     $query = $this->db->query($sql);
     $queues = array();
     while ($row = $this->db->fetch_array($query)) {
         $queues[$row['status']][] = $row;
         $update_run_time_sql = 'UPDATE ' . DB_PREFIX . 'ftpqueue SET run_time=run_time+' . $row['setinterval'] . ' WHERE id=' . $row['id'];
         $this->db->query($update_run_time_sql);
     }
     $update_run_time_sql = '';
     //初次建立索引文件
     if ($queues[1]) {
         foreach ($queues[1] as $v) {
             $files = $this->create_file_index($v['app'], $v['app_dir'], $v['allow_ftype']);
             if ($files && $this->create_index($v['sync_id'], $files)) {
                 $this->db->query('UPDATE ' . DB_PREFIX . 'ftpqueue SET status = 2 WHERE sync_id = ' . $v['sync_id']);
             }
         }
     }
     //获取修改或者新增的文件
     if ($queues[2]) {
         foreach ($queues[2] as $r) {
             $sql = 'SELECT * FROM ' . DB_PREFIX . 'ftpfile_index WHERE sync_id = ' . $r['sync_id'];
             $limit = ' LIMIT 0,' . $r['max_number'];
             $orderby = ' ORDER BY id ASC ';
             $sql = $sql . $orderby . $limit;
             $query = $this->db->query($sql);
             $files = array();
             while ($row = $this->db->fetch_array($query)) {
                 $files[$row['id']] = $row['filepath'];
             }
             if ($files) {
                 $config = array('hostname' => $r['hostname'], 'username' => $r['user'], 'password' => hg_encript_str($r['pass'], false), 'port' => $r['port'], 'server_dir' => $r['server_dir'], 'app_dir' => $r['app_dir']);
                 $responce = $this->upload_app_files($r['app'], $files, $config);
                 print_r($responce);
                 if ($responce['error'] && $responce['error'] != 4) {
                     $logadta = array('sync_id' => $r['sync_id'], 'server_id' => $r['server_id'], 'app' => $r['app'], 'sfile' => '', 'dfile' => '', 'status' => $responce['error'], 'message' => $responce['message']);
                     $this->log->create($logadta);
                 } else {
                     foreach ($files as $kid => $fl) {
                         $logadta = array('sync_id' => $r['sync_id'], 'server_id' => $r['server_id'], 'app' => $r['app'], 'sfile' => $fl, 'dfile' => '', 'status' => 0);
                         if ($responce['error'] == 4 && $responce['message'][$fl]) {
                             //上传失败
                             $logadta['dfile'] = $responce['message'][$fl];
                             $logadta['status'] = -1;
                             $this->log->create_error($logadta);
                         } else {
                             $logadta['message'] = '上传成功';
                             $this->log->create($logadta);
                         }
                         //成功与否都删除
                         $del_file_sql = 'DELETE FROM ' . DB_PREFIX . 'ftpfile_index WHERE id=' . $kid;
                         $this->db->query($del_file_sql);
                     }
                 }
             }
             //查找新增或者修改的文件
             $app_files = $this->create_file_index($r['app'], $r['app_dir'], $r['allow_ftype'], $r['setinterval']);
             $this->create_index($r['sync_id'], $app_files);
         }
     }
 }
Example #20
0
 /**
  *
  * 强制用户退出,非管理员角色使用需要赋予权限应用的“强制退出”权限 ...
  * @param user_id 强制退出用户ID
  * @param is_member 是否会员用户
  * 
  */
 public function force_logout_user()
 {
     $this->verify_content_prms(array('_action' => 'force_logout_user'));
     $userId = (int) $this->input['user_id'];
     !($userId > 0) && $this->errorOutput(NO_USER_ID);
     $isMember = isset($this->input['is_member']) && $this->input['is_member'] ? 1 : 0;
     $databasename = '';
     $servers = hg_load_login_serv();
     if (!$servers || !$isMember) {
         $newdb = hg_ConnectDB();
     } elseif ($servers && $isMember) {
         $server_index = $userId % count($servers);
         $server = $servers[$server_index];
         if ($server) {
             class_exists('db', false) or (include ROOT_PATH . 'lib/db/db_mysql.class.php');
             $server['pass'] = hg_encript_str($server['pass'], false);
             $newdb = new db();
             $newdb->connect($server['host'], $server['user'], $server['pass'], $server['database'], $server['charset'], $server['pconnect']);
             $databasename = $server['database'] . '.';
         } else {
             $newdb = hg_ConnectDB();
         }
     }
     $sql = 'DELETE FROM ' . $databasename . DB_PREFIX . 'user_login WHERE user_id = "' . $userId . '" AND is_member = ' . $isMember;
     $redata = array('status' => 0, 'user_id' => $userId, 'is_member' => $isMember, 'copywriting' => 'UserID = ' . $userId . '的TOKEN清除失败');
     $query = $newdb->query($sql);
     if ($query && $newdb->affected_rows()) {
         $redata['status'] = 1;
         $redata['copywriting'] = 'UserID = ' . $userId . '的TOKEN清除成功';
     } elseif ($query) {
         $redata['copywriting'] = 'UserID = ' . $userId . '的用户未登录';
     }
     $this->addItem($redata);
     $this->output();
 }
Example #21
0
 public function get_dir()
 {
     if (!$this->input['server_id'] || intval($this->input['server_id']) == -1) {
         $this->errorOutput('请选择一台服务器');
     }
     $dir = $this->input['dir'] ? $this->input['dir'] : '/';
     $sql = " SELECT * FROM " . DB_PREFIX . "server WHERE id = '" . intval($this->input['server_id']) . "'";
     $server = $this->db->query_first($sql);
     $cmd = array('action' => 'ls', 'para' => $dir, 'user' => $server['user'], 'pass' => hg_encript_str($server['password'], 0), 'charset' => 'utf8');
     $sock = new hgSocket();
     if (!($status = $sock->connect($server['ip'], $server['port']))) {
         $this->errorOutput('未连接上服务器,请检查python有没有启动');
     }
     $sock->sendCmd($cmd);
     $dir_content = $sock->readall();
     $dir_arr = explode("\n", trim($dir_content));
     $this->addItem($dir_arr);
     $this->output();
 }
Example #22
0
$curl->addRequestData('app', $install_app);
$ret = $curl->request('db.php');
$appdb = $ret;
if (!$appinfo['nodb']) {
    if ($appdb['app']) {
        if (!$dbserver) {
            $this->install('请指定数据库位置');
        }
        if (!$database) {
            $this->install('请设定数据库名');
        }
        if (!$servers[$dbserver]) {
            $this->install('所选数据库服务器不存在');
        }
        $db = json_decode($servers[$dbserver]['more_data'], 1);
        $db['pass'] = hg_encript_str($db['pass'], false);
        $link = @mysql_connect($db['host'], $db['user'], $db['pass']);
        if (!$link) {
            $message = '此数据库服务器无法连接,请确认信息是否准确';
            $this->install($message);
        }
        mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $link);
        $sql = "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME='{$database}'";
        $q = mysql_query($sql, $link);
        $dbexist = mysql_fetch_array($q);
        if (!$cover) {
            if ($dbexist) {
                $message = $database . '数据库已存在,您可以勾选覆盖数据库';
                $this->install($message);
            }
        }
Example #23
0
 function ping_db_server($server_info)
 {
     if (@mysql_connect($server_info['site_name'] . ':' . $server_info['port'], $server_info['user_name'], hg_encript_str($server_info['password'], false))) {
         mysql_close();
         return 1;
     }
     return 0;
 }
Example #24
0
 public function update()
 {
     $id = $this->input['cloud_id'];
     if (!$id) {
         $this->ReportError('指定记录不存在或已删除!');
     }
     $name = trim($this->input['cloud_name']);
     if (!$name) {
         $this->form('请填写名称');
     }
     $module_id = intval($this->input['module_id']);
     if (!$module_id) {
         $this->ReportError('请填写关联模块id');
     }
     $site_id = intval($this->input['site_id']);
     if (!$site_id) {
         $this->ReportError('请重新选择对应客户!');
     }
     $sql = 'SELECT * FROM ' . DB_PREFIX . 'cloud_site WHERE id=' . $site_id;
     $f = $this->db->query_first($sql);
     if (!$f) {
         $this->ReportError('此客户信息不存在或被删除!');
     }
     //检测是否添加过
     $data = array('cloud_name' => $name, 'site_id' => $site_id, 'module_id' => $module_id, 'remote_host' => trim(urldecode($this->input['remote_host'])), 'remote_dir' => trim(urldecode($this->input['remote_dir'])), 'remote_file' => trim(urldecode($this->input['remote_file'])), 'remote_update_file' => trim(urldecode($this->input['remote_update_file'])), 'remote_node_file' => trim(urldecode($this->input['remote_node_file'])), 'appid' => intval($this->input['appid']) ? intval($this->input['appid']) : $f['appid'], 'appkey' => trim(urldecode($this->input['appkey'])) ? trim(urldecode($this->input['appkey'])) : $f['appkey'], 'username' => trim(urldecode($this->input['username'])) ? trim(urldecode($this->input['username'])) : $f['username'], 'pwd' => trim(urldecode($this->input['pwd'])) ? hg_encript_str(trim($this->input['pwd']), true, $f['custom_appkey']) : $f['pwd'], 'authapi' => trim(urldecode($this->input['authapi'])) ? trim(urldecode($this->input['authapi'])) : $f['authapi'], 'localusername' => trim(urldecode($this->input['localusername'])) ? trim(urldecode($this->input['localusername'])) : $f['localusername'], 'localuserpwd' => trim($this->input['localuserpwd']) ? hg_encript_str(trim($this->input['localuserpwd'])) : $f['localuserpwd'], 'is_close' => intval($this->input['is_close']));
     hg_fetch_query_sql($data, 'cloud', 'cloud_id=' . $id);
     $this->cache->recache('cloud_manage');
     $this->redirect('更新成功', '?id=' . $site_id);
 }