Browse Source

增加install文件

document
陈家兴 4 years ago
parent
commit
a79fd92795
  1. 99
      install/ajax.php
  2. 78
      install/common.php
  3. 212
      install/database.php
  4. 57
      install/index.php
  5. 38
      install/lang.en.php
  6. 38
      install/lang.zh.php
  7. 69
      install/non_interactive.php

99
install/ajax.php

@ -0,0 +1,99 @@
<?php
// --------
// 如果你能在浏览器中看到本句话,则证明你没有安装好PHP运行环境。请先安装好PHP运行环境
// --------
ini_set("display_errors", "Off");
error_reporting(E_ALL | E_STRICT);
header("Content-type: text/html; charset=utf-8");
include("common.php");
if(file_exists('./install.lock') && $f = file_get_contents("./install.lock")){
ajax_out(L("lock"),10099);
}
if(!new_is_writeable("./")){
ajax_out(L("not_writable_install"),10098);
}
if(!new_is_writeable("../Public/Uploads")){
ajax_out(L("not_writable_upload"),10098);
}
if(!new_is_writeable("../server/Application/Runtime")){
ajax_out(L("not_writable_server_runtime"),10095);
}
if(!new_is_writeable("../server/Application/Home/Conf/config.php")){
ajax_out(L("not_writable_home_config"),10098);
}
$db_type = $_POST["db_type"] ? $_POST["db_type"] :"sqlite";
if ($db_type == "sqlite") {
if(!new_is_writeable("../Sqlite")){
ajax_out(L("not_writable_sqlite"),10097);
}
if(!new_is_writeable("../Sqlite/showdoc.db.php")){
ajax_out(L("not_writable_sqlite_db"),10096);
}
user_sqlite();
}
elseif ($db_type == "mysql") {
//showdoc不再支持mysql http://www.showdoc.cc/help?page_id=31990
}
function user_sqlite(){
clear_runtime();//清除缓存
write_js_lang();
$ret = write_home_config();
if ($ret) {
file_put_contents("./install.lock","https://www.showdoc.cc/");
ajax_out(L("install_success"));
}else{
ajax_out(L("not_writable_home_config"),10001);
}
}
function write_home_config(){
$lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
if ($lang == 'en') {
$DEFAULT_LANG = 'en-us';
}else{
$DEFAULT_LANG = 'zh-cn';
}
$config = "<?php ";
$config .= "
return array(
//'配置项'=>'配置值'
'DB_TYPE' => 'Sqlite',
'DB_NAME' => './Sqlite/showdoc.db.php',
'LANG_SWITCH_ON' => true, // 开启语言包功能
'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
'DEFAULT_LANG' => '{$DEFAULT_LANG}', // 默认语言
'LANG_LIST' => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
'VAR_LANGUAGE' => 'l', // 默认语言切换变量
);";
$ret = file_put_contents("../server/Application/Home/Conf/config.php", $config);
return $ret ;
}
function write_js_lang(){
$lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
if ($lang == 'en') {
replace_file_content("../web/index.html","zh-cn","en") ;
replace_file_content("../web_src/index.html","zh-cn","en") ;
}
}
function replace_file_content($file , $from ,$to ){
$content = file_get_contents($file);
$content2 = str_replace($from,$to,$content);
if ($content2) {
file_put_contents($file,$content2);
}
}

78
install/common.php

@ -0,0 +1,78 @@
<?php
/**
* 判断语言
*/
function lang(){
$lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
if ($lang == 'zh-CN') {
$lang = "zh";
}
return include("lang.".$lang.".php");
}
function L($field){
if (!isset($GLOBALS['lang'])) {
$GLOBALS['lang'] = lang();
}
return $GLOBALS['lang'][$field] ;
}
/**
* 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
*
* @param string $file 文件/目录
* @return boolean
*/
function new_is_writeable($file) {
if (is_dir($file)){
$dir = $file;
if ($fp = @fopen("$dir/test.txt", 'w')) {
@fclose($fp);
@unlink("$dir/test.txt");
$writeable = 1;
} else {
$writeable = 0;
}
} else {
if ($fp = @fopen($file, 'a+')) {
@fclose($fp);
$writeable = 1;
} else {
$writeable = 0;
}
}
return $writeable;
}
function clear_runtime($path = "../server/Application/Runtime"){
//给定的目录不是一个文件夹
if(!is_dir($path)){
return null;
}
$fh = opendir($path);
while(($row = readdir($fh)) !== false){
//过滤掉虚拟目录
if($row == '.' || $row == '..'|| $row == 'index.html'){
continue;
}
if(!is_dir($path.'/'.$row)){
unlink($path.'/'.$row);
}
clear_runtime($path.'/'.$row);
}
//关闭目录句柄,否则出Permission denied
closedir($fh);
return true;
}
function ajax_out($message,$error_code = 0){
echo json_encode(array("error_code"=>$error_code,"message"=>$message));
exit();
}

