install.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <?php
  2. set_time_limit(600);//默认十分钟的超时
  3. function params($key, $default_value = '')
  4. {
  5. return $_POST[$key] ?? $default_value;
  6. }
  7. $run = true;
  8. if (file_exists('./installed.lock')) {//如果没有安装的就提示安装
  9. header('Location: /');
  10. $run = false;
  11. return false;//阻止后续执行
  12. }
  13. if (!$run) {
  14. exit();
  15. }
  16. // 获取当前PHP版本
  17. $phpVersion = phpversion();
  18. // 检查是否大于7.4
  19. $php_version = false;
  20. if (version_compare($phpVersion, '7.4', '>')) {
  21. $php_version = true;
  22. }
  23. $fileinfo_ext = false;
  24. if (extension_loaded('fileinfo')) {
  25. $fileinfo_ext = true;
  26. }
  27. $zip_ext = false;
  28. if (extension_loaded('zip')) {
  29. $zip_ext = true;
  30. }
  31. $mysqli_ext = false;
  32. if (extension_loaded('mysqli')) {
  33. $mysqli_ext = true;
  34. }
  35. $curl_ext = false;
  36. if (extension_loaded('curl')) {
  37. $curl_ext = true;
  38. }
  39. // 连接数据库
  40. $servername = 'localhost';
  41. $db_username = params('db_username', false);
  42. $db_password = params('db_password', false);
  43. $db_host = params('db_host', '');
  44. $db_port = params('db_port', 3306);
  45. $table_name = params('table_name', '');
  46. $admin_email = params('admin_email', '');
  47. $admin_password = params('admin_password', '');
  48. $database_type = params('database_type', 1);//1=全新安装,2=使用已存在数据库不安装数据库
  49. $error = false;
  50. $conn = null;
  51. $status = false;
  52. function isDatabaseVersionValid($conn): bool
  53. {
  54. global $error;
  55. $serverInfo = mysqli_get_server_info($conn);
  56. if (strpos($serverInfo, 'MariaDB') !== false) {
  57. return true;
  58. // preg_match('/^(\d+\.\d+\.\d+)/', $serverInfo, $matches);
  59. // $mariaDbVersion = $matches[1];
  60. // if (version_compare(trim($mariaDbVersion), '10.0.0', '>=')) {//验证MariaDB数据库版本是否大于10.2.3
  61. // return true;
  62. // }else{
  63. // $error = '<div style="text-align: center">数据库相关错误,详细信息如下</div>' . "<div style='margin-top:15px;text-align: center'>MariaDB版本低于10.0.0,请升级MariaDB版本至10.0.0及以上!</div>";
  64. // return false;
  65. // }
  66. }
  67. if (version_compare($serverInfo, '5.7', '>=')) {//验证数据库版本是否大于5.7
  68. return true;
  69. }
  70. $error = '<div style="text-align: center">数据库相关错误,详细信息如下</div>' . "<div style='margin-top:15px;text-align: center'>Mysql数据库版本低于5.7,请升级Mysql数据库至5.7及以上!</div>";
  71. return false;
  72. }
  73. if ($db_username && $php_version && $fileinfo_ext && $curl_ext && $zip_ext) {
  74. $conn = new mysqli($db_host, $db_username, $db_password, null, $db_port);
  75. if ($conn->connect_error) {
  76. $error = '<div style="text-align: center">数据库相关错误,详细信息如下</div>' . "<div style='margin-top:15px;text-align: center'>{$conn->connect_error}</div>";
  77. } else if (!isDatabaseVersionValid($conn)) {
  78. } else {
  79. if ($database_type == 1) {//全新安装
  80. $sql = "DROP DATABASE $table_name";//删除原来的
  81. $conn->query($sql);
  82. $sql = "CREATE DATABASE $table_name";//创建新的
  83. if ($conn->query($sql) !== TRUE) {
  84. $error = '数据表创建失败';
  85. }
  86. $conn = new mysqli($db_host, $db_username, $db_password, $table_name, $db_port);
  87. //数据库的格式内容数据
  88. $sql_file_content = file_get_contents('../install.sql');
  89. // 解析SQL文件内容并执行
  90. $sql_statements = explode(';', trim($sql_file_content));
  91. foreach ($sql_statements as $sql_statement) {
  92. if (!empty($sql_statement)) {
  93. try {
  94. $conn->query($sql_statement);
  95. }catch (Exception $exception){
  96. }
  97. }
  98. }
  99. //默认的一些基础数据
  100. $sql_file_content = file_get_contents('../defaultData.sql');
  101. // 解析SQL文件内容并执行
  102. $sql_statements = explode(';', trim($sql_file_content));
  103. foreach ($sql_statements as $sql_statement) {
  104. if (!empty($sql_statement)) {
  105. try {
  106. $conn->query($sql_statement);
  107. }catch (Exception $exception){
  108. }
  109. }
  110. }
  111. $admin_password = md5($admin_password);
  112. //添加默认管理员
  113. $AdminSql = ("
  114. INSERT INTO user (mail, password, create_time, login_ip, register_ip, manager, login_fail_count, login_time)
  115. VALUES ('$admin_email', '$admin_password', null, null, null, 1, DEFAULT, null);
  116. ");
  117. $conn->query($AdminSql);
  118. $conn->close();
  119. file_put_contents('./installed.lock', 'installed');
  120. $status = true;
  121. }
  122. }
  123. }
  124. if ($status) {
  125. $env = <<<EOF
  126. APP_DEBUG = false
  127. [APP]
  128. [DATABASE]
  129. TYPE = mysql
  130. HOSTNAME = {$db_host}
  131. DATABASE = {$table_name}
  132. USERNAME = {$db_username}
  133. PASSWORD = {$db_password}
  134. HOSTPORT = {$db_port}
  135. CHARSET = utf8mb4
  136. DEBUG = false
  137. [CACHE]
  138. DRIVER = file
  139. EOF;
  140. file_put_contents('../.env', $env);
  141. }
  142. ?>
  143. <?php if ($status === false) { ?>
  144. <!DOCTYPE html>
  145. <html lang="zh">
  146. <head>
  147. <title>mTab新标签页安装页面</title>
  148. <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'>
  149. <style>
  150. body {
  151. font-family: Arial, sans-serif;
  152. background: url("static/background.jpeg") no-repeat center/cover;
  153. }
  154. *::-webkit-scrollbar {
  155. display: none;
  156. }
  157. * {
  158. scrollbar-width: none;
  159. -ms-overflow-style: none;
  160. }
  161. form {
  162. max-width: 900px;
  163. margin: 0 auto 100px;
  164. background-color: #fff;
  165. padding: 20px 20px 30px 20px;
  166. border-radius: 12px;
  167. box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  168. }
  169. label {
  170. display: block;
  171. margin-bottom: 10px;
  172. font-weight: bold;
  173. margin-top: 15px;
  174. }
  175. input[type='text'], input[type='password'], input[type='number'] {
  176. text-indent: 15px;
  177. width: calc(100% - 8px);
  178. height: 45px;
  179. line-height: 30px;
  180. border: 2px solid transparent;
  181. border-radius: 10px;
  182. outline: none;
  183. background-color: #f3f3f3;
  184. color: #0d0c22;
  185. transition: .5s ease;
  186. font-size: 16px;
  187. }
  188. input[type='submit'] {
  189. width: 100%;
  190. background-color: rgb(255, 171, 84);
  191. color: #fff;
  192. border-radius: 0.9em;
  193. border: none;
  194. padding: 0.8em 1.2em 0.8em 1em;
  195. transition: all ease-in-out 0.2s;
  196. font-size: 16px;
  197. }
  198. .input:focus, input:hover {
  199. outline: none;
  200. border-color: rgba(255, 171, 84, 0.85);
  201. background-color: #fff;
  202. box-shadow: 0 0 0 5px rgba(253, 224, 99, 0.3);
  203. }
  204. input[type='submit']:hover {
  205. background-color: rgb(255, 171, 84);
  206. }
  207. #error-popup {
  208. position: fixed;
  209. left: 0;
  210. right: 0;
  211. top: 0;
  212. bottom: 0;
  213. margin: auto;
  214. width: 500px;
  215. height: fit-content;
  216. padding: 10px 20px 20px;
  217. background-color: rgb(255, 101, 2);
  218. color: #fff;
  219. border-radius: 12px;
  220. justify-content: center;
  221. z-index: 9999;
  222. }
  223. </style>
  224. <link rel='icon' href='/static/mtab.png'>
  225. </head>
  226. <body>
  227. <?php if ($error) { ?>
  228. <div id='error-popup'>
  229. <div style='text-align: center'><h2>错误提示</h2></div>
  230. <p style='text-align: center;font-size: 18px'><?php echo $error ?></p>
  231. </div>
  232. <script>
  233. setTimeout(function () {
  234. document.querySelector("#error-popup").style.display = "none";
  235. }, 5000);
  236. </script>
  237. }
  238. <?php } ?>
  239. <h1 style="text-align: center;color: #fff">mTab书签安装程序</h1>
  240. <form method='post' action='install.php'>
  241. <div style="font-size: 25px;font-weight: bold;margin-bottom: 15px;">
  242. 请优先授权程序可执行权限(755及以上的权限),并检查并安装以下php扩展
  243. </div>
  244. <div style="margin-bottom: 20px;display: flex;flex-wrap: wrap;gap:15px 40px;">
  245. <b>
  246. php版本>7.4
  247. <?php if ($php_version) { ?>
  248. <span style='color: limegreen'>✔</span>
  249. <?php } else { ?>
  250. <span style='color: red'>✘</span>
  251. <?php } ?>
  252. </b>
  253. <b>
  254. fileinfo扩展
  255. <?php if ($fileinfo_ext) { ?>
  256. <span style='color: limegreen'>✔</span>
  257. <?php } else { ?>
  258. <span style='color: red'>✘</span>
  259. <?php } ?>
  260. </b>
  261. <b>
  262. zip扩展
  263. <?php if ($zip_ext) { ?>
  264. <span style='color: limegreen'>✔</span>
  265. <?php } else { ?>
  266. <span style='color: red'>✘</span>
  267. <?php } ?>
  268. </b>
  269. <b>
  270. curl扩展
  271. <?php if ($curl_ext) { ?>
  272. <span style='color: limegreen'>✔</span>
  273. <?php } else { ?>
  274. <span style='color: red'>✘</span>
  275. <?php } ?>
  276. </b>
  277. <b>
  278. mysqli扩展
  279. <?php if ($mysqli_ext) { ?>
  280. <span style='color: limegreen'>✔</span>
  281. <?php } else { ?>
  282. <span style='color: red'>✘</span>
  283. <?php } ?>
  284. </b>
  285. </div>
  286. <div style='margin-bottom: 30px;font-weight: bolder;font-size: 19px;color: #19a673;'>
  287. mTab书签相关文档:<a target="_blank" style="color:inherit" href="https://www.mtab.cc/document.html">https://www.mtab.cc/document.html</a>
  288. </div>
  289. <label for='db_host'>mysql数据库地址: <span style='font-size: 13px;color: #1d5cdc'>Mysql数据库版本必须大于等于5.7及以上,内存大于6G推荐Mysql8,小于推荐Mysql5.7</span></label>
  290. <input value="<?php echo $db_host; ?>"
  291. placeholder="本地一般是127.0.0.1,docker部署请勿填写127.0.0.1,请使用内网ip或docker容器网关ip或者能到达数据库服务的ip"
  292. type='text' name='db_host' id='db_host'
  293. required><br>
  294. <label for='db_port'>mysql数据库端口号:</label>
  295. <input type='number' value="<?php echo $db_port; ?>" placeholder='默认 3306' name='db_port' id='db_port'
  296. required><br>
  297. <label for='db_username'>mysql数据库用户名:<span style="font-size: 13px;color: #1d5cdc">前提是当前用户名有数据库的控制权限,并且允许访问来源权限是当前服务的IP,或者是 %(代表任何来源)</span></label>
  298. <input type='text' placeholder="请输入数据库用户名" value="<?php echo $db_username; ?>" name='db_username'
  299. id='db_username' required><br>
  300. <label for='db_password'>mysql数据库密码:</label>
  301. <input type='text' name='db_password' value="<?php echo $db_password; ?>" placeholder="请输入数据库密码"
  302. id='db_password' required><br>
  303. <label for='table_name'>mysql数据库名称:</label>
  304. <input type='text' value="<?php echo $table_name; ?>" placeholder="请输入创建的数据库名称" name='table_name'
  305. id='table_name' required><br>
  306. <label for='redis_port'>管理员邮箱账号:</label>
  307. <input type='text' value="<?php echo $admin_email; ?>" placeholder='请输入邮箱,用于默认的管理员账号登录使用'
  308. name='admin_email'
  309. id='redis_port'
  310. required><br>
  311. <label for='redis_port'>管理员密码:</label>
  312. <input type='text' value="<?php echo $admin_password; ?>" placeholder='请设置管理员账号密码'
  313. name='admin_password'
  314. id='redis_port'
  315. required><br>
  316. <label for='redis_port'>数据库安装其他选项</label>
  317. <label for='install_other'></label>
  318. <label>
  319. <input checked type='radio' name='database_type' value='1' required>
  320. 全新安装(如果数据库存在则删除原来的数据库,重新安装)
  321. </label>
  322. <label>
  323. <input type='radio' name='database_type' value='2' required>
  324. 使用已存在数据库(不会覆盖数据库,仅安装代码,注意的是数据库的数据表要和最新版本的程序的库一致,否则使用旧版本的数据库表<b
  325. style="color: red">却</b>安装最新版的代码,否则导致有些服务异常)
  326. </label>
  327. <input type='submit' value='安装(点击后请耐心等待安装完成)' style="margin-top: 30px">
  328. <div style='margin-top: 30px;font-size: 14px;line-height: 24px;display: flex;flex-direction: column;align-items: center;text-align: center'>
  329. <b style="font-size: 18px">温馨提示</b>如果您在安装阶段出现问题或对安装方式(特别是Nas部署用户)不知如何操作,可联系我们为您提供解决方法或辅助您安装,本服务不收费
  330. <a target='_blank'
  331. style='text-decoration: none;color: #ffffff;padding: 5px 15px;background: #1e9fff;border-radius: 30px;margin-top: 10px;'
  332. href='https://mtab.cc'>点我跳转至官网,点击右下角客服即可联系</a>
  333. </div>
  334. </form>
  335. </body>
  336. </html>
  337. <?php } else { ?>
  338. <!DOCTYPE html>
  339. <html lang="zh">
  340. <head>
  341. <meta charset="UTF-8">
  342. <title>网站安装完毕</title>
  343. <style>
  344. body {
  345. font-family: Arial, sans-serif;
  346. background-color: #fff;
  347. text-align: center;
  348. margin: 0;
  349. padding: 0;
  350. }
  351. .container {
  352. background-color: #fff;
  353. padding: 20px;
  354. border-radius: 10px;
  355. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  356. margin: 50px auto;
  357. max-width: 800px;
  358. }
  359. h1 {
  360. color: #333;
  361. }
  362. p {
  363. color: #666;
  364. font-size: 18px;
  365. }
  366. .btn-container {
  367. margin-top: 20px;
  368. }
  369. .btn {
  370. display: inline-block;
  371. padding: 10px 20px;
  372. margin-right: 10px;
  373. background-color: rgb(255, 171, 84);
  374. color: #fff;
  375. text-decoration: none;
  376. border-radius: 5px;
  377. transition: background-color 0.3s;
  378. }
  379. .btn:hover {
  380. background-color: rgb(255, 147, 38);
  381. }
  382. </style>
  383. <link rel='icon' href='favicon.png'>
  384. </head>
  385. <body>
  386. <div class='container'>
  387. <h1 style="align-content: center">mTab书签安装完毕</h1>
  388. <div style="display: flex;justify-content: center">
  389. <svg style="width: 100px" t='1694607796889' class='icon' viewBox='0 0 1024 1024' version='1.1'
  390. xmlns='http://www.w3.org/2000/svg'
  391. p-id='40460' width='128' height='128'>
  392. <path d='M512 0C230.4 0 0 230.4 0 512c0 281.6 230.4 512 512 512 281.6 0 512-230.4 512-512C1024 230.4 793.6 0 512 0zM512 960c-249.6 0-448-204.8-448-448 0-249.6 204.8-448 448-448 249.6 0 448 198.4 448 448C960 761.6 761.6 960 512 960zM691.2 339.2 454.4 576 332.8 454.4c-19.2-19.2-51.2-19.2-76.8 0C243.2 480 243.2 512 262.4 531.2l153.6 153.6c19.2 19.2 51.2 19.2 70.4 0l51.2-51.2 224-224c19.2-19.2 25.6-51.2 0-70.4C742.4 320 710.4 320 691.2 339.2z'
  393. fill='#54E283' p-id='40461'></path>
  394. </svg>
  395. </div>
  396. <p>欢迎使用mTab书签,<br>点击下方按钮跳转到首页。</p>
  397. <div class='btn-container'>
  398. <a class='btn' href='/'>进入首页</a>
  399. </div>
  400. <p>后台进入方式,需要用管理员账户登录客户端<br/></p>
  401. <p><b>鼠标在桌面右击打开菜单->点击设置->个人中心->登录管理员的账号</b><br/>
  402. <b>
  403. ->再次进入个人中心即可看到->管理后台->进入即可</b></p>
  404. <p>这是一个多用户的书签导航程序,用户之间数据是隔离的不受干扰</p>
  405. <p>可以使用鼠标右键在桌面点击呼出菜单。</p>
  406. <p>很多功能就在鼠标右键菜单内。别怪我没告诉你哟hahaha~</p>
  407. <div style='margin-bottom: 30px;font-weight: bolder;font-size: 19px;color: #19a673;'>
  408. mTab书签相关文档:<a target='_blank' style='color:inherit' href='https://www.mtab.cc/document.html'>https://www.mtab.cc/document.html</a>
  409. </div>
  410. </div>
  411. </body>
  412. </html>
  413. <?php } ?>