[enh] add a debug() method to messages, and set this instead of LOG() for most api calls => only api calls that CHANGES something are now calling log() (which logs) and others are calling debug() which logs nothing by default. A variable allow for debugging

This commit is contained in:
Benjamin Sonntag 2018-06-28 00:27:10 +02:00
parent bcde8a9ef2
commit dbb41924bd
12 changed files with 78 additions and 55 deletions

View File

@ -211,7 +211,7 @@ class m_admin {
*/
function get($uid, $recheck = false) {
global $msg, $db, $lst_users_properties;
// $msg->log("admin","get",$uid);
$msg->debug("admin","get",$uid);
if (!$this->enabled) {
$msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
return false;
@ -267,7 +267,7 @@ class m_admin {
*/
function get_creator($uid) {
global $msg, $db;
// $msg->log("admin","get",$uid);
$msg->debug("admin","get_creator",$uid);
if (!$this->enabled) {
$msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
return false;
@ -342,7 +342,7 @@ class m_admin {
*/
function get_list($all = 0, $creator = 0, $pattern = FALSE, $pattern_type = FALSE) {
global $msg, $mem, $cuid;
$msg->log("admin", "get_list");
$msg->debug("admin", "get_list");
if (!$this->enabled) {
$msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
return false;
@ -470,7 +470,7 @@ class m_admin {
$creators = array();
$msg->log("admin", "get_reseller_list");
$msg->debug("admin", "get_creator_list");
if (!$this->enabled) {
$msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
return false;

View File

@ -47,7 +47,7 @@ class m_cron {
*/
function lst_cron() {
global $cuid, $db, $msg;
$msg->log("cron", "lst_cron");
$msg->debug("cron", "lst_cron");
$db->query("SELECT * FROM cron WHERE uid = ? ORDER BY url;", array($cuid));
$r = Array();
while ($db->next_record()) {
@ -191,7 +191,7 @@ class m_cron {
*/
function hook_quota_get() {
global $cuid, $db, $msg;
$msg->log("cron", "alternc_get_quota");
$msg->debug("cron", "alternc_get_quota");
$q = Array("name" => "cron", "description" => _("Scheduled tasks"), "used" => 0);
$db->query("select count(*) as cnt from cron where uid = ? ;", array($cuid));
if ($db->next_record()) {
@ -206,8 +206,9 @@ class m_cron {
* this function EXIT at the end.
*/
function execute_cron() {
global $db;
global $db,$msg;
$msg->debug("cron", "execute_cron");
if (!isset($GLOBALS["DEBUG"])) {
$GLOBALS["DEBUG"] = false;
}

View File

@ -91,7 +91,7 @@ class m_dom {
function get_panel_url_list() {
global $db, $msg;
$msg->log("dom", "get_panel_url_list");
$msg->debug("dom", "get_panel_url_list");
$db->query("SELECT sd.id as sub_id, if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) as fqdn from sub_domaines sd where type = 'PANEL';");
$t = array();
while ($db->next_record()) {
@ -106,7 +106,7 @@ class m_dom {
*/
public static function get_sub_domain_id_and_member_by_name($fqdn) {
global $db, $msg;
$msg->log("dom", "get_sub_domain_by_name");
$msg->debug("dom", "get_sub_domain_by_name");
$db->query("select sd.* from sub_domaines sd where if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) = ?;", array($fqdn));
if (!$db->next_record()) {
return false;
@ -154,7 +154,7 @@ class m_dom {
*/
function domains_type_lst() {
global $db, $msg;
$msg->log("dom", "domains_type_lst");
$msg->debug("dom", "domains_type_lst");
if (empty($this->cache_domains_type_lst)) {
$db->query("select * from domaines_type order by advanced;");
$this->cache_domains_type_lst = array();
@ -168,7 +168,7 @@ class m_dom {
function domains_type_enable_values() {
global $db, $msg, $cuid;
$msg->log("dom", "domains_type_enable_values");
$msg->debug("dom", "domains_type_enable_values");
$db->query("desc domaines_type;");
$r = array();
while ($db->next_record()) {
@ -188,7 +188,7 @@ class m_dom {
*/
function domains_type_target_values($type = null) {
global $db, $msg;
$msg->log("dom", "domains_type_target_values");
$msg->debug("dom", "domains_type_target_values");
if (is_null($type)) {
$db->query("desc domaines_type;");
$r = array();
@ -602,7 +602,7 @@ class m_dom {
*/
function enum_domains($uid = -1) {
global $db, $msg, $cuid;
$msg->log("dom", "enum_domains");
$msg->debug("dom", "enum_domains");
if ($uid == -1) {
$uid = $cuid;
}
@ -854,7 +854,7 @@ class m_dom {
function lst_default_subdomains() {
global $db, $msg;
$msg->log("dom", "lst_default_subdomains");
$msg->debug("dom", "lst_default_subdomains");
$c = array();
$db->query("select * from default_subdomains;");
@ -937,7 +937,7 @@ class m_dom {
*/
function whois($domain) {
global $msg;
$msg->log("dom", "whois", $domain);
$msg->debug("dom", "whois", $domain);
// pour ajouter un nouveau TLD, utiliser le code ci-dessous.
// echo "whois : $domain<br />";
preg_match("#.*\.([^\.]*)#", $domain, $out);
@ -1164,7 +1164,7 @@ class m_dom {
*/
function get_domain_all($dom) {
global $db, $msg, $cuid;
$msg->log("dom", "get_domain_all", $dom);
$msg->debug("dom", "get_domain_all", $dom);
// Locked ?
if (!$this->islocked) {
$msg->raise("ERROR", "dom", _("--- Program error --- No lock on the domains!"));
@ -1226,7 +1226,7 @@ class m_dom {
*/
function get_sub_domain_all($sub_domain_id) {
global $db, $msg, $cuid;
$msg->log("dom", "get_sub_domain_all", $sub_domain_id);
$msg->debug("dom", "get_sub_domain_all", $sub_domain_id);
// Locked ?
if (!$this->islocked) {
$msg->raise("ERROR", "dom", _("--- Program error --- No lock on the domains!"));
@ -1352,7 +1352,7 @@ class m_dom {
function can_create_subdomain($dom, $sub, $type, $sub_domain_id = 0) {
global $db, $msg;
$sub_domain_id=intval($sub_domain_id);
$sub_domain_id=intval($sub_domain_id);
$msg->log("dom", "can_create_subdomain", $dom . "/" . $sub . "/" .$type . "/" . $sub_domain_id);
// Get the compatibility list for this domain type
@ -1891,7 +1891,7 @@ class m_dom {
*/
function lock() {
global $msg;
$msg->log("dom", "lock");
$msg->debug("dom", "lock");
if ($this->islocked) {
$msg->raise("ERROR", "dom", _("--- Program error --- Lock already obtained!"));
}
@ -1910,7 +1910,7 @@ class m_dom {
*/
function unlock() {
global $msg;
$msg->log("dom", "unlock");
$msg->debug("dom", "unlock");
if (!$this->islocked) {
$msg->raise("ERROR", "dom", _("--- Program error --- No lock on the domains!"));
}
@ -1957,7 +1957,7 @@ class m_dom {
*/
function hook_quota_get() {
global $db, $msg, $cuid;
$msg->log("dom", "get_quota");
$msg->debug("dom", "get_quota");
$q = Array("name" => "dom", "description" => _("Domain name"), "used" => 0);
$db->query("SELECT COUNT(*) AS cnt FROM domaines WHERE compte= ?", array($cuid));
if ($db->next_record()) {
@ -2185,7 +2185,7 @@ class m_dom {
*/
function generation_todo() {
global $db, $msg;
$msg->log("dom", "generation_todo");
$msg->debug("dom", "generation_todo");
$db->query("select id as sub_id, web_action, type from sub_domaines where web_action !='ok';");
$r = array();
while ($db->next_record()) {

View File

@ -140,7 +140,7 @@ class m_ftp {
*/
function get_list() {
global $db, $msg, $cuid;
$msg->log("ftp", "get_list");
$msg->debug("ftp", "get_list");
$r = array();
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid= ? ORDER BY name;", array($cuid));
if ($db->num_rows()) {
@ -169,7 +169,7 @@ class m_ftp {
*/
function get_ftp_details($id) {
global $db, $msg, $cuid;
$msg->log("ftp", "get_ftp_details", $id);
$msg->debug("ftp", "get_ftp_details", $id);
$r = array();
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid= ? AND id= ?;", array($cuid, $id));
if ($db->num_rows()) {
@ -421,7 +421,7 @@ class m_ftp {
*/
function is_ftp($dir) {
global $db, $msg;
$msg->log("ftp", "is_ftp", $dir);
$msg->debug("ftp", "is_ftp", $dir);
if (substr($dir, 0, 1) == "/") {
$dir = substr($dir, 1);
}
@ -468,7 +468,7 @@ class m_ftp {
*/
function hook_quota_get() {
global $db, $msg, $cuid;
$msg->log("ftp", "getquota");
$msg->debug("ftp", "getquota");
$q = Array("name" => "ftp", "description" => _("FTP accounts"), "used" => 0);
$db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE uid= ? ", array($cuid));
if ($db->next_record()) {

View File

@ -102,7 +102,7 @@ class m_hta {
*/
function ListDir() {
global$msg, $mem;
$msg->log("hta", "listdir");
$msg->debug("hta", "listdir");
$sortie = array();
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"];
exec("find " . escapeshellarg($absolute) . " -name .htpasswd|sort", $sortie);
@ -133,7 +133,7 @@ class m_hta {
*/
function is_protected($dir) {
global $mem, $msg;
$msg->log("hta", "is_protected", $dir);
$msg->debug("hta", "is_protected", $dir);
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir";
if (file_exists("$absolute/.htpasswd")) {
return true;
@ -153,7 +153,7 @@ class m_hta {
*/
function get_hta_detail($dir) {
global $mem, $msg;
$msg->log("hta", "get_hta_detail");
$msg->debug("hta", "get_hta_detail");
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir";
if (file_exists("$absolute/.htaccess")) {
/* if (!_reading_htaccess($absolute)) {
@ -407,7 +407,7 @@ class m_hta {
*/
private function _reading_htaccess($absolute) {
global $msg;
$msg->log("hta", "_reading_htaccess", $absolute);
$msg->debug("hta", "_reading_htaccess", $absolute);
$file = fopen("$absolute/.htaccess", "r+");
$lignes = array(1, 1, 1);
$errr = 0;

View File

@ -30,7 +30,7 @@ class m_log {
*/
function list_logs_directory($dir) {
global $cuid, $msg;
$msg->log("log", "list_logs_directory");
$msg->debug("log", "list_logs_directory");
$c = array();
foreach (glob("${dir}/*log*") as $absfile) {
@ -81,7 +81,7 @@ class m_log {
*/
function list_logs_directory_all($dirs) {
global $msg;
$msg->log("log", "get_logs_directory_all");
$msg->debug("log", "get_logs_directory_all");
$c = array();
foreach ($dirs as $dir => $val) {
$c[$dir] = $this->list_logs_directory($val);
@ -92,7 +92,7 @@ class m_log {
function get_logs_directory() {
global $cuid, $mem, $msg;
$msg->log("log", "get_logs_directory");
$msg->debug("log", "get_logs_directory");
// Return an array to allow multiple directory in the future
if (defined('ALTERNC_LOGS_ARCHIVE')) {
$c = array("dir" => ALTERNC_LOGS_ARCHIVE . "/" . $cuid . "-" . $mem->user["login"]);
@ -123,7 +123,7 @@ class m_log {
*/
function tail($file, $lines = 20) {
global $msg;
$msg->log("log", "tail");
$msg->debug("log", "tail");
$lines = intval($lines);
if ($lines <= 0) {
$lines = 20;

View File

@ -191,7 +191,7 @@ class m_mail {
*/
function hook_quota_get() {
global $db, $msg, $cuid, $quota;
$msg->log("mail", "getquota");
$msg->debug("mail", "getquota");
$q = Array("name" => "mail", "description" => _("Email addresses"), "used" => 0);
$db->query("SELECT COUNT(*) AS cnt FROM address a, domaines d WHERE a.domain_id=d.id AND d.compte= ? AND a.type='';", array($cuid));
if ($db->next_record()) {
@ -217,7 +217,7 @@ class m_mail {
*/
function enum_domains($uid = -1) {
global $db, $msg, $cuid;
$msg->log("mail", "enum_domains");
$msg->debug("mail", "enum_domains");
if ($uid == -1) {
$uid = $cuid;
}
@ -284,7 +284,7 @@ ORDER BY
*/
function enum_domain_mails($dom_id = null, $search = "", $offset = 0, $count = 30, $show_systemmails = false) {
global $db, $msg, $hooks;
$msg->log("mail", "enum_domains_mail");
$msg->debug("mail", "enum_domains_mail");
$query_args = array($dom_id);
$search = trim($search);
@ -401,7 +401,7 @@ ORDER BY
*/
function get_details($mail_id) {
global $db, $msg, $hooks;
$msg->log("mail", "get_details");
$msg->debug("mail", "get_details");
$mail_id = intval($mail_id);
// Validate that this email is owned by me...

View File

@ -610,7 +610,7 @@ Cordially.
*/
function get_creator_by_uid($uid) {
global $db, $msg;
$msg->log("dom", "get_creator_by_uid");
$msg->debug("dom", "get_creator_by_uid");
$db->query("select creator from membres where uid = ? ;", array($uid));
if (!$db->next_record()) {
return false;

View File

@ -264,4 +264,26 @@ class m_messages {
);
}
/**
* Log an API function call into /var/log/alternc/bureau.log
*
* This function logs in /var/log/alternc an API function call of AlternC
*
* @param integer $clsid Number of the class doing the call
* @param string $function Name of the called function
* @param string $param non-mandatory parameters of the API call
* @return boolean TRUE if the log where successfull, FALSE if not
*
*/
function debug($clsid, $function, $param = "") {
global $mem;
if (variable_get("debug_panel", "0", "Set it to 1 to enable panel debug in /var/log/alternc/bureau.log")) {
return @file_put_contents(
$this->logfile,
date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - DEBUG - " . $mem->user["login"] . " - $clsid - $function - $param\n",
FILE_APPEND
);
}
}
} /* Class m_messages */

View File

@ -137,7 +137,7 @@ class m_mysql {
*/
function get_dblist() {
global $db, $msg, $bro, $cuid;
$msg->log("mysql", "get_dblist");
$msg->debug("mysql", "get_dblist");
$db->free();
$db->query("SELECT login,pass,db, bck_mode, bck_dir FROM db WHERE uid= ? ORDER BY db;", array($cuid));
$c = array();
@ -188,7 +188,7 @@ class m_mysql {
function get_mysql_details($dbn) {
global $db, $msg, $cuid;
$root = getuserpath();
$msg->log("mysql", "get_mysql_details");
$msg->debug("mysql", "get_mysql_details");
$pos = strpos($dbn, '_');
if ($pos === false) {
$dbname = $dbn;
@ -284,7 +284,7 @@ class m_mysql {
// Grant the special user every rights.
if ($this->dbus->exec("CREATE DATABASE $dbname;")) { // secured: dbname is checked against ^[0-9a-z]*$
$msg->log("mysql", "add_db_succes", $dbn);
$msg->log("mysql", "add_db", "Success: ".$dbn);
// Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed
$db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES (?, ?, ?, ? ,0)", array($cuid, $myadm, $password, $dbname));
$dbuser = $dbname;
@ -296,7 +296,7 @@ class m_mysql {
$this->dbus->query("FLUSH PRIVILEGES;");
return true;
} else {
$msg->log("mysql", "add_db", $dbn);
$msg->log("mysql", "add_db", "Error: ".$dbn);
$msg->raise("ERROR", "mysql", _("An error occured. The database could not be created"));
return false;
}
@ -564,7 +564,7 @@ class m_mysql {
*/
function get_userslist($all = null) {
global $db, $msg, $cuid;
$msg->log("mysql", "get_userslist");
$msg->debug("mysql", "get_userslist");
$c = array();
if (!$all) {
$db->query("SELECT name FROM dbusers WHERE uid= ? and enable not in ('ADMIN','HIDDEN') ORDER BY name;", array($cuid));
@ -587,7 +587,7 @@ class m_mysql {
function get_defaultsparam($dbn) {
global $db, $msg, $cuid;
$msg->log("mysql", "getdefaults");
$msg->debug("mysql", "getdefaults");
$dbu = $dbn;
$r = array();
@ -932,7 +932,7 @@ class m_mysql {
*/
function hook_quota_get() {
global $msg, $mem, $quota;
$msg->log("mysql", "alternc_get_quota");
$msg->debug("mysql", "alternc_get_quota");
$q = Array("name" => "mysql", "description" => _("MySQL Databases"), "used" => 0);
$c = $this->get_dblist();
if (is_array($c)) {
@ -1069,7 +1069,7 @@ class m_mysql {
*/
function get_dbus_size($db_name, $db_host, $db_login, $db_password, $db_client) {
global $msg;
$msg->log("mysql", "get_dbus_size", $db_host);
$msg->debug("mysql", "get_dbus_size", $db_host);
$this->dbus = new DB_Sql("mysql",$db_host,$db_login,$db_password);

View File

@ -144,7 +144,7 @@ class m_piwik {
function get_users_access_from_site($site_id) {
global $msg, $cuid;
$msg->log("piwik","get_users_access_from_site");
$msg->debug("piwik","get_users_access_from_site");
$this->get_alternc_sites();
$this->get_alternc_users();
@ -240,7 +240,7 @@ class m_piwik {
function user_has_sites() {
global $db, $cuid, $msg;
$msg->log("piwik","user_has_sites");
$msg->debug("piwik","user_has_sites");
$db->query("SELECT id FROM piwik_users WHERE uid='$cuid'");
if ($db->num_rows() <= 1) {
@ -283,7 +283,7 @@ class m_piwik {
function users_list() {
global $db, $cuid, $msg;
$msg->log("piwik","users_list");
$msg->debug("piwik","users_list");
$db->query("SELECT login FROM piwik_users WHERE uid = ?;", array($cuid));
if ($db->num_rows() == 0)
@ -323,7 +323,7 @@ class m_piwik {
function site_list() {
global $msg;
$msg->log("piwik","site_list");
$msg->debug("piwik","site_list");
$this->get_alternc_sites();
$api_data = $this->call_privileged_page('API', 'SitesManager.getAllSites');
@ -473,7 +473,7 @@ class m_piwik {
function call_page($module, $method, $arguments=array(), $output = 'JSON') {
global $msg;
$msg->log("piwik","call_page");
$msg->debug("piwik","call_page");
$url = sprintf('%s/?module=%s&method=%s&format=%s', $this->piwik_server_uri, $module, $method, $output);
foreach ($arguments AS $k=>$v)
@ -507,7 +507,7 @@ class m_piwik {
function call_privileged_page($module, $method, $arguments=array(), $output = 'JSON') {
global $msg;
$msg->log("piwik","call_privileged_page");
$msg->debug("piwik","call_privileged_page");
$arguments['token_auth'] = $this->piwik_admin_token;
return $this->call_page($module, $method, $arguments, $output);

View File

@ -141,7 +141,7 @@ class m_quota {
function synchronise_user_profile() {
global $db, $msg;
$msg->log("quota", "synchronise_user_profile");
$q = "insert into quotas select m.uid as uid, d.quota as name, d.value as total from membres m, defquotas d left join quotas q on q.name=d.quota where m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);";
$q = "INSERT INTO quotas SELECT m.uid AS uid, d.quota AS name, d.value AS total FROM membres m, defquotas d LEFT JOIN quotas q ON q.name=d.quota WHERE m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);";
if (!$db->query($q)) {
return false;
}
@ -173,7 +173,7 @@ class m_quota {
*/
function getquota($ressource = "", $recheck = false) {
global $db, $msg, $cuid, $get_quota_cache, $hooks, $mem;
$msg->log("quota", "getquota", $ressource);
$msg->debug("quota", "getquota", $ressource);
if ($recheck) { // rebuilding quota
$get_quota_cache = null;
$this->quotas = array();