add_server.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Aisky-Sixth</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  8. <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  11. <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
  12. <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  15. <!--可用來建立使用者小圖示-->
  16. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  17. <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.dev.js"></script>
  18. <!-- <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script>-->
  19. <!-- <script src="https://cdn.socket.io/4.0.1/socket.io.min.js" integrity="sha384-LzhRnpGmQP+lOvWruF/lgkcqD+WDVt9fU3H4BWmwP5u5LTmkUGafMcpZKNObVMLU" crossorigin="anonymous"></script>-->
  20. <style>
  21. body {
  22. margin:0;
  23. }
  24. .navbar-dark .navbar-nav .nav-link {
  25. color: white;
  26. cursor: pointer;
  27. text-decoration:none;
  28. width: 130px;
  29. height: 46px;
  30. }
  31. .nav-top {
  32. line-height:40px;
  33. background-color: #C4C4C4;
  34. }
  35. .website_title{
  36. font-family: Roboto;
  37. font-style: normal;
  38. font-weight: normal;
  39. font-size: 30px;
  40. color: #000000;
  41. }
  42. .navbar-nav > li{
  43. float: none;
  44. display: inline-block;
  45. width: 110px;
  46. margin: 0 auto;
  47. text-align: center;
  48. }
  49. .navbar-nav > li a{
  50. font-size: 20px;
  51. }
  52. .main-page {
  53. margin-top: 150px;
  54. }
  55. .page-title {
  56. font-family: Roboto;
  57. font-style: normal;
  58. font-weight: bold;
  59. font-size: 36px;
  60. }
  61. .flex {
  62. display: flex;
  63. flex-direction: row;
  64. flex-wrap: wrap;
  65. justify-content: center;
  66. }
  67. .set-link {
  68. display: inline-block;
  69. width: 350px;
  70. height: 100px;
  71. line-height: 100px;
  72. background: #008CBA;
  73. border: 1px solid #CFCFCF;
  74. box-sizing: border-box;
  75. color: #FFFFFF;
  76. border-radius: 10px;
  77. font-size: 36px;
  78. }
  79. .fa{
  80. display: inline-block;
  81. font: normal normal normal 14px/1 FontAwesome;
  82. font-size: inherit;
  83. text-rendering: auto;
  84. -webkit-font-smoothing: antialiased;
  85. }
  86. .fa-user-o:before{
  87. content: "\f2c0";
  88. }
  89. button {
  90. cursor: pointer;
  91. }
  92. @media(max-width:373px){
  93. .card {
  94. margin-right: 0px;
  95. }
  96. }
  97. @media(max-width:577px){
  98. }
  99. @media(min-width:576px){
  100. }
  101. @media(min-width:768px){
  102. .navbar-nav > li {
  103. margin-left: 0px;
  104. }
  105. .navbar-nav .li-block {
  106. display:none;
  107. }
  108. }
  109. @media(min-width:991px){
  110. .navbar-nav > li {
  111. margin-left: 20px;
  112. }
  113. .navbar-nav .li-block {
  114. display:none;
  115. }
  116. }
  117. @media(min-width:1200px){
  118. .navbar-nav > li {
  119. margin-left: 35px;
  120. }
  121. .navbar-nav .li-block {
  122. display: inline-block;
  123. width: 100px;
  124. }
  125. }
  126. @media(min-width:1400px){
  127. .navbar-nav .li-block {
  128. display: inline-block;
  129. width: 200px;
  130. }
  131. }
  132. @media(min-width:1689px) {
  133. .navbar-nav > li {
  134. margin-left: 50px;
  135. }
  136. .navbar-nav .li-block {
  137. display: inline-block;
  138. width: 500px;
  139. }
  140. }
  141. </style>
  142. <script>
  143. // // 原本就註解
  144. // //驗證token,如果不符合或過期就登出回登入頁
  145. // var str = localStorage.getItem('Hello');
  146. // $.ajax({
  147. // type: "GET",
  148. // url: "/auth",
  149. // headers: {'Authorization': 'Bearer ' + str},
  150. // success: function(result){
  151. // console.log(result.identity);
  152. // },
  153. // error: function(result){
  154. // window.location.href='/logout';
  155. // }
  156. // });
  157. var install_item_list = []; // 所有安裝的套件 1-1. python3.8
  158. const STATUS = '{{params.STATUS}}';
  159. console.log("STATUS: " + STATUS);
  160. $(document).ready(function(){
  161. if (STATUS === '3') {
  162. document.getElementById("Item3").checked = false;
  163. document.getElementById("Item5").checked = false;
  164. document.getElementById("Item3").setAttribute('disabled', 'disabled');
  165. document.getElementById("Item5").setAttribute('disabled', 'disabled');
  166. }
  167. package_update();
  168. })
  169. $(function(){
  170. var namespace = '/test_conn';
  171. var url = 'http://127.0.0.1';
  172. var port = '5000';
  173. // var socket = io.connect(url + ':' + port + namespace);
  174. });
  175. function package_update() {
  176. // console.log("install_item_list: " + install_item_list);
  177. var select_install_item_list = install_item_list.slice();
  178. var Item_select_list = []; // 勾選欲安裝的項目
  179. for (let i = 1; i < 9; i++) {
  180. var install_item_true = document.getElementById("Item" + i).checked;
  181. if (install_item_true) {
  182. Item_select_list.push(String(i));
  183. }
  184. }
  185. // console.log("Item_select_list: " + Item_select_list);
  186. for (let x = select_install_item_list.length-1; x >= 0; x--) {
  187. if (Item_select_list.indexOf(select_install_item_list[x].substring(0,1)) == -1) {
  188. select_install_item_list.splice(x, 1);
  189. }
  190. }
  191. // console.log("select_install_item_list: " + select_install_item_list);
  192. item_table = '<h1>Item install status</h1>' +
  193. '<table class="table table-bordered" style="font-size:23px;margin-top:30px;">' +
  194. '<tbody>' +
  195. '<tr><th>Item</th><th>Status</th></tr>';
  196. for (let itable = 0; itable < select_install_item_list.length; itable++) {
  197. var package_index = select_install_item_list[itable].indexOf('.');
  198. var package_name = select_install_item_list[itable].substring(package_index+1);
  199. item_table += '<tr>' +
  200. '<td>' + select_install_item_list[itable] + '</td>' +
  201. '<td>' +
  202. '<div class="progress" style="height:35px;">' +
  203. '<div id="' + package_name + '-status" name="' + package_name + '-status" class="progress-bar progress-bar-striped" style="width:0%; height:35px; font-size:20px; color:black; text-align:center;">0%</div>' +
  204. '</div>' +
  205. '</td>' +
  206. '</tr>';
  207. }
  208. item_table += '</tbody>' + '</table>';
  209. var target_item = document.getElementById("install_items");
  210. target_item.innerHTML = '';
  211. target_item.innerHTML = item_table;
  212. }
  213. </script>
  214. </head>
  215. <body>
  216. <nav class="fixed-top">
  217. <nav class="navbar navbar-expand-md nav-top justify-content-center">
  218. <div>
  219. <span class="website_title">伺服器建置</span>
  220. </div>
  221. </nav>
  222. <nav class="navbar navbar-expand-md bg-dark navbar-dark nav-bottom">
  223. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
  224. <span class="navbar-toggler-icon"></span>
  225. </button>
  226. <div class="collapse navbar-collapse" id="collapsibleNavbar">
  227. <ul class="navbar-nav">
  228. <li class="nav-item">
  229. <a class="nav-link" href="/">首頁</a>
  230. </li>
  231. <li class="nav-item">
  232. <a class="nav-link" href="/incoming_check">進貨檢測</a>
  233. </li>
  234. <li class="nav-item">
  235. <a class="nav-link" href="/burn_program">感測器燒錄</a>
  236. </li>
  237. <li class="nav-item">
  238. <a class="nav-link" href="/modify_permissions">權限設置</a>
  239. </li>
  240. <li class="nav-item">
  241. <a class="nav-link" href="/add_sensor">新增感測器</a>
  242. </li>
  243. <li class="nav-item">
  244. <a class="nav-link" href="/add_server">伺服器建置</a>
  245. </li>
  246. <li class="li-block"></li>
  247. <li class="nav-item">
  248. <a class="nav-link" href="#"><i class="fa fa-user-o"></i> {{params.username}}</a>
  249. </li>
  250. <li class="nav-item">
  251. <a class="nav-link" href="/logout">Logout</a>
  252. </li>
  253. </ul>
  254. </div>
  255. </nav>
  256. </nav>
  257. <div class="main-page">
  258. <div class="container">
  259. <div class="row">
  260. <div class="col" style="margin: auto; ">
  261. <!-- 說明文件 -->
  262. <div style="text-align:center; font-size: 23px; color: crimson;">
  263. <a href="http://60.250.156.230:3000/Automatic_build_system/Automatically_install_files/src/master/README.md"
  264. target="_blank">自動布建伺服器環境建置手冊</a>
  265. </div>
  266. <table class="table table-bordered" style="font-size:23px;margin-top:30px;">
  267. <tbody>
  268. <tr>
  269. <td>1.請輸入您的IP位置:</td>
  270. <td><input type="text" name="user_ip" value="60.250.156.232"></td>
  271. </tr>
  272. <tr>
  273. <td>2.請輸入您的登入帳號:</td>
  274. <td><input type="text" name="user_loginname" value="root"></td>
  275. </tr>
  276. <tr>
  277. <td>3.請輸入您的username:</td>
  278. <td><input type="text" name="user_username" value="gs1802"></td>
  279. </tr>
  280. <tr>
  281. <td>4.請輸入您的password:</td>
  282. <td><input type="password" name="user_password" value="g53743001"></td>
  283. </tr>
  284. <!-- 勾選安裝套件 -->
  285. <tr>
  286. <th>請勾選欲安裝之套件</th>
  287. <td>
  288. <input type="checkbox" class="" id="Item1" onclick="package_update()" checked>
  289. <label for="Item1">Item1 - Common Command</label><br>
  290. <input type="checkbox" class="" id="Item2" onclick="package_update()" checked>
  291. <label for="Item2">Item2 - LAMP</label><br>
  292. <input type="checkbox" class="" id="Item3" onclick="package_update()" checked>
  293. <label for="Item3">Item3 - MQTT Server</label><br>
  294. <input type="checkbox" class="" id="Item4" onclick="package_update()" checked>
  295. <label for="Item4">Item4 - Watchdog</label><br>
  296. <input type="checkbox" class="" id="Item5" onclick="package_update()" checked>
  297. <label for="Item5">Item5 - Git Server</label><br>
  298. <input type="checkbox" class="" id="Item6" onclick="package_update()" checked>
  299. <label for="Item6">Item6 - Python packegs Library</label><br>
  300. <input type="checkbox" class="" id="Item7" onclick="package_update()" checked >
  301. <label for="Item7">Item7 - AP(WebPage)</label><br>
  302. <input type="checkbox" class="" id="Item8" onclick="package_update()" checked>
  303. <label for="Item8">Item8 - ROS ubuntu 18.04 melodic</label>
  304. </td>
  305. </tr>
  306. </tbody>
  307. </table>
  308. <div class="text-center">
  309. <input type="button" value="建置" name="add_server" style="cursor:pointer;" onclick="AddServer()">
  310. </div>
  311. <div class="text-center" id="addServer-status" style="margin-top:30px;color:red;visibility:hidden;">
  312. <h2>伺服器建置中...</h2>
  313. </div>
  314. <div id="install_items">
  315. <h1>Item install status</h1>
  316. <table class="table table-bordered" style="font-size:23px;margin-top:30px;">
  317. <tbody>
  318. <tr>
  319. <th>Item</th>
  320. <th>Status</th>
  321. </tr>
  322. {% for item in params.L %}
  323. <script>
  324. var item = '{{item}}';
  325. install_item_list.push(item);
  326. </script>
  327. <tr>
  328. <td>{{loop.index}}.{{item}}</td>
  329. <td>{{item}}</td>
  330. <td>
  331. <div class="progress" style="height:35px;">
  332. <div id="{{item}}-status" name="{{item}}-status" class="progress-bar progress-bar-striped"
  333. style="width:0%; height:35px; font-size:20px; color:black; text-align:center;">0%
  334. </div>
  335. </div>
  336. </td>
  337. </tr>
  338. {% endfor %}
  339. </tbody>
  340. </table>
  341. </div>
  342. </div>
  343. </div>
  344. </div>
  345. </div>
  346. </body>
  347. <script>
  348. function AddBarIndex(obj){
  349. // console.log("obj: ", obj)
  350. var item = document.getElementById(obj);
  351. // console.log("item: ", item)
  352. //因假設元素id內有.或是空格的使用jQuery選擇器會找不到,所以改成用js的節點來設置
  353. //[0].style.width 讓width顯示為%值,使用css.('width')會顯示px
  354. //var width = obj[0].style.width;
  355. var width = item.style.width;
  356. // console.log("width: " + width);
  357. var current_width = width.substring(0, width.length-1);
  358. console.log("current_width: " + current_width);
  359. item.style.width = Number(current_width) + 2 + '%';
  360. // console.log("item.style.width: " + item.style.width);
  361. item.innerText = Number(current_width) + 2 + '%';
  362. // console.log("item.innerText: " + item.innerText);
  363. if (current_width == 94) {
  364. console.log(obj + ' INSTALLATION AddBar Pause');
  365. // eval('clearInterval(timer)');
  366. clearInterval(timer);
  367. }
  368. };
  369. function AddServer(){
  370. //var item = document.getElementById('python3.8-status');
  371. //item.style.width = '2%';
  372. //item.innerText = '2%';
  373. //timer_python38 = window.setInterval("AddBarIndex('python3.8-status')", 2000);
  374. $("#addServer-status").css('visibility','visible');
  375. var ip = $("input[name=user_ip]").val();
  376. var loginname = $("input[name=user_loginname]").val();
  377. var username = $("input[name=user_username]").val();
  378. var password = $("input[name=user_password]").val();
  379. var item1_checked = document.getElementById("Item1").checked;
  380. var item2_checked = document.getElementById("Item2").checked;
  381. var item3_checked = document.getElementById("Item3").checked;
  382. var item4_checked = document.getElementById("Item4").checked;
  383. var item5_checked = document.getElementById("Item5").checked;
  384. var item6_checked = document.getElementById("Item6").checked;
  385. var item7_checked = document.getElementById("Item7").checked;
  386. var item8_checked = document.getElementById("Item8").checked;
  387. var json = { "ip":ip,
  388. "loginname":loginname,
  389. "username":username,
  390. "password":password,
  391. "item1_checked":item1_checked,
  392. "item2_checked":item2_checked,
  393. "item3_checked":item3_checked,
  394. "item4_checked":item4_checked,
  395. "item5_checked":item5_checked,
  396. "item6_checked":item6_checked,
  397. "item7_checked":item7_checked,
  398. "item8_checked":item8_checked
  399. };
  400. var abs_update_interval = window.setInterval("abs_update()", 1000);
  401. $.post('/add_server', json, function(resText){
  402. $("#addServer-status").css('visibility','hidden');
  403. if(resText == 'Authentication failed.'){
  404. resText = '您輸入的密碼有誤,請重新輸入!';
  405. $("input[name=user_ip]").val('');
  406. $("input[name=user_username]").val('');
  407. $("input[name=user_password]").val('');
  408. };
  409. clearInterval(abs_update_interval);
  410. setTimeout(alert(resText), 1000);
  411. }, 'text');
  412. };
  413. Automatic_Build_System_installation = {
  414. 'python3.8-installation': 'Wait',
  415. 'python3-pip-installation': 'Wait',
  416. 'cryptography-installation': 'Wait',
  417. 'upgrade-installation': 'Wait',
  418. 'grep-installation': 'Wait',
  419. 'git-installation': 'Wait',
  420. 'gitpython-installation': 'Wait',
  421. 'python3-tk-installation': 'Wait',
  422. 'wget-installation': 'Wait',
  423. 'python3-dev-installation': 'Wait',
  424. 'default-libmysqlclient-dev-installation': 'Wait',
  425. 'build-essential-installation': 'Wait',
  426. 'tasksel-installation': 'Wait',
  427. 'lamp-server-installation': 'Wait',
  428. 'phpMyAdmin-5.1.0-all-languages.tar.gz-installation': 'Wait',
  429. 'openssl-installation': 'Wait',
  430. 'php-common-installation': 'Wait',
  431. 'php-curl-installation': 'Wait',
  432. 'php-json-installation': 'Wait',
  433. 'php-mbstring-installation': 'Wait',
  434. 'php-mysql-installation': 'Wait',
  435. 'php-xml-installation': 'Wait',
  436. 'php-zip-installation': 'Wait',
  437. 'php7.2-mbstring-installation': 'Wait',
  438. 'php7.2-xml-installation': 'Wait',
  439. 'php7.2-mysql-installation': 'Wait',
  440. 'php7.2-common-installation': 'Wait',
  441. 'php7.2-curl-installation': 'Wait',
  442. 'php7.2-json-installation': 'Wait',
  443. 'php7.2-zip-installation': 'Wait',
  444. 'apache2-installation': 'Wait',
  445. 'paho-mqtt-installation': 'Wait',
  446. 'mosquitto-installation': 'Wait',
  447. 'mqtt_server_setting-installation': 'Wait',
  448. 'rclocal/rc.local-installation': 'Wait',
  449. 'golang-installation': 'Wait',
  450. 'gogsfile-installation': 'Wait',
  451. 'requirements-installation': 'Wait',
  452. 'CoffeeProject-installation': 'Wait',
  453. 'BBend-Test-JWT-installation': 'Wait',
  454. 'Coffee_MySQL-installation': 'Wait',
  455. 'chrony-installation': 'Wait',
  456. 'ntpdate-installation': 'Wait',
  457. '--keyserver-installation': 'Wait',
  458. 'update-installation': 'Wait',
  459. 'ros-melodic-desktop-full-installation': 'Wait',
  460. 'ros-melodic-rqt*-installation': 'Wait',
  461. 'python-rosdep-installation': 'Wait',
  462. 'python-rosinstall-installation': 'Wait',
  463. 'python-rosinstall-generator-installation': 'Wait',
  464. 'python-wstool-installation': 'Wait',
  465. 'catkin_make-installation': 'Wait'
  466. }
  467. var abs_update_process = 0;
  468. var timer;
  469. function abs_update() {
  470. if (abs_update_process === 1) {
  471. return;
  472. }
  473. abs_update_process = 1;
  474. $.ajax({
  475. async:false,
  476. type:"GET",
  477. url:"/ABS_update",
  478. dataType:"JSON",
  479. success:function(response){
  480. for (const key of Object.entries(response)) {
  481. // console.log("TT" + response['requirements'])
  482. if (response[key[0]] == 'Install') {
  483. if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Wait') {
  484. Automatic_Build_System_installation[key[0] + '-installation'] = 'Install';
  485. timer = window.setInterval("AddBarIndex(\"" + key[0] + "-status\")", 2000);
  486. // eval('var ' + key[0] + '_timer = window.setInterval("AddBarIndex(\"' + key[0] + '-status\")", 2000);')
  487. // alert('!!!')
  488. }
  489. } else if (response[key[0]] == '0') {
  490. // pass
  491. } else if (response[key[0]] == 'Error') {
  492. if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  493. Automatic_Build_System_installation[key[0] + '-installation'] = 'Error';
  494. ItemInstallFail(timer, key[0]);
  495. }
  496. // } else if (response[key[0]] == 'Success') {
  497. // if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  498. // Automatic_Build_System_installation[key[0] + '-installation'] = 'Success';
  499. // ItemInstallSuccess(timer, key[0]);
  500. // }
  501. // // ========== Rita 0428 測試保留 ==========
  502. // } else if (Number(response[key[0]]) !== NaN) {
  503. // if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  504. // Automatic_Build_System_installation[key[0] + '-installation'] = 'Success';
  505. // ItemInstallSuccess(timer, key[0], response[key[0]]);
  506. // }
  507. // // ========== Rita 0428 測試保留 ==========
  508. } else if (Number(response[key[0]]) !== NaN) {
  509. // Automatic_Build_System_installation[key[0] + '-installation'] = response[key[0]];
  510. // ItemInstallSuccess(timer, key[0], response[key[0]]);
  511. if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  512. Automatic_Build_System_installation[key[0] + '-installation'] = response[key[0]];
  513. ItemInstallSuccess(timer, key[0], response[key[0]]);
  514. } else if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Wait') {
  515. Automatic_Build_System_installation[key[0] + '-installation'] = response[key[0]];
  516. console.log(key[0] + " : " + response[key[0]]);
  517. ItemInstallSuccess(timer, key[0], response[key[0]]);
  518. }
  519. } else {
  520. console.log("response[key[0]]: " + response[key[0]]);
  521. }
  522. }
  523. abs_update_process = 0;
  524. },
  525. error:function(thrownError){
  526. console.log("thrownError: " + thrownError);
  527. abs_update_process = 0;
  528. }
  529. });
  530. };
  531. function ItemInstallSuccess(timer_item, item_name, execution_time){
  532. eval('clearInterval(' + timer_item + ')');
  533. var item = document.getElementById(item_name + '-status');
  534. item.style.width = '100%';
  535. item.innerText = execution_time + 's';
  536. };
  537. function ItemInstallFail(timer_item, item_name){
  538. eval('clearInterval(' + timer_item + ')');
  539. var item = document.getElementById(item_name + '-status');
  540. item.style.width = '0%';
  541. item.innerText = 'Fail';
  542. item.style.color = 'red';
  543. item.style.fontWeight = 'bold';
  544. };
  545. </script>
  546. </html>