Compare commits

...

5 Commits

Author SHA1 Message Date
Clemens Schwaighofer
382cc0524a file upload page updates, config updates
Update the files upload page with missing unlinks for certain actions
and ACL settings

Add LIVE_SCHEMA to config & var set check
2018-05-24 15:08:18 +09:00
Clemens Schwaighofer
aa57c6218f various fixes for PHP 7.2 compatible 2018-05-16 13:42:31 +09:00
Clemens Schwaighofer
b3f9fd27e6 Update for <? in the table_array list, fix binaries folder name 2018-05-14 15:37:05 +09:00
Clemens Schwaighofer
4e6463a849 Password check & change update
The password check flow is now dedicated method.

The password change has been updated to check for a valid password
before accepting it (default is only min 8 chars).
Success message is printed out.
On error the overlay stays visible.
Old password correct check uses normal password check method now.
No passwords in any form are logged for error or printed anywhere at
all.
2018-05-09 15:12:13 +09:00
Clemens Schwaighofer
5ad0419613 Login class rehash part: do not use variable
Write the new hash directly to the DB, we don't need to store it in
variable
2018-05-09 11:55:12 +09:00
16 changed files with 238 additions and 95 deletions

View File

@@ -52,6 +52,9 @@ if (!$show_type) {
$show_type = 'P'; $show_type = 'P';
} }
// set edit access array
$edit_access_ids = array_keys($cms->user_unit);
// yes no list (online) // yes no list (online)
$yesno_list['f'] = 'No'; $yesno_list['f'] = 'No';
$yesno_list['t'] = 'Yes'; $yesno_list['t'] = 'Yes';
@@ -262,9 +265,16 @@ if ($cms->action == 'delete' && $cms->action_yes == 'true') {
} }
if (QUEUE == 'live_queue') { if (QUEUE == 'live_queue') {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action, file) VALUES ("; $q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action, file) VALUES (";
$q .= "'".$cms->queue_name."', '".$file_uid."', 'file_uid', 'DELETE', 'file', '', '".$cms->queue_key."', '".$cms->action."', '".BASE.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."')"; $q .= "'".$cms->queue_name."', '".$file_uid."', 'file_uid', 'DELETE', 'file', '', '".$cms->queue_key."', '".$cms->action."', '".
$q .= BASE.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."')";
} }
@unlink(BASE.MEDIA.$cms->data_path[$file_type].DEV_SCHEMA."_".$file_uid); @unlink(BASE.MEDIA.$cms->data_path[$file_type].DEV_SCHEMA."_".$file_uid);
// wipe out any old cache data for this new upload
if (is_array(glob($cms->cache_pictures."thumb_".TEST_SCHEMA."_".$file_uid."*"))) {
foreach (glob($cms->cache_pictures."thumb_".TEST_SCHEMA."_".$file_uid."*") as $filename) {
@unlink($filename);
}
}
unset($file_uid); unset($file_uid);
unset($file_id); unset($file_id);
$delete_done = 1; $delete_done = 1;
@@ -297,6 +307,12 @@ if ($cms->action_flag == 'set_live' && $cms->action = 'set_delete') {
$q_del = "DELETE FROM ".PUBLIC_SCHEMA.".file WHERE file_uid = '".$res['pkid'].'"'; $q_del = "DELETE FROM ".PUBLIC_SCHEMA.".file WHERE file_uid = '".$res['pkid'].'"';
$cms->db_exec($q_del); $cms->db_exec($q_del);
@unlink(BASE.MEDIA.$cms->data_path[$res['type']].PUBLIC_SCHEMA."_".$res['file_uid']); @unlink(BASE.MEDIA.$cms->data_path[$res['type']].PUBLIC_SCHEMA."_".$res['file_uid']);
// wipe out any old cache data for this new upload
if (is_array(glob($cms->cache_pictures."thumb_".LIVE_SCHEMA."_".$file_uid."*"))) {
foreach (glob($cms->cache_pictures."thumb_".LIVE_SCHEMA."_".$file_uid."*") as $filename) {
@unlink($filename);
}
}
} }
$q = "DELETE FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'"; $q = "DELETE FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
$cms->db_exec($q); $cms->db_exec($q);
@@ -304,13 +320,21 @@ if ($cms->action_flag == 'set_live' && $cms->action = 'set_delete') {
if (DEV_SCHEMA != PUBLIC_SCHEMA) { if (DEV_SCHEMA != PUBLIC_SCHEMA) {
// read out possible deleted, to add "delete from live" // read out possible deleted, to add "delete from live"
$q = "SELECT pkid FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'"; $q = "SELECT pkid FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
if ($cms->access_rights['base_acl'] < 90) {
$q .= "AND edit_access_id IN (".join(',', $edit_access_ids).") ";
}
while ($res = $cms->db_return($q, 3)) { while ($res = $cms->db_return($q, 3)) {
$cms->DATA['set_delete'][]['pkid'] = $res['pkid']; $cms->DATA['set_delete'][]['pkid'] = $res['pkid'];
} }
} }
// get th max entries // get th max entries
$q = "SELECT COUNT(file_uid) FROM file "; $q = "SELECT COUNT(file_uid) FROM file ";
$q_search_where = "WHERE type in ('".str_replace(',', "','", $show_type)."') "; $q_search_where = "WHERE ";
// only for current edit_access id, unless it is an admin user, then he can see all of them
if ($cms->access_rights['base_acl'] < 90) {
$q_search_where .= "edit_access_id IN (".join(',', $edit_access_ids).") AND ";
}
$q_search_where .= "type in ('".str_replace(',', "','", $show_type)."') ";
if ($search_what) { if ($search_what) {
$q_search_where .= "AND LOWER(name_en) LIKE '%".addslashes(strtolower($search_what))."%' OR name_ja LIKE '%".addslashes($search_what)."%' OR LOWER(file_name) LIKE '%".addslashes(strtolower($search_what))."%' "; $q_search_where .= "AND LOWER(name_en) LIKE '%".addslashes(strtolower($search_what))."%' OR name_ja LIKE '%".addslashes($search_what)."%' OR LOWER(file_name) LIKE '%".addslashes(strtolower($search_what))."%' ";
} }

View File

@@ -117,3 +117,5 @@ if (false === strstr(LAYOUT.DEFAULT_TEMPLATE.LANG, $cms->lang_dir) || strcasecmp
// $cms->debug("LANGUAGE", "L: $lang | ".$cms->lang_dir." | MO File: ".$cms->l->mofile); // $cms->debug("LANGUAGE", "L: $lang | ".$cms->lang_dir." | MO File: ".$cms->l->mofile);
$cms->debug("LANGUAGE", "SL: ".$_SESSION['DEFAULT_CHARSET']." | ".$_SESSION['LANG']." | ".$_SESSION['DEFAULT_LANG']); $cms->debug("LANGUAGE", "SL: ".$_SESSION['DEFAULT_CHARSET']." | ".$_SESSION['LANG']." | ".$_SESSION['DEFAULT_LANG']);
$cms->debug("TEMPLATE", "P: ".$smarty->getTemplateDir()[0]); $cms->debug("TEMPLATE", "P: ".$smarty->getTemplateDir()[0]);
# __END__

View File

@@ -90,7 +90,7 @@ $cms->DEBUG_DATA['DEBUG'] = @$DEBUG_TMPL;
// create main data array // create main data array
$cms->CONTENT_DATA = array_merge($cms->HEADER, $cms->DATA, $cms->DEBUG_DATA); $cms->CONTENT_DATA = array_merge($cms->HEADER, $cms->DATA, $cms->DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc) // data is 1:1 mapping (all vars, values, etc)
while (list($key, $value) = each($cms->CONTENT_DATA)) { foreach ($cms->CONTENT_DATA as $key => $value) {
$smarty->assign($key, $value); $smarty->assign($key, $value);
} }
if (is_dir(BASE.TEMPLATES_C)) { if (is_dir(BASE.TEMPLATES_C)) {
@@ -100,3 +100,5 @@ if (is_dir(BASE.CACHE)) {
$smarty->setCacheDir(BASE.CACHE); $smarty->setCacheDir(BASE.CACHE);
} }
$smarty->display($MASTER_TEMPLATE_NAME, $TEMPLATE.$lang, $TEMPLATE.$lang); $smarty->display($MASTER_TEMPLATE_NAME, $TEMPLATE.$lang, $TEMPLATE.$lang);
# __END__

View File

@@ -1,4 +1,4 @@
<? <?php
$edit_access = array ( $edit_access = array (
"table_array" => array ( "table_array" => array (
"edit_access_id" => array ( "edit_access_id" => array (
@@ -74,3 +74,5 @@ $edit_access = array (
) )
) )
); );
# __END__

View File

@@ -1,4 +1,4 @@
<? <?php
$edit_groups = array ( $edit_groups = array (
"table_array" => array ( "table_array" => array (
"edit_group_id" => array ( "edit_group_id" => array (
@@ -97,3 +97,5 @@ $edit_groups = array (
) // edit pages ggroup ) // edit pages ggroup
) )
); );
# __END__

View File

@@ -1,4 +1,4 @@
<? <?php
$edit_languages=array ( $edit_languages=array (
"table_array" => array ( "table_array" => array (
"edit_language_id" => array ( "edit_language_id" => array (
@@ -70,3 +70,5 @@ $edit_languages=array (
), ),
"table_name" => "edit_language" "table_name" => "edit_language"
); );
# __END__

View File

@@ -1,4 +1,4 @@
<? <?php
$edit_menu_group = array ( $edit_menu_group = array (
"table_array" => array ( "table_array" => array (
"edit_menu_group_id" => array ( "edit_menu_group_id" => array (
@@ -35,3 +35,5 @@ $edit_menu_group = array (
) )
) )
); );
# __END__

View File

@@ -1,4 +1,4 @@
<? <?php
$edit_pages = array ( $edit_pages = array (
"table_array" => array ( "table_array" => array (
"edit_page_id" => array ( "edit_page_id" => array (
@@ -26,7 +26,7 @@ $edit_pages = array (
"int" => 1, "int" => 1,
"order" => 1 "order" => 1
), ),
/* "flag" => array ( /* "flag" => array (
"value" => $GLOBALS["flag"], "value" => $GLOBALS["flag"],
"output_name" => "Page Flag", "output_name" => "Page Flag",
"type" => "drop_down_array", "type" => "drop_down_array",
@@ -175,3 +175,5 @@ $edit_pages = array (
) // query_string element list ) // query_string element list
) // element list ) // element list
); );
# __END__

View File

@@ -1,4 +1,4 @@
<? <?php
$edit_schemes = array ( $edit_schemes = array (
"table_array" => array ( "table_array" => array (
"edit_scheme_id" => array ( "edit_scheme_id" => array (
@@ -53,3 +53,4 @@ $edit_schemes = array (
) )
); // main array ); // main array
# __END__

View File

@@ -1,4 +1,4 @@
<? <?php
$edit_users = array ( $edit_users = array (
"table_array" => array ( "table_array" => array (
"edit_user_id" => array ( "edit_user_id" => array (
@@ -251,3 +251,5 @@ $edit_users = array (
) // edit pages ggroup ) // edit pages ggroup
) )
); );
# __END__

View File

@@ -1,30 +1,32 @@
<? <?php
$edit_visible_group = array ( $edit_visible_group = array (
"table_array" => array ( "table_array" => array (
"edit_visible_group_id" => array ( "edit_visible_group_id" => array (
"value" => $GLOBALS["edit_visible_group_id"], "value" => $GLOBALS["edit_visible_group_id"],
"type" => "hidden", "type" => "hidden",
"pk" => 1 "pk" => 1
),
"name" => array (
"value" => $GLOBALS["name"],
"output_name" => $this->l->__("Group name"),
"mandatory" => 1,
"type" => "text"
),
"flag" => array (
"value" => $GLOBALS["flag"],
"output_name" => $this->l->__("Flag"),
"mandatory" => 1,
"type" => "text",
"error_check" => "alphanumeric|unique"
)
), ),
"table_name" => "edit_visible_group", "name" => array (
"load_query" => "SELECT edit_visible_group_id, name FROM edit_visible_group ORDER BY name", "value" => $GLOBALS["name"],
"show_fields" => array ( "output_name" => $this->l->__("Group name"),
array ( "mandatory" => 1,
"name" => "name" "type" => "text"
) ),
"flag" => array (
"value" => $GLOBALS["flag"],
"output_name" => $this->l->__("Flag"),
"mandatory" => 1,
"type" => "text",
"error_check" => "alphanumeric|unique"
) )
); ),
"table_name" => "edit_visible_group",
"load_query" => "SELECT edit_visible_group_id, name FROM edit_visible_group ORDER BY name",
"show_fields" => array (
array (
"name" => "name"
)
)
);
# __END__

View File

@@ -272,7 +272,7 @@ input[type="text"]:focus, textarea:focus, select:focus {
} }
/* spacer for line break in float elements */ /* spacer for line break in float elements */
.spacer { .clr, .spacer {
clear: both; clear: both;
} }

View File

@@ -69,8 +69,17 @@ class Login extends \CoreLibs\DB\IO
private $logout; // logout button private $logout; // logout button
private $login_error; // login error code, can be matched to the array login_error_msg, which holds the string private $login_error; // login error code, can be matched to the array login_error_msg, which holds the string
private $password_change = false; // if this is set to true, the user can change passwords private $password_change = false; // if this is set to true, the user can change passwords
private $password_change_ok = false; // password change was successful
private $pw_change_deny_users = array (); // array of users for which the password change is forbidden private $pw_change_deny_users = array (); // array of users for which the password change is forbidden
// if we have password change we need to define some rules
private $password_min_length = 8;
// can have several regexes, if nothing set, all is ok
private $password_valid_chars = array (
// '^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,}$',
// '^(?.*(\pL)u)(?=.*(\pN)u)(?=.*([^\pL\pN])u).{8,}',
);
// all possible login error conditions // all possible login error conditions
private $login_error_msg = array (); private $login_error_msg = array ();
// this is an array holding all strings & templates passed from the outside (translation) // this is an array holding all strings & templates passed from the outside (translation)
@@ -229,6 +238,55 @@ class Login extends \CoreLibs\DB\IO
parent::__destruct(); parent::__destruct();
} }
// METHOD: loginPasswordCheck
// PARAMS: hash, optional password, to override
// RETURN: true or false
// DESC : checks if password is valid, sets internal error login variable
private function loginPasswordCheck($hash, $password = '')
{
$password_ok = false;
if (!$password) {
$password = $this->password;
}
if ((preg_match("/^\\$2(a|y)\\$/", $hash) && CRYPT_BLOWFISH != 1) ||
(preg_match("/^\\$1\\$/", $hash) && CRYPT_MD5 != 1) ||
(preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash) && CRYPT_STD_DES != 1)
) {
// this means password cannot be decrypted because of missing crypt methods
$this->login_error = 9999;
$password_ok = false;
} elseif ((preg_match("/^\\$2(a)\\$/", $hash) ||
// old password have $07$ so we check this
(preg_match("/^\\$2(y)\\$/", $hash) && preg_match("/\\$07\\$/", $hash)) ||
preg_match("/^\\$1\\$/", $hash) ||
preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash)) &&
!$this->verifyCryptString($password, $hash)
) {
// check passwword as crypted, $2a$ or $2y$ is blowfish start, $1$ is MD5 start, $\w{12} is standard DES
// this is only for OLD $07$ password
$this->login_error = 1011;
$password_ok = false;
} elseif (preg_match("/^\\$2y\\$/", $hash) &&
!$this->passwordVerify($password, $hash)
) {
// this is the new password hash methid, is only $2y$
$this->login_error = 1013;
$password_ok = false;
} elseif (!preg_match("/^\\$2(a|y)\\$/", $hash) &&
!preg_match("/^\\$1\\$/", $hash) &&
!preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash) &&
$hash != $password
) {
// check old plain password, non case sensitive
$this->login_error = 1012;
$password_ok = false;
} else {
// all ok
$password_ok = true;
}
return $password_ok;
}
// METHOD: loginLoginUser // METHOD: loginLoginUser
// WAS : login_login_user // WAS : login_login_user
// PARAMS: none // PARAMS: none
@@ -285,42 +343,14 @@ class Login extends \CoreLibs\DB\IO
} elseif ($res['locked']) { } elseif ($res['locked']) {
// user is locked, either set or auto set // user is locked, either set or auto set
$this->login_error = 105; $this->login_error = 105;
} elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) && CRYPT_BLOWFISH != 1) || } elseif (!$this->loginPasswordCheck($res['password'])) {
(preg_match("/^\\$1\\$/", $res['password']) && CRYPT_MD5 != 1) || // none to be set, set in login password check
(preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && CRYPT_STD_DES != 1)
) {
// this means password cannot be decrypted because of missing crypt methods
$this->login_error = 9999;
} elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) ||
preg_match("/^\\$1\\$/", $res['password']) ||
preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password'])) &&
// old password have $07$ so we check this
preg_match("/\\$07\\$/", $res['password']) &&
!$this->verifyCryptString($this->password, $res['password'])
) {
// check passwword as crypted, $2a$ or $2y$ is blowfish start, $1$ is MD5 start, $\w{12} is standard DES
// this is only for OLD $07$ password
$this->login_error = 1011;
} elseif (preg_match("/^\\$2y\\$/", $res['password']) &&
!preg_match("/\\$07\\$/", $res['password']) &&
!$this->passwordVerify($this->password, $res['password'])
) {
// this is the new password hash methid, is only $2y$
$this->login_error = 1013;
} elseif (!preg_match("/^\\$2(a|y)\\$/", $res['password']) &&
!preg_match("/^\\$1\\$/", $res['password']) &&
!preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) &&
$res['password'] != $this->password
) {
// check old plain password, non case sensitive
$this->login_error = 1012;
} else { } else {
// check if the current password is an invalid hash and do a rehash and set password // check if the current password is an invalid hash and do a rehash and set password
// $this->debug('LOGIN', 'Hash: '.$res['password'].' -> VERIFY: '.($this->passwordVerify($this->password, $res['password']) ? 'OK' : 'FAIL').' => HASH: '.($this->passwordRehashCheck($res['password']) ? 'NEW NEEDED' : 'OK')); // $this->debug('LOGIN', 'Hash: '.$res['password'].' -> VERIFY: '.($this->passwordVerify($this->password, $res['password']) ? 'OK' : 'FAIL').' => HASH: '.($this->passwordRehashCheck($res['password']) ? 'NEW NEEDED' : 'OK'));
if ($this->passwordRehashCheck($res['password'])) { if ($this->passwordRehashCheck($res['password'])) {
$new_hash = $this->passwordSet($this->password);
// update password hash to new one now // update password hash to new one now
$q = "UPDATE edit_user SET password = '".$this->dbEscapeString($new_hash)."' WHERE edit_user_id = ".$res['edit_user_id']; $q = "UPDATE edit_user SET password = '".$this->dbEscapeString($this->passwordSet($this->password))."' WHERE edit_user_id = ".$res['edit_user_id'];
$this->dbExec($q); $this->dbExec($q);
} }
// normal user processing // normal user processing
@@ -653,6 +683,28 @@ class Login extends \CoreLibs\DB\IO
} }
} }
// METHOD: loginPasswordChangeValidPassword
// PARAMS: the new password
// RETURN: true or false
// DESC : checks if the password is in a valid format
private function loginPasswordChangeValidPassword($password)
{
$is_valid_password = true;
// check for valid in regex arrays in list
if (is_array($this->password_valid_chars)) {
foreach ($this->password_valid_chars as $password_valid_chars) {
if (!preg_match("/$password_valid_chars/", $password)) {
$is_valid_password = false;
}
}
}
// check for min length
if (strlen($password) < $this->password_min_length) {
$is_valid_password = false;
}
return $is_valid_password;
}
// METHOD: loginPasswordChange // METHOD: loginPasswordChange
// WAS : login_password_change // WAS : login_password_change
// PARAMS: none // PARAMS: none
@@ -664,7 +716,7 @@ class Login extends \CoreLibs\DB\IO
$event = 'Password Change'; $event = 'Password Change';
// check that given username is NOT in the deny list, else silent skip (with error log) // check that given username is NOT in the deny list, else silent skip (with error log)
if (!in_array($this->pw_username, $this->pw_change_deny_users)) { if (!in_array($this->pw_username, $this->pw_change_deny_users)) {
if (!$this->pw_username || !$this->pw_password) { if (!$this->pw_username || !$this->pw_old_password) {
$this->login_error = 200; $this->login_error = 200;
$data = 'Missing username or old password.'; $data = 'Missing username or old password.';
} }
@@ -680,9 +732,9 @@ class Login extends \CoreLibs\DB\IO
} }
// check old passwords match -> error // check old passwords match -> error
if (!$this->login_error) { if (!$this->login_error) {
$q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->dbEscapeString($this->pw_username)."' AND password = '".$this->dbEscapeString($this->pw_old_password)."'"; $q = "SELECT edit_user_id, password FROM edit_user WHERE enabled = 1 AND username = '".$this->dbEscapeString($this->pw_username)."'";
list ($edit_user_id) = $this->dbReturnRow($q); list ($edit_user_id, $old_password_hash) = $this->dbReturnRow($q);
if (!$edit_user_id) { if (!$edit_user_id || !$this->loginPasswordCheck($old_password_hash, $this->pw_old_password)) {
// old password wrong // old password wrong
$this->login_error = 202; $this->login_error = 202;
$data = 'The old password does not match'; $data = 'The old password does not match';
@@ -699,15 +751,23 @@ class Login extends \CoreLibs\DB\IO
if (!$this->login_error) { if (!$this->login_error) {
if ($this->pw_new_password != $this->pw_new_password_confirm) { if ($this->pw_new_password != $this->pw_new_password_confirm) {
$this->login_error = 204; $this->login_error = 204;
$data = 'The new passwords do not match: '.$this->pw_new_password.' == '.$this->pw_new_password_confirm; $data = 'The new passwords do not match';
}
}
// password shall match to something in minimum length or form
if (!$this->login_error) {
if (!$this->loginPasswordChangeValidPassword($this->pw_new_password)) {
$this->login_error = 205;
$data = 'The new password string is not valid';
} }
} }
// no error change this users password // no error change this users password
if (!$this->login_error) { if (!$this->login_error) {
// update the user (edit_user_id) with the new password // update the user (edit_user_id) with the new password
$q = "UPDATE edit_user SET password = '".$this->dbEscapeString($this->cryptString($this->pw_new_password))."' WHERE edit_user_id = ".$edit_user_id; $q = "UPDATE edit_user SET password = '".$this->dbEscapeString($this->passwordSet($this->pw_new_password))."' WHERE edit_user_id = ".$edit_user_id;
$this->dbExec($q); $this->dbExec($q);
$data = 'Password change for user "'.$this->pw_username.'" from "'.$this->pw_old_password.'" to "'.$this->pw_new_password.'"'; $data = 'Password change for user "'.$this->pw_username.'"';
$this->password_change_ok = true;
} }
} else { } else {
// illegal user error // illegal user error
@@ -715,7 +775,7 @@ class Login extends \CoreLibs\DB\IO
$data = 'Illegal user for password change: '.$this->pw_username; $data = 'Illegal user for password change: '.$this->pw_username;
} }
// log this password change attempt // log this password change attempt
$this->write_log($event, $data, $this->login_error, $pw_username, $pw_old_password); $this->writeLog($event, $data, $this->login_error, $this->pw_username);
} // button pressed } // button pressed
} }
@@ -745,29 +805,43 @@ class Login extends \CoreLibs\DB\IO
// pre change the data in the PASSWORD_CHANGE_DIV first // pre change the data in the PASSWORD_CHANGE_DIV first
foreach ($this->login_template['strings'] as $string => $data) { foreach ($this->login_template['strings'] as $string => $data) {
if ($data) { if ($data) {
$html_string_password_change = str_replace("{".$string."}", $data, $html_string_password_change); $html_string_password_change = str_replace('{'.$string.'}', $data, $html_string_password_change);
} }
} }
// print error messagae
if ($this->login_error) {
$html_string_password_change = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string_password_change);
} else {
$html_string_password_change = str_replace('{ERROR_MSG}', '<br>', $html_string_password_change);
}
// if pw change action, show the float again
if ($this->change_password && !$this->password_change_ok) {
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '<script language="JavaScript">ShowHideDiv(\'pw_change_div\');</script>', $html_string_password_change);
} else {
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '', $html_string_password_change);
}
$this->login_template['strings']['PASSWORD_CHANGE_DIV'] = $html_string_password_change; $this->login_template['strings']['PASSWORD_CHANGE_DIV'] = $html_string_password_change;
} }
// put in the logout redirect string // put in the logout redirect string
if ($this->logout && $LOGOUT_TARGET) { if ($this->logout && $LOGOUT_TARGET) {
$html_string = str_replace("{LOGOUT_TARGET}", '<meta http-equiv="refresh" content="0; URL='.$LOGOUT_TARGET.'">', $html_string); $html_string = str_replace('{LOGOUT_TARGET}', '<meta http-equiv="refresh" content="0; URL='.$LOGOUT_TARGET.'">', $html_string);
} else { } else {
$html_string = str_replace("{LOGOUT_TARGET}", '', $html_string); $html_string = str_replace('{LOGOUT_TARGET}', '', $html_string);
} }
// print error messagae // print error messagae
if ($this->login_error) { if ($this->login_error) {
$html_string = str_replace("{ERROR_MSG}", $this->login_error_msg[$this->login_error]."<br>", $html_string); $html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string);
} elseif ($this->password_change_ok && $this->password_change) {
$html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[300].'<br>', $html_string);
} else { } else {
$html_string = str_replace("{ERROR_MSG}", "<br>", $html_string); $html_string = str_replace('{ERROR_MSG}', '<br>', $html_string);
} }
// create the replace array context // create the replace array context
foreach ($this->login_template['strings'] as $string => $data) { foreach ($this->login_template['strings'] as $string => $data) {
$html_string = str_replace("{".$string."}", $data, $html_string); $html_string = str_replace('{'.$string.'}', $data, $html_string);
} }
// return the created HTML here // return the created HTML here
@@ -800,7 +874,7 @@ class Login extends \CoreLibs\DB\IO
$q = "SELECT username, password FROM edit_user WHERE edit_user_id = ".$this->euid; $q = "SELECT username, password FROM edit_user WHERE edit_user_id = ".$this->euid;
list($username, $password) = $this->dbReturnRow($q); list($username, $password) = $this->dbReturnRow($q);
} // if euid is set, get username (or try) } // if euid is set, get username (or try)
$this->writeLog($event, '', $this->login_error, $username, $password); $this->writeLog($event, '', $this->login_error, $username);
} // write log under certain settings } // write log under certain settings
// now close DB connection // now close DB connection
// $this->error_msg = $this->_login(); // $this->error_msg = $this->_login();
@@ -845,6 +919,8 @@ class Login extends \CoreLibs\DB\IO
"202" => $this->l->__("Fatal Error: <b>Password change - The old password is not correct</b>"), "202" => $this->l->__("Fatal Error: <b>Password change - The old password is not correct</b>"),
"203" => $this->l->__("Fatal Error: <b>Password change - Please fill out both new password fields</b>"), "203" => $this->l->__("Fatal Error: <b>Password change - Please fill out both new password fields</b>"),
"204" => $this->l->__("Fatal Error: <b>Password change - The new passwords do not match</b>"), "204" => $this->l->__("Fatal Error: <b>Password change - The new passwords do not match</b>"),
"205" => $this->l->__("Fatal Error: <b>Password change - The new password is not in a valid format</b>"), // we should also not here WHAT is valid
"300" => $this->l->__("Success: <b>Password change successful</b>"), // for OK password change
"9999" => $this->l->__("Fatal Error: <b>necessary crypt engine could not be found</b>. Login is impossible") // this is bad bad error "9999" => $this->l->__("Fatal Error: <b>necessary crypt engine could not be found</b>. Login is impossible") // this is bad bad error
); );
@@ -871,6 +947,7 @@ class Login extends \CoreLibs\DB\IO
<tr><td></td><td><input type="submit" name="change_password" value="{PASSWORD_CHANGE_BUTTON_VALUE}"><input type="button" name="pw_change" value="{CLOSE}" OnClick="ShowHideDiv('pw_change_div');"></td></tr> <tr><td></td><td><input type="submit" name="change_password" value="{PASSWORD_CHANGE_BUTTON_VALUE}"><input type="button" name="pw_change" value="{CLOSE}" OnClick="ShowHideDiv('pw_change_div');"></td></tr>
</table> </table>
</div> </div>
{PASSWORD_CHANGE_SHOW}
EOM; EOM;
} else { } else {
$strings = array_merge($strings, array ( $strings = array_merge($strings, array (
@@ -881,14 +958,14 @@ EOM;
} }
// first check if all strings are set from outside, if not, set with default ones // first check if all strings are set from outside, if not, set with default ones
while (list($string, $data) = each($strings)) { foreach ($strings as $string => $data) {
if (!array_key_exists($string, $this->login_template['strings'])) { if (!array_key_exists($string, $this->login_template['strings'])) {
$this->login_template['strings'][$string] = $data; $this->login_template['strings'][$string] = $data;
} }
} }
// error msgs the same // error msgs the same
while (list($code, $data) = each($error_msgs)) { foreach ($error_msgs as $code => $data) {
if (!array_key_exists($code, $this->login_error_msg)) { if (!array_key_exists($code, $this->login_error_msg)) {
$this->login_error_msg[$code] = $data; $this->login_error_msg[$code] = $data;
} }
@@ -968,12 +1045,14 @@ EOM;
// error -> if error, write error string (not enougth data, etc) // error -> if error, write error string (not enougth data, etc)
// RETURN: none // RETURN: none
// DESC : writes detailed data into the edit user log table (keep log what user does) // DESC : writes detailed data into the edit user log table (keep log what user does)
private function writeLog($event, $data, $error = "", $username = "", $password = "") private function writeLog($event, $data, $error = '', $username = '')
{ {
if ($this->login) { if ($this->login) {
$this->action = 'Login'; $this->action = 'Login';
} elseif ($this->logout) { } elseif ($this->logout) {
$this->action = 'Logout'; $this->action = 'Logout';
} else {
$this->action = '';
} }
$_data_binary = array ( $_data_binary = array (
'_SESSION' => $_SESSION, '_SESSION' => $_SESSION,
@@ -988,7 +1067,7 @@ EOM;
$q .= "(username, password, euid, event_date, event, error, data, data_binary, page, "; $q .= "(username, password, euid, event_date, event, error, data, data_binary, page, ";
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, "; $q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) "; $q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ('".$this->dbEscapeString($username)."', '".$this->dbEscapeString($password)."', ".(($this->euid) ? $this->euid : 'NULL').", "; $q .= "VALUES ('".$this->dbEscapeString($username)."', 'PASSWORD', ".(($this->euid) ? $this->euid : 'NULL').", ";
$q .= "NOW(), '".$this->dbEscapeString($event)."', '".$this->dbEscapeString($error)."', '".$this->dbEscapeString($data)."', '".$data_binary."', '".$this->page_name."', "; $q .= "NOW(), '".$this->dbEscapeString($event)."', '".$this->dbEscapeString($error)."', '".$this->dbEscapeString($data)."', '".$data_binary."', '".$this->page_name."', ";
foreach (array('REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'SCRIPT_FILENAME', 'QUERY_STRING', 'SERVER_NAME', 'HTTP_HOST', 'HTTP_ACCEPT', 'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT_ENCODING') as $server_code) { foreach (array('REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'SCRIPT_FILENAME', 'QUERY_STRING', 'SERVER_NAME', 'HTTP_HOST', 'HTTP_ACCEPT', 'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT_ENCODING') as $server_code) {
if (array_key_exists($server_code, $_SERVER)) { if (array_key_exists($server_code, $_SERVER)) {

View File

@@ -123,7 +123,7 @@ class Basic
private $log_print_file = 'error_msg##LOGID####LEVEL####CLASS####PAGENAME####DATE##'; private $log_print_file = 'error_msg##LOGID####LEVEL####CLASS####PAGENAME####DATE##';
private $log_file_unique_id; // a unique ID set only once for call derived from this class private $log_file_unique_id; // a unique ID set only once for call derived from this class
public $log_print_file_date = 1; // if set add Y-m-d and do automatic daily rotation public $log_print_file_date = 1; // if set add Y-m-d and do automatic daily rotation
private $log_file_id = LOG_FILE_ID ? LOG_FILE_ID : ''; // a alphanumeric name that has to be set as global definition private $log_file_id = ''; // a alphanumeric name that has to be set as global definition
public $log_per_level = 0; // set, it will split per level (first parameter in debug call) public $log_per_level = 0; // set, it will split per level (first parameter in debug call)
public $log_per_class = 0; // set, will split log per class public $log_per_class = 0; // set, will split log per class
public $log_per_page = 0; // set, will split log per called file public $log_per_page = 0; // set, will split log per called file
@@ -179,9 +179,30 @@ class Basic
"class_author" => 'Clemens Schwaighofer' "class_author" => 'Clemens Schwaighofer'
); );
// before we start any work, we should check that all MUST constants are defined
$abort = false;
foreach (array(
'DS', 'DIR', 'BASE', 'ROOT', 'LIB', 'INCLUDES', 'LAYOUT', 'PICTURES', 'FLASH', 'VIDEOS', 'DOCUMENTS', 'PDFS', 'BINARIES', 'ICONS',
'UPLOADS', 'CSV', 'JS', 'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES', 'TEMPLATES_C',
'TEMPLATES_FRONTEND', 'DEFAULT_TEMPLATE', 'DEFAULT_TEMPLATE_FILE', 'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH',
'DEFAULT_ACL_LEVEL', 'LOGOUT_TARGET', 'PASSWORD_CHANGE', 'AJAX_REQUEST_TYPE', 'USE_PROTOTYPE', 'USE_SCRIPTACULOUS', 'USE_JQUERY',
'PAGE_WIDTH', 'MASTER_TEMPLATE_NAME', 'PUBLIC_SCHEMA', 'TEST_SCHEMA', 'DEV_SCHEMA', 'LIVE_SCHEMA', 'LOGIN_DB', 'MAIN_DB', 'DB_SCHEMA',
'LOGIN_DB_SCHEMA', 'GLOBAL_DB_SCHEMA', 'TARGET', 'DEBUG', 'SHOW_ALL_ERRORS'
) as $constant) {
if (!defined($constant)) {
echo "Constant $constant misssing<br>";
$abort = true;
}
}
if ($abort === true) {
die('Core Constant missing. Check config file.');
}
// set the page name // set the page name
$this->page_name = $this->getPageName(); $this->page_name = $this->getPageName();
$this->host_name = $this->getHostName(); $this->host_name = $this->getHostName();
// init the log file id
$this->log_file_id = defined('LOG_FILE_ID') ? LOG_FILE_ID : '';
// set the paths matching to the valid file types // set the paths matching to the valid file types
$this->data_path = array ( $this->data_path = array (
@@ -328,7 +349,7 @@ class Basic
// initial the session if there is no session running already // initial the session if there is no session running already
if (!session_id()) { if (!session_id()) {
// check if we have an external session name given, else skip this step // check if we have an external session name given, else skip this step
if (SET_SESSION_NAME) { if (defined('SET_SESSION_NAME')) {
// set the session name for possible later check // set the session name for possible later check
$this->session_name = SET_SESSION_NAME; $this->session_name = SET_SESSION_NAME;
} }
@@ -434,7 +455,7 @@ class Basic
// DESC : wrapper around microtime function to print out y-m-d h:i:s.ms // DESC : wrapper around microtime function to print out y-m-d h:i:s.ms
public static function printTime($set_microtime = -1) public static function printTime($set_microtime = -1)
{ {
list($microtime, $timestamp) = explode(" ", microtime()); list($microtime, $timestamp) = explode(' ', microtime());
$string = date("Y-m-d H:i:s", $timestamp); $string = date("Y-m-d H:i:s", $timestamp);
// if microtime flag is -1 no round, if 0, no microtime, if >= 1, round that size // if microtime flag is -1 no round, if 0, no microtime, if >= 1, round that size
if ($set_microtime == -1) { if ($set_microtime == -1) {

View File

@@ -501,7 +501,7 @@ class IO extends \CoreLibs\Basic
// NOTE : used in db_dump_data only // NOTE : used in db_dump_data only
private function __printArray($array) private function __printArray($array)
{ {
while (list($key, $value) = each($array)) { foreach ($array as $key => $value) {
$string .= $this->nbsp.'<b>'.$key.'</b> => '; $string .= $this->nbsp.'<b>'.$key.'</b> => ';
if (is_array($value)) { if (is_array($value)) {
$this->nbsp .= '&nbsp;&nbsp;&nbsp;'; $this->nbsp .= '&nbsp;&nbsp;&nbsp;';
@@ -1111,7 +1111,7 @@ class IO extends \CoreLibs\Basic
$this->cursor_ext[$md5]['read_rows'] ++; $this->cursor_ext[$md5]['read_rows'] ++;
// if reset is <3 caching is done, else no // if reset is <3 caching is done, else no
if ($reset < 3) { if ($reset < 3) {
while (list($field_name, $data) = each($return)) { foreach ($return as $field_name => $data) {
$temp[$field_name] = $data; $temp[$field_name] = $data;
} }
$this->cursor_ext[$md5][] = $temp; $this->cursor_ext[$md5][] = $temp;