From 02608271bb2a9f3a65ed536984d306ee14b48e34 Mon Sep 17 00:00:00 2001 From: Geo Halkiadakis Date: Sun, 12 Jul 2026 15:51:52 +0300 Subject: initialize repository; add docker config; migrate configuration to new specs --- public/includes/functions.php | 135 +++++++++++++++++++++++++++++++++++ public/includes/menu-contents.php | 50 +++++++++++++ public/includes/menu.php | 16 +++++ public/includes/sessions.php | 143 ++++++++++++++++++++++++++++++++++++++ public/includes/ui-login.php | 98 ++++++++++++++++++++++++++ public/includes/ui-message.php | 47 +++++++++++++ public/includes/ui-panel.php | 141 +++++++++++++++++++++++++++++++++++++ 7 files changed, 630 insertions(+) create mode 100644 public/includes/functions.php create mode 100644 public/includes/menu-contents.php create mode 100644 public/includes/menu.php create mode 100644 public/includes/sessions.php create mode 100644 public/includes/ui-login.php create mode 100644 public/includes/ui-message.php create mode 100644 public/includes/ui-panel.php (limited to 'public/includes') diff --git a/public/includes/functions.php b/public/includes/functions.php new file mode 100644 index 0000000..5e83994 --- /dev/null +++ b/public/includes/functions.php @@ -0,0 +1,135 @@ + $section) { + foreach ($section->childs as $kk => $field) { + + // find the field + if ($field->nam == $fkey) { + + $values = array(); // human readble values if select (comma separated) + + if ($field->typ == 'select') { + $multi = true; + + if ($inp !='') { + $codes = explode(",", $inp); // split coded values + foreach ($field->opt as $kkk => $v) { + if (in_array($v->id, $codes)) { // check if option is in array + $values[] = ($field->nam == 'ccode') ? ($v->id.": ".$v->tag) : $v->tag; + } + } + } + + } + else $multi = false; + + // return everything in an array + return array( + 'label' => $field->lab, + 'multi' => $multi, + 'value' => ($multi ? $values : $inp) + ); + } + } + } + + // if not escaped already, then name return same + return array('label' => $fkey, 'multi' => false, 'value' => $inp ); + } + + // Parse anythig from ccode + function parse_ccode($ckey) { + $ccARRAY = json_decode(CODEJSON); + + foreach ($ccARRAY as $key => $val) { + // find the field + if ($val->id == $ckey) { + // return everything in an array + return $val; + } + } + } + + + // Get totals of alla categories ///////////////////////////////////////////// + // RETURN array of items (value) per category (array key) + // --------------------------------------------------------------------------- + function get_totals() { + $result = array(); + $sum = 0; + + $dbc = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DBMS); + if ($dbc->connect_errno) { + echo "Database connection failed; Please try in a few minutes. "; + if (TESTING) echo $dbc->connect_error; + $dbc->close(); die(); + } + $dbc->set_charset("utf8"); + + // prepare statemet + $stm = $dbc->prepare("SELECT ccode, count(id) total FROM `items` GROUP BY ccode"); + $stm->execute(); // execute query + $stm->store_result(); // store result + $stm->bind_result($c, $tot); + while ($stm->fetch()) { + // using md5() you can have any unicode string as key ;) + // credit: https://stackoverflow.com/questions/10696067/characters-allowed-in-php-array-keys -> Rob's answer + // but newer versions of php (v7+) seem to handle unicide keys nicely + $result[$c] = $tot; + $sum += $tot; + } + + $result['all'] = $sum; + + return $result; + } + + + // Preview Local Datetime //////////////////////////////////////////////////// + // (in Greek format and names ) + // --------------------------------------------------------------------------- + function local_dt($t) { + $day = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); + $dayL = array("Κυρ", "Δευ", "Τρι", "Τετ", "Πεμ", "Παρ", "Σαβ"); + $mon = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); + $monL = array("Ιαν", "Φεβ", "Μαρ", "Απρ", "Μαϊ", "Ιουν", "Ιουλ", "Αυγ", "Σεπ", "Οκτ", "Νοε", "Δεκ"); + $tm = array("am", "pm"); + $tmL = array("πμ", "μμ"); + $r = date("D. j M. Y, h:i:sa", $t); + $r = str_replace($day, $dayL, $r); + $r = str_replace($mon, $monL, $r); + $r = str_replace($tm, $tmL, $r); + return $r; + } + + + // Part of string + // UTF-8 SAFE + function str_part($str, $len) { + return (mb_strlen($str) > $len) ? mb_substr($str, 0, $len-1) ."…" : $str; + } diff --git a/public/includes/menu-contents.php b/public/includes/menu-contents.php new file mode 100644 index 0000000..7cdee94 --- /dev/null +++ b/public/includes/menu-contents.php @@ -0,0 +1,50 @@ + + + + + Πίνακας Ελέγχου + Εισαγωγή Αντικειμένου + Αναζήτηση + + + + + + + += ADMIN) : ?> + + Αρχειοθέτηση + Κατάλογοι Αντικειμένων + Τοπικό Backup + + + + + + + + +Χρήστες + +Προφίλ Χρήστη + += ADMIN) : ?> + Διαχείριση Χρηστών + + + + + + +Αποσύνδεση diff --git a/public/includes/menu.php b/public/includes/menu.php new file mode 100644 index 0000000..754a805 --- /dev/null +++ b/public/includes/menu.php @@ -0,0 +1,16 @@ + + +
+ +
+ diff --git a/public/includes/sessions.php b/public/includes/sessions.php new file mode 100644 index 0000000..d33aa30 --- /dev/null +++ b/public/includes/sessions.php @@ -0,0 +1,143 @@ +connect_errno) { + $_cError = "Database connection failed; Please try in a few minutes. "; + if (TESTING) echo $_dbc->connect_error; + $_dbc->close(); die(); + } + $_dbc->set_charset("utf8"); + + $_hack = $_dbc->prepare("INSERT INTO users (user, salt, pass, acid, role, birthstamp, realname) VALUES (?, ?, ?, ?, ?, ?, ?)"); + $_hack->bind_param( "sssiids", $user, $salt, $pass, $acid, $role, $time, $name ); + $_chk = $_hack->execute(); + if ((TESTING) && (!$_chk)) echo "Database workaround failed; ". $_hack->error; + else echo "Workaround succeded!"; + $_hack->close(); + die(); +--- */ + + + +// -- 00. INITIALIZATION /////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +session_name(MAIN_COOKIE); // set a custom session name +session_start(); + + +if ( (isset($_SESSION['user_status'])) && ($_SESSION['user_status'] == 1) ) { + define("ROLE", $_SESSION['role']); +} +else + define("ROLE", 0); + +// -- 01. Session Functions needed ///////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +// check session existance ----------------------------------------------------- +//////////////////////////////////////////////////////////////////////////////// + function check_session_existance__() { + // session should exist from the first time of code + // what really matters is if has certain keys + if (!isset($_SESSION['user_status'])) { + $_SESSION['user_status'] = 0; + } + } + +// check and update SESSION ID ------------------------------------------------- +//////////////////////////////////////////////////////////////////////////////// + function check_update_session__() { + if (!isset($_SESSION['sess_update'])) { + $_SESSION['sess_update'] = time() + SESSION_UPD; // set sess_uddate limt if not exist + } + else if ($_SESSION['sess_update'] < time()) { // session needs to update id to mitigate session fixation + session_regenerate_id(); // change session ID (invalidate old session ID) + $_SESSION['sess_update'] = time() + SESSION_UPD; // shall re-update after SESS_UPD seconds + } + } + +// check and remove SESSION if expired ----------------------------------------- +//////////////////////////////////////////////////////////////////////////////// + function check_kill_session__() { + + if (isset($_SESSION['sess_expire']) && ($_SESSION['sess_expire'] < time())) { + session_unset(); // unset $_SESSION variable for the run-time + session_destroy(); // destroy session data in storage before continue + session_start(); + session_regenerate_id(); + + // TODO: + // should you save any data|indo before destroy? + } + $_SESSION['sess_expire'] = time() + SESSION_TTL; // set new expire limit; + } + +// common session data --------------------------------------------------------- +// format: json | string | array | or other format of data +// (includes data for user's browser via cookie) +//////////////////////////////////////////////////////////////////////////////// + function common_session_data__($format = 'json') { + + if ((isset($_SESSION['uid'])) && (isset($_SESSION['role']))) { + $arr = array( + "uid" => $_SESSION['uid'], + "name" => $_SESSION['realname'], + "role" => $_SESSION['role'] + ); + } + else $arr = array( + "uid" => '', "name" => '', "role" => '' + ); + + switch ($format) { + case 'array': + return $arr; + break; + + case ('semicolon'): + case (';'): + return implode(";", $arr); + break; + + default: + return json_encode($arr); + break; + } + } + + + + + +// -- 02. Handle Security Issues /////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// do it every time nomater what + +check_session_existance__(); + +check_kill_session__(); + +check_update_session__(); + + +// check_login_attempts__() +// check_inquire_attempts__() + // TODO + // all these should become a single function + // this function shall validate all session's keys + // print_r($_SESSION); die(); diff --git a/public/includes/ui-login.php b/public/includes/ui-login.php new file mode 100644 index 0000000..8ab4d9b --- /dev/null +++ b/public/includes/ui-login.php @@ -0,0 +1,98 @@ + + + + + + + + + <?=PROJECT?> : Είσοδος + + + + + + + + +
+
+
+

+

Είσοδος στη βάση δεδομένων

+
+ +
+ +
+ + +
+
+ + +
+
+ + + +
+ +
+
+
+ + + + + + + + + diff --git a/public/includes/ui-message.php b/public/includes/ui-message.php new file mode 100644 index 0000000..55ff531 --- /dev/null +++ b/public/includes/ui-message.php @@ -0,0 +1,47 @@ + 'Application Error!', + 'message' => "

Παρακαλώ ενημερώστε τον διαχειριστή του συστήματος. Στη σχετική ενημέρωση επισυνάψτε τα παρακάτω στοιχεία:

+
".
+                "\n". ((isset($_SERVER['REQUEST_URI'])) ? "URI: ".$_SERVER['REQUEST_URI'] : "") .
+                "\n". ((isset($_SERVER['REQUEST_METHOD'])) ? "Method: ".$_SERVER['REQUEST_METHOD'] : "") .
+                "\n". ((isset($_SERVER['HTTP_USER_AGENT'])) ? "Agent: ".$_SERVER['HTTP_USER_AGENT'] : "") .
+                "\nTimestamp: ". time() . ((isset($_SERVER['HTTP_REFERER'])) ? "\nRef: ".$_SERVER['HTTP_REFERER'] : "") ."
" + ); +} +?> + + + + + + + + <?=PROJECT?> : Message + + + + + + + +
+
+
+

+

+
+
+
+
+ +
+
+
+ + + diff --git a/public/includes/ui-panel.php b/public/includes/ui-panel.php new file mode 100644 index 0000000..1f40803 --- /dev/null +++ b/public/includes/ui-panel.php @@ -0,0 +1,141 @@ + + + + + + + + + <?=PROJECT?> : Πίνακας Ελέγχου + + + + + + + + + +
+
+ +
+

+
+ + +
+

Πίνακας Ελέγχου

+
+ +
+ + +
+ + + EDITOR) : ?> +

+ Στατιστικά +

+
+
+ + $val) { + if (isset($stats[$val->id])) { + echo " + + + + "; + } + } + ?> + +
". $val->id ." ". $val->tag . "Αναζήτηση". $stats[$val->id] ."
Σύνολο
+
+
+ + + + + + + + + + +
+ +
+
+ + + + + + + + + + + + + -- cgit v1.2.3