index.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <?php
  2. include_once("../../../auth.php");
  3. include_once("hideApps.php");
  4. $hideModules = getHideAppList(); //See hideApp.config for more hidden apps config
  5. if (isset($_GET["request"]) && $_GET["request"] == "true"){
  6. //This page is used for data requesting
  7. $AOBroot = $rootPath;
  8. if (isset($_GET['contentType']) == false){
  9. echo 'Request Mode enabled. Page loading disabled by default. <br>
  10. Please use the following command in this page to optain information regarding the List Menu.<br>
  11. contentType=webapp/system<br>';
  12. }else{
  13. $contentType = $_GET['contentType'];
  14. if ($contentType == "webapp"){
  15. $modules = glob("$AOBroot*");
  16. $webappList = [];
  17. foreach ($modules as $webapp){
  18. if (is_dir($webapp) && in_array(str_replace($AOBroot,"",$webapp),$hideModules) == false){
  19. if (file_exists($webapp . "/index.php") || file_exists($webapp . "/index.html")){
  20. $emSupport = false;
  21. if (file_exists($webapp ."/embedded.php")){
  22. $emSupport = true;
  23. }
  24. $fwSupport = false;
  25. if (file_exists($webapp . "/FloatWindow.php")){
  26. $fwSupport = true;
  27. }
  28. $displayName = str_replace($AOBroot,"",$webapp);
  29. $iconPath = $webapp . "/img/function_icon.png";
  30. if (file_exists($webapp . "/img/small_icon.png")){
  31. $iconPath = $webapp . "/img/small_icon.png";
  32. }
  33. array_push($webappList,[$displayName,$webapp . "/",$emSupport,$fwSupport,$iconPath]);
  34. }
  35. }
  36. }
  37. header('Content-Type: application/json');
  38. echo json_encode($webappList);
  39. }else if ($contentType == "system"){
  40. $utilDir = $AOBroot . "SystemAOB/utilities/";
  41. $iconDir = $utilDir . "sysicon/";
  42. $utils = glob($utilDir . "*.php");
  43. $utillist = [];
  44. foreach ($utils as $tool){
  45. $icon = $iconDir . "noname.png";
  46. if (file_exists($iconDir . basename($tool,".php") .".png")){
  47. $icon = $iconDir . basename($tool,".php") .".png";
  48. }
  49. array_push($utillist,[basename($tool,".php"),$utilDir . $tool,$icon]);
  50. }
  51. header('Content-Type: application/json');
  52. echo json_encode($utillist);
  53. }else{
  54. echo "Unknown content type value.";
  55. }
  56. }
  57. exit();
  58. }
  59. $iconPath = "../personalization/usericon/";
  60. if (file_exists($iconPath . $_SESSION['login'] . ".png")){
  61. $imagePath = $iconPath . $_SESSION['login'] . ".png";
  62. }else if (file_exists($iconPath . $_SESSION['login'] . ".jpg")){
  63. $imagePath = $iconPath . $_SESSION['login'] . ".jpg";
  64. }else if (file_exists($iconPath . $_SESSION['login'] . ".gif")){
  65. $imagePath = $iconPath . $_SESSION['login'] . ".gif";
  66. }else if (file_exists($iconPath . $_SESSION['login'] . ".jpeg")){
  67. $imagePath = $iconPath . $_SESSION['login'] . ".jpeg";
  68. }else{
  69. $imagePath = $iconPath . "user.png";
  70. }
  71. ?>
  72. <html>
  73. <head>
  74. <title>
  75. List Menu
  76. </title>
  77. <link rel="stylesheet" href="../../../script/tocas/tocas.css">
  78. <script type='text/javascript' src="../../../script/tocas/tocas.js"></script>
  79. <script src="../../../script/jquery.min.js"></script>
  80. <script src="../../../script/ao_module.js"></script>
  81. <style>
  82. body{
  83. background:rgba(46,46,46,0.7);
  84. border-radius: 3px 3px 0px 0px;
  85. }
  86. .appList{
  87. background-color:#f5f5f5;
  88. position:fixed;
  89. left:10px;
  90. top:15px;
  91. width:66%;
  92. bottom:20px;
  93. }
  94. .rightList{
  95. position:fixed;
  96. padding:10px;
  97. right:10px;
  98. top:10px;
  99. height:510px;
  100. width:27%;
  101. }
  102. .shutdown{
  103. color:white;
  104. border: 1px solid white;
  105. padding-left:8px;
  106. padding-top:2px;
  107. padding-bottom:2px;
  108. padding-right:3px;
  109. position:absolute;
  110. left:0px;
  111. bottom: 0px;
  112. cursor: pointer;
  113. background:rgba(46,46,46,0.7);
  114. letter-spacing: 1px;
  115. font-size:80% !important;
  116. }
  117. .shutdown:hover{
  118. background:rgba(255,255,255,0.3) !important;
  119. }
  120. .sidebar.item{
  121. color:white !important;
  122. padding-left:5px !important;
  123. padding-top:6px !important;
  124. padding-bottom:6px !important;
  125. cursor: pointer !important;
  126. font-size:85% !important;
  127. }
  128. .sidebar.item:hover{
  129. background:rgba(255,255,255,0.3);
  130. border-radius: 2px;
  131. }
  132. #moduleList{
  133. height:90%;
  134. overflow-y:auto;
  135. }
  136. .module.item{
  137. border: 1px solid transparent;
  138. margin-right:5px !important;
  139. }
  140. .module.item:hover{
  141. border: 1px solid #C8D8E9;
  142. background-color:#DDEAFB !important;
  143. }
  144. .sidebar{
  145. color:white;
  146. padding-left:0px;
  147. padding-top:3px;
  148. padding-bottom:4px;
  149. }
  150. .searchbar{
  151. }
  152. #shutdownMenu{
  153. position:fixed;
  154. right:0px;
  155. background-color:#282828;
  156. z-index:10;
  157. padding-top:14px;
  158. padding-bottom: 14px;
  159. }
  160. .selectable{
  161. padding-left:10px !important;
  162. padding-right:5px !important;
  163. padding-top:5px !important;
  164. padding-bottom:5px !important;
  165. cursor: pointer;
  166. }
  167. .selectable:hover{
  168. background-color:#404040;
  169. }
  170. .textwrap{
  171. text-overflow: ellipsis !important;
  172. display:block !important;
  173. overflow-wrap: break-word;
  174. word-break: break-all;
  175. }
  176. </style>
  177. </head>
  178. <body>
  179. <div class="appList">
  180. <div id="moduleList" class="ts middle aligned selection list">
  181. </div>
  182. <div class="searchbar">
  183. <div class="ts fluid small icon input">
  184. <input id="searchInput" type="text" placeholder="Search">
  185. <i class="search icon"></i>
  186. </div>
  187. </div>
  188. </div>
  189. <div class="rightList">
  190. <img class="ts small bordered image" style="border: 3px solid white;" src="<?php echo $imagePath;?>">
  191. <div id="username" class="sidebar"></div>
  192. <div class="ts list">
  193. <div class="sidebar item" onClick="openMediaFolder(1);">Music</div>
  194. <div class="sidebar item" onClick="openMediaFolder(2);">Video</div>
  195. <div class="sidebar item" onClick="openMediaFolder(3);">Pictures</div>
  196. <div class="sidebar item" onClick="openMediaFolder(4);">Documents</div>
  197. <div class="ts divider"></div>
  198. <div class="sidebar item" onClick="myComputer();"><i class="disk outline icon"></i>  My Host</div>
  199. <div class="sidebar item" onClick="AOR();"><i class="folder open outline icon"></i>  File View</div>
  200. <div class="sidebar item" onClick="controlPanel();"><i class="setting icon"></i>  Settings</div>
  201. <div class="ts divider"></div>
  202. <div class="sidebar item" onClick="window.open('http://aroz.online');">Help / Support</div>
  203. </div>
  204. <div class="shutdown" onClick="toggleShutDownMenu();">
  205. Shut down <i class="caret right icon" style="border-left: 1px solid white;"></i>
  206. </div>
  207. <div class="selectionArrow">
  208. <i class = ""></i>
  209. </div>
  210. </div>
  211. <div id="shutdownMenu" style="display:none;">
  212. <div class="ts list">
  213. <div class="selectable item" style="color:white !important;" onClick="Logout();">Logout</div>
  214. <div class="selectable item" style="color:white !important;" onClick="RestartApache();">Restart Apache</div>
  215. <div class="selectable item" style="color:white !important;" onClick="Reboot();">Reboot</div>
  216. <div class="selectable item" style="color:white !important;" onCLick="Shutdown();">Shutdown</div>
  217. </div>
  218. </div>
  219. <script>
  220. var moduleTemplate = '\
  221. <div class="module item" fw="{fw}" embedded="{embedded}" name="{name}" onClick="launchModule(this);">\
  222. <img class="ts avatar image" src="{moduleIcon}">\
  223. <div class="content">\
  224. <div class="header">{moduleName}</div>\
  225. </div>\
  226. </div>';
  227. var systoolTemplate = '\
  228. <div class="module item" name="{name}" path="{path}" onClick="launchTool(this);">\
  229. <img class="ts avatar image" src="{toolIcon}">\
  230. <div class="content">\
  231. <div class="header">{tool}</div>\
  232. </div>\
  233. </div>';
  234. var toggleSystemTools = '\
  235. <div class="module item" onClick="changeMode(this);">\
  236. <div class="content">\
  237. <div class="header">{label}</div>\
  238. </div>\
  239. </div>';
  240. var currentMode = 0; //0 = WebApp List, 1 = System Tools
  241. var is_safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  242. if (!is_safari){
  243. //If this is not Safari, hide the menu immediately
  244. parent.$('#powerMenu').hide();
  245. }
  246. $("body").css("background",parent.themeColor["theme"]);
  247. $("#shutdownMenu").css("background-color",parent.themeColor["active"]);
  248. $(document).ready(function(){
  249. loadModules();
  250. updateUserName();
  251. if (is_safari){
  252. //Safari requie the DIV to be visiable in order to use AJAX.load function.
  253. parent.$('#powerMenu').hide();
  254. }
  255. });
  256. window.addEventListener("focus", function(event)
  257. {
  258. $("#searchInput").focus();
  259. }, false);
  260. //When the user type anything in the input box of the list menu
  261. var searchTimeout;
  262. $("#searchInput").on("keyup",function(e){
  263. if (e.keyCode == 13){
  264. //Enter is pressed. Perform action
  265. if ($(".preselect").length > 0){
  266. openThisResult($(".preselect")[0]);
  267. }
  268. }else{
  269. //Other things has been inputted. Do searching.
  270. if ($("#searchInput").val().length > 0){
  271. //Show search menu
  272. if (currentMode != 2){
  273. currentMode = 2;
  274. changeMode();
  275. }
  276. if (searchTimeout !== undefined){
  277. clearTimeout(searchTimeout);
  278. }
  279. searchTimeout = setTimeout(updateSearchResult,1000);
  280. }else{
  281. //return to webapp list menu
  282. if (currentMode != 1){
  283. if (searchTimeout !== undefined){
  284. clearTimeout(searchTimeout);
  285. }
  286. currentMode = 1;
  287. changeMode();
  288. }
  289. }
  290. }
  291. });
  292. function updateSearchResult(){
  293. var keyword = $("#searchInput").val();
  294. $( "#moduleList" ).html("");
  295. $( "#moduleList" ).append('<div id="searchResultsList" class="unstyled"><div id="webAppList" class="ts selection list"></div>\
  296. <div id="utilList" class="ts selection list"></div>\
  297. <div id="resultFileList" class="ts selection list"></div></div>\
  298. <div id="loadingCover" class="ts active inverted dimmer">\
  299. <div class="ts text loader">Loading</div>\
  300. </div>');
  301. $.get("searchFile.php?keyword=" + keyword,function(data){
  302. if (data.constructor !== Array && data.includes("ERROR")){
  303. //Somethings goes wrong
  304. }else{
  305. var ll = Math.min(data.length,12);
  306. for (var i =0; i < ll; i++){
  307. var obj = data[i];
  308. var ext = obj[0].split(".").pop();
  309. var icon = ao_module_utils.getIconFromExt(ext);
  310. $("#resultFileList").append('<div class="mini textwrap searchResult item" filepath="' + obj[0] + '" rType="file" onClick="openThisResult(this);"><i class="' + icon +' icon"></i>' + obj[1] + '</div>');
  311. }
  312. $("#loadingCover").hide();
  313. selectFirstSearchResult();
  314. }
  315. });
  316. $.get("systemSearch.php?search=" + keyword,function(data){
  317. var moduleList = data[0];
  318. var utilList = data[1];
  319. if (moduleList.length > 0){
  320. for (var i =0; i < moduleList.length; i++){
  321. $("#webAppList").append('<div class="mini textwrap searchResult item" filepath="' + moduleList[i][0] + '" rType="webApp" onClick="openThisResult(this);">\
  322. <img class="ts avatar image" src="' + moduleList[i][1] + '">\
  323. <span>' + moduleList[i][0] + '</span></div>');
  324. }
  325. }else{
  326. $("#webAppList").hide();
  327. }
  328. if (utilList.length > 0){
  329. for (var i =0; i < utilList.length; i++){
  330. $("#utilList").append('<div class="mini textwrap searchResult item" filepath="' + utilList[i][0] + '" rType="utils" onClick="openThisResult(this);">\
  331. <img class="ts avatar image" src="' + utilList[i][1] + '">\
  332. <span>' + utilList[i][0] + '</span></div>');
  333. }
  334. }else{
  335. $("#utilList").hide();
  336. }
  337. $("#loadingCover").hide();
  338. selectFirstSearchResult();
  339. });
  340. //$("#searchResultsList").append('<div class="mini textwrap item" onClick="moreResult();" style="padding-left:10px;cusor:pointer;">Advance Search <i class="caret right icon"></i></div>');
  341. }
  342. function selectFirstSearchResult(){
  343. $(".searchResult").removeClass("preselect");
  344. $(".searchResult").first().addClass("preselect");
  345. }
  346. function moreResult(){
  347. alert("Work in progress");
  348. }
  349. function openThisResult(object){
  350. var type = $(object).attr("rType");
  351. if (type == "file"){
  352. //This is a file. Open it with the corrisponding module with ao_module API
  353. var filepath = $(object).attr("filepath");
  354. var filename = $(object).text();
  355. //Quick function for removing the file extension
  356. //filename = filename.split(".");filename.pop();filename = filename.join(".");
  357. ao_module_openFile(filepath,filename);
  358. hideListMenu();
  359. //Cleanup the search result
  360. $("#searchInput").val("");
  361. currentMode = 1;
  362. changeMode();
  363. }else if (type == "webApp"){
  364. //parent.LaunchFloatWindowFromModule($(object).attr("filepath"),true);
  365. var moduleName = $(object).attr("filepath");
  366. ao_module_newfw(moduleName + "/index.php",moduleName,"file",ao_module_utils.getRandomUID());
  367. hideListMenu();
  368. $("#searchInput").val("");
  369. currentMode = 1;
  370. changeMode();
  371. }else if (type == "utils"){
  372. var toolName = $(object).attr("filepath");
  373. ao_module_newfw("SystemAOB/utilities/" + toolName + ".php",toolName,"file",ao_module_utils.getRandomUID());
  374. hideListMenu();
  375. $("#searchInput").val("");
  376. currentMode = 1;
  377. changeMode();
  378. }
  379. }
  380. function toggleShutDownMenu(){
  381. $("#shutdownMenu").css("left",$(".shutdown").offset().left - 8);
  382. $("#shutdownMenu").css("top",$(".shutdown").offset().top - $("#shutdownMenu").height() - $(".shutdown").height() - 8);
  383. if ($("#shutdownMenu").is(":hidden")){
  384. $("#shutdownMenu").slideDown('fast');
  385. }else{
  386. $("#shutdownMenu").slideUp('fast');
  387. }
  388. }
  389. $(document).on("click",function(e){
  390. if ($(e.target).hasClass("shutdown") == false){
  391. if ($("#shutdownMenu").is(":hidden") == false){
  392. $("#shutdownMenu").slideUp('fast');
  393. }
  394. }
  395. });
  396. function updateUserName(){
  397. var username = localStorage.getItem("ArOZusername");
  398. if (username.length > 7){
  399. username = username.substring(0,7) + "..";
  400. }
  401. $("#username").html('<i class="angle double right icon"></i>' + username);
  402. }
  403. function replaceValue(source,keyword,value){
  404. return source.replace("{" + keyword + "}",value);
  405. }
  406. function loadModules(){
  407. $( "#moduleList" ).html("<div><i class='loading spinner icon'></i>Loading...</div>");
  408. $.get( "index.php?request=true&contentType=webapp", function( data ) {
  409. $( "#moduleList" ).html("");
  410. for (var i =0; i < data.length; i++){
  411. var box = moduleTemplate;
  412. box = replaceValue(box,'moduleIcon',data[i][4]);
  413. box = replaceValue(box,'fw',data[i][3]);
  414. box = replaceValue(box,'embedded',data[i][2]);
  415. box = replaceValue(box,'name',data[i][0]);
  416. box = replaceValue(box,'moduleName',data[i][0]);
  417. $( "#moduleList" ).append(box);
  418. }
  419. currentMode = 0;
  420. generateButton();
  421. });
  422. }
  423. function changeMode(){
  424. if (currentMode == 0){
  425. //Switch to Util Menu
  426. loadSystemUtil();
  427. }else if (currentMode == 1){
  428. //Switch to WebApp list mode
  429. loadModules();
  430. }else if (currentMode == 2){
  431. //Switch to search menu mode
  432. loadSearchMenu();
  433. }
  434. }
  435. function loadSearchMenu(){
  436. $( "#moduleList" ).html('<br><br><div class="ts container"><div class="ts header">\
  437. <i class="search icon"></i> System Search\
  438. <div class="sub header">Type something to search for webApps, utilities and files.</div>\
  439. </div></div>');
  440. }
  441. function loadSystemUtil(){
  442. $( "#moduleList" ).html("<div><i class='loading spinner icon'></i>Loading...</div>");
  443. $.get( "index.php?request=true&contentType=system", function( data ) {
  444. console.log(data);
  445. $( "#moduleList" ).html("");
  446. for (var i =0; i < data.length; i++){
  447. var box = systoolTemplate;
  448. box = replaceValue(box,'tool',data[i][0]);
  449. box = replaceValue(box,'name',data[i][0]);
  450. box = replaceValue(box,'path',data[i][1]);
  451. box = replaceValue(box,'toolIcon',data[i][2]);
  452. $("#moduleList").append(box);
  453. }
  454. currentMode = 1;
  455. generateButton();
  456. });
  457. }
  458. function launchTool(object){
  459. var toolName = $(object).attr("name");
  460. var uid = Math.floor(Date.now() / 1000);
  461. ao_module_newfw("SystemAOB/utilities/" + toolName + ".php",toolName,"file",uid,0,0,0,0);
  462. hideListMenu();
  463. window.location.reload();
  464. }
  465. function generateButton(){
  466. var box = toggleSystemTools;
  467. if (currentMode == 0){
  468. //Generate button for going into System Tool
  469. box = replaceValue(box,"label"," <i class='caret right icon'></i> System Tools");
  470. }else{
  471. //Generate button for going back to WebApp list
  472. box = replaceValue(box,"label"," <i class='caret left icon'></i> All WebApps");
  473. }
  474. $("#moduleList").append(box);
  475. }
  476. function launchModule(object){
  477. var uid = Math.floor(Date.now() / 1000);
  478. var moduleName = $(object).attr("name");
  479. var embedded = $(object).attr('embedded').trim() == "true";
  480. var fw = $(object).attr("fw").trim() == "true";
  481. if (fw){
  482. //Legacy code for calling function_bar to open a FloatWindow
  483. parent.LaunchFloatWindowFromModule(moduleName,true);
  484. }else{
  485. ao_module_newfw(moduleName + "/index.php",moduleName,"file",uid);
  486. }
  487. hideListMenu();
  488. window.location.reload();
  489. }
  490. function hideListMenu(){
  491. parent.$('#powerMenu').fadeOut('fast');
  492. }
  493. function openMediaFolder(target){
  494. if (target == 1){
  495. //Music
  496. ao_module_openPath("Audio/uploads");
  497. }else if (target == 2){
  498. //Video
  499. ao_module_openPath("Video/playlist");
  500. }else if (target == 3){
  501. //Pictures
  502. ao_module_openPath("Photo/storage");
  503. }else if (target == 4){
  504. //Documents
  505. ao_module_openPath("Document/doc");
  506. }
  507. hideListMenu();
  508. }
  509. function myComputer(){
  510. ao_module_newfw("Desktop/myHost.php","My Host","disk outline","myHost",1050,650,undefined,undefined,true,true);
  511. hideListMenu();
  512. }
  513. function AOR(){
  514. ao_module_openPath("");
  515. hideListMenu();
  516. }
  517. function controlPanel(){
  518. ao_module_newfw("System Settings/index.php","System Settings","setting","system_setting",1300,650,50,50,true,true);
  519. hideListMenu();
  520. }
  521. function Logout(){
  522. window.top.location = "../../../logout.php"
  523. }
  524. //legacy codes are used here to make sure the power functions are working fine
  525. function RestartApache(){
  526. $.ajax({
  527. url: "../power/apache_restart.php",
  528. error: function(){
  529. // Loading for reboot
  530. setTimeout(Ping, 2000);
  531. },
  532. success: function(){
  533. //not possible
  534. },
  535. timeout: 3000 // sets timeout to 3 seconds
  536. });
  537. }
  538. function Reboot(){
  539. $.ajax({
  540. url: "../power/reboot_cb42e419a589258b332488febcd5246591ea4699974d10982255d16bee656fd8.php",
  541. error: function(){
  542. // Start a fake progress bar to make people think it is rebooting
  543. setTimeout(function(){
  544. location.reload();
  545. }, 30000);
  546. },
  547. success: function(){
  548. //something crashed when reboot.
  549. console.log("Something went wrong while rebooting.");
  550. },
  551. timeout: 3000 // sets timeout to 3 seconds
  552. });
  553. }
  554. function Ping(){
  555. $.ajax({
  556. url: "../power/ping.php",
  557. error: function(){
  558. // Start a fake progress bar to make people think it is rebooting
  559. setTimeout(Ping, 2000);
  560. },
  561. success: function(){
  562. //something crashed when reboot.
  563. location.reload();
  564. },
  565. timeout: 3000 // sets timeout to 3 seconds
  566. });
  567. }
  568. function Shutdown(){
  569. window.top.location = "../power/shutdown-gui_2053da6fb9aa9b7605555647ee7086b181dc90b23b05c7f044c8a2fcfe933af1.php";
  570. }
  571. </script>
  572. </body>
  573. </html>