public function auth() { $curl = new curl($this->settings['App_auth']['host'], $this->settings['App_auth']['dir']); $curl->mAutoInput = false; $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $sql = 'SELECT * FROM ' . DB_PREFIX . 'applications ORDER BY id desc'; $q = $this->db->query($sql); while ($row = $this->db->fetch_array($q)) { echo $row['name'] . '<br />'; $row['dir'] = str_replace($row['admin_dir'], '', $row['dir']); $curl->initPostData(); foreach ($row as $k => $v) { $curl->addRequestData($k, $v); } $curl->addRequestData('bundle', $row['softvar']); $ret = $curl->request('admin/apps.php'); } $sql = 'SELECT * FROM ' . DB_PREFIX . 'modules ORDER BY id desc'; $q = $this->db->query($sql); $app_main_module = array(); while ($row = $this->db->fetch_array($q)) { echo $row['name'] . '<br />'; $row['dir'] = str_replace($row['admin_dir'], '', $row['dir']); $row['main_module'] = 0; if ($row['app_uniqueid'] == $row['mod_uniqueid']) { $row['main_module'] = 1; } if ($row['menu_pos'] == -1) { $row['main_module'] = 2; } $modules[$row['id']] = $row; if ($row['main_module']) { //纪录各个应用主模块 menu_pos优先 if ($modules[$app_main_module[$row['app_uniqueid']]]['main_module'] <= $row['main_module']) { $app_main_module[$row['app_uniqueid']] = $row['id']; } } } if ($modules) { foreach ($modules as $mid => $row) { if ($row['main_module'] && in_array($row['id'], $app_main_module)) { $row['main_module'] = 1; } else { $row['main_module'] = 0; } $curl->initPostData(); foreach ($row as $k => $v) { $curl->addRequestData($k, $v); } $ret = $curl->request('admin/modules.php'); } } }
function config() { $curl = new curl('localhost', 'livsns/api/auth/'); $curl->setSubmitType('post'); $curl->setReturnFormat('json'); $curl->initPostData(); $curl->addRequestData('a', 'settings'); $ret = $curl->request('configuare.php'); $user_configs = array('base' => $ret['base'], 'define' => $ret['define']); $curl = new curl('10.0.1.40', 'livworkbench/api/'); $curl->setSubmitType('post'); $curl->setReturnFormat('json'); $curl->initPostData(); $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $curl->addRequestData('app', 'auth'); $curl->addRequestData('version', '1.0.0'); $curl->addRequestData('pre_release', '1'); $new_configs = $curl->request('config.php'); if ($new_configs) { $doset = array(); foreach ($new_configs as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { if (!$user_configs[$k][$kk]) { $doset[$k][$kk] = $vv; } } } } } if ($doset) { $curl = new curl('localhost', 'livsns/api/auth/'); $curl->setSubmitType('post'); $curl->setReturnFormat('json'); $curl->initPostData(); $curl->addRequestData('a', 'doset'); foreach ($doset as $k => $v) { foreach ($v as $kk => $vv) { if (is_array($vv)) { foreach ($vv as $kkk => $vvv) { $curl->addRequestData($k . "[{$kk}][{$kkk}]", $vvv); } } else { $curl->addRequestData($k . "[{$kk}]", $vv); } } } $ret = $curl->request('configuare.php'); } print_r($doset); print_r($curl); }
function __construct() { parent::__construct(); $app = trim($this->input['app']); if (!$app) { $app = 'livworkbench'; } $this->mApp = $app; $pre_release = intval($this->input['pre_release']); if (defined('NEED_AUTH') && NEED_AUTH) { include_once ROOT_PATH . 'lib/class/curl.class.php'; $curl = new curl($this->mAuthServer['host'], $this->mAuthServer['dir']); $curl->mAutoInput = false; $curl->setClient($this->input['appid'], $this->input['appkey']); $curl->setToken(''); $curl->initPostData(); $postdata = array('a' => 'get_user_info'); foreach ($postdata as $k => $v) { $curl->addRequestData($k, $v); } $ret = $curl->request('get_access_token.php'); $ret = $ret[0]; $this->mUser = $ret; if ($ret['install_type'] == 'pre-release') { $pre_release = 1; } } if ($pre_release) { $this->mVersionDir = 'pre-release/'; } else { $this->mVersionDir = 'release/'; } $version = trim($this->input['version']); $version_dir = $this->mRootDir . $this->mVersionDir; if (!$version) { $version = $this->getLastestVesion($version_dir); } $this->mProductDir = $version_dir; $this->mVersion = $version; if ($this->input['debug']) { echo '<pre>'; print_r($this); } }
$update_apps = @file_get_contents(CACHE_DIR . 'onekupdate'); $update_apps = json_decode($update_apps, 1); $tdb = $update_apps['okupdatedbinfo']; unset($update_apps['okupdatedbinfo']); if ($update_apps) { unset($update_apps[$install_app]); if ($update_apps) { $update_apps['okupdatedbinfo'] = $tdb; $onekupdate = json_encode($update_apps); } else { $onekupdate = ''; } file_put_contents(CACHE_DIR . 'onekupdate', $onekupdate); } $curl = new curl($this->product_server['host'] . ':' . $this->product_server['port'], ''); $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $curl->setSubmitType('get'); $curl->setReturnFormat('json'); $curl->initPostData(); $curl->addRequestData('app', $install_app); $new_configs = $curl->request('config.php'); if ($new_configs) { $doset = array(); foreach ($new_configs as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { if (!$user_configs[$k][$kk]) { $doset[$k][$kk] = $vv; } } }
public function show_layout() { $curl = new curl($this->appstore_server['host'], $this->appstore_server['dir']); $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); //$curl->setClient(67, 'Bj2IRKxQgxV6XJVbTMb5lz8WwAQYorcP'); $curl->setSubmitType('post'); $curl->setReturnFormat('json'); $curl->initPostData(); $curl->addRequestData('a', 'get_temp'); $curl->addRequestData('type', 4); $mode_info = $curl->request('template.php'); if ($mode_info && is_array($mode_info)) { foreach ($mode_info as $k => $v) { if ($v['chg_status'] == '2') { $v['op_name'] = '更新'; } elseif ($v['chg_status'] == '0') { $v['op_name'] = '安装'; } else { $v['op_name'] = ''; } $v['attr'] = ' onclick="return hg_ajax_post(this, \'更新\', 1);"'; $v['link'] = '?a=temp_do&type=4'; $datas[$v['id']] = $v; } } $list_fields = array('id' => array('title' => 'ID', 'exper' => '$v[id]'), 'name' => array('title' => '名称', 'exper' => '$v[title]')); $op = 1; $batch_op = array('temp_do' => array('name' => '更新', 'brief' => '', 'attr' => ' onclick="return hg_ajax_batchpost(this, \'temp_do\', \'更新\', 1,\'\',\'\',\'ajax\');"')); $str = 'var gBatchAction = new Array();gBatchAction[\'temp_do\'] = \'?a=temp_do&type=4\';'; hg_add_head_element('js-c', $str); $this->tpl->addHeaderCode(hg_add_head_element('echo')); $this->tpl->addVar('list_fields', $list_fields); $this->tpl->addVar('batch_op', $batch_op); $this->tpl->addVar('op', $op); $this->tpl->addVar('primary_key', 'sign'); $this->tpl->addVar('type', '4'); $this->tpl->addVar('list', $datas); $this->tpl->outTemplate('layout'); }
public function dologin() { $username = $this->input['username']; $password = $this->input['password']; $secret_value = $this->input['secret_value']; /*用户输入密保卡的值*/ $security_zuo = $this->input['security_zuo']; /*密保卡坐标*/ if ($this->settings['App_auth']) { //$this->show('授权服务器通信失败(配置文件缺失)!'); $this->curl = new curl($this->settings['App_auth']['host'], $this->settings['App_auth']['dir']); $this->curl->initPostData(); $this->curl->addRequestData('appid', APPID); $this->curl->addRequestData('appkey', APPKEY); $this->curl->addRequestData('username', $username); $this->curl->addRequestData('password', $password); $this->curl->addRequestData('ip', hg_getip()); //密保卡相关验证参数 $this->curl->addRequestData('security_zuo', $security_zuo); $this->curl->addRequestData('secret_value', $secret_value); $ret = $this->curl->request('get_access_token.php'); if ($ret['ErrorCode']) { $this->show($ret['ErrorCode'] . $ret['ErrorText']); } $ret = $ret[0]; if ($ret['forced_change_pwd']) { //如果开启了强制修改密码,第一次登陆的时候必须修改密码 $this->tpl->addVar('admin_id', $ret['id']); $this->tpl->addVar('user_name', $ret['user_name']); $this->tpl->outTemplate('change_pwd'); } if ($ret['domain'] && $ret['domain'] != $_SERVER['HTTP_HOST']) { $this->show('用户名或密码错误'); } if (!$ret['token']) { $_SESSION['livmcp_userinfo'] = array(); $this->show('获取令牌错误!'); } //客户端过期检测 if ($ret['app_expire_time'] && $ret['app_expire_time'] < TIMENOW) { $_SESSION['livmcp_userinfo'] = array(); $this->show('客户端授权到期'); } if ($ret['default_page']) { if (substr($ret['default_page'], 0, 7) != 'http://') { $ret['default_page'] = 'http://' . $ret['default_page']; } } if (is_file(CACHE_DIR . 'expire.m2o')) { if (!is_writeable(CACHE_DIR . 'expire.m2o')) { $this->ReportError('请将' . CACHE_DIR . 'expire.m2o文件权限设置为可写'); } $filemtime = filemtime(CACHE_DIR . 'expire.m2o'); if (time() - $filemtime > 86400) { $updateauth = true; } else { $content = file_get_contents(CACHE_DIR . 'expire.m2o'); $license = hoge_de($content); $updateauth = false; if (!$license) { $updateauth = true; } } } else { $updateauth = true; } if ($updateauth) { $curl = new curl($this->settings['verify_custom_api']['host'], $this->settings['verify_custom_api']['dir']); $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $curl->setToken(''); $curl->setErrorReturn(''); $curl->setCurlTimeOut(10); $curl->mAutoInput = false; $curl->initPostData(); $postdata = array('useappkey' => 1); foreach ($postdata as $k => $v) { $curl->addRequestData($k, $v); } $auth = $curl->request('Authorization.php'); if (is_array($auth)) { if ($auth['ErrorCode'] == 'NO_APP_INFO') { $this->ReportError('授权非法,请联系软件提供商'); } if ($auth['ErrorCode'] == 'APP_AUTH_EXPIRED') { $this->ReportError('授权已到期,请联系软件提供商'); } } $license = hoge_de($auth); if ($license) { if ($license['appid']) { file_put_contents(CACHE_DIR . 'expire.m2o', $auth); } } } $timedelay = 0; if (intval($license['expire_time'])) { $license['expire'] = date('Y-m-d', $license['expire_time']); $license['leftday'] = intval(($license['expire_time'] - TIMENOW) / 86400); if ($license['expire_time'] < time()) { $this->ReportError('授权已到期,请联系软件提供商'); } if ($license['leftday'] <= 30) { $license_alert = '<div style="font-size:14px;">授权将在 <strong style="color:red;">' . $license['leftday'] . '</strong> 天后到期, 为了保证您正常使用系统,请提前联系软件提供商。</div>'; $timedelay = 5; } } $_SESSION['livmcp_userinfo'] = $ret; $user = $ret; /* if($ret['id']) { $this->curl->initPostData(); $this->curl->addRequestData('user_id', $user['id']); $this->curl->addRequestData('a', 'get_dynamic_token'); $ret = $this->curl->request('admin/set_dynamic_token.php'); $ret = $ret[0]; if($ret['dynamic_token'] && $this->input['dynamic_token']!=$ret['dynamic_token']); { //$_SESSION['livmcp_userinfo'] = array(); //$this->show('该用户已经绑定手机密保,请安装手机客户端密保软件!'); } }*/ } else { $username = $this->input['username']; $password = $this->input['password']; if ($this->settings['admin_user']) { $users = $this->settings['admin_user']; if (!$users[$username] || md5($password) != $users[$username]) { $this->show('用户名或密码错误'); } $_SESSION['livmcp_userinfo'] = array('id' => -1, 'user_name' => $username, 'group_type' => 1); } else { //创建临时用户 $this->show('用户名或密码错误'); } } if ($this->input['ajax']) { $func = 'hg_dialog_close();'; } if ($this->input['referto'] && strpos($this->input['referto'], '.php') && !strpos($this->input['referto'], 'login.php')) { $reffer = '?referto=' . urlencode($this->input['referto']); } global $gUser; $gUser = $user; include_once ROOT_PATH . 'lib/class/log.class.php'; $log = new hglog(); $log->add_log('登录平台'); $this->input['goon'] = 1; if ($this->input['code'] && $this->channel['id'] && $this->settings['App_interactive']['mid'][$gUser['group_type']]) { //$this->input['code'].$this->settings['App_interactive']['host']. $reffer = 'run.php?mid=' . $this->settings['App_interactive']['mid'][$gUser['group_type']]; $this->Redirect('成功登录系统.' . $license_alert, $reffer, $timedelay, 0, $func); } elseif ($user['default_page'] && $user['open_way'] == 1) { header('Location:' . $user['default_page']); } else { $this->Redirect('成功登录系统.' . $license_alert, 'index.php' . $reffer, $timedelay, 0, $func); } }
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 doupgrade() { $installinfo = array('host' => $this->settings['mcphost'], 'ip' => $this->settings['mcphost'], 'port' => 6233); if (!is_writeable('conf/config.php')) { hg_run_cmd($installinfo, 'runcmd', 'chmod -Rf 777 ' . realpath('conf/config.php')); } if (!is_writeable('conf/config.php')) { $message = '平台无法升级,请将此文件(conf/config.php)设为可写'; $this->upgrade($message); } $curl = new curl($this->product_server['host'] . ':' . $this->product_server['port'], $this->product_server['dir']); $curl->mAutoInput = false; $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $curl->initPostData(); $postdata = array('app' => 'livworkbench', 'a' => 'checklastversion'); foreach ($postdata as $k => $v) { $curl->addRequestData($k, $v); } $lastversion = $curl->request('check_version.php'); if ($this->settings['version'] >= $lastversion) { $this->ReportError('当前已是最新版本'); } $db = $this->dbconfig; $db['user'] = $this->input['dbuser']; $db['pass'] = $_REQUEST['dbpass']; $link = @mysql_connect($db['host'], $db['user'], $db['pass']); if (!$link) { $message = '此数据库无法连接,请确认密码是否准确'; $this->show($message); } mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $link); $socket = new hgSocket(); $con = $socket->connect($installinfo['host'], $installinfo['port']); if (!intval($con)) { $message = '服务器无法连接,请确认服务器ip是否正确或服务程序hogeMonitor.py是否监听在' . $installinfo['ip'] . ':' . $installinfo['port'] . '上'; $this->show($message); } $socket->close(); $app_path = realpath(ROOT_PATH); $app_path .= '/'; $curl = new curl($this->product_server['host'] . ':' . $this->product_server['port'], ''); $curl->mAutoInput = false; $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $curl->setSubmitType('get'); $curl->setReturnFormat('json'); $curl->initPostData(); $curl->addRequestData('app', 'livworkbench'); $ret = $curl->request('db.php'); ob_start(); if (is_array($ret)) { //更新数据库 hg_flushMsg('开始更新数据库'); mysql_select_db($db['database'], $link); $structs = $this->getDbStruct($db['database'], $link); if (!$ret['app']) { $ret['app'] = array(); } foreach ($ret['app'] as $tab => $v) { $pre = substr($tab, 0, 4); if ($pre == 'liv_') { $newtab = DB_PREFIX . substr($tab, 4); } if ($pre == 'm2o_') { $newtab = DB_PREFIX . substr($tab, 4); } if (!$structs[$newtab]) { $addsql = $ret['create'][$tab]; if ($addsql) { $addsql = preg_replace('/CREATE\\s+TABLE\\s+([`]{0,1})' . $pre . '/is', 'CREATE TABLE \\1' . DB_PREFIX, $addsql); hg_flushMsg('新增数据表' . $newtab); mysql_query($addsql, $link); } continue; } $struct = $v['struct']; $index = $v['index']; if ($struct) { $altersql = array(); foreach ($struct as $f => $a) { if (!$structs[$newtab]['struct'][$f]) { if ($a['Null'] == 'NO') { $null = ' NOT NULL'; } else { $null = ' NULL'; } if ($a['Default']) { $default = " DEFAULT '{$a['Default']}'"; } else { $default = ''; } if ($a['Comment']) { $comment = " COMMENT '{$a['Comment']}'"; } else { $comment = ''; } $altersql[] = " ADD `{$f}` {$a['Type']}{$null}{$default}{$comment}"; } else { $cur = $structs[$newtab]['struct'][$f]; if ($a['Null'] == 'NO') { $null = ' NOT NULL'; } else { $null = ' NULL'; } if ($a['Default']) { $default = " DEFAULT '{$a['Default']}'"; } else { $default = ''; } if ($a['Comment']) { $comment = " COMMENT '{$a['Comment']}'"; } else { $comment = ''; } if ($a['Type'] != $cur['Type'] || $a['Default'] != $cur['Default']) { $altersql[] = " CHANGE `{$f}` `{$f}` {$a['Type']}{$null}{$default}{$comment}"; } } } if ($altersql) { hg_flushMsg('开始更新数据表' . $newtab); $altersql = 'ALTER TABLE ' . $newtab . ' ' . implode(',', $altersql); mysql_query($altersql, $link); } } if ($index) { foreach ($index as $unique => $ind) { if (!$ind) { continue; } if (!$unique) { $typ = 'UNIQUE'; } else { $typ = 'INDEX'; } foreach ($ind as $pk => $f) { if ($pk == 'PRIMARY') { continue; } $curind = $structs[$newtab]['index'][$unique][$pk]; if (!$curind) { $altersql = 'ALTER TABLE ' . $newtab . ' ADD ' . $typ . ' (' . implode(',', $f) . ')'; // echo $altersql . '<br />'; mysql_query($altersql, $link); } else { $change = array_diff($curind, $f); $change1 = array_diff($f, $curind); if ($change || $change1) { $altersql = 'ALTER TABLE ' . $newtab . ' DROP INDEX ' . $pk . ', ADD ' . $typ . ' (' . implode(',', $f) . ')'; // echo $altersql . '<br />'; mysql_query($altersql, $link); } } } } } $newindex = $index; $index = $structs[$newtab]['index']; if ($index) { foreach ($index as $unique => $ind) { if (!$ind) { continue; } if (!$unique) { $typ = 'UNIQUE'; } else { $typ = 'INDEX'; } foreach ($ind as $pk => $f) { if ($pk == 'PRIMARY') { continue; } $newind = $newindex[$unique][$pk]; if (!$curind) { $altersql = 'ALTER TABLE ' . $newtab . ' DROP INDEX ' . $pk; mysql_query($altersql, $link); } } } } $sql = 'OPTIMIZE TABLE ' . $newtab; mysql_query($sql, $link); } hg_flushMsg('数据库更新完毕'); } //下载程序 hg_flushMsg('开始下载应用程序更新包'); $curl = new curl($this->product_server['host'] . ':' . $this->product_server['port'], ''); $curl->mAutoInput = false; $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $curl->setSubmitType('get'); $curl->setReturnFormat('json'); $curl->initPostData(); $curl->addRequestData('app', 'livworkbench'); $program_url = $curl->request('check_version.php'); if (!(strstr($program_url, 'http://') && strstr($program_url, '.zip')) || $program_url == 'NO_VERSION') { $message = '获取应用程序失败或程序版本不存在.'; $this->show($message); } hg_run_cmd($installinfo, 'download', $program_url, $app_path); $appversion = @file_get_contents($app_path . 'version'); $match = preg_match('/^[0-9]+\\.[0-9]+\\.[0-9]+$/is', $appversion); if (!$match) { $appversion = ''; } if ($appversion < $lastversion) { $message = '平台程序更新失败,请重试.'; $this->upgrade($message); } hg_run_cmd($installinfo, 'runcmd', 'chmod +x ' . $app_path . 'cron/*.py'); $domain = $installinfo['host']; $dir = $installinfo['dir']; hg_flushMsg('应用程序包下载完成'); hg_flushMsg('应用设置更新完成'); hg_flushMsg('开始更新模板'); hg_flushMsg('模板更新完成'); $content = @file_get_contents('conf/config.php'); $match = preg_match("/\\\$gGlobalConfig\\['version'\\]\\s*=\\s*\\'.*\\';/is", $content); if ($match) { $content = preg_replace("/\\\$gGlobalConfig\\['version'\\]\\s*=\\s*\\'.*?\\';/is", "\$gGlobalConfig['version'] = '{$lastversion}';", $content); } else { $content = preg_replace("/\\?>/is", "\n\$gGlobalConfig['version'] = '{$lastversion}';\n?>", $content); } @file_put_contents('conf/config.php', $content); $sql = 'SELECT * FROM ' . DB_PREFIX . 'modules'; $q = $this->db->query($sql); $program = array(); while ($mod = $this->db->fetch_array($q)) { $program[$mod['id']][$mod['func_name']] = $mod['func_name']; } $sql = 'SELECT * FROM ' . DB_PREFIX . 'module_op'; $q = $this->db->query($sql); while ($mod = $this->db->fetch_array($q)) { $program[$mod['module_id']][$mod['op']] = $mod['op']; } if ($program) { hg_flushMsg('开始重建应用程序'); include ROOT_PATH . 'lib/class/program.class.php'; $rebuildprogram = new program(); foreach ($program as $mid => $ops) { if ($ops) { foreach ($ops as $op) { $rebuildprogram->compile($mid, $op); } } } hg_flushMsg('应用程序重建完成'); } //清理模板 $this->clearfile(CACHE_DIR . 'tpl/livworkbench/'); $this->clearfile(CACHE_DIR . 'tpl/css/livworkbench/'); $update_apps = @file_get_contents(CACHE_DIR . 'onekupdate'); $update_apps = json_decode($update_apps, 1); $tdb = $update_apps['okupdatedbinfo']; unset($update_apps['okupdatedbinfo']); if ($update_apps) { unset($update_apps['livworkbench']); if ($update_apps) { $update_apps['okupdatedbinfo'] = $tdb; $onekupdate = json_encode($update_apps); } else { $onekupdate = ''; } file_put_contents(CACHE_DIR . 'onekupdate', $onekupdate); } if ($this->input['onekupdate']) { $url = 'appstore.php?a=goonekupdate'; } else { $url = 'index.php'; } $this->appstore->initPostData(); $this->appstore->addRequestData('a', 'updated'); $this->appstore->addRequestData('app', 'livworkbench'); $this->appstore->request('index.php'); hg_flushMsg('平台更新成功', $url); //$this->redirect('应用更新成功', $url); }
$sql = 'SELECT * FROM ' . DB_PREFIX . "menu WHERE app_uniqueid='{$mmenu['app_uniqueid']}' AND mod_uniqueid='{$mmenu['mod_uniqueid']}'"; $q = $this->db->query_first($sql); if ($q) { $sql = 'UPDATE ' . DB_PREFIX . "menu SET name='{$mmenu['name']}', father_id={$mmenu['father_id']},order_id={$mmenu['order_id']},url='{$mmenu['url']}', module_id='{$mmenu['module_id']}' WHERE id={$q['id']} "; $this->db->query($sql); } else { $sql = 'INSERT INTO ' . DB_PREFIX . 'menu (' . implode(',', array_keys($mmenu)) . ') VALUES '; $sql .= "('" . implode("','", $mmenu) . "')"; $this->db->query($sql); $q['id'] = $this->db->insert_id(); $sql = 'UPDATE ' . DB_PREFIX . "menu set include_apps=concat(include_apps, '{$install_app}', ',') WHERE id=" . intval($mmenu['father_id']); $this->db->query($sql); } //向授权系统提交应用信息 $curl = new curl($this->settings['App_auth']['host'], $this->settings['App_auth']['dir']); $curl->setClient($m2oappid, $m2oappkey); $curl->initPostData(); $curl->mAutoInput = false; unset($applications['appid'], $applications['appkey']); if ($appinfo['api_uniqueid']) { $applications['dir'] = $appinfo['api_uniqueid'] . '/'; } else { $applications['dir'] = $install_app . '/'; } $applications['use_message'] = $appinfo['use_message']; $applications['use_material'] = $appinfo['use_material']; $applications['use_textsearch'] = $appinfo['use_textsearch']; $applications['use_logs'] = $appinfo['use_logs']; $applications['use_recycle'] = $appinfo['use_recycle']; $applications['use_access'] = $appinfo['use_access']; foreach ($applications as $k => $v) {
public function install($message = '') { if (DEVELOP_MODE) { $this->ReportError('对不起,开发模式不允许安装'); } if ($this->input['app']) { $this->appstore->initPostData(); $this->appstore->addRequestData('a', 'detail'); $this->appstore->addRequestData('app', $this->input['app']); $appinfo = $this->appstore->request('index.php'); $appinfo = $appinfo[0]; if ($appinfo['status'] != 0) { $this->install('应用' . $appinfo['name'] . '已经安装'); } $this->input['app'] = $appinfo['app_uniqueid']; } if (!$appinfo) { $this->ReportError('指定应用不存在,无法安装'); } $this->check_version($appinfo); $sql = 'SELECT * FROM ' . DB_PREFIX . 'server ORDER BY id DESC'; $q = $this->db->query($sql); $servers = array(); while ($r = $this->db->fetch_array($q)) { if (in_array($r['type'], array('api'))) { $type = 'app'; } else { $type = $r['type']; } $servers[$type][$r['id']] = $r['name'] . '_' . $r['ip']; } if (!$formdata) { $formdata = $this->input; if (!$this->input['dbserver']) { $dbs = @array_keys($servers['db']); $formdata['dbserver'] = $dbs[0]; } if (!$this->input['appserver']) { $apps = @array_keys($servers['app']); $formdata['appserver'] = $apps[0]; } if (!$this->input['database']) { $formdata['database'] = ($this->settings['dbprefix'] ? $this->settings['dbprefix'] : 'm2o_') . $this->input['app']; } if (!$this->input['dbprefix']) { $formdata['dbprefix'] = 'm2o_'; } } $formdata['example_domain'] = $this->input['app'] . '_api.' . $this->settings['license']; $formdata['apidomain'] = $this->input['app'] . '_api.' . $this->settings['license']; $formdata['dir'] = ($this->settings['webdir'] ? $this->settings['webdir'] : '/web/') . $this->settings['license'] . '/' . $this->input['app'] . '_api.' . $this->settings['license'] . '/'; $servers['db'][0] = '新增数据库服务器'; $servers['app'][0] = '新增应用服务器'; $this->tpl->addHeaderCode(' <script type="text/javascript"> //<![CDATA[ ' . $script . ' //]]> </script> '); $curl = new curl($this->product_server['host'] . ':' . $this->product_server['port'], ''); $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); if (!$appinfo['nodb']) { $curl->initPostData(); $curl->addRequestData('install', 1); $curl->addRequestData('app', $this->input['app']); $ret = $curl->request('db.php'); } $this->tpl->addVar('hasdb', $ret['app']); $this->tpl->addVar('formdata', $formdata); $this->tpl->addVar('servers', $servers); $this->tpl->addVar('appinfo', $appinfo); $this->tpl->addVar('message', $message); $this->tpl->outTemplate('appstore_install'); }
public function show() { include ROOT_DIR . 'lib/class/cron.class.php'; $crond = new crond(); if ($this->settings['croncmd']) { $crond->setCronCmd($this->settings['croncmd']); } $cron_status = $crond->isRun(); $curl = new curl($this->settings['verify_custom_api']['host'], $this->settings['verify_custom_api']['dir']); $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $curl->setToken(''); $curl->setCurlTimeOut(5); $curl->setErrorReturn(''); $curl->mAutoInput = false; $curl->initPostData(); $postdata = array('a' => 'get_user_info'); foreach ($postdata as $k => $v) { $curl->addRequestData($k, $v); } $license = $curl->request('get_access_token.php'); if (!$license) { $this->ReportError('未获取到授权信息,请确认服务器网络正常或联系软件提供商'); } if ($license['ErrorCode'] == 'APP_AUTH_EXPIRED') { $this->ReportError('授权已到期,请联系软件提供商'); } $license = $license[0]; if ($license['appid']) { $license['expire'] = date('Y-m-d', $license['expire_time']); $license['leftday'] = intval(($license['expire_time'] - TIMENOW) / 86400); $this->tpl->addVar('license', $license); } $curl = new curl($this->settings['App_auth']['host'], $this->settings['App_auth']['dir']); $curl->setSubmitType('post'); $curl->setCurlTimeOut(5); $curl->setReturnFormat('json'); $ret = $curl->request('applications.php'); $instlled_apps = array(); $app_stats = array(); if (is_array($ret)) { foreach ($ret as $v) { $start_time = microtime(); $result = $this->check_status($v); $v['runtime'] = hg_page_debug($start_time); $v['inited'] = $result[1]['define']['INITED_APP']; $v['debuged'] = $result[1]['debuged']; $v['http_code'] = $result[0]['http_code']; $v['db'] = $result[1]['db']; $v['dbconnected'] = $result[1]['dbconnected']; $v['connect_time'] = $result[1]['connect_time']; $v['ip'] = gethostbyname($v['host']); $v['db']['ip'] = gethostbyname($v['db']['host']); $v['api_dir'] = $result[1]['api_dir']; $v['config_file_purview'] = $result[1]['config_file_purview']; $v['data_file_purview'] = $result[1]['data_file_purview']; $v['cache_file_purview'] = $result[1]['cache_file_purview']; $v['freespace'] = $result[1]['freespace']; if ($v['bundle'] == $_GET['b']) { print_r($v); exit; } $app_stats[$v['bundle']] = $v; } } if ($this->settings['App_livmedia']) { $curl = new curl($this->settings['App_livmedia']['host'], $this->settings['App_livmedia']['dir'] . 'admin/'); $curl->setErrorReturn(''); $curl->setCurlTimeOut(30); $curl->mAutoInput = false; $curl->initPostData(); $curl->addRequestData('a', 'stats'); $vod_status = $curl->request('vod.php'); $vod_status = $vod_status[0]; } $this->tpl->addVar('app_stats', $app_stats); $this->tpl->addVar('vod_status', $vod_status); $this->tpl->addVar('cron_status', $cron_status); $this->tpl->outTemplate('stats'); }
public function dorelease() { $version = $this->appinfo['pre_version']; $ret = file_get_contents('http://web.innner.hogesoft.com/control/release.php?app=' . $this->appinfo['app_uniqueid'] . '&version=' . $version); if ($ret == 'VERSION_FORMAT_ERROR') { $this->pre_release('对不起,版本号设置错误'); } $curl = new curl($this->product_server['host'], $this->product_server['dir']); $curl->mAutoInput = false; $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY); $i = 0; $success = false; while (true && $i < 30) { $curl->initPostData(); $postdata = array('app' => $this->appinfo['app_uniqueid'], 'a' => 'checklastversion'); foreach ($postdata as $k => $v) { $curl->addRequestData($k, $v); } $rversion = $curl->request('check_version.php'); if ($rversion == $version) { $success = true; break; } sleep(1); $i++; } $this->appstore->initPostData(); $this->appstore->addRequestData('a', 'update_version'); $this->appstore->addRequestData('version', $version); $this->appstore->addRequestData('app', $this->appinfo['app_uniqueid']); $appinfo = $this->appstore->request('index.php'); $appinfo = $appinfo[0]; if ($appinfo['id'] && $success) { $url = '?'; $this->redirect('应用版本发布成功', $url); } else { $this->pre_release('应用版本发布失败'); } }