header('Location:./index.php'); } $server = $servers[$_REQUEST['id']]; if (!$server) { header('Location:./index.php'); } $file = $Cfg['servertype'][$server['type']]['conf'][$_REQUEST['file']]; if (!$file) { header('Location:./index.php'); } $sock = new hgSocket(); switch ($action) { case 'df': $configs = hg_run_cmd($sock, $server, 'df'); $doaction = 'babbaa'; include 'tpl/man.tpl.php'; break; case 'getfile': $configs = get_serv_file($sock, $server, $file); $doaction = 'dowritefile'; include 'tpl/man.tpl.php'; break; case 'dowritefile': $configs = write_serv_file($sock, $server, $file, $_REQUEST['content']); header('Location:./man.php?action=getfile&id=' . $_REQUEST['id'] . '&file=' . $_REQUEST['file']); break; default: $configs = 'No specify file'; include 'tpl/man.tpl.php'; break; }
$auth->addRequestData('a', 'create'); $auth->addRequestData('custom_name', $v['vname']); $auth->addRequestData('display_name', $v['name']); $auth->addRequestData('domain', $licenseinfo['domain']); $auth->addRequestData('bundle_id', $var); $auth->addRequestData('custom_desc', $v['name']); $auth->addRequestData('expire_time', 0); $ret = $auth->request('admin/auth_update.php'); $ret = $ret[0]; $appid = $ret['appid']; $appkey = $ret['appkey']; if ($v['appid'] == 1 && !$defined) { $defined = true; file_put_contents('db/appauth.php', "<?php\ndefine('APPID', '{$appid}');\ndefine('APPKEY', '{$appkey}');\n?>"); } $content = get_serv_file($v['serv'], $v['confile']); if ($var == 'cron') { $content = preg_replace("/APPID\\s*=\\s*\\d+/is", "APPID = {$appid}", $content); $content = preg_replace("/APPKEY\\s*=\\s*\\'.*?\\'/is", "APPKEY = '{$appkey}'", $content); } else { $content = preg_replace("/(define\\('APPID',)\\s*(.*?)(\\);)/is", '\\1\'' . $appid . '\'\\3', $content); $content = preg_replace("/(define\\('APPKEY',)\\s*(.*?)(\\);)/is", '\\1\'' . $appkey . '\'\\3', $content); } write_serv_file($v['serv'], $v['confile'], $content, 'utf8'); } @unlink('db/apply_auth'); hg_flushMsg('接口授权申请成功'); } echo ' <div align="center"> <input type="button" name="s" value=" 下一步 " style="width:100px;height:40px;color:#fff;font-size:16px;margin-top:20px;" onclick="document.location.href=\'index.php?action=install8\'" /> </div>';
} write_serv_file($v, $confile, $content, 'utf8'); hg_run_cmd($app, 'runcmd', 'chmod -Rf 777 ' . $confile); } } if ($this->settings['App_mediaserver']) { $v['ip'] = $this->settings['App_mediaserver']['host']; $v['port'] = 6233; $appcurl = new curl($v['host'], $v['dir']); $appcurl->setSubmitType('post'); $appcurl->setReturnFormat('str'); $appcurl->initPostData(); $appcurl->addRequestData('a', 'getapp_path'); $confile = $appcurl->request('configuare.php'); $confile = $confile . '/conf/config.php'; $content = get_serv_file($v, $confile); $match = preg_match("/define\\('PUBLISH_SET_ID',\\s*.*?\\s*\\);/is", $content); if ($match) { $appcurl->setReturnFormat('json'); $appcurl->initPostData(); $appcurl->addRequestData('a', 'create_publish_table'); $appcurl->addRequestData('apihost', $v['host']); $appcurl->addRequestData('apidir', $v['dir']); $planret = $appcurl->request('configuare.php'); $planret = $planret['ret']; if ($planret) { $content = preg_replace("/define\\('PUBLISH_SET_ID',\\s*.*?\\s*\\);/is", "define('PUBLISH_SET_ID', '{$planret[1]}');", $content); $content = preg_replace("/define\\('PUBLISH_SET_SECOND_ID',\\s*.*?\\s*\\);/is", "define('PUBLISH_SET_SECOND_ID', '{$planret[2]}');", $content); } write_serv_file($v, $confile, $content, 'utf8'); hg_run_cmd($app, 'runcmd', 'chmod -Rf 777 ' . $confile);
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'); }
public function add_appserver() { $app = $this->input['appserver']; if (!$app['ip']) { $message = '请填写服务器ip'; $this->redirect($message, 0, 0, '', "hg_add_appservererr_back('{$message}')"); } $app['ip'] = trim($app['ip']); $sql = 'SELECT * FROM ' . DB_PREFIX . "server WHERE ip = '{$app['ip']}' AND type != 'db'"; $q = $this->db->query_first($sql); if ($q) { $message = '此服务器ip已存在,无需重复添加'; $this->redirect($message, 0, 0, '', "hg_add_appservererr_back('{$message}')"); } $app['port'] = 6233; $socket = new hgSocket(); $con = $socket->connect($app['ip'], $app['port']); if (!intval($con)) { $message = '服务器无法连接,请确认服务器ip是否正确或服务程序hogeMonitor.py是否监听在' . $app['ip'] . ':' . $app['port'] . '上'; $socket->close(); $this->redirect($message, 0, 0, '', "hg_add_appservererr_back('{$message}')"); } $socket->close(); $app_data = json_encode($app); $sql = 'INSERT INTO ' . DB_PREFIX . "server (name, brief, ip, outip, type, more_data,create_time) VALUES \r\n\t\t\t\t('{$app['name']}', '', '{$app['ip']}', '{$app['outip']}', 'api', '{$app_data}', " . TIMENOW . ")"; $this->db->query($sql); $id = $this->db->insert_id(); $sql = 'SELECT * FROM ' . DB_PREFIX . "server_domain sd LEFT JOIN " . DB_PREFIX . 'server s ON sd.server_id=s.id'; $q = $this->db->query($sql); $hostscontent = get_serv_file($app, '/etc/hosts'); $hosts = hg_get_hosts($hostscontent); while ($r = $this->db->fetch_array($q)) { $domain = $r['domain']; if ($domain && !$hosts[$domain]) { $hostscontent .= "\n" . $r['ip'] . ' ' . $domain; } } write_serv_file($app, '/etc/hosts', $hostscontent); $this->redirect('应用服务器添加成功', 0, 0, '', "hg_add_appserver_back({$id}, '{$app['name']}_{$app['ip']}')"); }