home.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. <?php
  2. /**
  3. * Copyright 2021, 2024 5 Mode
  4. *
  5. * This file is part of Homogram.
  6. *
  7. * Homogram is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Homogram is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Homogram. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * home.php
  21. *
  22. * Homogram home page.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2021, 2024, 5 Mode
  26. */
  27. $contextType = PUBLIC_CONTEXT_TYPE;
  28. $cmd = PHP_STR;
  29. $opt = PHP_STR;
  30. $param1 = PHP_STR;
  31. $param2 = PHP_STR;
  32. $param3 = PHP_STR;
  33. $curPicture = "";
  34. $prevPicture = "";
  35. $nextPicture = "";
  36. function myExecPrivatifyCommand() {
  37. global $param1;
  38. global $curPath;
  39. $privateData = [];
  40. $curFile = substr($curPath, strlen(APP_REPO_PATH)) . DIRECTORY_SEPARATOR . $param1;
  41. //echo "curFile=$curFile";
  42. // Update .private file
  43. $privateFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".private";
  44. //echo "curFile=$privateFile";
  45. if (file_exists($privateFile)) {
  46. $privateData = file($privateFile);
  47. }
  48. if (!in_array($curFile . "\n", $privateData)) {
  49. $privateData[] = $curFile . "\n";
  50. file_put_contents($privateFile, implode('', $privateData));
  51. }
  52. }
  53. function myExecDelCommand() {
  54. global $param1;
  55. global $curPath;
  56. $curFile = $curPath . DIRECTORY_SEPARATOR . $param1;
  57. unlink($curFile);
  58. }
  59. function myExecPublicifyCommand() {
  60. global $param1;
  61. global $curPath;
  62. $privateData = [];
  63. $curFile = substr($curPath, strlen(APP_REPO_PATH)) . DIRECTORY_SEPARATOR . $param1;
  64. //echo "curFile=$curFile";
  65. // Update .private file
  66. $privateFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".private";
  67. //echo "curFile=$privateFile";
  68. if (file_exists($privateFile)) {
  69. $privateData = file($privateFile);
  70. }
  71. $key = array_search($curFile . "\n", $privateData);
  72. if ($key!==false) {
  73. unset($privateData[$key]);
  74. file_put_contents($privateFile, implode('', $privateData));
  75. }
  76. }
  77. function myExecMakeDirCommand() {
  78. global $param1;
  79. global $curPath;
  80. $newpath = $curPath . DIRECTORY_SEPARATOR . $param1;
  81. mkdir($newpath, 0777);
  82. }
  83. function parseCommand() {
  84. global $command;
  85. global $cmd;
  86. global $opt;
  87. global $param1;
  88. global $param2;
  89. global $param3;
  90. $str = trim($command);
  91. $ipos = stripos($str, PHP_SPACE);
  92. if ($ipos > 0) {
  93. $cmd = left($str, $ipos);
  94. $str = substr($str, $ipos+1);
  95. } else {
  96. $cmd = $str;
  97. return;
  98. }
  99. if (left($str, 1) === "-") {
  100. $ipos = stripos($str, PHP_SPACE);
  101. if ($ipos > 0) {
  102. $opt = left($str, $ipos);
  103. $str = substr($str, $ipos+1);
  104. } else {
  105. $opt = $str;
  106. return;
  107. }
  108. }
  109. $ipos = stripos($str, PHP_SPACE);
  110. if ($ipos > 0) {
  111. $param1 = left($str, $ipos);
  112. $str = substr($str, $ipos+1);
  113. } else {
  114. $param1 = $str;
  115. return;
  116. }
  117. $ipos = stripos($str, PHP_SPACE);
  118. if ($ipos > 0) {
  119. $param2 = left($str, $ipos);
  120. $str = substr($str, $ipos+1);
  121. } else {
  122. $param2 = $str;
  123. return;
  124. }
  125. $ipos = stripos($str, PHP_SPACE);
  126. if ($ipos > 0) {
  127. $param3 = left($str, $ipos);
  128. $str = substr($str, $ipos+1);
  129. } else {
  130. $param3 = $str;
  131. return;
  132. }
  133. }
  134. function is_subfolderdest(string $path): bool
  135. {
  136. global $curPath;
  137. $ret=false;
  138. if ($path === "../") {
  139. return $ret;
  140. }
  141. if ($path!=PHP_STR) {
  142. $folderName = left($path, strlen($path)-1);
  143. if (!is_word($folderName)) {
  144. return $ret;
  145. }
  146. if (is_dir($curPath . PHP_SLASH . $folderName) && (right($path,1)==="/")) {
  147. $ret=true;
  148. }
  149. }
  150. return $ret;
  151. }
  152. function privatifyparamValidation() {
  153. global $curPath;
  154. global $opt;
  155. global $param1;
  156. global $param2;
  157. global $param3;
  158. //opt!=""
  159. if ($opt!==PHP_STR) {
  160. //updateHistoryWithErr("invalid options");
  161. return false;
  162. }
  163. //param1!="" and isword
  164. if (($param1===PHP_STR) || !is_word($param1)) {
  165. //updateHistoryWithErr("invalid image file");
  166. return false;
  167. }
  168. //param2==""
  169. if ($param2!==PHP_STR) {
  170. //updateHistoryWithErr("invalid parameters");
  171. return false;
  172. }
  173. //param3==""
  174. if ($param3!==PHP_STR) {
  175. //updateHistoryWithErr("invalid parameters");
  176. return false;
  177. }
  178. //param1 exist
  179. $path = $curPath . DIRECTORY_SEPARATOR . $param1;
  180. if (!file_exists($path)) {
  181. //updateHistoryWithErr("file must exists");
  182. return false;
  183. }
  184. //param1 is_file
  185. if (!is_file($path)) {
  186. //updateHistoryWithErr("invalid inventory file");
  187. return false;
  188. }
  189. //param1 file extension == gif | png | jpg | jpeg
  190. $fileExt = strtolower(pathinfo($param1, PATHINFO_EXTENSION));
  191. if ($fileExt !== "gif" && $fileExt !== "png" && $fileExt !== "jpg" && $fileExt !== "jpeg") {
  192. //updateHistoryWithErr("invalid inventory file");
  193. return false;
  194. }
  195. return true;
  196. }
  197. function publicifyparamValidation() {
  198. global $curPath;
  199. global $opt;
  200. global $param1;
  201. global $param2;
  202. global $param3;
  203. //opt!=""
  204. if ($opt!==PHP_STR) {
  205. //updateHistoryWithErr("invalid options");
  206. return false;
  207. }
  208. //param1!="" and isword
  209. if (($param1===PHP_STR) || !is_word($param1)) {
  210. //updateHistoryWithErr("invalid image file");
  211. return false;
  212. }
  213. //param2==""
  214. if ($param2!==PHP_STR) {
  215. //updateHistoryWithErr("invalid parameters");
  216. return false;
  217. }
  218. //param3==""
  219. if ($param3!==PHP_STR) {
  220. //updateHistoryWithErr("invalid parameters");
  221. return false;
  222. }
  223. //param1 exist
  224. $path = $curPath . DIRECTORY_SEPARATOR . $param1;
  225. if (!file_exists($path)) {
  226. //updateHistoryWithErr("file must exists");
  227. return false;
  228. }
  229. //param1 is_file
  230. if (!is_file($path)) {
  231. //updateHistoryWithErr("invalid inventory file");
  232. return false;
  233. }
  234. //param1 file extension == gif | png | jpg | jpeg
  235. $fileExt = strtolower(pathinfo($param1, PATHINFO_EXTENSION));
  236. if ($fileExt !== "gif" && $fileExt !== "png" && $fileExt !== "jpg" && $fileExt !== "jpeg") {
  237. //updateHistoryWithErr("invalid inventory file");
  238. return false;
  239. }
  240. return true;
  241. }
  242. function delparamValidation() {
  243. global $curPath;
  244. global $opt;
  245. global $param1;
  246. global $param2;
  247. global $param3;
  248. //opt!=""
  249. if ($opt!==PHP_STR) {
  250. //updateHistoryWithErr("invalid options");
  251. return false;
  252. }
  253. //param1!="" and isword
  254. if (($param1===PHP_STR) || !is_word($param1)) {
  255. //updateHistoryWithErr("invalid image file");
  256. return false;
  257. }
  258. //param2==""
  259. if ($param2!==PHP_STR) {
  260. //updateHistoryWithErr("invalid parameters");
  261. return false;
  262. }
  263. //param3==""
  264. if ($param3!==PHP_STR) {
  265. //updateHistoryWithErr("invalid parameters");
  266. return false;
  267. }
  268. //param1 exist
  269. $path = $curPath . DIRECTORY_SEPARATOR . $param1;
  270. if (!file_exists($path)) {
  271. //updateHistoryWithErr("file must exists");
  272. return false;
  273. }
  274. //param1 is_file
  275. if (!is_file($path)) {
  276. //updateHistoryWithErr("invalid inventory file");
  277. return false;
  278. }
  279. //param1 file extension == gif | png | jpg | jpeg
  280. $fileExt = strtolower(pathinfo($param1, PATHINFO_EXTENSION));
  281. if ($fileExt !== "gif" && $fileExt !== "png" && $fileExt !== "jpg" && $fileExt !== "jpeg") {
  282. //updateHistoryWithErr("invalid inventory file");
  283. return false;
  284. }
  285. return true;
  286. }
  287. function makedirparamValidation() {
  288. global $curPath;
  289. global $opt;
  290. global $param1;
  291. global $param2;
  292. global $param3;
  293. //opt!=""
  294. if ($opt!==PHP_STR) {
  295. //updateHistoryWithErr("invalid options");
  296. return false;
  297. }
  298. //param1!="" and isword
  299. if (($param1===PHP_STR) || !is_word($param1)) {
  300. //updateHistoryWithErr("invalid folder name");
  301. return false;
  302. }
  303. //param2==""
  304. if ($param2!==PHP_STR) {
  305. //updateHistoryWithErr("invalid parameters");
  306. return false;
  307. }
  308. //param3==""
  309. if ($param3!==PHP_STR) {
  310. //updateHistoryWithErr("invalid parameters");
  311. return false;
  312. }
  313. //param1 exist
  314. $path = $curPath . DIRECTORY_SEPARATOR . $param1;
  315. if (file_exists($path)) {
  316. //updateHistoryWithErr("file must not exists");
  317. return false;
  318. }
  319. //param1 file extension != gif | png | jpg | jpeg
  320. $fileExt = strtolower(pathinfo($param1, PATHINFO_EXTENSION));
  321. if ($fileExt === "gif" || $fileExt === "png" || $fileExt === "jpg" || $fileExt === "jpeg") {
  322. //updateHistoryWithErr("invalid inventory file");
  323. return false;
  324. }
  325. return true;
  326. }
  327. function upload() {
  328. global $curPath;
  329. global $prompt;
  330. //if (!empty($_FILES['files'])) {
  331. if (!empty($_FILES['files']['tmp_name'][0])) {
  332. // Updating history..
  333. //$output = [];
  334. //$output[] = $prompt . " " . "File upload" . "\n";
  335. //updateHistory($output, HISTORY_MAX_ITEMS);
  336. $uploads = (array)fixMultipleFileUpload($_FILES['files']);
  337. //no file uploaded
  338. if ($uploads[0]['error'] === PHP_UPLOAD_ERR_NO_FILE) {
  339. //updateHistoryWithErr("No file uploaded.", false);
  340. return;
  341. }
  342. foreach($uploads as &$upload) {
  343. switch ($upload['error']) {
  344. case PHP_UPLOAD_ERR_OK:
  345. break;
  346. case PHP_UPLOAD_ERR_NO_FILE:
  347. //updateHistoryWithErr("One or more uploaded files are missing.", false);
  348. return;
  349. case PHP_UPLOAD_ERR_INI_SIZE:
  350. //updateHistoryWithErr("File exceeded INI size limit.", false);
  351. return;
  352. case PHP_UPLOAD_ERR_FORM_SIZE:
  353. //updateHistoryWithErr("File exceeded form size limit.", false);
  354. return;
  355. case PHP_UPLOAD_ERR_PARTIAL:
  356. //updateHistoryWithErr("File only partially uploaded.", false);
  357. return;
  358. case PHP_UPLOAD_ERR_NO_TMP_DIR:
  359. //updateHistoryWithErr("TMP dir doesn't exist.", false);
  360. return;
  361. case PHP_UPLOAD_ERR_CANT_WRITE:
  362. //updateHistoryWithErr("Failed to write to the disk.", false);
  363. return;
  364. case PHP_UPLOAD_ERR_EXTENSION:
  365. //updateHistoryWithErr("A PHP extension stopped the file upload.", false);
  366. return;
  367. default:
  368. //updateHistoryWithErr("Unexpected error happened.", false);
  369. return;
  370. }
  371. if (!is_uploaded_file($upload['tmp_name'])) {
  372. //updateHistoryWithErr("One or more file have not been uploaded.", false);
  373. return;
  374. }
  375. // name
  376. $name = (string)substr((string)filter_var($upload['name']), 0, 255);
  377. if ($name == PHP_STR) {
  378. //updateHistoryWithErr("Invalid file name: " . $name, false);
  379. return;
  380. }
  381. $upload['name'] = $name;
  382. // fileType
  383. $fileType = substr((string)filter_var($upload['type']), 0, 30);
  384. $upload['type'] = $fileType;
  385. // tmp_name
  386. $tmp_name = substr((string)filter_var($upload['tmp_name']), 0, 300);
  387. if ($tmp_name == PHP_STR || !file_exists($tmp_name)) {
  388. //updateHistoryWithErr("Invalid file temp path: " . $tmp_name, false);
  389. return;
  390. }
  391. $upload['tmp_name'] = $tmp_name;
  392. //size
  393. $size = substr((string)filter_var($upload['size'], FILTER_SANITIZE_NUMBER_INT), 0, 12);
  394. if ($size == "") {
  395. //updateHistoryWithErr("Invalid file size.", false);
  396. return;
  397. }
  398. $upload["size"] = $size;
  399. $tmpFullPath = $upload["tmp_name"];
  400. $originalFilename = pathinfo($name, PATHINFO_FILENAME);
  401. $originalFileExt = pathinfo($name, PATHINFO_EXTENSION);
  402. $FileExt = strtolower(pathinfo($name, PATHINFO_EXTENSION));
  403. if ($originalFileExt!==PHP_STR) {
  404. $destFileName = $originalFilename . "." . $originalFileExt;
  405. } else {
  406. $destFileName = $originalFilename;
  407. }
  408. $destFullPath = $curPath . DIRECTORY_SEPARATOR . $destFileName;
  409. if (file_exists($destFullPath)) {
  410. //updateHistoryWithErr("destination already exists", false);
  411. return;
  412. }
  413. copy($tmpFullPath, $destFullPath);
  414. // Updating history..
  415. //$output = [];
  416. //$output[] = $destFileName . " " . "uploaded" . "\n";
  417. //updateHistory($output, HISTORY_MAX_ITEMS);
  418. // Cleaning up..
  419. // Delete the tmp file..
  420. unlink($tmpFullPath);
  421. }
  422. }
  423. }
  424. function showImages() {
  425. global $curPath;
  426. global $contextType;
  427. $privateData = [];
  428. $privateFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".private";
  429. if (file_exists($privateFile)) {
  430. $privateData = file($privateFile);
  431. }
  432. ///$root = "img";
  433. $root = APP_REPO_PATH;
  434. //subpath
  435. ///$subpath = mb_substr((string)filter_input(INPUT_GET, "path", FILTER_SANITIZE_STRING), 0, 500);
  436. $subpath = $curPath;
  437. if ($subpath!=="" && is_dir($subpath)) {
  438. $path = $subpath;
  439. } else {
  440. $path = $root;
  441. }
  442. /*
  443. * Display Link to Home
  444. */
  445. if ($path!==$root) {
  446. $title = "Parent";
  447. $ipos = mb_strripos($subpath, "/");
  448. $parentPath = substr($subpath, 0, $ipos);
  449. $relPath = substr($parentPath, strlen(APP_REPO_PATH));
  450. $cdate = date("d-m-Y", filectime($parentPath));
  451. echo "<table style='float:left;width:235px;height:200px;margin-top:5px;margin-right:4px;border:0px solid #D2D2D2'>";
  452. echo "<tr><td style='text-align:center;font-size:11px'>{$title}</td><tr>";
  453. echo "<tr><td style='padding:3px;'><a href='#' onclick='changePath(\"{$relPath}\")'><img src='/res/folder-home.png' width='100%' height='200px'></a></td><tr>";
  454. echo "<tr><td style='text-align:center;font-size:11px'>{$cdate}</td><tr>";
  455. echo "</table>";
  456. } else {
  457. $title = "Parent";
  458. $cdate = date("d-m-Y", filectime($root));
  459. echo "<table style='float:left;width:235px;height:200px;margin-top:5px;margin-right:4px;border:0px solid #D2D2D2'>";
  460. echo "<tr><td style='text-align:center;font-size:11px'>{$title}</td><tr>";
  461. echo "<tr><td style='padding:3px;'><img src='/res/folder-home-dis.png' width='100%' height='200px'></td><tr>";
  462. echo "<tr><td style='text-align:center;font-size:11px'>{$cdate}</td><tr>";
  463. echo "</table>";
  464. }
  465. if ($contextType === PERSONAL_CONTEXT_TYPE) {
  466. $title = "Add folder";
  467. $cdate = date("d-m-Y");
  468. echo "<table style='float:left;width:235px;height:200px;margin-top:5px;margin-right:4px;border:0px solid #D2D2D2'>";
  469. echo "<tr><td style='text-align:center;font-size:11px'>{$title}</td><tr>";
  470. echo "<tr><td style='padding:3px;cursor:pointer;' onclick='makeNewFolder()'><img src='/res/new-folder.png' width='100%' height='200px'></td><tr>";
  471. echo "<tr><td style='text-align:center;font-size:11px'>{$cdate}</td><tr>";
  472. echo "</table>";
  473. }
  474. $pattern = $path . "/*";
  475. /*
  476. * Display subfolders
  477. */
  478. $aDirs = glob($pattern, GLOB_ONLYDIR);
  479. sort($aDirs);
  480. foreach ($aDirs as &$fsEntry) {
  481. $relPath = substr($fsEntry, strlen(APP_REPO_PATH));
  482. $ipos = mb_strripos($fsEntry, "/");
  483. $title = substr($fsEntry, $ipos+1);
  484. $cdate = date("d-m-Y", filectime($fsEntry));
  485. echo "<table style='float:left;width:235px;height:200px;margin-top:5px;margin-right:4px;border:0px solid #D2D2D2'>";
  486. echo "<tr><td style='text-align:center;font-size:11px'>{$title}</td><tr>";
  487. echo "<tr><td style='padding:3px;'><a href='#' onclick='changePath(\"{$relPath}\")'><img src='/res/folder.png' width='100%' height='200px'></a></td><tr>";
  488. echo "<tr><td style='text-align:center;font-size:11px'>{$cdate}</td><tr>";
  489. echo "</table>";
  490. }
  491. $aImages = glob($pattern);
  492. sort($aImages);
  493. $serverName = filter_input(INPUT_SERVER, "SERVER_NAME");
  494. $i=1;
  495. foreach ($aImages as &$fsEntry) {
  496. if (!is_dir($fsEntry)) {
  497. $relPath = "/" . substr(APP_REPO_PATH, strlen(APP_PATH)+1) . substr($fsEntry, strlen(APP_REPO_PATH));
  498. $fileName = basename($fsEntry);
  499. $curFile = substr($curPath, strlen(APP_REPO_PATH)) . DIRECTORY_SEPARATOR . $fileName;
  500. $isPrivateFile = false;
  501. $imgLock = "/res/public.png";
  502. if (in_array($curFile . "\n",$privateData)) {
  503. $isPrivateFile = true;
  504. $imgLock = "/res/private.png";
  505. }
  506. $ipos = mb_strripos($fsEntry, "/");
  507. $title = substr($fsEntry, $ipos+1);
  508. $ipos = mb_stripos($title, ".");
  509. $title = substr($title, 0, $ipos);
  510. $cdate = date("d-m-Y", filectime($fsEntry));
  511. if ((!$isPrivateFile && ($contextType === PUBLIC_CONTEXT_TYPE)) || ($contextType === PERSONAL_CONTEXT_TYPE)) {
  512. echo "<div style='float:left;width:235px;margin-right:4px;'>";
  513. echo "<table style='width:235px;height:230px;margin-top:5px;margin-right:4px;background-color:#e1e1e1;border:1px solid #D2D2D2'>";
  514. echo "<tr>";
  515. if ($contextType === PERSONAL_CONTEXT_TYPE) {
  516. echo "<td style='width:23px;cursor:pointer; vertical-align:bottom;' ondblclick='delImg(\"{$i}\",\"{$fileName}\")'><img id='del-{$i}' class='imgdel' src='/res/del.png' style='height:19px;'></td>";
  517. echo "<td style='width:45px;cursor:pointer' ondblclick='changeVisibility(\"{$i}\",\"{$fileName}\")'><img id='lock-{$i}' class='imglock' src='{$imgLock}' style='height:23px;'></td>";
  518. } else {
  519. echo "<td style='width:1px;cursor:pointer; vertical-align:bottom;'><img id='del-{$i}' class='imgdel' src='/res/pxl.gif' style='height:1px;'></td>";
  520. echo "<td style='width:1px;cursor:pointer'><img id='lock-{$i}' class='imglock' src='/res/pxl.gif' style='height:1px;'></td>";
  521. }
  522. //echo "<td style='height:23px;text-align:center;font-size:11px;'>";
  523. if ($contextType === PERSONAL_CONTEXT_TYPE) {
  524. echo "<td style='height:23px;text-align:right;font-size:11px;'>";
  525. echo "{$title}&nbsp;";
  526. } else {
  527. echo "<td style='height:23px;text-align:center;font-size:11px;'>";
  528. echo "{$title}&nbsp;";
  529. }
  530. echo "</td>";
  531. echo "<tr>";
  532. echo "<tr><td style='padding:3px;width:235px;height:200px;background-image:url(\"{$relPath}\");background-size:235px 200px;cursor:zoom-in;' colspan='3' onclick=\"openPic('$fileName')\"'>&nbsp;</td><tr>";
  533. echo "<tr><td style='text-align:left;font-size:11px' colspan='3'>&nbsp;{$cdate}</td><tr>";
  534. echo "</table>";
  535. echo "<div style='position:relative;top:-35px;text-align:right;padding-right:1.5px;'>";
  536. echo "<a href=\"https://www.facebook.com/sharer/sharer.php?u=http://{$serverName}{$relPath}&t=\" onclick=\"javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;\" target=\"_blank\" title=\"Share on Facebook\"><img src='/res/fb.png'></a>";
  537. echo "<a href=\"https://twitter.com/share?url=http://{$serverName}{$relPath}&text=\" onclick=\"javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;\" target=\"_blank\" title=\"Share on Twitter\"><img src='/res/twitter.png'></a>";
  538. echo "<a href=\"whatsapp://send?text=http://{$serverName}{$relPath}\" data-action=\"share/whatsapp/share\" onClick=\"javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;\" target=\"_blank\" title=\"Share on whatsapp\"><img src='/res/whatsapp.png'></a>";
  539. echo "</div>";
  540. echo "</div>";
  541. }
  542. $i++;
  543. }
  544. }
  545. }
  546. function openPicParamValidation()
  547. {
  548. global $curPath;
  549. global $opt;
  550. global $param1;
  551. global $param2;
  552. global $param3;
  553. //opt!=""
  554. if ($opt!==PHP_STR) {
  555. echo("invalid options");
  556. return false;
  557. }
  558. //param1!="" and isword
  559. if (($param1===PHP_STR) || !is_word($param1)) {
  560. echo("invalid pic file");
  561. return false;
  562. }
  563. //param2==""
  564. if ($param2!==PHP_STR) {
  565. echo("invalid parameters");
  566. return false;
  567. }
  568. //param3==""
  569. if ($param3!==PHP_STR) {
  570. echo("invalid parameters");
  571. return false;
  572. }
  573. //param1 exist
  574. $path = $curPath . DIRECTORY_SEPARATOR . $param1;
  575. if (!file_exists($path)) {
  576. echo("pic must exists");
  577. return false;
  578. }
  579. //param1 is_file
  580. if (!is_file($path)) {
  581. echo("invalid pic file:" . $param1);
  582. return false;
  583. }
  584. //param1 is_image
  585. if (!is_image($param1)) {
  586. echo("invalid pic file" . $param1);
  587. return false;
  588. }
  589. return true;
  590. }
  591. function myExecOpenPicCommand() {
  592. global $curPath;
  593. global $curPicture;
  594. global $param1;
  595. $curPicture = substr($curPath.DIRECTORY_SEPARATOR.$param1, strlen(dirname(APP_REPO_PATH)));
  596. }
  597. $password = filter_input(INPUT_POST, "Password");
  598. $command = filter_input(INPUT_POST, "CommandLine");
  599. $pwd = filter_input(INPUT_POST, "pwd");
  600. $hideSplash = filter_input(INPUT_POST, "hideSplash");
  601. $hideHCSplash = filter_input(INPUT_POST, "hideHCSplash");
  602. if ($password !== PHP_STR) {
  603. $hash = hash("sha256", $password . APP_SALT, false);
  604. if ($hash !== APP_HASH) {
  605. $password=PHP_STR;
  606. }
  607. }
  608. $curPath = APP_REPO_PATH;
  609. if ($pwd!==PHP_STR) {
  610. ///if (left($pwd, strlen(APP_REPO_PATH)) === APP_REPO_PATH) {
  611. if (file_exists(APP_REPO_PATH . $pwd) && is_dir(APP_REPO_PATH . $pwd)) {
  612. $curPath = APP_REPO_PATH . $pwd;
  613. }
  614. }
  615. chdir($curPath);
  616. $ipos = strripos($curPath, PHP_SLASH);
  617. $curDir = substr($curPath, $ipos);
  618. parseCommand($command);
  619. //echo("cmd=" . $cmd . "<br>");
  620. //echo("opt=" . $opt . "<br>");
  621. //echo("param1=" . $param1 . "<br>");
  622. //echo("param2=" . $param2 . "<br>");
  623. if ($password !== PHP_STR) {
  624. upload();
  625. if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $command . "|")) {
  626. if ($command === "refresh") {
  627. // refreshing Msg Board..
  628. }
  629. } else if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $cmd . "|")) {
  630. if ($cmd === "privatify") {
  631. if (privatifyparamValidation()) {
  632. myExecPrivatifyCommand();
  633. }
  634. } else if ($cmd === "publicify") {
  635. if (publicifyparamValidation()) {
  636. myExecPublicifyCommand();
  637. }
  638. } else if ($cmd === "del") {
  639. if (delparamValidation()) {
  640. myExecDelCommand();
  641. }
  642. } else if ($cmd === "makedir") {
  643. if (makedirparamValidation()) {
  644. myExecMakeDirCommand();
  645. }
  646. } else if ($cmd === "openpic") {
  647. if (openPicParamValidation()) {
  648. myExecOpenPicCommand();
  649. }
  650. }
  651. } else {
  652. }
  653. $contextType = PERSONAL_CONTEXT_TYPE;
  654. } else {
  655. if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $cmd . "|")) {
  656. if ($cmd === "openpic") {
  657. if (openPicParamValidation()) {
  658. myExecOpenPicCommand();
  659. }
  660. }
  661. }
  662. }
  663. ?>
  664. <!DOCTYPE html>
  665. <html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
  666. <head>
  667. <meta charset="UTF-8"/>
  668. <meta name="style" content="day1"/>
  669. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  670. <!--
  671. Copyright 2021, 2024 5 Mode
  672. This file is part of Homogram.
  673. Homogram is free software: you can redistribute it and/or modify
  674. it under the terms of the GNU General Public License as published by
  675. the Free Software Foundation, either version 3 of the License, or
  676. (at your option) any later version.
  677. Homogram is distributed in the hope that it will be useful,
  678. but WITHOUT ANY WARRANTY; without even the implied warranty of
  679. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  680. GNU General Public License for more details.
  681. You should have received a copy of the GNU General Public License
  682. along with Homogram. If not, see <https://www.gnu.org/licenses/>.
  683. -->
  684. <title>Homogram: every person its pictures..</title>
  685. <link rel="shortcut icon" href="./res/favicon.ico?v=<?php echo(time()); ?>" />
  686. <meta name="description" content="Welcome to <?php echo(APP_NAME); ?>"/>
  687. <meta name="author" content="5 Mode"/>
  688. <meta name="robots" content="index,follow"/>
  689. <script src="./js/jquery-3.1.0.min.js" type="text/javascript"></script>
  690. <script src="./js/common.js" type="text/javascript"></script>
  691. <script src="./js/bootstrap.min.js" type="text/javascript"></script>
  692. <script src="./js/sha.js" type="text/javascript"></script>
  693. <script src="./js/home.js" type="text/javascript" defer></script>
  694. <link href="./css/bootstrap.min.css" type="text/css" rel="stylesheet">
  695. <link href="./css/style.css?v=<?php echo(time()); ?>" type="text/css" rel="stylesheet">
  696. </head>
  697. <body>
  698. <div id="HCsplash" style="padding-top: 160px; text-align:center;color:#ffffff;display:none;">
  699. <div id="myh1"><H1>Homogram</H1></div><br>
  700. <img src="res/HGlogo2.png" style="width:310px;">
  701. </div>
  702. <?php
  703. //echo ("curPicture=**$curPicture**");
  704. if ($curPicture != PHP_STR) {
  705. $apic = glob($curPath . DIRECTORY_SEPARATOR . "*");
  706. $i=0;
  707. foreach($apic as &$path) {
  708. $fileName = basename($path);
  709. if (is_file($curPath . DIRECTORY_SEPARATOR . $fileName)) {
  710. $path=$fileName;
  711. } else {
  712. unset($apic[$i]);
  713. }
  714. $i++;
  715. }
  716. $i=array_search(basename($curPicture), $apic);
  717. // if the only one
  718. if (count($apic)==1) {
  719. $prevPicture = basename($apic[0]);
  720. $nextPicture = basename($apic[0]);
  721. // if first
  722. } else if ($i==0) {
  723. $prevPicture = basename($apic[count($apic)-1]);
  724. $nextPicture = basename($apic[1]);
  725. // if last
  726. } else if ($i==(count($apic)-1)) {
  727. $prevPicture = basename($apic[$i-1]);
  728. $nextPicture = basename($apic[0]);
  729. } else {
  730. $prevPicture = basename($apic[$i-1]);
  731. $nextPicture = basename($apic[$i+1]);
  732. }
  733. $hidePlayer = "0";
  734. } else {
  735. $hidePlayer = "1";
  736. }
  737. ?>
  738. <div id="picPlayer" style="width:100%;height:1900px;vertical-align:middle;text-align:center;background:#000000;display:<?php echo(($hidePlayer==="1"? "none": "inline"));?>;">
  739. <div id="closePlayer" style="position: absolute; top:20px; left:20px; cursor:pointer;" onclick="closePlayer()"><img src="/res/parent.png" style="width:64px;"></div>
  740. <div id="myPicCont" style="width:100%;max-width:100%;clear:both;margin:auto;vertical-align:middle;background:#000000;"><img id="myPic" src="<?php echo($curPicture);?>" style="width:100%;vertical-align:middle;display:none;;background:#000000;"></div>
  741. <div id="navPlayer1" style="position:absolute;top:3000px;width:175px;cursor:pointer;overflow-x:hidden;border:0px solid red;" onclick="openPic('<?php echo($prevPicture);?>')"><img src="/res/picPrev.png" style="width:200px;position:relative;left:-125px;"></div>
  742. <div id="navPlayer2" style="position:absolute;top:3000px;width:175px;cursor:pointer;overflow-x:hidden;border:0px solid red;" onclick="openPic('<?php echo($nextPicture);?>')"><img src="/res/picNext.png" style="width:200px;position:relative;left:+100px;"></div>
  743. </div>
  744. <form id="frmHC" method="POST" action="/" target="_self" enctype="multipart/form-data" style="display:<?php echo((($hideHCSplash == "1") && ($hidePlayer == "1")?"inline":"none"));?>;">
  745. <div class="header">
  746. <a href="http://homogram.org" target="_blank" style="color:#000000; text-decoration: none;"><img src="res/HGlogo2.png" style="width:45px;">&nbsp;Homogram</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://github.com/par7133/Homogram" style="color:#000000;"><span style="color:#119fe2">on</span> github</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="mailto:info@homogram.org" style="color:#000000;"><span style="color:#119fe2">for</span> feedback</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="tel:+39-331-4029415" style="font-size:13px;background-color:#15c60b;border:2px solid #15c60b;color:#000000;height:27px;text-decoration:none;">&nbsp;&nbsp;get support&nbsp;&nbsp;</a>
  747. </div>
  748. <div style="clear:both; float:left; padding:8px; width:15%; height:100%; text-align:center;">
  749. <div style="padding-left:12px;text-align: left;">
  750. &nbsp;
  751. <?php if ($password!==PHP_STR): ?>
  752. <a href="#" id="upload" style="color:#5ab5e4;" onclick="upload()">Upload</a>
  753. <input id="files" name="files[]" type="file" accept=".gif,.png,.jpg,.jpeg" style="visibility: hidden;">
  754. <?php else: ?>
  755. <br>
  756. <?php endif; ?>
  757. </div>
  758. <br><br>
  759. <img src="res/HGgenius.png" alt="HG Genius" title="HG Genius" style="position:relative; left:+6px; width:90%; border: 1px dashed #EEEEEE;">
  760. &nbsp;<br><br><br>
  761. &nbsp;<input type="text" id="Password" name="Password" placeholder="password" style="font-size:10px; background:#393939; color:#ffffff; width: 90%; border-radius:3px;" value="<?php echo($password);?>" autocomplete="off"><br>
  762. &nbsp;<input type="text" id="Salt" placeholder="salt" style="position:relative; top:+5px; font-size:10px; background:#393939; color:#ffffff; width: 90%; border-radius:3px;" autocomplete="off"><br>
  763. &nbsp;<a href="#" onclick="showEncodedPassword();" style="position:relative; left:-2px; top:+5px; color:#000000; font-size:12px;">Hash Me!</a>
  764. <input type="hidden" id="CommandLine" name="CommandLine">
  765. <input type="hidden" id="pwd" name="pwd" value="<?php echo(substr($curPath, strlen(APP_REPO_PATH))); ?>" style="color:black">
  766. <input type="hidden" name="hideSplash" value="<?php echo($hideSplash); ?>">
  767. <input type="hidden" name="hideHCSplash" value="1">
  768. </div>
  769. <div style="float:left; width:85%;height:100%; padding:8px; border-left: 1px solid #2c2f34;">
  770. <?php if (APP_SPLASH): ?>
  771. <?php if ($hideSplash !== PHP_STR): ?>
  772. <div id="splash" style="border-radius:20px; position:relative; left:+3px; width:98%; background-color: #33aced; padding: 20px; margin-bottom:8px;">
  773. <button type="button" class="close" aria-label="Close" onclick="closeSplash();" style="position:relative; left:-10px;">
  774. <span aria-hidden="true">&times;</span>
  775. </button>
  776. Hello and welcome to Homogram!<br><br>
  777. Homogram is a light and simple software on premise to share your images.<br><br>
  778. Homogram is released under GPLv3 license, it is supplied AS-IS and we do not take any responsibility for its misusage.<br><br>
  779. The name *Homogram* comes from a prank on the name 'instagram', in fact differently from the latter Homogram gives priorities to homines..<br><br>
  780. However Homogram doesn't birth as a replacement but just like its alter ego.. :o)<br><br>
  781. First step, use the left side panel password and salt fields to create the hash to insert in the config file. Remember to manually set there also the salt value.<br><br>
  782. As you are going to run Homogram in the PHP process context, using a limited web server or phpfpm user, you must follow some simple directives for an optimal first setup:<br>
  783. <ol>
  784. <li>Check the write permissions of your "HGRepo" folder in your web app public path; and set its path in the config file.</li>
  785. <li>Check the write permissions of your "data" folder in your web app private path; and set its path in the config file.</li>
  786. </ol>
  787. <br>
  788. Hope you can enjoy it and let us know about any feedback: <a href="mailto:info@homogram.org" style="color:#e6d236;">info@homogram.org</a>
  789. </div>
  790. <?php endif; ?>
  791. <?php endif; ?>
  792. <?php
  793. if ($contextType === PUBLIC_CONTEXT_TYPE) {
  794. echo("&nbsp;You are in <span style='color:orange;'>~/" . substr($curPath, strlen(APP_REPO_PATH)+1) . "</span> as <span style='color:black;'>guest</span><br>");
  795. } else {
  796. echo("&nbsp;You are in <span style='color:orange;'>~/" . substr($curPath, strlen(APP_REPO_PATH)+1) . "</span> as <span style='color:green;'>owner</span><br>");
  797. }
  798. ?><br>
  799. <div id="Console" style="hei-ght:493px; over-flow-y:auto; margin-top:10px;">
  800. <?php showImages(); ?>
  801. </div>
  802. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  803. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  804. </div>
  805. </form>
  806. <div class="footer">
  807. <div id="footerCont">&nbsp;</div>
  808. <div id="footer"><span style="background:#E1E1E1;color:black;opacity:1.0;margin-right:10px;">&nbsp;&nbsp;A <a href="http://5mode.com">5 Mode</a> project and <a href="http://wysiwyg.systems">WYSIWYG</a> system. Some rights reserved.</span></div>
  809. </div>
  810. <script>
  811. $(document).ready(function() {
  812. $("#Password").on("keydown",function(e){
  813. key = e.which;
  814. //alert(key);
  815. if (key===13) {
  816. e.preventDefault();
  817. frmHC.submit();
  818. } else {
  819. //e.preventDefault();
  820. }
  821. });
  822. });
  823. function setPPlayer() {
  824. $("#picPlayer").css("height", parseInt(window.innerHeight)+"px");
  825. $("#myPicCont").css("height", parseInt(window.innerHeight)+"px");
  826. $("#myPicCont").css("max-width", parseInt(window.innerWidth)+"px");
  827. $("#closePlayer").css("left", "10px");
  828. $("#navPlayer1").css("top", parseInt((window.innerHeight-200)/2)+"px");
  829. $("#navPlayer2").css("top", parseInt((window.innerHeight-200)/2)+"px");
  830. $("#navPlayer2").css("left", parseInt(window.innerWidth-175)+"px");
  831. if (document.getElementById("myPic").src!="") {
  832. if ($("#myPic").width() > $("#myPic").height()) {
  833. f = $("#myPic").width() / $("#myPic").height();
  834. $("#myPic").css("padding-top", parseInt((window.innerHeight - $("#myPic").height()) / 2)+"px");
  835. $("#myPic").css("width", "100%"); //parseInt(window.innerWidth)+"px");
  836. $("#myPic").css("height", "");
  837. $("#myPic").css("max-height", parseInt(window.innerHeight)+"px");
  838. } else {
  839. $("#myPic").css("width", "");
  840. $("#myPic").css("max-width", parseInt(window.innerWidth)+"px");
  841. $("#myPic").css("height", "100%"); //parseInt(window.innerHeight)+"px");
  842. $("#myPicCont").css("max-width", parseInt(window.innerWidth)+"px");
  843. }
  844. $("#myPic").css("display", "inline");
  845. }
  846. $(document.body).css("overflow-x","hidden");
  847. }
  848. function hideTitle() {
  849. $("#myh1").hide("slow");
  850. }
  851. function startApp() {
  852. $("#HCsplash").hide("slow");
  853. $(document.body).css("background","#ffffff");
  854. $("#frmHC").show();
  855. }
  856. <?php if($hideHCSplash!=="1"): ?>
  857. window.addEventListener("load", function() {
  858. $(document.body).css("background","#000000");
  859. $("#HCsplash").show("slow");
  860. setTimeout("hideTitle()", 2000);
  861. setTimeout("startApp()", 4000);
  862. }, true);
  863. <?php else: ?>
  864. window.addEventListener("load", function() {
  865. <?php if ($hidePlayer == "1"): ?>
  866. startApp();
  867. <?php endif; ?>
  868. });
  869. <?php endif; ?>
  870. window.addEventListener("load", function() {
  871. <?php if ($hideHCSplash != "1" || $hidePlayer != "1"): ?>
  872. $(document.body).css("backgrond","#000000");
  873. <?php else: ?>
  874. $(document.body).css("backgrond","#FFFFFF");
  875. <?php endif; ?>
  876. });
  877. window.addEventListener("load", function() {
  878. <?php if($password===PHP_STR):?>
  879. $("#Password").addClass("emptyfield");
  880. <?php endif; ?>
  881. //maxY = document.getElementById("Console").scrollHeight;
  882. //alert(maxY);
  883. <?php if ($hidePlayer == "0"): ?>
  884. setPPlayer();
  885. <?php endif; ?>
  886. }, true);
  887. window.addEventListener("resize", function() {
  888. <?php if ($hidePlayer == "0"): ?>
  889. setPPlayer();
  890. <?php endif; ?>
  891. }, true);
  892. </script>
  893. </body>
  894. </html>