Example #1
0
                foreach ($vv as $kkk => $vvv) {
                    if (is_array($vvv)) {
                        foreach ($vvv as $kkkk => $vvvv) {
                            if (is_array($vvvv)) {
                                foreach ($vvvv as $kkkkk => $vvvvv) {
                                    $curl->addRequestData($k . "[{$kk}][{$kkk}][{$kkkk}][{$kkkkk}]", $vvvvv);
                                }
                            } else {
                                $curl->addRequestData($k . "[{$kk}][{$kkk}][{$kkkk}]", $vvvv);
                            }
                        }
                    } else {
                        $curl->addRequestData($k . "[{$kk}][{$kkk}]", $vvv);
                    }
                }
            } else {
                $curl->addRequestData($k . "[{$kk}]", $vv);
            }
        }
    }
    $ret = $curl->request('configuare.php');
}
if ($this->input['onekupdate']) {
    $url = 'appstore.php?a=goonekupdate';
} else {
    if (!is_file(CACHE_DIR . 'upgrade/' . date('Ymd') . '/' . $install_app . '.sql')) {
        $url = '?app=' . $install_app;
    }
}
hg_flushMsg('应用更新成功', $url);
Example #2
0
            }
            $mod['host'] = $gGlobalConfig['App_' . $mod['app_uniqueid']]['host'];
            $sdir = $mod['dir'];
            $mod['dir'] = $gGlobalConfig['App_' . $mod['app_uniqueid']]['dir'];
            if (strstr($sdir, 'admin/')) {
                $mod['dir'] .= 'admin/';
            }
            if (!$sql) {
                $sql = 'REPLACE INTO liv_crontab (`' . implode('`,`', array_keys($mod)) . '`) VALUES ';
            }
            $sql .= "('" . implode("','", $mod) . "'),";
        }
    }
    $sql = rtrim($sql, ',');
    mysql_query($sql, $link);
    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=install9\'" />
	  </div>';
    include 'tpl/foot.tpl.php';
}
//创建管理员
if ($action == 'install9') {
    include 'tpl/head.tpl.php';
    include 'tpl/admin.tpl.php';
    include 'tpl/foot.tpl.php';
}
if ($action == 'install10') {
    $user_name = trim($_REQUEST['user_name']);
    $password = trim($_REQUEST['password']);
    $confirmpassword = trim($_REQUEST['confirmpassword']);
Example #3
0
function hg_updateDb($app, $link, $dbname)
{
    $struct = hg_getServDbStruct($app);
    $cur_struct = hg_getDbStruct($link, $dbname);
    if (!is_array($struct)) {
        return;
    }
    $ndbs = array_keys($struct);
    if (is_array($cur_struct)) {
        $dbs = array_keys($cur_struct);
    } else {
        $dbs = array();
    }
    $add = array_diff($ndbs, $dbs);
    foreach ($add as $table) {
        hg_flushMsg('新增数据表 ' . $dbname . '.' . $table);
        $sql = hg_createSql($app, $table);
        mysql_query($sql, $link);
    }
    foreach ($struct as $table => $s) {
        if ($cur_struct[$table]) {
            $fields = array_keys($s);
            $cur_fields = array_keys($cur_struct[$table]);
            $add = array_diff($fields, $cur_fields);
            if ($add) {
                $altersql = array();
                foreach ($add as $f) {
                    hg_flushMsg('数据表 ' . $table . '新增字段 ' . $f);
                    $a = $s[$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}";
                }
                $altersql = 'ALTER TABLE ' . $table . ' ' . implode(',', $altersql);
                mysql_query($altersql, $link);
            }
        }
    }
    //$this->redirect('数据库更新完毕');
}
Example #4
0
function step5()
{
    $db = $_REQUEST['db'];
    if (!$db['host'] || !$db['user'] || !$db['database']) {
        step4('请设置数据库服务器地址,用户和数据库名');
    }
    $link = @mysql_connect($db['host'], $db['user'], $db['pass']);
    if (!$link) {
        step4($db['host'] . '连接失败,请确认输入正确的服务器地址,账号和密码');
    }
    mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $link);
    if (!$db['cover']) {
        $sql = "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME='{$db['database']}'";
        $q = mysql_query($sql, $link);
        $r = mysql_fetch_array($q);
        if ($r) {
            step4($db['database'] . '数据库已存在,您可以勾选覆盖数据库');
        }
    }
    $app = file_get_contents(CACHE_DIR . 'app.tmp');
    $app = json_decode($app, 1);
    $socket = new hgSocket();
    $con = $socket->connect($app['ip'], $app['port']);
    if (!intval($con)) {
        step4('安装无法完成,服务器无法连接,请确认服务器ip是否正确或服务程序hogeMonitor.py是否监听在' . $app['ip'] . ':' . $app['port'] . '上');
    }
    $socket->close();
    $auth = @file_get_contents(CACHE_DIR . 'auth.tmp');
    $auth = json_decode($auth, 1);
    $db['pass'] = hg_encript_str($db['pass'], true, $auth['appkey']);
    file_put_contents(CACHE_DIR . 'db.tmp', json_encode($db));
    global $Cfg;
    $curl = new curl($Cfg['upgradeServer']['host'] . ':' . $Cfg['upgradeServer']['port'], '', $Cfg['upgradeServer']['token']);
    $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY);
    $curl->setSubmitType('get');
    $curl->setReturnFormat('json');
    $curl->initPostData();
    $curl->addRequestData('install', 1);
    $curl->addRequestData('app', 'livworkbench');
    $ret = $curl->request('db.php');
    if (!is_array($ret)) {
        hg_errorReport('获取数据库结构失败,无法完成安装,请联系软件提供商');
    }
    $curl->initPostData();
    $curl->addRequestData('a', 'checklastversion');
    $curl->addRequestData('app', 'livworkbench');
    $lastversion = $curl->request('check_version.php');
    ob_start();
    if (!$db['cover']) {
        hg_flushMsg('开始创建数据库 ' . $db['database']);
        $sql = 'CREATE DATABASE ' . $db['database'] . ' DEFAULT CHARACTER SET UTF8';
        $q = mysql_query($sql, $link);
        if (!$q) {
            step4($db['database'] . '创建失败, 请确认此账号有权限创建数据库');
            continue;
        }
        hg_flushMsg('数据库 ' . $db['database'] . ' 已创建');
    }
    mysql_select_db($db['database'], $link);
    foreach ($ret as $table => $sql) {
        if (substr($table, 0, 4) == 'liv_') {
            $table = $db['dbprefix'] . substr($table, 4);
            $sql = preg_replace('/CREATE\\s+TABLE\\s+([`]{0,1})liv_/is', 'CREATE TABLE \\1' . $db['dbprefix'], $sql);
        }
        if (substr($table, 0, 4) == 'm2o_') {
            $table = $db['dbprefix'] . substr($table, 4);
            $sql = preg_replace('/CREATE\\s+TABLE\\s+([`]{0,1})m2o_/is', 'CREATE TABLE \\1' . $db['dbprefix'], $sql);
        }
        hg_flushMsg('开始创建数据表 ' . $table);
        if ($db['cover']) {
            $dropsql = 'DROP table ' . $table;
            mysql_query($dropsql, $link);
        }
        mysql_query($sql, $link);
    }
    hg_flushMsg('数据库创建完成 ');
    $content = get_serv_file($app, $app['dir'] . 'conf/config.php');
    $content = preg_replace("/\\\$gGlobalConfig\\s*\\['App_.*'\\]\\s*=\\s*array\\s*(.*?);/is", $appstring, $content);
    if ($db) {
        $db['pass'] = hg_encript_str($db['pass'], false, $auth['appkey']);
        $string = "\$gDBconfig = array(\n'host'     => '{$db['host']}',\n'user'     => '{$db['user']}',\n'pass'     => '{$db['pass']}',\n'database' => '{$db['database']}',\n'charset'  => 'utf8',\n'pconncet' => 0,\n);";
        $content = preg_replace("/\\\$gDBconfig\\s*=\\s*array\\s*(.*?);/is", $string, $content);
        $content = preg_replace("/define\\('DB_PREFIX',\\s*'.*?'\\);/is", "define('DB_PREFIX','{$db['dbprefix']}');", $content);
    }
    $match = preg_match("/define\\('INITED_APP',\\s*.*?\\s*\\);/is", $content);
    if ($match) {
        $content = preg_replace("/define\\('INITED_APP',\\s*.*?\\s*\\);/is", "define('INITED_APP', false);", $content);
    } else {
        $content = preg_replace("/\\?>/is", "\ndefine('INITED_APP', false);\n?>", $content);
    }
    $content = preg_replace("/define\\('APPID',\\s*'*\\d+'*\\);/is", "", $content);
    $content = preg_replace("/define\\('APPKEY',\\s*'.*?'\\);/is", "", $content);
    $content = preg_replace("/define\\('CUSTOM_APPID',\\s*\\d+\\);/is", "define('CUSTOM_APPID','{$auth['appid']}');", $content);
    $content = preg_replace("/define\\('CUSTOM_APPKEY',\\s*'.*?'\\);/is", "define('CUSTOM_APPKEY','{$auth['appkey']}');", $content);
    $content = preg_replace("/define\\('CUSTOM_NAME',\\s*'.*?'\\);/is", "define('CUSTOM_NAME','{$auth['display_name']}');", $content);
    $content = preg_replace("/define\\('DEBUG_MODE',\\s*.*?\\);/is", "define('DEBUG_MODE',false);", $content);
    $content = preg_replace("/define\\('DEVELOP_MODE',\\s*.*?\\);/is", "define('DEVELOP_MODE',0);", $content);
    $match = preg_match("/\\\$gGlobalConfig\\['license'\\]\\s*=\\s*\\'.*\\';/is", $content);
    if ($match) {
        $content = preg_replace("/\\\$gGlobalConfig\\['license'\\]\\s*=\\s*\\'.*?\\';/is", "\$gGlobalConfig['license'] = '{$auth['domain']}';", $content);
    } else {
        $content = preg_replace("/\\?>/is", "\n\$gGlobalConfig['license'] = '{$auth['domain']}';\n?>", $content);
    }
    $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);
    }
    $match = preg_match("/\\\$gGlobalConfig\\['mcphost'\\]\\s*=\\s*\\'.*\\';/is", $content);
    if ($match) {
        $content = preg_replace("/\\\$gGlobalConfig\\['mcphost'\\]\\s*=\\s*\\'.*?\\';/is", "\$gGlobalConfig['mcphost'] = '{$app['ip']}';", $content);
    } else {
        $content = preg_replace("/\\?>/is", "\n\$gGlobalConfig['mcphost'] = '{$app['ip']}';\n?>", $content);
    }
    $match = preg_match("/\\\$gGlobalConfig\\['php_run_type'\\]\\s*=\\s*\\'.*\\';/is", $content);
    if ($match) {
        $content = preg_replace("/\\\$gGlobalConfig\\['php_run_type'\\]\\s*=\\s*\\'.*?\\';/is", "\$gGlobalConfig['php_run_type'] = '{$app['php_run_type']}';", $content);
    } else {
        $content = preg_replace("/\\?>/is", "\n\$gGlobalConfig['php_run_type'] = '{$app['php_run_type']}';\n?>", $content);
    }
    $match = preg_match("/\\\$gGlobalConfig\\['php_socket_path'\\]\\s*=\\s*\\'.*\\';/is", $content);
    if ($match) {
        $content = preg_replace("/\\\$gGlobalConfig\\['php_socket_path'\\]\\s*=\\s*\\'.*?\\';/is", "\$gGlobalConfig['php_socket_path'] = '{$app['php_socket_path']}';", $content);
    } else {
        $content = preg_replace("/\\?>/is", "\n\$gGlobalConfig['php_socket_path'] = '{$app['php_socket_path']}';\n?>", $content);
    }
    write_serv_file($app, $app['dir'] . 'conf/config.php', $content, 'utf8');
    $template_conf = $app['dir'] . 'conf/template.conf.php';
    $content = get_serv_file($app, $template_conf);
    if ($content) {
        global $Cfg;
        $curl = new curl($Cfg['upgradeServer']['host'] . ':' . $Cfg['upgradeServer']['port'], '', $Cfg['upgradeServer']['token']);
        $curl->setClient(CUSTOM_APPID, CUSTOM_APPKEY);
        $curl->setSubmitType('get');
        $curl->setReturnFormat('json');
        $curl->initPostData();
        $curl->addRequestData('install', 1);
        $curl->addRequestData('app', 'livtemplates');
        $templates_url = $curl->request('check_version.php');
        $content = preg_replace("/define\\('CACHE_TEMPLATE',\\s*.*?\\);/is", "define('CACHE_TEMPLATE',true);", $content);
        $content = preg_replace("/define\\('RESOURCE_URL',\\s*.*?\\);/is", "define('RESOURCE_URL','./res/images/');", $content);
        $content = preg_replace("/define\\('SCRIPT_URL',\\s*.*?\\);/is", "define('SCRIPT_URL','./res/scripts/');", $content);
        $content = preg_replace("/define\\('COMBO_URL',\\s*.*?\\);/is", "define('COMBO_URL','');", $content);
        $content = preg_replace("/define\\('TEMPLATE_API',\\s*.*?\\);/is", "define('TEMPLATE_API','{$templates_url}');", $content);
        write_serv_file($app, $template_conf, $content, 'utf8');
    }
    $cron_conf = $app['dir'] . 'cron/config.py';
    $content = get_serv_file($app, $cron_conf);
    if ($content) {
        $content = preg_replace("/CRON_TAB\\s*=\\s*\\(.*?\\)/is", "CRON_TAB = ('{$app['domain']}', 80, 'token', 'crontab.php')", $content);
        write_serv_file($app, $cron_conf, $content, 'utf8');
    }
    hg_flushMsg('配置系统完成');
    hg_redirect('?action=step6');
}
Example #5
0
 function sync_table_struct()
 {
     //获取liv_record表结构和索引信息
     $record_fileds = $this->getFields(DB_PREFIX . 'record');
     $record_index = $this->getIndex(DB_PREFIX . 'record');
     //获取liv_record表结构和索引信息
     hg_flushMsg('开始更新表结构');
     $sql = "SHOW tables";
     $q = $this->db->query($sql);
     while (($row = $this->db->fetch_array($q)) !== false) {
         list($a, $table_name) = each($row);
         if (preg_match('/^' . DB_PREFIX . 'record_[0-9]*$/', $table_name)) {
             hg_flushMsg("更新表" . $table_name);
             $fields = $this->getFields($table_name);
             $index = $this->getIndex($table_name);
             foreach ((array) $record_fileds as $k => $v) {
                 $altersql = array();
                 if (!$fields[$k]) {
                     if ($v['Null'] == 'NO') {
                         $null = ' NOT NULL';
                     } else {
                         $null = ' NULL';
                     }
                     if ($v['Default']) {
                         $default = " DEFAULT '{$v['Default']}'";
                     } else {
                         $default = '';
                     }
                     if ($v['Comment']) {
                         $comment = " COMMENT '{$v['Comment']}'";
                     } else {
                         $comment = '';
                     }
                     $altersql[] = " ADD `{$k}` {$v['Type']}{$null} {$v['Extra']}{$default}{$comment}";
                 } else {
                     $cur = $record_fileds[$k];
                     if ($v['Null'] == 'NO') {
                         $null = ' NOT NULL';
                     } else {
                         $null = ' NULL';
                     }
                     if ($v['Default']) {
                         $default = " DEFAULT '{$v['Default']}'";
                     } else {
                         $default = '';
                     }
                     if ($v['Comment']) {
                         $comment = " COMMENT '{$v['Comment']}'";
                     } else {
                         $comment = '';
                     }
                     if ($v['Type'] != $cur['Type'] || $v['Default'] != $cur['Default']) {
                         $altersql[] = " CHANGE `{$k}` `{$k}` {$v['Type']}{$null} {$v['Extra']}{$default}{$comment}";
                     }
                 }
                 if ($altersql) {
                     $altersql = 'ALTER TABLE ' . $table_name . ' ' . implode(',', $altersql);
                     hg_flushMsg($altersql);
                     $this->db->query($altersql);
                 }
             }
             //处理增加或修改的索引
             if ($record_index) {
                 foreach ($record_index as $unique => $ind) {
                     if (!$ind) {
                         continue;
                     }
                     if (!$unique) {
                         $typ = 'UNIQUE';
                     } else {
                         $typ = 'INDEX';
                     }
                     foreach ($ind as $pk => $f) {
                         if ($pk == 'PRIMARY') {
                             continue;
                         }
                         $curind = $index[$unique][$pk];
                         if (!$curind) {
                             $altersql = 'ALTER TABLE  ' . $table_name . ' ADD ' . $typ . ' (' . implode(',', $f) . ')';
                             hg_flushMsg($altersql);
                             $this->db->query($altersql);
                         } else {
                             $change = array_diff($curind, $f);
                             $change1 = array_diff($f, $curind);
                             if ($change || $change1) {
                                 $altersql = 'ALTER TABLE  ' . $table_name . ' DROP INDEX ' . $pk . ', ADD ' . $typ . ' (' . implode(',', $f) . ')';
                                 hg_flushMsg($altersql);
                                 $this->db->query($altersql);
                             }
                         }
                     }
                 }
             }
             //处理已删除的索引
             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 = $record_index[$unique][$pk];
                         if (!$newind) {
                             $altersql = 'ALTER TABLE  ' . $table_name . ' DROP INDEX ' . $pk;
                             hg_flushMsg($altersql);
                             $this->db->query($altersql);
                         }
                     }
                 }
             }
             $sql = 'OPTIMIZE TABLE  ' . $table_name;
             $this->db->query($sql);
         }
     }
     hg_flushMsg('表更新完成');
 }
