-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
468 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
namespace app\controller; | ||
|
||
use PDO; | ||
use Exception; | ||
use app\BaseController; | ||
use think\facade\View; | ||
use think\facade\Cache; | ||
|
||
class Install extends BaseController | ||
{ | ||
public function index() | ||
{ | ||
if (file_exists(app()->getRootPath().'.env')){ | ||
return '当前已经安装成功,如果需要重新安装,请手动删除根目录.env文件'; | ||
} | ||
if(request()->isPost()){ | ||
$mysql_host = input('post.mysql_host', null, 'trim'); | ||
$mysql_port = intval(input('post.mysql_port', '3306')); | ||
$mysql_user = input('post.mysql_user', null, 'trim'); | ||
$mysql_pwd = input('post.mysql_pwd', null, 'trim'); | ||
$mysql_name = input('post.mysql_name', null, 'trim'); | ||
$mysql_prefix = input('post.mysql_prefix', 'cloud_', 'trim'); | ||
$admin_username = input('post.admin_username', null, 'trim'); | ||
$admin_password = input('post.admin_password', null, 'trim'); | ||
|
||
if(!$mysql_host || !$mysql_user || !$mysql_pwd || !$mysql_name || !$admin_username || !$admin_password){ | ||
return json(['code'=>0, 'msg'=>'必填项不能为空']); | ||
} | ||
|
||
$configdata = file_get_contents(app()->getRootPath().'.env.example'); | ||
$configdata = str_replace(['{dbhost}','{dbname}','{dbuser}','{dbpwd}','{dbport}','{dbprefix}'], [$mysql_host, $mysql_name, $mysql_user, $mysql_pwd, $mysql_port, $mysql_prefix], $configdata); | ||
|
||
try{ | ||
$DB=new PDO("mysql:host=".$mysql_host.";dbname=".$mysql_name.";port=".$mysql_port,$mysql_user,$mysql_pwd); | ||
}catch(Exception $e){ | ||
if($e->getCode() == 2002){ | ||
$errorMsg='连接数据库失败:数据库地址填写错误!'; | ||
}elseif($e->getCode() == 1045){ | ||
$errorMsg='连接数据库失败:数据库用户名或密码填写错误!'; | ||
}elseif($e->getCode() == 1049){ | ||
$errorMsg='连接数据库失败:数据库名不存在!'; | ||
}else{ | ||
$errorMsg='连接数据库失败:'.$e->getMessage(); | ||
} | ||
return json(['code'=>0, 'msg'=>$errorMsg]); | ||
} | ||
$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); | ||
$DB->exec("set sql_mode = ''"); | ||
$DB->exec("set names utf8"); | ||
|
||
$sqls=file_get_contents(app()->getRootPath().'install.sql'); | ||
$sqls=explode(';', $sqls); | ||
$sqls[]="REPLACE INTO `".$mysql_prefix."config` VALUES ('syskey', '".random(16)."')"; | ||
$success=0;$error=0;$errorMsg=null; | ||
foreach ($sqls as $value) { | ||
$value=trim($value); | ||
if(empty($value))continue; | ||
$value = str_replace('cloud_',$mysql_prefix,$value); | ||
if($DB->exec($value)===false){ | ||
$error++; | ||
$dberror=$DB->errorInfo(); | ||
$errorMsg.=$dberror[2]."\n"; | ||
}else{ | ||
$success++; | ||
} | ||
} | ||
if(empty($errorMsg)){ | ||
if(!file_put_contents(app()->getRootPath().'.env', $configdata)){ | ||
return json(['code'=>0, 'msg'=>'保存失败,请确保网站根目录有写入权限']); | ||
} | ||
Cache::clear(); | ||
return json(['code'=>1, 'msg'=>'安装完成!成功执行SQL语句'.$success.'条']); | ||
}else{ | ||
return json(['code'=>0, 'msg'=>$errorMsg]); | ||
} | ||
} | ||
return view(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
|
||
Linux_Version="7.9.3" | ||
Windows_Version="7.6.0" | ||
|
||
FILES=( | ||
public/install/src/panel6.zip | ||
public/install/update/LinuxPanel-${Linux_Version}.zip | ||
public/install/install_6.0.sh | ||
public/install/update_panel.sh | ||
public/install/update6.sh | ||
public/win/install/panel_update.py | ||
public/win/panel/panel_${Windows_Version}.zip | ||
public/win/panel/data/api.py | ||
public/win/panel/data/setup.py | ||
) | ||
|
||
DIR=$1 | ||
SITEURL=$2 | ||
|
||
if [ ! -d "$DIR" ]; then | ||
echo "网站目录不存在" | ||
exit 1 | ||
fi | ||
if [ "$SITEURL" = "" ]; then | ||
echo "网站URL不正确" | ||
exit 1 | ||
fi | ||
|
||
function handleFile() | ||
{ | ||
Filename=$1 | ||
if [ "${Filename##*.}" = "zip" ]; then | ||
handleZipFile $Filename | ||
else | ||
handleTextFile $Filename | ||
fi | ||
} | ||
|
||
function handleZipFile() | ||
{ | ||
Filename=$1 | ||
mkdir -p /tmp/package | ||
unzip -o -q $Filename -d /tmp/package | ||
grep -rl --include=\*.py --include=\*.sh --include=index.js 'http://www.example.com' /tmp/package | xargs -I @ sed -i "s|http://www.example.com|${SITEURL}|g" @ | ||
Sprit_SITEURK=${SITEURL//\//\\\\\/} | ||
grep -rl --include=\*.sh 'http:\\\/\\\/www.example.com' /tmp/package | xargs -I @ sed -i "s|http:\\\/\\\/www.example.com|${Sprit_SITEURK}|g" @ | ||
rm -f $Filename | ||
cd /tmp/package && zip -9 -q -r $Filename * && cd - | ||
rm -rf /tmp/package | ||
} | ||
|
||
function handleTextFile() | ||
{ | ||
sed -i "s|http://www.example.com|${SITEURL}|g" $1 | ||
} | ||
|
||
|
||
echo "==========================" | ||
echo "正在处理中..." | ||
echo "==========================" | ||
|
||
for File in ${FILES[@]} | ||
do | ||
Filename="${DIR}${File}" | ||
if [ -f "$Filename" ]; then | ||
handleFile $Filename | ||
echo -e "成功处理文件:\033[32m${Filename}\033[0m" | ||
else | ||
echo -e "文件不存在:\033[33m${Filename}\033[0m" | ||
fi | ||
done | ||
|
||
echo "==========================" | ||
echo "处理完成" | ||
echo "==========================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.