From ff154144e5b23ccc3511587bfec14dd9d65d40cd Mon Sep 17 00:00:00 2001 From: quenenni Date: Tue, 15 Aug 2017 03:39:37 +0200 Subject: [PATCH] fonctions + local + db --- bureau/class/config.php | 7 +++---- bureau/class/db_mysql.php | 5 ++--- bureau/class/functions.php | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/bureau/class/config.php b/bureau/class/config.php index ff578321..1d937dd6 100755 --- a/bureau/class/config.php +++ b/bureau/class/config.php @@ -90,7 +90,8 @@ require_once(dirname(__FILE__) . "/local.php"); // Define constants from vars of /etc/alternc/local.sh // The you can't choose where is the AlternC Panel -define("DEFAULT_PASS_SIZE", 8); + +define("DEFAULT_PASS_SIZE", 10); define('ALTERNC_MAIL', "$L_ALTERNC_MAIL"); define('ALTERNC_HTML', "$L_ALTERNC_HTML"); if (isset($L_ALTERNC_LOGS_ARCHIVE)) { @@ -163,9 +164,9 @@ foreach (glob($root . "class/class_system_*.php") as $fcs) { include_once("lang_env.php"); $mem = new m_mem(); -$err = new m_err(); $authip = new m_authip(); $hooks = new m_hooks(); +$msg = new m_messages(); if (isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && $_SERVER["HTTP_X_FORWARDED_PROTO"]=="https") { $_SERVER["HTTPS"]="on"; @@ -186,7 +187,6 @@ if ((variable_get('force_https', '0', "This variable is set to 0 (default) if us $fatalcsrf=false; if (count($_POST) && !defined("NOCSRF")) { if (csrf_check()<=0) { - $error=$err->errstr(); // We will trigger the error LATER in the code => need initialization of classes $fatalcsrf=true; } @@ -200,7 +200,6 @@ if (!defined('NOCHECK')) { header('HTTP/1.0 401 Unauthorized'); exit(); } - $error = $err->errstr(); include("$root/admin/index.php"); exit(); } diff --git a/bureau/class/db_mysql.php b/bureau/class/db_mysql.php index 1a2b5395..3d6b0a64 100644 --- a/bureau/class/db_mysql.php +++ b/bureau/class/db_mysql.php @@ -68,7 +68,6 @@ class DB_Sql { * @return the class variable $Link_ID */ function connect($Database = "", $Host = "", $User = "", $Password = "") { - global $err; $this->halt('Mysql::connect() : This function should no longer be used'); /* Handle defaults */ if ("" == $Database) @@ -348,8 +347,8 @@ class DB_Sql { /* public: return table metadata */ function metadata($table='',$full=false) { - global $err; - $err->raise('Mysql', 'function is no longer implemented (metadata())'); + global $msg; + $msg->raise("Error", 'Mysql', 'function is no longer implemented (metadata())'); return FALSE; } diff --git a/bureau/class/functions.php b/bureau/class/functions.php index e6e062c6..a4ae63ee 100755 --- a/bureau/class/functions.php +++ b/bureau/class/functions.php @@ -848,16 +848,40 @@ function pager($offset, $count, $total, $url, $before = "", $after = "", $echo = /** * * @param int $length + * @param int $classcount * @return string */ -function create_pass($length = 8) { - $chars = "1234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - $i = 0; - $password = ""; - while ($i <= $length) { - $password .= @$chars{mt_rand(0, strlen($chars))}; - $i++; +function create_pass($length = 10, $classcount = 3) { + $sets = array(); + + // Si classcount policy est 4 catégories différents, on utilise les 4 cat, sinon, on en utilise 3 + if ($classcount < 4) + $available_sets='lud'; + else + $available_sets='luds'; + + if(strpos($available_sets, 'l') !== false) + $sets[] = 'abcdefghijklmnopqrstuvwxyz'; + if(strpos($available_sets, 'u') !== false) + $sets[] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + if(strpos($available_sets, 'd') !== false) + $sets[] = '0123456789'; + if(strpos($available_sets, 's') !== false) + $sets[] = '(!#$%)*+,-./:;<=>?@[\]^_'; + + $all = ''; + $password = ''; + foreach($sets as $set) { + $password .= $set[array_rand(str_split($set))]; + $all .= $set; } + + $all = str_split($all); + for($i = 0; $i < $length - count($sets); $i++) + $password .= $all[array_rand($all)]; + + $password = str_shuffle($password); + return $password; }