212
install/database.php

@ -0,0 +1,212 @@
<?php
// ShowDoc安装脚本
// install Showdoc
//
// --------
// 如果你能在浏览器中看到本句话,则证明你没有安装好PHP运行环境。请先安装好PHP运行环境
// --------
include("common.php");
$cur_lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
header("Content-type: text/html; charset=utf-8");
// 检测PHP环境
if(version_compare(PHP_VERSION,'5.3.0','<')) die(L('require_php_version'));
if(file_exists('./install.lock') && $f = file_get_contents("./install.lock")){
echo L("lock").'<br>';
exit();
}
$go = 1 ;
//检测文件权限
if(!new_is_writeable("./")){
echo L("not_writable_install").'<br>';
$go = 0;
}
if(!new_is_writeable("../Public/Uploads")){
echo L("not_writable_upload").'<br>';
$go = 0;
}
if(!new_is_writeable("../server/Application/Runtime")){
echo L("not_writable_server_runtime").'<br>';
$go = 0;
}
if(!new_is_writeable("../server/Application/Common/Conf/config.php")){
echo L("not_writable_config").'<br>';
$go = 0;
}
if(!new_is_writeable("../server/Application/Home/Conf/config.php")){
echo L("not_writable_home_config").'<br>';
$go = 0;
}
if ($cur_lang == 'en') {
if(!new_is_writeable("../web/index.html")){
echo L("not_writable_web_docconfig").'<br>';
$go = 0;
}
if(!new_is_writeable("../web_src/index.html")){
echo L("not_writable_web_src_docconfig").'<br>';
$go = 0;
}
}
//检查扩展
if(!extension_loaded("gd")){
echo '请安装php-gd<br>';
$go = 0;
}
/*
if(!extension_loaded("mcrypt")){
echo '请安装php-mcrypt<br>';
$go = 0;
}
*/
if(!extension_loaded("mbstring")){
echo '请安装php-mbstring<br>';
$go = 0;
}
if(!extension_loaded("zlib")){
echo '请安装php-zlib<br>';
$go = 0;
}
if(!extension_loaded("PDO") && !extension_loaded("pdo") ){
echo '请安装php-pdo<br>';
$go = 0;
}
/*if(extension_loaded("sqlite") || extension_loaded("sqlite3")){
echo '请安装php-sqlite<br>';
$go = 0;
}
*/
if (!$go) {
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> ShowDoc</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="../Public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
@charset "utf-8";
body {
font:14px/1.5 "Microsoft Yahei","微软雅黑",Tahoma,Arial,Helvetica,STHeiti;
}
.form-signin{
display: none;
}
</style>
</head>
<body>
<link rel="stylesheet" href="../Public/css/login.css" />
<div class="container">
<form class="form-signin" method="post">
<h3 class="form-signin-heading"><?php echo L("install_title");?></h3>
<br>
<div>
<select id="db_type">
<option value="sqlite"><?php echo L("use_sqlite");?></option>
<option value="mysql"><?php echo L("use_mysql");?></option>
</select>
</div>
<br>
<div class="mysql-info" style="display:none">
<input type="text" class="input-block-level" name="db_host" id = "db_host" placeholder="<?php echo L("server_address");?>">
<input type="text" class="input-block-level" name="db_port" id = "db_port" placeholder="<?php echo L("server_port");?>">
<input type="text" class="input-block-level" name="db_name" id = "db_name" placeholder="<?php echo L("db_name");?>">
<input type="text" class="input-block-level" name="db_user" id = "db_user" placeholder="<?php echo L("db_user");?>">
<input type="text" class="input-block-level" name="db_password" id = "db_password" placeholder="<?php echo L("db_password");?>">
</div>
<div class="sqlite_tips" ><?php echo L("sqlite_tips");?></div>
<input type="hidden" value="<?php echo $cur_lang;?>" id="lang">
<br>
<div>
<button class="btn btn-large btn-primary " id="start" type="submit"><?php echo L("go");?>&nbsp;&nbsp;<i class="icon-circle-arrow-right"></i></button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://www.showdoc.cc/help?page_id=16118" target="_blank"><?php echo L("FAQ");?></a>
</div>
</form>
</div> <!-- /container -->
<script src="../Public/js/common/jquery.min.js"></script>
<script src="../Public/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
<script type="text/javascript">
$(function(){
$("#db_type").change(function(){
if ($("#db_type").val() == 'mysql') {
$(".mysql-info").show();
$(".sqlite_tips").hide();
};
if ($("#db_type").val() == 'sqlite') {
$(".mysql-info").hide();
$(".sqlite_tips").show();
};
});
function install(){
var db_type = $("#db_type").val();
var db_host = $("#db_host").val();
var db_port = $("#db_port").val();
var db_name = $("#db_name").val();
var db_user = $("#db_user").val();
var lang = $("#lang").val();
var db_password = $("#db_password").val();
$.post(
'ajax.php',
{"lang":lang,"db_type":db_type,"db_host":db_host,"db_port":db_port,"db_name":db_name,"db_user":db_user,"db_password":db_password},
function(data){
if (data.error_code === 0) {
//安装成功
//alert(data.message);
var text = '<div><?php echo L("install_success_help");?></div><br>';
text += '<div><a href="../" ><?php echo L("home");?></a></div>';
$(".form-signin").html(text);
$(".form-signin").show();
}else{
alert(data.message);
}
},
"json"
);
}
$("#start").click(function(){
install();
return false;
});
//showdoc不再支持mysql,所以不再让用户选择数据库,而是直接跳过去.
install();
});
</script>

57
install/index.php

@ -0,0 +1,57 @@
<?php
// ShowDoc安装脚本
// install Showdoc
//
// --------
// 如果你能在浏览器中看到本句话,则证明你没有安装好PHP运行环境。请先安装好PHP运行环境
// --------
include("common.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> ShowDoc</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="../Public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
@charset "utf-8";
body {
font:14px/1.5 "Microsoft Yahei","微软雅黑",Tahoma,Arial,Helvetica,STHeiti;
}
</style>
</head>
<body>
<link rel="stylesheet" href="../Public/css/login.css" />
<div class="container">
<form class="form-signin" method="get" action="database.php">
<h3 class="form-signin-heading">选择语言<br>(Choose language)</h3>
<br>
<div>
<select id="db_type" name="lang">
<option value="zh">中文</option>
<option value="en">English</option>
</select>
</div>
<br>
<br>
<div>
<button class="btn btn-large btn-primary " id="start" type="submit">ok&nbsp;&nbsp;<i class="icon-circle-arrow-right"></i></button>
</div>
</form>
</div> <!-- /container -->
<script src="../Public/js/common/jquery.min.js"></script>
<script src="../Public/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

38
install/lang.en.php

@ -0,0 +1,38 @@
<?php
return array(
"install_title"=>'Install ShowDoc',
"use_sqlite"=>'Use Sqlite Database',
"use_mysql"=>'Use Mysql Database',
"server_address"=>'Server address (e.g: localhost)',
"server_port"=>'Port(e.g:3306)',
"db_name"=>'Database Name(e.g:showdoc)',
"db_user"=>'Database Username',
"db_password"=>' Database Password',
"sqlite_tips"=>'Sqlite has supported by PHP and you just need to click the Go buttun',
"go"=>'Go',
"install_success_help"=>'Installation success!The password of the default administrator account is showdoc/123456 ,After login, you can see the management backstage access in the upper right corner.In addition, it is strongly recommended to modify the administrator password .<br>More help :<a href="https://www.showdoc.cc/help-en" target="_blank">https://www.showdoc.cc/help-en</a>',
"home"=>'Website Home',
"FAQ"=>'FAQ',
"lock"=>'ShowDoc has been installed!If you want to reinstall,please delete file /install/install.lock ',
"not_writable_install"=>' Directory install is not writable !',
"not_writable_upload"=>'Directory Public/Uploads/ is not writable !',
"not_writable_runtime"=>'Directory server/Application/Runtime is not writable !',
"not_writable_server_runtime"=>'Directory server/Application/Runtime is not writable !',
"not_writable_config"=>'File server/Application/Common/Conf/config.php is not writable !',
"not_writable_home_config"=>'File server/Application/Home/Conf/config.php is not writable !',
"not_writable_sqlite"=>'Directory Sqlite is not writable !',
"not_writable_sqlite_db"=>'File Sqlite/showdoc.db.php is not writable !',
"not_writable_web_docconfig"=>'File web/index.html is not writable !',
"not_writable_web_src_docconfig"=>'File web_src/index.html is not writable !',
"install_success"=>'Installation success!Please delete the /install directory, avoid the script to be executed again',
"install_config_not_writable"=>'Fail to write config file ',
"db_wrong"=>'Database connection error',
"db_has_data"=>'Database tables already exists,please clear up and try again',
"create_table_fail"=>'Fail to create table',
"install_config_not_writable"=>'Fail to write config file',
"require_php_version" => "require PHP > 5.3.0 ",
);

38
install/lang.zh.php

@ -0,0 +1,38 @@
<?php
return array(
"install_title"=>'安装ShowDoc',
"use_sqlite"=>'使用Sqlite数据库',
"use_mysql"=>'使用Mysql数据库',
"server_address"=>'服务器地址,一般为localhost',
"server_port"=>'端口,一般为3306',
"db_name"=>'数据库名,建议数据库名为showdoc',
"db_user"=>'数据库用户名',
"db_password"=>'数据库密码',
"sqlite_tips"=>'PHP内置支持Sqlite数据库,你无须再配置数据库,直接点击开始即可',
"go"=>'开始',
"install_success_help"=>'安装成功!默认管理员账户密码是showdoc/123456。登录后,在右上角可以看到管理后台入口。此外,强烈建议修改管理员初始密码。若再遇到问题,可参考ShowDoc帮助文档:<a href="https://www.showdoc.cc/help" target="_blank">https://www.showdoc.cc/help</a>',
"home"=>'进入网站首页',
"FAQ"=>'常见问题',
"lock"=>'本程序已经安装过!如果要解除安装锁定,则可删除install目录下的install.lock文件后再重新访问本页面',
"not_writable_install"=>'请赋予 install 目录以可写权限!',
"not_writable_upload"=>'请赋予 Public/Uploads/ 目录以可写权限!',
"not_writable_runtime"=>'请赋予 server/Application/Runtime 目录以可写权限!',
"not_writable_server_runtime"=>'请赋予 server/Application/Runtime 目录以可写权限!',
"not_writable_config"=>'请赋予 server/Application/Common/Conf/config.php 文件以可写权限!',
"not_writable_home_config"=>'请赋予 server/Application/Home/Conf/config.php 文件以可写权限!<br>(如果你确定赋予了文件权限但却一直看到此信息,则可考虑关闭selinux试试)',
"not_writable_sqlite"=>'请赋予 Sqlite 目录以可写权限!',
"not_writable_sqlite_db"=>'请赋予 Sqlite/showdoc.db.php 以可写权限!',
"not_writable_web_docconfig"=>'请赋予 web/index.html 以可写权限!',
"not_writable_web_src_docconfig"=>'请赋予 web_src/index.html 以可写权限!',
"install_success"=>'安装成功!建议删除install目录,以免安装脚本被再次执行。',
"install_config_not_writable"=>'安装失败,配置文件写入错误!',
"db_wrong"=>'数据库链接错误,请检查配置信息是否填写正确',
"db_has_data"=>'检测到该数据库已经存在数据。请清理后再重试',
"create_table_fail"=>'创建数据库表失败!',
"install_config_not_writable"=>'安装失败,配置文件写入错误!',
"require_php_version" => "需要PHP5.3.0以上版本",
);

69
install/non_interactive.php

@ -0,0 +1,69 @@
<?php
// --------
// 如果你能在浏览器中看到本句话,则证明你没有安装好PHP运行环境。请先安装好PHP运行环境
// --------
ini_set("display_errors", "Off");
error_reporting(E_ALL | E_STRICT);
header("Content-type: text/html; charset=utf-8");
include("common.php");
if(file_exists('./install.lock') && $f = file_get_contents("./install.lock")){
echo L("lock")."\n";
}else{
user_sqlite();
}
function user_sqlite(){
clear_runtime();//清除缓存
write_js_lang();
$ret = write_home_config();
if ($ret) {
file_put_contents("./install.lock","https://www.showdoc.cc/");
echo 'install success !!!'."\n";
}else{
echo "\n".L("not_writable_home_config")."\n";
}
}
function write_home_config(){
$lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
if ($lang == 'en') {
$DEFAULT_LANG = 'en-us';
}else{
$DEFAULT_LANG = 'zh-cn';
}
$config = "<?php ";
$config .= "
return array(
//'配置项'=>'配置值'
'DB_TYPE' => 'Sqlite',
'DB_NAME' => './Sqlite/showdoc.db.php',
'LANG_SWITCH_ON' => true, // 开启语言包功能
'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
'DEFAULT_LANG' => '{$DEFAULT_LANG}', // 默认语言
'LANG_LIST' => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
'VAR_LANGUAGE' => 'l', // 默认语言切换变量
);";
$ret = file_put_contents("../server/Application/Home/Conf/config.php", $config);
return $ret ;
}
function write_js_lang(){
$lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
if ($lang == 'en') {
replace_file_content("../web/index.html","zh-cn","en") ;
replace_file_content("../web_src/index.html","zh-cn","en") ;
}
}
function replace_file_content($file , $from ,$to ){
$content = file_get_contents($file);
$content2 = str_replace($from,$to,$content);
if ($content2) {
file_put_contents($file,$content2);
}
}
Loading…
Cancel
Save