add_server.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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. <table class="table table-bordered" style="font-size:23px;margin-top:30px;">
  262. <tbody>
  263. <tr>
  264. <td>1.請輸入您的IP位置:</td>
  265. <td><input type="text" name="user_ip" value="60.250.156.232"></td>
  266. </tr>
  267. <tr>
  268. <td>2.請輸入您的登入帳號:</td>
  269. <td><input type="text" name="user_loginname" value="root"></td>
  270. </tr>
  271. <tr>
  272. <td>3.請輸入您的username:</td>
  273. <td><input type="text" name="user_username" value="gs1802"></td>
  274. </tr>
  275. <tr>
  276. <td>4.請輸入您的password:</td>
  277. <td><input type="password" name="user_password" value="g53743001"></td>
  278. </tr>
  279. <!-- 勾選安裝套件 -->
  280. <tr>
  281. <th>請勾選欲安裝之套件</th>
  282. <td>
  283. <input type="checkbox" class="" id="Item1" onclick="package_update()" disabled>
  284. <label for="Item1">Item1 - Common Command</label><br>
  285. <input type="checkbox" class="" id="Item2" onclick="package_update()" disabled>
  286. <label for="Item2">Item2 - LAMP</label><br>
  287. <input type="checkbox" class="" id="Item3" onclick="package_update()" >
  288. <label for="Item3">Item3 - MQTT</label><br>
  289. <input type="checkbox" class="" id="Item4" onclick="package_update()" >
  290. <label for="Item4">Item4 - Watchdog</label><br>
  291. <input type="checkbox" class="" id="Item5" onclick="package_update()" >
  292. <label for="Item5">Item5 - Git Server</label><br>
  293. <input type="checkbox" class="" id="Item6" onclick="package_update()" disabled>
  294. <label for="Item6">Item6 - Python packegs Library</label><br>
  295. <input type="checkbox" class="" id="Item7" onclick="package_update()" >
  296. <label for="Item7">Item7 - AP(WebPage)</label><br>
  297. <input type="checkbox" class="" id="Item8" onclick="package_update()" >
  298. <label for="Item8">Item8 - ROS ubuntu 18.04 melodic</label>
  299. </td>
  300. </tr>
  301. </tbody>
  302. </table>
  303. <div class="text-center">
  304. <input type="button" value="建置" name="add_server" style="cursor:pointer;" onclick="AddServer()">
  305. </div>
  306. <div class="text-center" id="addServer-status" style="margin-top:30px;color:red;visibility:hidden;">
  307. <h2>伺服器建置中...</h2>
  308. </div>
  309. <div id="install_items">
  310. <h1>Item install status</h1>
  311. <table class="table table-bordered" style="font-size:23px;margin-top:30px;">
  312. <tbody>
  313. <tr>
  314. <th>Item</th>
  315. <th>Status</th>
  316. </tr>
  317. {% for item in params.L %}
  318. <script>
  319. var item = '{{item}}';
  320. install_item_list.push(item);
  321. </script>
  322. <tr>
  323. <td>{{loop.index}}.{{item}}</td>
  324. <td>{{item}}</td>
  325. <td>
  326. <div class="progress" style="height:35px;">
  327. <div id="{{item}}-status" name="{{item}}-status" class="progress-bar progress-bar-striped"
  328. style="width:0%; height:35px; font-size:20px; color:black; text-align:center;">0%
  329. </div>
  330. </div>
  331. </td>
  332. </tr>
  333. {% endfor %}
  334. </tbody>
  335. </table>
  336. </div>
  337. </div>
  338. </div>
  339. </div>
  340. </div>
  341. </body>
  342. <script>
  343. function AddBarIndex(obj){
  344. // console.log("obj: ", obj)
  345. var item = document.getElementById(obj);
  346. // console.log("item: ", item)
  347. //因假設元素id內有.或是空格的使用jQuery選擇器會找不到,所以改成用js的節點來設置
  348. //[0].style.width 讓width顯示為%值,使用css.('width')會顯示px
  349. //var width = obj[0].style.width;
  350. var width = item.style.width;
  351. // console.log("width: " + width);
  352. var current_width = width.substring(0, width.length-1);
  353. console.log("current_width: " + current_width);
  354. item.style.width = Number(current_width) + 2 + '%';
  355. // console.log("item.style.width: " + item.style.width);
  356. item.innerText = Number(current_width) + 2 + '%';
  357. // console.log("item.innerText: " + item.innerText);
  358. if (current_width == 94) {
  359. console.log(obj + ' INSTALLATION AddBar Pause');
  360. // eval('clearInterval(timer)');
  361. clearInterval(timer);
  362. }
  363. };
  364. function AddServer(){
  365. //var item = document.getElementById('python3.8-status');
  366. //item.style.width = '2%';
  367. //item.innerText = '2%';
  368. //timer_python38 = window.setInterval("AddBarIndex('python3.8-status')", 2000);
  369. $("#addServer-status").css('visibility','visible');
  370. var ip = $("input[name=user_ip]").val();
  371. var loginname = $("input[name=user_loginname]").val();
  372. var username = $("input[name=user_username]").val();
  373. var password = $("input[name=user_password]").val();
  374. var item1_checked = document.getElementById("Item1").checked;
  375. var item2_checked = document.getElementById("Item2").checked;
  376. var item3_checked = document.getElementById("Item3").checked;
  377. var item4_checked = document.getElementById("Item4").checked;
  378. var item5_checked = document.getElementById("Item5").checked;
  379. var item6_checked = document.getElementById("Item6").checked;
  380. var item7_checked = document.getElementById("Item7").checked;
  381. var item8_checked = document.getElementById("Item8").checked;
  382. var json = { "ip":ip,
  383. "loginname":loginname,
  384. "username":username,
  385. "password":password,
  386. "item1_checked":item1_checked,
  387. "item2_checked":item2_checked,
  388. "item3_checked":item3_checked,
  389. "item4_checked":item4_checked,
  390. "item5_checked":item5_checked,
  391. "item6_checked":item6_checked,
  392. "item7_checked":item7_checked,
  393. "item8_checked":item8_checked
  394. };
  395. var abs_update_interval = window.setInterval("abs_update()", 1000);
  396. $.post('/add_server', json, function(resText){
  397. $("#addServer-status").css('visibility','hidden');
  398. if(resText == 'Authentication failed.'){
  399. resText = '您輸入的密碼有誤,請重新輸入!';
  400. $("input[name=user_ip]").val('');
  401. $("input[name=user_username]").val('');
  402. $("input[name=user_password]").val('');
  403. };
  404. clearInterval(abs_update_interval);
  405. setTimeout(alert(resText), 1000);
  406. }, 'text');
  407. };
  408. Automatic_Build_System_installation = {
  409. 'python3.8-installation': 'Wait',
  410. 'python3-pip-installation': 'Wait',
  411. 'cryptography-installation': 'Wait',
  412. 'upgrade-installation': 'Wait',
  413. 'grep-installation': 'Wait',
  414. 'git-installation': 'Wait',
  415. 'gitpython-installation': 'Wait',
  416. 'python3-tk-installation': 'Wait',
  417. 'wget-installation': 'Wait',
  418. 'python3-dev-installation': 'Wait',
  419. 'default-libmysqlclient-dev-installation': 'Wait',
  420. 'build-essential-installation': 'Wait',
  421. 'tasksel-installation': 'Wait',
  422. 'lamp-server-installation': 'Wait',
  423. 'phpMyAdmin-5.1.0-all-languages.tar.gz-installation': 'Wait',
  424. 'openssl-installation': 'Wait',
  425. 'php-common-installation': 'Wait',
  426. 'php-curl-installation': 'Wait',
  427. 'php-json-installation': 'Wait',
  428. 'php-mbstring-installation': 'Wait',
  429. 'php-mysql-installation': 'Wait',
  430. 'php-xml-installation': 'Wait',
  431. 'php-zip-installation': 'Wait',
  432. 'php7.2-mbstring-installation': 'Wait',
  433. 'php7.2-xml-installation': 'Wait',
  434. 'php7.2-mysql-installation': 'Wait',
  435. 'php7.2-common-installation': 'Wait',
  436. 'php7.2-curl-installation': 'Wait',
  437. 'php7.2-json-installation': 'Wait',
  438. 'php7.2-zip-installation': 'Wait',
  439. 'apache2-installation': 'Wait',
  440. 'paho-mqtt-installation': 'Wait',
  441. 'mosquitto-installation': 'Wait',
  442. 'mqtt_server_setting-installation': 'Wait',
  443. 'rclocal/rc.local-installation': 'Wait',
  444. 'golang-installation': 'Wait',
  445. 'gogsfile-installation': 'Wait',
  446. 'requirements-installation': 'Wait',
  447. 'CoffeeProject-installation': 'Wait',
  448. 'BBend-Test-JWT-installation': 'Wait',
  449. 'Coffee_MySQL-installation': 'Wait',
  450. 'chrony-installation': 'Wait',
  451. 'ntpdate-installation': 'Wait',
  452. '--keyserver-installation': 'Wait',
  453. 'update-installation': 'Wait',
  454. 'ros-melodic-desktop-full-installation': 'Wait',
  455. 'ros-melodic-rqt*-installation': 'Wait',
  456. 'python-rosdep-installation': 'Wait',
  457. 'python-rosinstall-installation': 'Wait',
  458. 'python-rosinstall-generator-installation': 'Wait',
  459. 'python-wstool-installation': 'Wait',
  460. 'catkin_make-installation': 'Wait'
  461. }
  462. var abs_update_process = 0;
  463. var timer;
  464. function abs_update() {
  465. if (abs_update_process === 1) {
  466. return;
  467. }
  468. abs_update_process = 1;
  469. $.ajax({
  470. async:false,
  471. type:"GET",
  472. url:"/ABS_update",
  473. dataType:"JSON",
  474. success:function(response){
  475. for (const key of Object.entries(response)) {
  476. // console.log("TT" + response['requirements'])
  477. if (response[key[0]] == 'Install') {
  478. if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Wait') {
  479. Automatic_Build_System_installation[key[0] + '-installation'] = 'Install';
  480. timer = window.setInterval("AddBarIndex(\"" + key[0] + "-status\")", 2000);
  481. // eval('var ' + key[0] + '_timer = window.setInterval("AddBarIndex(\"' + key[0] + '-status\")", 2000);')
  482. // alert('!!!')
  483. }
  484. } else if (response[key[0]] == '0') {
  485. // pass
  486. } else if (response[key[0]] == 'Error') {
  487. if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  488. Automatic_Build_System_installation[key[0] + '-installation'] = 'Error';
  489. ItemInstallFail(timer, key[0]);
  490. }
  491. // } else if (response[key[0]] == 'Success') {
  492. // if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  493. // Automatic_Build_System_installation[key[0] + '-installation'] = 'Success';
  494. // ItemInstallSuccess(timer, key[0]);
  495. // }
  496. // // ========== Rita 0428 測試保留 ==========
  497. // } else if (Number(response[key[0]]) !== NaN) {
  498. // if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  499. // Automatic_Build_System_installation[key[0] + '-installation'] = 'Success';
  500. // ItemInstallSuccess(timer, key[0], response[key[0]]);
  501. // }
  502. // // ========== Rita 0428 測試保留 ==========
  503. } else if (Number(response[key[0]]) !== NaN) {
  504. // Automatic_Build_System_installation[key[0] + '-installation'] = response[key[0]];
  505. // ItemInstallSuccess(timer, key[0], response[key[0]]);
  506. if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Install') {
  507. Automatic_Build_System_installation[key[0] + '-installation'] = response[key[0]];
  508. ItemInstallSuccess(timer, key[0], response[key[0]]);
  509. } else if (Automatic_Build_System_installation[key[0] + '-installation'] == 'Wait') {
  510. Automatic_Build_System_installation[key[0] + '-installation'] = response[key[0]];
  511. console.log(key[0] + " : " + response[key[0]]);
  512. ItemInstallSuccess(timer, key[0], response[key[0]]);
  513. }
  514. } else {
  515. console.log("response[key[0]]: " + response[key[0]]);
  516. }
  517. }
  518. abs_update_process = 0;
  519. },
  520. error:function(thrownError){
  521. console.log("thrownError: " + thrownError);
  522. abs_update_process = 0;
  523. }
  524. });
  525. };
  526. function ItemInstallSuccess(timer_item, item_name, execution_time){
  527. eval('clearInterval(' + timer_item + ')');
  528. var item = document.getElementById(item_name + '-status');
  529. item.style.width = '100%';
  530. item.innerText = execution_time + 's';
  531. };
  532. function ItemInstallFail(timer_item, item_name){
  533. eval('clearInterval(' + timer_item + ')');
  534. var item = document.getElementById(item_name + '-status');
  535. item.style.width = '0%';
  536. item.innerText = 'Fail';
  537. item.style.color = 'red';
  538. item.style.fontWeight = 'bold';
  539. };
  540. </script>
  541. </html>