Example #6
0
 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);
 }
Example #7
0
            $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);
            }
        }
    }
    //发布计划创建
}
if ($appinfo['sourceapp']['app_uniqueid']) {
    $url = '?a=install&app=' . $appinfo['sourceapp']['app_uniqueid'];
} else {
    $url = '?app=' . $install_app;
}
if ($install_app == 'auth') {
    $url = 'login.php?a=logout';
}
hg_flushMsg('应用安装成功', $url);
Example #8
0
 public function rebuild_templates($appid = 0)
 {
     if ($appid) {
         $cond = ' WHERE application_id=' . $appid;
     }
     $sql = 'SELECT a.*, m.* FROM ' . DB_PREFIX . 'modules m LEFT JOIN ' . DB_PREFIX . 'applications a ON m.application_id=a.id ' . $cond;
     $q = $this->db->query($sql);
     $templates = array();
     $program = array();
     $modid = array();
     $modules = array();
     while ($mod = $this->db->fetch_array($q)) {
         $modid[] = $mod['id'];
         if ($mod['template']) {
             $templates[$mod['id']][] = $mod['template'];
         }
         $program[$mod['id']][$mod['func_name']] = $mod['func_name'];
         $modules[$mod['id']] = $mod;
     }
     $cond = '';
     if ($appid && $modid) {
         $cond = ' WHERE module_id IN (' . implode(',', $modid) . ')';
     }
     $sql = 'SELECT * FROM ' . DB_PREFIX . 'module_op' . $cond;
     $q = $this->db->query($sql);
     while ($mod = $this->db->fetch_array($q)) {
         $program[$mod['module_id']][$mod['op']] = $mod['op'];
         if ($mod['template']) {
             $templates[$mod['module_id']][] = $mod['template'];
         }
     }
     if ($templates) {
         hg_flushMsg('开始更新模板');
         $configtpls = array('settings', 'iframe_list');
         foreach ($templates as $m => $tpl) {
             if ($modules[$m]) {
                 hg_flushMsg('开始更新' . $modules[$m]['name'] . '模板');
                 $this->tpl->setSoftVar($modules[$m]['softvar']);
                 //设置软件界面
                 if (DEVELOP_MODE) {
                     $this->tpl->setTemplateVersion('');
                     $this->tpl->setScriptDir('');
                 } else {
                     $this->tpl->setScriptDir('app_' . $modules[$m]['softvar'] . '/');
                     $this->tpl->setTemplateVersion($modules[$m]['softvar'] . '/' . $modules[$m]['version']);
                 }
                 if (is_array($tpl)) {
                     foreach ($tpl as $t) {
                         hg_flushMsg('开始更新模板' . $t);
                         $this->tpl->recacheTemplate($t);
                     }
                 }
                 hg_flushMsg($modules[$m]['name'] . '模板更新完成');
             }
         }
         foreach ($configtpls as $t) {
             hg_flushMsg('开始更新模板' . $t);
             $this->tpl->recacheTemplate($t);
         }
         hg_flushMsg('模板更新完成');
     }
     if ($appid && $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('模块程序重建完成');
     }
 }