diff --git a/README.md b/README.md index 7014183..50f0048 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,19 @@ ## 使用方法 +### 初始设置 - 在`系统基本设置`修改宝塔面板接口设置。你需要一个官方最新脚本安装并绑定账号的宝塔面板,用于获取最新插件列表及插件包。并根据界面提示安装好专用插件。 - 在`定时任务设置`执行所显示的命令从宝塔官方获取最新的插件列表并批量下载插件包(增量更新)。当然你也可以去插件列表,一个一个点击下载。 +### 替换域名 +#### 方法1 一键替换 +- cd 进入当前项目目录 输入 python ./tools/update_domain.py 运行脚本 跟随提示输入信息即可。 +- 注意需要使用 Python3 哦。 +#### 方法2 手动替换 - 在public/install/src和update文件夹里面分别是Linux面板安装包和更新包,解压后源码里面全部的 www.example.com 替换成你自己搭建的云端域名(如果云端用了强制https也需要单独改),然后重新打包。可使用VSCode等支持批量替换的软件。 - 在public/win/panel/panel_x.x.x.zip是Windows面板的更新包,同样方法替换域名。 - Linux面板安装脚本public/install/install_6.0.sh和更新脚本update6.sh里面的 www.example.com 替换成你自己搭建的云端域名。 - Windows面板更新脚本 public/win/install/panel_update.py、public/win/panel/data/setup.py、api.py 里面的 www.example.com 替换成你自己搭建的云端域名。 +### 安装脚本 - 访问网站`/download`查看使用此第三方云端的一键安装脚本 ## 其他 diff --git a/tools/update_domain.py b/tools/update_domain.py new file mode 100644 index 0000000..edc13b6 --- /dev/null +++ b/tools/update_domain.py @@ -0,0 +1,94 @@ +# coding=utf-8 +import os +import re +import zipfile + +replaceFile = [ + "./public/install/install_6.0.sh", + "./public/install/update_panel.sh", + "./public/install/update6.sh", + "./public/win/install/panel_update.py", + "./public/win/panel/data/setup.py", + "./public/win/panel/data/api.py", +] + +replaceZipDir = [ + "./public/install/src/", + "./public/install/update/", + "./public/win/panel/", +] + +originalDomain = "www.example.com" + +originalDomainSSL = { + "http://www.example.com": "https://", + "http:\/\/www.example.com": "https:\/\/", +} + +isSSL = False + + +def replaceStringInFile(filePath, newString): + with open(filePath, "r+", encoding="utf-8") as f: + fileContent = f.read() + if isSSL: + for key, value in originalDomainSSL.items(): + fileContent = fileContent.replace(key, value+newString) + else: + fileContent = fileContent.replace(originalDomain, newString) + f.seek(0) + f.write(fileContent) + f.truncate() + + +def replaceStringInZip(zipPath, newString): + if zipPath.endswith(".zip"): + oldZipPath = zipPath + ".old" + os.rename(zipPath, oldZipPath) + with zipfile.ZipFile(oldZipPath) as inZip, zipfile.ZipFile(zipPath, "w") as outZip: + for inZipInfo in inZip.infolist(): + with inZip.open(inZipInfo) as inFile: + if (inZipInfo.filename.endswith(".py") or inZipInfo.filename.endswith(".sh")) and inZipInfo.filename != "panel/class/sewer/cli.py": + data = inFile.read() + if isSSL: + for key, value in originalDomainSSL.items(): + data = data.replace(key.encode("utf-8"), (value + newString).encode("utf-8")) + else: + data = data.replace(originalDomain.encode("utf-8"), newString.encode("utf-8")) + outZip.writestr(inZipInfo, data) + else: + outZip.writestr(inZipInfo, inFile.read()) + os.remove(oldZipPath) + + +if __name__ == '__main__': + newDomain = input("Please enter your domain(www.aaaa.com): ") + if not re.match("^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})*$", newDomain): + print("Domain format error!") + exit() + print("Your domain is: " + newDomain) + + ssl = input("Is your domain SSL?(y/n): ") + if ssl == "y": + isSSL = True + elif ssl == "n": + isSSL = False + else: + print("Input error!") + exit() + + projectPath = os.path.abspath(__file__+"/../..") + print("Your project path is: " + projectPath) + + for aFilePath in replaceFile: + aFileFullPath = os.path.abspath(projectPath+aFilePath) + replaceStringInFile(aFileFullPath, newDomain) + print("Single file replace done. wait for zip file replace...") + + for aZipDir in replaceZipDir: + if os.path.exists(aZipDir): + for aZipFile in os.listdir(aZipDir): + if aZipFile.endswith(".zip"): + print(os.path.abspath(projectPath+aZipDir+aZipFile)) + replaceStringInZip(aZipDir+aZipFile, newDomain) + print("All done.")