home.php 37 KB

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