Add function to handle cookie creation at login.

This commit is contained in:
Retro_Guy 2024-07-17 06:33:48 -07:00
parent 718af651da
commit c908cb71fb
1 changed files with 86 additions and 65 deletions

View File

@ -199,12 +199,12 @@ function validate_email($address)
{ {
global $validate_email; global $validate_email;
$return = true; $return = true;
if (($validate_email >= 1) && ($return == true)) if (($validate_email >= 1) && ($return == true))
/* Need to clean up this regex to work properly with preg_match /* Need to clean up this regex to work properly with preg_match
$return = (preg_match('^[-!#$%&\'*+\\./0-9=?A-Z^_A-z{|}~]+'.'@'. $return = (preg_match('^[-!#$%&\'*+\\./0-9=?A-Z^_A-z{|}~]+'.'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_A-z{|}~]+\.'. '[-!#$%&\'*+\\/0-9=?A-Z^_A-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_A-z{|}~]+$',$address)); '[-!#$%&\'*+\\./0-9=?A-Z^_A-z{|}~]+$',$address));
*/ */
$return = 1; $return = 1;
if (($validate_email >= 2) && ($return == true)) { if (($validate_email >= 2) && ($return == true)) {
$addressarray = address_decode($address, "garantiertungueltig"); $addressarray = address_decode($address, "garantiertungueltig");
@ -1279,6 +1279,27 @@ function group_display_name($gname)
return $gname; return $gname;
} }
function set_user_logged_in_cookies($name, $keys) {
$name = trim($name);
$auth_expire = 14400;
$authkey = password_hash($name . $keys[0] . get_user_config($name, 'encryptionkey'), PASSWORD_DEFAULT);
$pkey = hash('crc32', get_user_config($name, 'encryptionkey'));
set_user_config(strtolower($name), "pkey", $pkey);
?>
<script type="text/javascript">
if (navigator.cookieEnabled)
var authcookie = "<?php echo $authkey; ?>";
var savename = "<?php echo stripslashes($name); ?>";
var auth_expire = "<?php echo $auth_expire; ?>";
var name_expire = "7776000";
var pkey = "<?php echo $pkey; ?>";
document.cookie = "mail_auth="+authcookie+"; max-age="+auth_expire+"; path=/";
document.cookie = "mail_name="+savename+"; max-age="+name_expire+"; path=/";
document.cookie = "pkey="+pkey+"; max-age="+name_expire+"; path=/";
</script>
<?php
}
function check_bbs_auth($username, $password) function check_bbs_auth($username, $password)
{ {
global $config_dir, $spooldir, $CONFIG; global $config_dir, $spooldir, $CONFIG;
@ -1735,18 +1756,18 @@ function mail_db_open($database, $table = 'messages')
echo 'Connection failed: ' . $e->getMessage(); echo 'Connection failed: ' . $e->getMessage();
exit(); exit();
} }
$dbh->exec("CREATE TABLE IF NOT EXISTS messages( $dbh->exec("CREATE TABLE IF NOT EXISTS messages(
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
msgid TEXT UNIQUE, msgid TEXT UNIQUE,
mail_from TEXT, mail_from TEXT,
mail_viewed TEXT, mail_viewed TEXT,
rcpt_to TEXT, rcpt_to TEXT,
rcpt_viewed TEXT, rcpt_viewed TEXT,
rcpt_target TEXT, rcpt_target TEXT,
date TEXT, date TEXT,
subject TEXT, subject TEXT,
message TEXT, message TEXT,
from_hide TEXT, from_hide TEXT,
to_hide TEXT)"); to_hide TEXT)");
return ($dbh); return ($dbh);
} }
@ -1768,9 +1789,9 @@ function threads_db_open($database, $table = "threads")
echo 'Connection failed: ' . $e->getMessage(); echo 'Connection failed: ' . $e->getMessage();
exit(); exit();
} }
$dbh->exec("CREATE TABLE IF NOT EXISTS threads( $dbh->exec("CREATE TABLE IF NOT EXISTS threads(
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
headers TEXT, headers TEXT,
unique (headers))"); unique (headers))");
return ($dbh); return ($dbh);
} }
@ -1783,16 +1804,16 @@ function history_db_open($database, $table = 'history')
echo 'Connection failed: ' . $e->getMessage(); echo 'Connection failed: ' . $e->getMessage();
exit(); exit();
} }
$dbh->exec("CREATE TABLE IF NOT EXISTS history( $dbh->exec("CREATE TABLE IF NOT EXISTS history(
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
newsgroup TEXT, newsgroup TEXT,
number TEXT, number TEXT,
msgid TEXT, msgid TEXT,
status TEXT, status TEXT,
statusdate TEXT, statusdate TEXT,
statusreason TEXT, statusreason TEXT,
statusnotes TEXT, statusnotes TEXT,
unique (newsgroup, msgid), unique (newsgroup, msgid),
unique (newsgroup, number))"); unique (newsgroup, number))");
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_status on ' . $table . '(status)'); $stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_status on ' . $table . '(status)');
$stmt->execute(); $stmt->execute();
@ -1815,20 +1836,20 @@ function overview_db_open($database, $table = 'overview')
echo 'Connection failed: ' . $e->getMessage(); echo 'Connection failed: ' . $e->getMessage();
exit(); exit();
} }
$dbh->exec("CREATE TABLE IF NOT EXISTS overview( $dbh->exec("CREATE TABLE IF NOT EXISTS overview(
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
newsgroup TEXT, newsgroup TEXT,
number TEXT, number TEXT,
msgid TEXT, msgid TEXT,
date TEXT, date TEXT,
datestring TEXT, datestring TEXT,
name TEXT, name TEXT,
subject TEXT, subject TEXT,
refs TEXT, refs TEXT,
bytes TEXT, bytes TEXT,
lines TEXT, lines TEXT,
xref TEXT, xref TEXT,
unique (newsgroup, msgid), unique (newsgroup, msgid),
unique (newsgroup, number))"); unique (newsgroup, number))");
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_date on ' . $table . '(date)'); $stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_date on ' . $table . '(date)');
$stmt->execute(); $stmt->execute();
@ -1863,15 +1884,15 @@ function article_db_open($database, $table = 'articles')
echo 'Connection failed: ' . $e->getMessage(); echo 'Connection failed: ' . $e->getMessage();
exit(); exit();
} }
$dbh->exec("CREATE TABLE IF NOT EXISTS articles( $dbh->exec("CREATE TABLE IF NOT EXISTS articles(
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
newsgroup TEXT, newsgroup TEXT,
number TEXT UNIQUE, number TEXT UNIQUE,
msgid TEXT UNIQUE, msgid TEXT UNIQUE,
date TEXT, date TEXT,
name TEXT, name TEXT,
subject TEXT, subject TEXT,
search_snippet TEXT, search_snippet TEXT,
article TEXT)"); article TEXT)");
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS db_number on ' . $table . '(number)'); $stmt = $dbh->query('CREATE INDEX IF NOT EXISTS db_number on ' . $table . '(number)');
@ -1883,19 +1904,19 @@ function article_db_open($database, $table = 'articles')
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS db_name on ' . $table . '(name)'); $stmt = $dbh->query('CREATE INDEX IF NOT EXISTS db_name on ' . $table . '(name)');
$stmt->execute(); $stmt->execute();
$dbh->exec("CREATE VIRTUAL TABLE IF NOT EXISTS search_fts USING fts5( $dbh->exec("CREATE VIRTUAL TABLE IF NOT EXISTS search_fts USING fts5(
newsgroup, newsgroup,
number, number,
msgid, msgid,
date, date,
name, name,
subject, subject,
search_snippet)"); search_snippet)");
$dbh->exec("CREATE TRIGGER IF NOT EXISTS after_articles_insert AFTER INSERT ON $table BEGIN $dbh->exec("CREATE TRIGGER IF NOT EXISTS after_articles_insert AFTER INSERT ON $table BEGIN
INSERT INTO search_fts(newsgroup, number, msgid, date, name, subject, search_snippet) VALUES(new.newsgroup, new.number, new.msgid, new.date, new.name, new.subject, new.search_snippet); INSERT INTO search_fts(newsgroup, number, msgid, date, name, subject, search_snippet) VALUES(new.newsgroup, new.number, new.msgid, new.date, new.name, new.subject, new.search_snippet);
END;"); END;");
$dbh->exec("CREATE TRIGGER IF NOT EXISTS after_articles_delete AFTER DELETE ON $table BEGIN $dbh->exec("CREATE TRIGGER IF NOT EXISTS after_articles_delete AFTER DELETE ON $table BEGIN
DELETE FROM search_fts WHERE msgid = old.msgid; DELETE FROM search_fts WHERE msgid = old.msgid;
END;"); END;");
return ($dbh); return ($dbh);
} }