. * * home.php * * Homomm home page. * * @author Daniele Bonini * @copyrights (c) 2021, 2024, 5 Mode */ $msgHistory = []; $cmd = PHP_STR; $opt = PHP_STR; $param1 = PHP_STR; $param2 = PHP_STR; $param3 = PHP_STR; $user = PHP_STR; $userName = PHP_STR; $chatHint = PHP_STR; $chatHintResolved = PHP_STR; $picPath = PHP_STR; $curPicture = PHP_STR; $curLocale = APP_LOCALE; $lastMessage = PHP_STR; function showHistory() { global $msgHistory; global $user; global $curPath; global $picPath; global $CONFIG; global $curLocale; global $LOCALE; global $EMOTICONS; global $lastMessage; $i = 1; $totMsgs = count($msgHistory); $oldDate = ""; $m = 1; foreach($msgHistory as $val) { $delFunc = false; if ((mb_stripos($val, "-master") !== false) && ($user == "MASTER")) { $float = "right"; $bgcolor = "#E3FAE3"; } else if ((mb_stripos($val, "-master") === false) && ($user != "MASTER")) { $float = "right"; $bgcolor = "#E3FAE3"; } else { $float = "left"; $bgcolor = "#FFFFFF"; } echo("
"); $val = rtrim($val,"\n"); // grab the date converting to the given time zone.. //$dateori = left($val, 8); $dated = new DateTime(left($val,4)."-".substr($val,4,2)."-".substr($val,6,2)." ".substr($val,9,2).":".substr($val,11,2).":".substr($val,13,2)); $dated = date_add1("H", ltrim($CONFIG['AUTH'][$user]['TIMEZONE'],"+")-APP_SERVER_TIMEZONE, $dated); $date = $dated->format("l j F"); //$date = date("l j F", mktime(0,0,0,substr($dateori,4,2),right($dateori,2),left($dateori,4))); if (in_array($curLocale, ["CN", "JP", "KR"])) { $date = str_phrase_reverse($date); } $date = getResource($date, $curLocale); if ($date!=$oldDate) { echo("
$date

"); $oldDate = $date; } // grab the time //preg_match('/^.+-(\d{6})-/i', $val, $matches); //$timereg = $matches[1]; //$time = ltrim(left($timereg,2),"0") . ":" . substr($timereg,2,2); $time = $dated->format("H:i"); // Checking for del functionality.. // If it is one of the logged user msg.. if ((($m==$totMsgs) || ($m==$totMsgs-1)) && ($float === "right")) { // file date //$origin = new DateTime(left($dateori,4) ."-". substr($dateori,4,2) ."-". right($dateori,2) . " " . left($timereg,2) .":". substr($timereg,2,2) .":". "00"); //echo($dated->format("YMd H:i:s")); // current date $target = new DateTime(); $interval = $dated->diff($target); $minInterval = $interval->format("%i"); if ($minInterval<2) { $delFunc = true; } } if (is_image($val)) { // display the img $img = substr($picPath, strlen(APP_PATH)) . DIRECTORY_SEPARATOR . $val; $deldiv=PHP_STR; if ($delFunc) { $deldiv = "
"; } echo("
$time
$deldiv



"); } else { // display the msg $msg = HTMLencode(file_get_contents($curPath . DIRECTORY_SEPARATOR . "msgs" . DIRECTORY_SEPARATOR . $val)); $msg = enableEmails($msg); $msg = enableLinks($msg); $msg = enableEmoticons($msg); $deldiv=PHP_STR; if ($delFunc) { $deldiv = "
"; } echo("
".str_replace("\n", "
", $msg)."
$time
$deldiv



"); } echo("
"); echo("
"); $lastMessage = hash("sha256", $val . APP_SALT, false); $m++; } } function updateHistory(&$update, $maxItems) { global $msgHistory; global $curPath; global $picPath; // Making enough space in $msgHistory for the update.. $shift = (count($msgHistory) + count($update)) - $maxItems; if ($shift > 0) { $msgHistory = array_slice($msgHistory, $shift, $maxItems); } // Adding $msgHistory update.. if (count($update) > $maxItems) { $beginUpd = count($update) - ($maxItems-1); } else { $beginUpd = 0; } $update = array_slice($update, $beginUpd, $maxItems); foreach($update as $val) { $msgHistory[] = $val; } // Deleting unused message files.. foreach (glob($curPath . DIRECTORY_SEPARATOR . "msgs" . DIRECTORY_SEPARATOR . "*.msg") as $msgFilePath) { $msgFileName = basename($msgFilePath); if (!in_array($msgFileName."\n", $msgHistory)) { unlink($curPath . DIRECTORY_SEPARATOR . "msgs" . DIRECTORY_SEPARATOR . $msgFileName); } } // Deleting unused pic files.. foreach (glob($picPath . DIRECTORY_SEPARATOR . "*") as $imgFilePath) { $imgFileName = basename($imgFilePath); if (!in_array($imgFileName."\n", $msgHistory)) { unlink($picPath . DIRECTORY_SEPARATOR . $imgFileName); } } // Writing out $msgHistory on disk.. $filepath = $curPath . DIRECTORY_SEPARATOR . ".HMM_history"; file_put_contents($filepath, implode('', $msgHistory)); } 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 upload() { global $curPath; global $user; global $userName; global $picPath; global $msgSign; //if (!empty($_FILES['files'])) { if (!empty($_FILES['files']['tmp_name'][0])) { $uploads = (array)fixMultipleFileUpload($_FILES['files']); //no file uploaded if ($uploads[0]['error'] === PHP_UPLOAD_ERR_NO_FILE) { echo("WARNING: No file uploaded."); return; } $google = "abcdefghijklmnopqrstuvwxyz"; if (count($uploads)>strlen($google)) { echo("WARNING: Too many uploaded files."); return; } // Checking for repeated upload cause ie. caching prb.. $duplicateMsgs = glob($picPath . DIRECTORY_SEPARATOR . date("Ymd-H") . "*-$msgSign*.*"); if (!empty($duplicateMsgs)) { echo("WARNING: destination already exists"); return; } $i=1; 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)); $date = date("Ymd-His"); $rnd = $msgSign; if ($originalFileExt!==PHP_STR) { if ($user == "MASTER") { $destFileName = $date . "-" . $rnd . substr($google, $i-1, 1) . "-master.$fileExt"; } else { $destFileName = $date . "-" . $rnd . substr($google, $i-1, 1) . "-$userName.$fileExt"; } } else { return; } $destFullPath = $picPath . DIRECTORY_SEPARATOR . $destFileName; if (file_exists($destFullPath)) { echo("WARNING: destination already exists"); return; } copy($tmpFullPath, $destFullPath); // Updating history.. $output = []; $output[] = $destFileName . "\n"; updateHistory($output, HISTORY_MAX_ITEMS); // Cleaning up.. // Delete the tmp file.. unlink($tmpFullPath); $i++; } } } function myExecSendMessage() { global $curPath; global $message; global $user; global $userName; global $sendSMS; global $CONFIG; global $chatHintResolved; global $msgSign; $date = date("Ymd-His"); $rnd = $msgSign; $duplicateMsgs = glob($curPath . DIRECTORY_SEPARATOR . "msgs" . DIRECTORY_SEPARATOR . date("Ymd-H") . "*-$msgSign*.msg"); if (!empty($duplicateMsgs)) { return; } if (!empty($message)) { if ($user == "MASTER") { $fileName = $date . "-" . $rnd . "-master.msg"; } else { $fileName = $date . "-" . $rnd . "-$userName.msg"; } $msg = $message; if (right($msg,1)!="\n") { $msg = $msg . "\n"; } // Creating the msg file.. file_put_contents($curPath . DIRECTORY_SEPARATOR . "msgs" . DIRECTORY_SEPARATOR . $fileName, $msg); // Updating message history.. $output = []; $output[] = $fileName . "\n"; updateHistory($output, HISTORY_MAX_ITEMS); if ($user == "MASTER") { $smsUser = $chatHintResolved; } else { $smsUser = "MASTER"; } // Sending out the sms notifcation.. if ($sendSMS && SMS_USERNAME!=PHP_STR) { $message = array( 'To'=>$CONFIG['AUTH'][$smsUser]['PHONE'], 'MessagingServiceSid'=>SMS_MESSAGING_SERVICE, 'Body'=>SMS_BODY ); sendSMS($message, SMS_API_URL, SMS_USERNAME, SMS_PASSWORD); } } } function delMsgParamValidation() { global $curPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { //updateHistoryWithErr("invalid options"); return false; } //param1!="" and isword if (($param1===PHP_STR) || !is_word($param1)) { //updateHistoryWithErr("invalid msg file"); return false; } //param2=="" if ($param2!==PHP_STR) { //updateHistoryWithErr("invalid parameters"); return false; } //param3=="" if ($param3!==PHP_STR) { //updateHistoryWithErr("invalid parameters"); return false; } //param1 exist $path = $curPath . DIRECTORY_SEPARATOR . "msgs" . DIRECTORY_SEPARATOR . $param1; if (!file_exists($path)) { //updateHistoryWithErr("file must exists"); return false; } //param1 is_file if (!is_file($path)) { //updateHistoryWithErr("invalid msg file"); return false; } //param1 file extension == msg if (!is_msg($param1)) { //updateHistoryWithErr("invalid msg file"); return false; } // Checking file date // grab date $dateori = left($param1, 8); // grab time preg_match('/^.+-(\d{6})-/i', $param1, $matches); $timereg = $matches[1]; $origin = new DateTime(left($dateori,4) ."-". substr($dateori,4,2) ."-". right($dateori,2) . " " . left($timereg,2) .":". substr($timereg,2,2) .":". right($timereg,2)); //echo($origin->format("YMd H:i:s")); // current date $target = new DateTime(); $interval = $origin->diff($target); $minInterval = $interval->format("%i"); if ($minInterval>=2) { return false; } return true; } function myExecDelMsgCommand() { global $curPath; global $param1; global $msgHistory; // searching the file name in the msgHsitory $msgkey = array_search($param1."\n", $msgHistory); if ($msgkey !== false) { // Clearing out the msg from the history.. unset($msgHistory[$msgkey]); $hpath = $curPath . DIRECTORY_SEPARATOR . ".HMM_history"; file_put_contents($hpath, implode('', $msgHistory)); // Deleting the msg file.. $msgpath = $curPath . DIRECTORY_SEPARATOR . "msgs" . DIRECTORY_SEPARATOR . $param1; if (file_exists($msgpath)) { unlink($msgpath); } } } function delPicParamValidation() { global $picPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { //updateHistoryWithErr("invalid options"); return false; } //param1!="" and isword if (($param1===PHP_STR) || !is_word($param1)) { //updateHistoryWithErr("invalid pic file"); return false; } //param2=="" if ($param2!==PHP_STR) { //updateHistoryWithErr("invalid parameters"); return false; } //param3=="" if ($param3!==PHP_STR) { //updateHistoryWithErr("invalid parameters"); return false; } //param1 exist $path = $picPath . DIRECTORY_SEPARATOR . $param1; if (!file_exists($path)) { //updateHistoryWithErr("pic must exists"); return false; } //param1 is_file if (!is_file($path)) { //updateHistoryWithErr("invalid pic file"); return false; } //param1 is_image if (!is_image($param1)) { //updateHistoryWithErr("invalid pic file"); return false; } // Checking file date // grab date $dateori = left($param1, 8); // grab time preg_match('/^.+-(\d{6})-/i', $param1, $matches); $timereg = $matches[1]; $origin = new DateTime(left($dateori,4) ."-". substr($dateori,4,2) ."-". right($dateori,2) . " " . left($timereg,2) .":". substr($timereg,2,2) .":". right($timereg,2)); //echo($origin->format("YMd H:i:s")); // current date $target = new DateTime(); $interval = $origin->diff($target); $minInterval = $interval->format("%i"); if ($minInterval>=2) { return false; } return true; } function myExecDelPicCommand() { global $picPath; global $curPath; global $param1; global $msgHistory; // searching the file name in the msgHistory $msgkey = array_search($param1."\n", $msgHistory); if ($msgkey !== false) { // Clearing out the msg from the history.. unset($msgHistory[$msgkey]); $hpath = $curPath . DIRECTORY_SEPARATOR . ".HMM_history"; file_put_contents($hpath, implode('', $msgHistory)); // Deleting the pic file.. $picpath = $picPath . DIRECTORY_SEPARATOR . $param1; if (file_exists($picpath)) { unlink($picpath); } } } function openPicParamValidation() { global $picPath; global $opt; global $param1; global $param2; global $param3; //opt!="" if ($opt!==PHP_STR) { //updateHistoryWithErr("invalid options"); return false; } //param1!="" and isword if (($param1===PHP_STR) || !is_word($param1)) { //updateHistoryWithErr("invalid pic file"); return false; } //param2=="" if ($param2!==PHP_STR) { //updateHistoryWithErr("invalid parameters"); return false; } //param3=="" if ($param3!==PHP_STR) { //updateHistoryWithErr("invalid parameters"); return false; } //param1 exist $path = $picPath . DIRECTORY_SEPARATOR . $param1; if (!file_exists($path)) { //updateHistoryWithErr("pic must exists"); return false; } //param1 is_file if (!is_file($path)) { //updateHistoryWithErr("invalid pic file"); return false; } //param1 is_image if (!is_image($param1)) { //updateHistoryWithErr("invalid pic file"); return false; } return true; } function myExecOpenPicCommand() { global $picPath; global $curPicture; global $param1; $curPicture = substr($picPath.DIRECTORY_SEPARATOR.$param1, strlen(dirname(APP_PIC_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); $message = filter_input(INPUT_POST, "MessageLine")??""; $message = strip_tags($message); $sendSMS1 = filter_input(INPUT_POST, "chkSMS")??""; $sendSMS1 = strip_tags($sendSMS1); $oldMsgSign = filter_input(INPUT_POST, "old-msg-sign")??""; $oldMsgSign = strip_tags($oldMsgSign); $msgSign = filter_input(INPUT_POST, "msg-sign")??""; $msgSign = strip_tags($msgSign); if ($sendSMS1!=PHP_STR) { $sendSMS = true; } else { $sendSMS = false; } $pwd = PHP_STR; $chatHint = filter_input(INPUT_POST, "chatHint")??""; $chatHint = strip_tags($chatHint); // chat validation $chatHintResolved = PHP_STR; if ($chatHint!=PHP_STR) { $found=false; foreach ($CONFIG['AUTH'] as $key => $val) { if ($chatHint==$val['USERNAME']) { $chatHintResolved = $key; $found=true; break; } } if (!$found) { die("Invalid chat!"); } } //echo ("chatHint*=".$chatHint."
"); //echo ("chatHintResolved*=".$chatHintResolved."
"); $hideSplash = filter_input(INPUT_POST, "hideSplash")??""; $hideSplash = strip_tags($hideSplash); $hideHCSplash = filter_input(INPUT_POST, "hideHCSplash")??""; $hideHCSplash = strip_tags($hideHCSplash); //echo "password=*$password*
"; if ($password != PHP_STR) { $hash = hash("sha256", $password . APP_SALT, false); $found=false; foreach ($CONFIG['AUTH'] as $key => $val) { //echo ("username=".$val['USERNAME']."
"); if ($hash==$val['HASH']) { $user = $key; if ($chatHintResolved==PHP_STR) { $chatHint=$val['USERNAME']; $chatHintResolved = $key; } else { if ($user != "MASTER") { if ($user != $chatHintResolved) { $found=false; break; } } } $found=true; //echo ("user=".$user."
"); //echo ("chatHint**=".$chatHint."
"); //echo ("chatHintResolved**=".$chatHintResolved."
"); break; } } if (!$found) { $password=PHP_STR; } if ($password != PHP_STR) { $userName = $CONFIG['AUTH'][$user]['USERNAME']; // xxx //$pwd = APP_REPO_PATH . DIRECTORY_SEPARATOR . $CONFIG['AUTH'][$chatHintResolved]['REPO_FOLDER']; $pwd = $CONFIG['AUTH'][$chatHintResolved]['REPO_FOLDER']; $picPath = APP_PIC_PATH . DIRECTORY_SEPARATOR . $CONFIG['AUTH'][$chatHintResolved]['PIC_FOLDER']; $curLocale = $CONFIG['AUTH'][$user]['LOCALE']; } } $curPath = APP_REPO_PATH; if ($pwd!=PHP_STR) { //if (left($pwd, strlen(APP_REPO_PATH)) === APP_REPO_PATH) { // $curPath = $pwd; if (file_exists(APP_REPO_PATH . DIRECTORY_SEPARATOR . $pwd)) { $curPath = APP_REPO_PATH . DIRECTORY_SEPARATOR . $pwd; chdir($curPath); if (!file_exists($curPath . DIRECTORY_SEPARATOR . ".HMM_history")) { $output = []; file_put_contents($curPath . DIRECTORY_SEPARATOR . ".HMM_history", $output); } if (!file_exists($curPath . DIRECTORY_SEPARATOR . "msgs")) { mkdir("msgs", 0777); } } else { // xxx $password = PHP_STR; } } else { // xxx $password = PHP_STR; } $ipos = strripos($curPath, PHP_SLASH); $curDir = substr($curPath, $ipos); if ($password != PHP_STR) { $msgHistory = file($curPath . DIRECTORY_SEPARATOR . ".HMM_history"); parseCommand($command); //echo("cmd=" . $cmd . "
"); //echo("opt=" . $opt . "
"); //echo("param1=" . $param1 . "
"); //echo("param2=" . $param2 . "
"); //upload(); if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $command . "|")) { if ($command === "sendmsg") { if (trim($message,"\n")!==PHP_STR) { myExecSendMessage(); upload(); } } else if ($command === "refreshbrd") { // refreshing Msg Board.. } } else if (mb_stripos(CMDLINE_VALIDCMDS, "|" . $cmd . "|")) { if ($cmd === "delmsg") { if (delMsgParamValidation()) { myExecDelMsgCommand(); } } else if ($cmd === "delpic") { if (delPicParamValidation()) { myExecDelPicCommand(); } } else if ($cmd === "openpic") { if (openPicParamValidation()) { myExecOpenPicCommand(); } } } else { // if I'm not saving data.. //if (empty($editBoardParams) || $editBoardParams[0]['location']===PHP_STR) { // if (empty($_FILES['files']['tmp_name'][0])) { // updateHistoryWithErr("invalid command"); // } //} } } else { $msgHistory = []; } ?> Homomm: every person its messages..
;">
;">
 Homomm       on github      for feedback       get support  
Hello and welcome to Homomm!

Homomm is a light and simple software on premise to exchange multimedia messages with friends.

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

Homomm name comes from the two words: "homines" meaning our choise to give chance to the human beings to come first and "mm" for "multimedia messaging".

Homomm doesn't want to be a replacement of Whats App, Telegram, Wechat, etc. but their alter ago.

First step, use the left side panel password and salt fields to create the hash to insert in the config file for every user. Remember to manually set there also the salt value.

As you are going to run Homomm 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 permissions of your "Repo" folder in your web app private path; and set its path in the config file.
  2. In the Repo path create a "user" folder for each user and give to this folder the write permission. Set it appropriately in the config file.
  3. Check the permissions of your "hmm-img" folder in your web app public path; and set its path in the config file.
  4. In hmm-img path create a "user" folder for each user and give to this folder the write permission. Set it appropriately in the config file.
  5. In the config file, set every "user" information appropriately like in the examples given.
  6. Configure your Twilio account information appropriately to send out sms notification.
  7. Configure the server pushing interval to be notified on new chat messages.
  8. Configure the max history items as required (default: 50).

Hope you can enjoy it and let us know about any feedback: posta@elettronica.lol
  
🙂
 SMS