home.php 37 KB

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