Skip to content

Commit

Permalink
ログインエラー対策で、session_nameを設定で指定可能にした #94
Browse files Browse the repository at this point in the history
  • Loading branch information
kujirahand committed Jun 26, 2024
1 parent 73f2e00 commit 3798ec3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions kona3engine/action/login.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ function kona3_action_login() {
}
// login form
$kona3conf["robots"] = "noindex";
kona3template('login.html', array(
kona3template('login.html', [
"page_title" => $page,
"msg" => $msg,
"action" => $action,
"signup_link" => kona3getPageURL($page, 'signup'),
"edit_token" => kona3_getEditToken($editTokenKey, TRUE),
));
]);
}


Expand Down
5 changes: 3 additions & 2 deletions kona3engine/index.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
}
}
// session
$wiki_title = isset($kona3conf['wiki_title']) ? $kona3conf['wiki_title'] : '_def';
session_start(['name' => urlencode("kona3{$wiki_title}")]);
$wiki_title = isset($kona3conf['wiki_title']) ? $kona3conf['wiki_title'] : 'KonaWiki3';
$session_name = isset($kona3conf['session_name']) ? $kona3conf['session_name'] : 'kona3session';
session_start(['name' => $session_name]);

// --------------------
// include library
Expand Down
1 change: 1 addition & 0 deletions kona3engine/kona3conf.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// --------------------
function kona3conf_init(&$conf) {
check_conf($conf, 'wiki_title', 'KonaWiki3');
check_conf($conf, 'session_name', 'kona3session');
check_conf($conf, 'admin_email', 'admin@example.com');
check_conf($conf, 'wiki_private', TRUE);
check_conf($conf, 'lang', 'ja');
Expand Down
8 changes: 4 additions & 4 deletions kona3engine/kona3lib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,13 @@ function kona3_getEditTokenForceUpdate($key = 'default') {
$sname = kona3_getEditTokenKeyName($key);
$sname_time = "{$sname}.time";
// update token
if (empty($kona3conf["{$sname}_token"])) {
if (empty($kona3conf[$sname])) {
$token = bin2hex(random_bytes(32));
$_SESSION[$sname] = $token;
$_SESSION[$sname_time] = time();
$kona3conf["{$sname}_token"] = $token;
$kona3conf[$sname] = $token;
}
return $kona3conf["{$sname}_token"];
return $kona3conf[$sname];
}

function kona3_getEditToken($key = 'default', $update = TRUE) {
Expand All @@ -716,7 +716,7 @@ function kona3_getEditToken($key = 'default', $update = TRUE) {
return kona3_getEditTokenForceUpdate($key);
}
// check time
$ONE_DAY = 60 * 60 * 24; // 1day
$ONE_DAY = 3;// 60 * 60 * 24; // 1day
$time = isset($_SESSION[$sname_time]) ? $_SESSION[$sname_time] : time();
$expire_time = $time + $ONE_DAY;
if (time() > $expire_time) {
Expand Down

0 comments on commit 3798ec3

Please sign in to comment.