. * * home.php * * Homogram home page. * * @author Daniele Bonini * @copyrights (c) 2021, 2024, 5 Mode */ $contextType = PUBLIC_CONTEXT_TYPE; $cmd = PHP_STR; $opt = PHP_STR; $param1 = PHP_STR; $param2 = PHP_STR; $param3 = PHP_STR; $curPicture = ""; $prevPicture = ""; $nextPicture = ""; $curLocale = APP_LOCALE; function parseCommand() { global $command; global $cmd; global $opt; global $param1; global $param2; global $param3; $str = trim($command); $ipos = stripos($str, PHP_SPACE); if ($ipos > 0) { $cmd = left($str, $ipos); $str = substr($str, $ipos+1); } else { $cmd = $str; return; } if (left($str, 1) === "-") { $ipos = stripos($str, PHP_SPACE); if ($ipos > 0) { $opt = left($str, $ipos); $str = substr($str, $ipos+1); } else { $opt = $str; return; } } if (left($str, 1) === "'") { $ipos = stripos($str, "'", 1); if ($ipos > 0) { $param1 = substr($str, 0, $ipos+1); $str = substr($str, $ipos+1); } else { $param1 = $str; return; } } else { $ipos = stripos($str, PHP_SPACE); if ($ipos > 0) { $param1 = left($str, $ipos); $str = substr($str, $ipos+1); } else { $param1 = $str; return; } } $ipos = stripos($str, PHP_SPACE); if ($ipos > 0) { $param2 = left($str, $ipos); $str = substr($str, $ipos+1); } else { $param2 = $str; return; } $ipos = stripos($str, PHP_SPACE); if ($ipos > 0) { $param3 = left($str, $ipos); $str = substr($str, $ipos+1); } else { $param3 = $str; return; } } function is_subfolderdest(string $path): bool { global $curPath; $ret=false; if ($path === "../") { return $ret; } if ($path!=PHP_STR) { $folderName = left($path, strlen($path)-1); if (!is_word($folderName)) { return $ret; } if (is_dir($curPath . PHP_SLASH . $folderName) && (right($path,1)==="/")) { $ret=true; } } return $ret; } function privatifyparamValidation() { global $curPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { echo("WARNING: invalid options
"); return false; } //param1!="" and isword $test_param1 = trim($param1,"'"); if (($test_param1===PHP_STR) || !is_word($test_param1)) { echo("WARNING: invalid image file
"); return false; } //param2=="" if ($param2!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param3=="" if ($param3!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param1 exist $path = $curPath . DIRECTORY_SEPARATOR . $test_param1; if (!file_exists($path)) { echo("WARNING: file must exists
"); return false; } //param1 is_file if (!is_file($path)) { echo("WARNING: invalid image file
"); return false; } //param1 file extension == gif | png | jpg | jpeg if (!is_image($test_param1)) { echo("WARNING: invalid image file
"); return false; } return true; } function myExecPrivatifyCommand() { global $param1; global $curPath; $privateData = []; $publicData = []; $real_param1 = trim($param1, "'"); $curFile = substr($curPath, strlen(APP_REPO_PATH)) . DIRECTORY_SEPARATOR . $real_param1; //echo "curFile=$curFile"; if (APP_DEFAULT_CONTEXT === "PUBLIC") { // Insert in .public $privateFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".private"; //echo "curFile=$privateFile"; if (file_exists($privateFile)) { $privateData = file($privateFile); } if (!in_array($curFile . "\n", $privateData)) { $privateData[] = $curFile . "\n"; file_put_contents($privateFile, implode('', $privateData)); } } else { // Cut off from .private $publicFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".public"; //echo "curFile=$publicFile"; if (file_exists($publicFile)) { $publicData = file($publicFile); } $key = array_search($curFile . "\n", $publicData); if ($key!==false) { unset($publicData[$key]); file_put_contents($publicFile, implode('', $publicData)); } } } function publicifyparamValidation() { global $curPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { echo("WARNING: invalid options
"); return false; } //param1!="" and isword $test_param1 = trim($param1,"'"); if (($test_param1===PHP_STR) || !is_word($test_param1)) { echo("WARNING: invalid image file
"); return false; } //param2=="" if ($param2!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param3=="" if ($param3!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param1 exist $path = $curPath . DIRECTORY_SEPARATOR . $test_param1; if (!file_exists($path)) { echo("WARNING: file must exists
"); return false; } //param1 is_file if (!is_file($path)) { echo("WARNING: invalid image file
"); return false; } //param1 file extension == gif | png | jpg | jpeg if (!is_image($test_param1)) { echo("WARNING: invalid image file
"); return false; } return true; } function myExecPublicifyCommand() { global $param1; global $curPath; $privateData = []; $publicData = []; $real_param1 = trim($param1, "'"); $curFile = substr($curPath, strlen(APP_REPO_PATH)) . DIRECTORY_SEPARATOR . $real_param1; //echo "curFile=$curFile"; if (APP_DEFAULT_CONTEXT === "PRIVATE") { // Insert in .public $publicFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".public"; //echo "curFile=$publicFile"; if (file_exists($publicFile)) { $publicData = file($publicFile); } if (!in_array($curFile . "\n", $publicData)) { $publicData[] = $curFile . "\n"; file_put_contents($publicFile, implode('', $publicData)); } } else { // Cut off from .private $privateFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".private"; //echo "curFile=$privateFile"; if (file_exists($privateFile)) { $privateData = file($privateFile); } $key = array_search($curFile . "\n", $privateData); if ($key!==false) { unset($privateData[$key]); file_put_contents($privateFile, implode('', $privateData)); } } } function delparamValidation() { global $curPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { echo("WARNING: invalid options
"); return false; } //param1!="" and isword $test_param1 = trim($param1,"'"); //echo("WARNING: ".$test_param1."
"); if (($test_param1===PHP_STR) || !is_word($test_param1)) { echo("WARNING: invalid image file
"); return false; } //param2=="" if ($param2!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param3=="" if ($param3!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param1 exist $path = $curPath . DIRECTORY_SEPARATOR . $test_param1; if (!file_exists($path)) { echo("WARNING: file must exists
"); return false; } //param1 is_file if (!is_file($path)) { echo("WARNING: invalid image file
"); return false; } //param1 file extension == gif | png | jpg | jpeg if (!is_image($test_param1)) { echo("WARNING: invalid image file
"); return false; } return true; } function myExecDelCommand() { global $param1; global $curPath; $real_param1 = trim($param1, "'"); $curFile = $curPath . DIRECTORY_SEPARATOR . $real_param1; unlink($curFile); $curFileThumb = $curPath . DIRECTORY_SEPARATOR . "thumbs" . DIRECTORY_SEPARATOR . $real_param1; if (is_readable($curFileThumb)) { unlink($curFileThumb); } } function makedirparamValidation() { global $curPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { echo("WARNING: invalid options
"); return false; } //param1!="" and isword $test_param1 = trim($param1,"'"); if (($test_param1===PHP_STR) || !is_word($test_param1)) { echo("WARNING: invalid folder name
"); return false; } //param2=="" if ($param2!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param3=="" if ($param3!==PHP_STR) { echo("WARNING: invalid parameters
"); return false; } //param1 exist $path = $curPath . DIRECTORY_SEPARATOR . $test_param1; if (file_exists($path)) { echo("WARNING: file must not exists
"); return false; } //param1 file extension != gif | png | jpg | jpeg if (is_image($test_param1)) { echo("WARNING: invalid folder name
"); return false; } return true; } function myExecMakeDirCommand() { global $param1; global $curPath; $real_param1 = trim($param1, "'"); $newpath = $curPath . DIRECTORY_SEPARATOR . $real_param1; mkdir($newpath, 0777); } function upload() { global $curPath; global $prompt; //if (!empty($_FILES['files'])) { if (!empty($_FILES['files']['tmp_name'][0])) { // Updating history.. //$output = []; //$output[] = $prompt . " " . "File upload" . "\n"; //updateHistory($output, HISTORY_MAX_ITEMS); $uploads = (array)fixMultipleFileUpload($_FILES['files']); //no file uploaded if ($uploads[0]['error'] === PHP_UPLOAD_ERR_NO_FILE) { echo("WARNING: No file uploaded.
"); return; } foreach($uploads as &$upload) { switch ($upload['error']) { case PHP_UPLOAD_ERR_OK: break; case PHP_UPLOAD_ERR_NO_FILE: echo("WARNING: One or more uploaded files are missing.
"); return; case PHP_UPLOAD_ERR_INI_SIZE: echo("WARNING: File exceeded INI size limit.
"); return; case PHP_UPLOAD_ERR_FORM_SIZE: echo("WARNING: File exceeded form size limit.
"); return; case PHP_UPLOAD_ERR_PARTIAL: echo("WARNING: File only partially uploaded.
"); return; case PHP_UPLOAD_ERR_NO_TMP_DIR: echo("WARNING: TMP dir doesn't exist.
"); return; case PHP_UPLOAD_ERR_CANT_WRITE: echo("WARNING: Failed to write to the disk.
"); return; case PHP_UPLOAD_ERR_EXTENSION: echo("WARNING: A PHP extension stopped the file upload.
"); return; default: echo("WARNING: Unexpected error happened.
"); return; } if (!is_uploaded_file($upload['tmp_name'])) { echo("WARNING: One or more file have not been uploaded.
"); return; } // name $name = (string)substr((string)filter_var($upload['name']), 0, 255); if ($name == PHP_STR) { echo("WARNING: Invalid file name: " . $name."
"); return; } $upload['name'] = $name; // fileType $fileType = substr((string)filter_var($upload['type']), 0, 30); $upload['type'] = $fileType; // tmp_name $tmp_name = substr((string)filter_var($upload['tmp_name']), 0, 300); if ($tmp_name == PHP_STR || !file_exists($tmp_name)) { echo("WARNING: Invalid file temp path: " . $tmp_name."
"); return; } $upload['tmp_name'] = $tmp_name; //size $size = substr((string)filter_var($upload['size'], FILTER_SANITIZE_NUMBER_INT), 0, 12); if ($size == "") { echo("WARNING: Invalid file size.
"); return; } $upload["size"] = $size; $tmpFullPath = $upload["tmp_name"]; $originalFilename = pathinfo($name, PATHINFO_FILENAME); $originalFileExt = pathinfo($name, PATHINFO_EXTENSION); $FileExt = strtolower(pathinfo($name, PATHINFO_EXTENSION)); if ($originalFileExt!==PHP_STR) { $destFileName = $originalFilename . "." . $originalFileExt; } else { $destFileName = $originalFilename; } $destFullPath = $curPath . DIRECTORY_SEPARATOR . $destFileName; if (file_exists($destFullPath)) { echo("WARNING: destination already exists.
"); return; } copy($tmpFullPath, $destFullPath); chmod($destFullPath, 0766); // Creating thumb file if (is_readable($curPath . DIRECTORY_SEPARATOR . "thumbs")) { $destFullPath = $curPath . DIRECTORY_SEPARATOR . "thumbs" . DIRECTORY_SEPARATOR . $destFileName; copy($tmpFullPath, $destFullPath); chmod($destFullPath, 0766); } // Updating history.. //$output = []; //$output[] = $destFileName . " " . "uploaded" . "\n"; //updateHistory($output, HISTORY_MAX_ITEMS); // Cleaning up.. // Delete the tmp file.. unlink($tmpFullPath); } } } function showImages() { global $curPath; global $contextType; global $curLocale; $exclData = []; if (APP_DEFAULT_CONTEXT === "PUBLIC") { $exclFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".private"; } else { $exclFile = APP_DATA_PATH . DIRECTORY_SEPARATOR . ".public"; } if (file_exists($exclFile)) { $exclData = file($exclFile); } ///$root = "img"; $root = APP_REPO_PATH; //subpath $subpath = $curPath; if ($subpath!=="" && is_dir($subpath)) { $path = $subpath; } else { $path = $root; } /* * Display Link to Home */ if ($path!==$root) { $title = getResource("Parent", $curLocale); $ipos = mb_strripos($subpath, "/"); $parentPath = substr($subpath, 0, $ipos); $relPath = substr($parentPath, strlen(APP_REPO_PATH)); $cdate = date("d-m-Y", filectime($parentPath)); echo ""; echo ""; echo ""; echo ""; echo "
{$title}
{$cdate}
"; } else { $title = getResource("Parent", $curLocale); $cdate = date("d-m-Y", filectime($root)); echo ""; echo ""; echo ""; echo ""; echo "
{$title}
{$cdate}
"; } if ($contextType === PERSONAL_CONTEXT_TYPE) { $title = getResource("Add folder", $curLocale); $cdate = date("d-m-Y"); echo ""; echo ""; echo ""; echo ""; echo "
{$title}
{$cdate}
"; } $pattern = $path . "/*"; /* * Display subfolders */ $aDirs = glob($pattern, GLOB_ONLYDIR); sort($aDirs); foreach ($aDirs as &$fsEntry) { $relPath = substr($fsEntry, strlen(APP_REPO_PATH)); $ipos = mb_strripos($fsEntry, "/"); $title = substr($fsEntry, $ipos+1); if ($title === "thumbs") { continue; } $cdate = date("d-m-Y", filectime($fsEntry)); echo ""; echo ""; echo ""; echo ""; echo "
{$title}
{$cdate}
"; } /* * Display images */ if (is_readable($path . "/thumbs")) { $pattern = $path . "/thumbs/*"; } else { $pattern = $path . "/*"; } $aImages = glob($pattern); sort($aImages); $serverName = filter_input(INPUT_SERVER, "SERVER_NAME"); $i=1; foreach ($aImages as &$fsEntry) { if (!is_dir($fsEntry)) { $relPath = "/" . substr(APP_REPO_PATH, strlen(APP_PATH)+1) . substr($fsEntry, strlen(APP_REPO_PATH)); $fileName = basename($fsEntry); $curFile = substr($curPath, strlen(APP_REPO_PATH)) . DIRECTORY_SEPARATOR . $fileName; if (APP_DEFAULT_CONTEXT === "PUBLIC") { $isPrivateFile = false; $imgLock = "/res/public.png"; if (in_array($curFile . "\n",$exclData)) { $isPrivateFile = true; $imgLock = "/res/private.png"; } } else { $isPrivateFile = true; $imgLock = "/res/private.png"; if (in_array($curFile . "\n",$exclData)) { $isPrivateFile = false; $imgLock = "/res/public.png"; } } $ipos = mb_strripos($fsEntry, "/"); $title = substr($fsEntry, $ipos+1); $ipos = mb_stripos($title, "."); $title = substr($title, 0, $ipos); //parsing title for underscore if (APP_LAST_UNDERSCORE_CHECK) { $ipos = mb_strripos($title, "_"); if ($ipos === false) { } else { $title = substr($title, $ipos+1); } } if (strlen($title)>22) { $title = left($title,22) . ".."; } $cdate = date("d-m-Y", filectime($fsEntry)); if ((!$isPrivateFile && ($contextType === PUBLIC_CONTEXT_TYPE)) || ($contextType === PERSONAL_CONTEXT_TYPE)) { echo ""; } $i++; } } } function openPicParamValidation() { global $curPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { echo("invalid options"); return false; } //param1!="" and isword if (($param1===PHP_STR) || !is_word($param1)) { echo("invalid image file"); return false; } //param2=="" if ($param2!==PHP_STR) { echo("invalid parameters"); return false; } //param3=="" if ($param3!==PHP_STR) { echo("invalid parameters"); return false; } //param1 exist $path = $curPath . DIRECTORY_SEPARATOR . $param1; if (!file_exists($path)) { echo("file must exists"); return false; } //param1 is_file if (!is_file($path)) { echo("invalid image file:" . $param1); return false; } //param1 is_image if (!is_image($param1)) { echo("invalid image file" . $param1); return false; } return true; } function myExecOpenPicCommand() { global $curPath; global $curPicture; global $param1; $curPicture = substr($curPath.DIRECTORY_SEPARATOR.$param1, strlen(dirname(APP_REPO_PATH))); } $password = filter_input(INPUT_POST, "Password")??""; $password = strip_tags($password); if ($password==PHP_STR) { $password = filter_input(INPUT_POST, "Password2")??""; $password = strip_tags($password); } $command = filter_input(INPUT_POST, "CommandLine")??""; $command = strip_tags($command); $pwd = filter_input(INPUT_POST, "pwd")??""; $pwd = strip_tags($pwd); $hideSplash = filter_input(INPUT_POST, "hideSplash")??""; $hideSplash = strip_tags($hideSplash); $hideHCSplash = filter_input(INPUT_POST, "hideHCSplash")??""; $hideHCSplash = strip_tags($hideHCSplash); if ($password !== PHP_STR) { $hash = hash("sha256", $password . APP_SALT, false); if ($hash !== APP_HASH) { $password=PHP_STR; } } $curPath = APP_REPO_PATH; if ($pwd!==PHP_STR) { ///if (left($pwd, strlen(APP_REPO_PATH)) === APP_REPO_PATH) { if (file_exists(APP_REPO_PATH . $pwd) && is_dir(APP_REPO_PATH . $pwd)) { $curPath = APP_REPO_PATH . $pwd; } } chdir($curPath); $ipos = strripos($curPath, PHP_SLASH); $curDir = substr($curPath, $ipos); parseCommand($command); //echo("cmd=" . $cmd . "
"); //echo("opt=" . $opt . "
"); //echo("param1=" . $param1 . "
"); //echo("param2=" . $param2 . "
"); if ($password !== PHP_STR) { upload(); if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $command . "|")) { if ($command === "refresh") { // refreshing Msg Board.. } } else if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $cmd . "|")) { if ($cmd === "privatify") { if (privatifyparamValidation()) { myExecPrivatifyCommand(); } } else if ($cmd === "publicify") { if (publicifyparamValidation()) { myExecPublicifyCommand(); } } else if ($cmd === "del") { if (delparamValidation()) { myExecDelCommand(); } } else if ($cmd === "makedir") { if (makedirparamValidation()) { myExecMakeDirCommand(); } } else if ($cmd === "openpic") { if (openPicParamValidation()) { myExecOpenPicCommand(); } } } else { } $contextType = PERSONAL_CONTEXT_TYPE; } else { if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $cmd . "|")) { if ($cmd === "openpic") { if (openPicParamValidation()) { myExecOpenPicCommand(); } } } } ?> Homogram: every person its pictures..
;">
;">
 Homogram       on github      for feedback       get support  
Hello and welcome to Homogram!

Homogram is a light and simple software on premise to share your images. And it can be used as a private repository (screenshots, private shots, etc).

Homogram is released under GPLv3 license, it is supplied AS-IS and we do not take any responsibility for its misusage.

The name *Homogram* comes from a prank on the name 'instagram', in fact differently from the latter Homogram gives priorities to homines. However Homogram doesn't birth as a replacement but just like its alter ego.

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.

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:
  1. Check the write permissions of your "HGRepo" folder in your web app public path; and set its path in the config file.
  2. Check the write permissions of your "data" folder in your web app private path; and set its path in the config file.
  3. Set the default Locale.
  4. Set the default Context to PUBLIC or PRIVATE (for a private repository).

Hope you can enjoy it and let us know about any feedback: posta@elettronica.lol
~/" . substr($curPath, strlen(APP_REPO_PATH)+1) . "" . getResource(" as ", $curLocale) . "" . getResource("guest", $curLocale) . "
"); } else { echo(" " . getResource("You are in ", $curLocale) . "~/" . substr($curPath, strlen(APP_REPO_PATH)+1) . "" . getResource(" as ", $curLocale) . "" . getResource("owner", $curLocale) . "
"); } ?>