log("action", "do_action");
+ global $msg, $L_INOTIFY_DO_ACTION;
+ $msg->log("action", "do_action");
if (!@touch($L_INOTIFY_DO_ACTION)) {
return FALSE;
}
@@ -152,14 +152,14 @@ class m_action {
*
* @global int $cuid
* @global m_mysql $db
- * @global m_err $err
+ * @global m_messages $msg
* @param string $archive Directory to archive within the archive_del_data folder if set in variable sql table
* If archive_del_data is not set we delete the folder
* @param string $dir sub_directory of the archive directory
* @return boolean
*/
function archive($archive, $dir = "html") {
- global $cuid, $db, $err;
+ global $cuid, $db, $msg;
$arch = variable_get('archive_del_data');
if (empty($arch)) {
@@ -170,7 +170,7 @@ class m_action {
$db->query("select login from membres where uid= ?;", array($cuid));
$db->next_record();
if (!$db->Record["login"]) {
- $err->raise("action", _("Login corresponding to $cuid not found"));
+ $msg->raise('Error', "action", _("Login corresponding to $cuid not found"));
return false;
}
$uidlogin = $cuid . "-" . $db->Record["login"];
@@ -187,15 +187,15 @@ class m_action {
* function inserting the action in the sql table
*
* @global m_mysql $db
- * @global m_err $err
+ * @global m_messages $msg
* @param string $type
* @param string|integer $user wich user do we impersonate?
* @param mixed $parameters
* @return boolean
*/
function set($type, $user, $parameters) {
- global $db, $err;
- $err->log("action", "set", $type);
+ global $db, $msg;
+ $msg->log("action", "set", $type);
$serialized = serialize($parameters);
$type = strtoupper($type);
if (in_array($type, array('CHMOD',
@@ -212,7 +212,7 @@ class m_action {
}
if (!$db->query($query)) {
- $err->raise("action", _("Error setting actions"));
+ $msg->raise('Error', "action", _("Error setting actions"));
return false;
}
return $this->do_action();
@@ -221,17 +221,17 @@ class m_action {
/**
* This seems to be unused ?
*
- * @global m_err $err
+ * @global m_messages $msg
* @global m_mysql $db
* @return boolean
*/
function get_old() {
- global $err, $db;
+ global $msg, $db;
$purge = "select * from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
$result = $db->query($purge);
if (!$result) {
- $err->raise("action", _("Error selecting old actions"));
+ $msg->raise('Error', "action", _("Error selecting old actions"));
return false;
}
return $db->num_rows($result);
@@ -239,13 +239,13 @@ class m_action {
/**
*
- * @global m_err $err
+ * @global m_messages $msg
* @global m_mysql $db
* @param type $all
* @return boolean
*/
function purge($all = null) {
- global $err, $db;
+ global $msg, $db;
if (is_null($all)) {
$purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2 and status = 0;";
} else {
@@ -253,7 +253,7 @@ class m_action {
}
$result = $db->query($purge);
if (!$result) {
- $err->raise("action", _("Error purging old actions"));
+ $msg->raise('Error', "action", _("Error purging old actions"));
return false;
}
return $db->num_rows($result);
@@ -263,11 +263,10 @@ class m_action {
* function returning the first not locked line of the action table
*
* @global m_mysql $db
- * @global m_err $err
* @return boolean or array
*/
function get_action() {
- global $db, $err;
+ global $db;
$tab = array();
$db->query('select * from actions where end = 0 and begin = 0 order by id limit 1;');
@@ -283,14 +282,14 @@ class m_action {
* function locking an entry while it is being executed by the action script
*
* @global m_mysql $db
- * @global m_err $err
+ * @global m_messages $msg
* @param int $id
* @return boolean
*/
function begin($id) {
- global $db, $err;
+ global $db, $msg;
if (!$db->query("update actions set begin=now() where id= ? ;", array($id))) {
- $err->raise("action", _("Error locking the action : $id"));
+ $msg->raise('Error', "action", _("Error locking the action : $id"));
return false;
}
return true;
@@ -300,15 +299,15 @@ class m_action {
* function locking an entry while it is being executed by the action script
*
* @global m_mysql $db
- * @global m_err $err
+ * @global m_messages $msg
* @param int $id
* @param integer $return
* @return boolean
*/
function finish($id, $return = 0) {
- global $db, $err;
+ global $db, $msg;
if (!$db->query("update actions set end=now(),status=? where id= ?;", array($return, $id))) {
- $err->raise("action", _("Error unlocking the action : $id"));
+ $msg->raise('Error', "action", _("Error unlocking the action : $id"));
return false;
}
return true;
@@ -317,14 +316,14 @@ class m_action {
/**
*
* @global m_mysql $db
- * @global m_err $err
+ * @global m_messages $msg
* @param int $id
* @return boolean
*/
function reset_job($id) {
- global $db, $err;
+ global $db, $msg;
if (!$db->query("update actions set end=0,begin=0,status='' where id= ?;", array($id))) {
- $err->raise("action", _("Error unlocking the action : $id"));
+ $msg->raise('Error', "action", _("Error unlocking the action : $id"));
return false;
}
return true;
@@ -334,7 +333,7 @@ class m_action {
* Returns a list of actions marked as executable and ready for execution
*
* @global m_mysql $db
- * @global m_err $err
+ * @global m_messages $msg
* @return boolean
*/
function get_job() {
diff --git a/bureau/class/m_authip.php b/bureau/class/m_authip.php
index 0f8c74bf..c8d77bd0 100644
--- a/bureau/class/m_authip.php
+++ b/bureau/class/m_authip.php
@@ -102,7 +102,7 @@ class m_authip {
* @return boolean Retourne FALSE si erreur, sinon TRUE
*/
function ip_delete($id) {
- global $db, $cuid;
+ global $db, $cuid, $msg;
$id = intval($id);
$db->query("SELECT id FROM authorised_ip_affected where authorised_ip_id = ?;", array($id));
@@ -110,7 +110,7 @@ class m_authip {
$this->ip_affected_delete($db->f('id'));
}
if (!$db->query("delete from authorised_ip where id= ? and ( uid= ? or uid=0) limit 1;", array($id, $cuid))) {
- echo "query failed: " . $db->Error;
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
return true;
@@ -126,9 +126,9 @@ class m_authip {
* @return array
*/
function get_allowed($s) {
- global $db, $cuid;
+ global $db, $cuid, $msg;
if (!$db->query("select ai.ip, ai.subnet, ai.infos, aia.parameters from authorised_ip ai, authorised_ip_affected aia where aia.protocol= ? and aia.authorised_ip_id = ai.id and ai.uid= ?;", array($s, $cuid))) {
- echo "query failed: " . $db->Error;
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
$r = Array();
@@ -145,9 +145,9 @@ class m_authip {
* @return boolean
*/
function is_wl($ip) {
- global $db;
+ global $db, $msg;
if (!$db->query("select ai.ip, ai.subnet from authorised_ip ai where ai.uid='0';")) {
- echo "query failed: " . $db->Error;
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
while ($db->next_record()) {
@@ -205,7 +205,7 @@ class m_authip {
*
*/
function ip_save($id, $ipsub, $infos, $uid = null) {
- global $db, $mem;
+ global $db, $mem, $msg;
// If we ask for uid=0, we have to check to be super-user
// else, juste use global cuid;
@@ -216,7 +216,7 @@ class m_authip {
}
$id = intval($id);
- $infos = mysql_real_escape_string($infos);
+ $infos = $db->quote(trim($infos));
// Extract subnet from ipsub
$tmp = explode('/', $ipsub);
@@ -224,7 +224,7 @@ class m_authip {
// Error if $ip not an IP
if (!checkip($ip) && !checkipv6($ip)) {
- echo "Failed : not an IP address";
+ $msg->raise('Error', 'authip', _("Failed : not an IP address")); // à traduire
return false;
}
@@ -249,8 +249,8 @@ class m_authip {
foreach ($list_affected as $k => $v) {
$this->call_hooks("authip_on_delete", $k);
}
- if (!$db->query("update authorised_ip set ip= ?, subnet= ?, infos= ? where id= ? and uid=? ;", array($id, $subnetn, $infos, $id, $cuid))) {
- echo "query failed: " . $db->Error;
+ if (!$db->query("update authorised_ip set ip= ?, subnet= ?, infos= ? where id= ? and uid=? ;", array($ip, $subnet, $infos, $id, $cuid))) {
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
foreach ($list_affected as $k => $v) {
@@ -258,7 +258,7 @@ class m_authip {
}
} else { // Insert
if (!$db->query("insert into authorised_ip (uid, ip, subnet, infos) values (?, ?, ?, ?);", array($cuid, $ip, $subnet, $infos))) {
- echo "query failed: " . $db->Error;
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
}
@@ -313,20 +313,20 @@ class m_authip {
* @return boolean Retourne FALSE si erreur, sinon TRUE
*/
function ip_affected_save($authorised_ip_id, $protocol, $parameters, $id = null) {
- global $db;
+ global $db, $msg;
$authorised_ip_id = intval($authorised_ip_id);
if ($id) {
$id = intval($id);
$this->call_hooks("authip_on_delete", $id);
if (!$db->query("update authorised_ip_affected set authorised_ip_id= ?, protocol= ?, parameters= ? where id = ? limit 1;", array($authorised_ip_id, $protocol, $parameters, $id))) {
- echo "query failed: " . $db->Error;
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
$this->call_hooks("authip_on_create", $id);
} else {
if (!$db->query("insert into authorised_ip_affected (authorised_ip_id, protocol, parameters) values (?, ?, ?);", array($authorised_ip_id, $protocol, $parameters))) {
- echo "query failed: " . $db->Error;
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
$this->call_hooks("authip_on_create", $db->lastid());
@@ -344,14 +344,14 @@ class m_authip {
* @return boolean Retourne FALSE si erreur, sinon TRUE
*/
function ip_affected_delete($id) {
- global $db;
+ global $db, $msg;
$id = intval($id);
// Call hooks
$this->call_hooks("authip_on_delete", $id);
if (!$db->query("delete from authorised_ip_affected where id= ? limit 1;", array($id))) {
- echo "query failed: " . $db->Error;
+ $msg->raise('Error', 'authip', _("query failed: " . $db->Error));
return false;
}
return true;
@@ -362,18 +362,18 @@ class m_authip {
* affectationt ip<=>ressource dont l'id est en parametre
*
* @global m_hooks $hooks
- * @global m_err $err
+ * @global m_messages $msg
* @param string $function Nom de la fonction a rechercher et appeller dans les classes
* @param integer $affectation_id Id de l'affectation correspondante
* @return boolean Retourne TRUE
*/
function call_hooks($function, $affectation_id) {
- global $hooks, $err;
+ global $hooks, $msg;
// On récure l'objet dont on parle
$d = $this->list_affected();
if (!isset($d[$affectation_id])) {
- $err->raise('authip', _("Object not available"));
+ $msg->raise('Error', 'authip', _("Object not available"));
return false;
}
@@ -382,7 +382,7 @@ class m_authip {
// On en déduis la classe qui le concerne
$e = $this->get_auth_class();
if (!isset($e[$affectation['protocol']])) {
- $err->raise('authip', sprintf(_("Can't identified class for the protocole %s"), $affectation['protocol']));
+ $msg->raise('Error', 'authip', sprintf(_("Can't identified class for the protocole %s"), $affectation['protocol']));
return false;
}
$c = $e[$affectation['protocol']]['class'];
diff --git a/bureau/class/m_cron.php b/bureau/class/m_cron.php
index b439477b..bba8214d 100644
--- a/bureau/class/m_cron.php
+++ b/bureau/class/m_cron.php
@@ -54,8 +54,8 @@ class m_cron {
* @return array an hash for each crontab.
*/
function lst_cron() {
- global $cuid, $db, $err;
- $err->log("cron", "lst_cron");
+ global $cuid, $db, $msg;
+ $msg->log("cron", "lst_cron");
$db->query("SELECT * FROM cron WHERE uid = ? ORDER BY url;", array($cuid));
$r = Array();
while ($db->next_record()) {
@@ -112,8 +112,8 @@ class m_cron {
* @return boolean TRUE if the crontab has been deleted
*/
function delete_one($id) {
- global $db, $err, $cuid;
- $err->log("cron", "delete_one");
+ global $db, $msg, $cuid;
+ $msg->log("cron", "delete_one");
return $db->query("DELETE FROM cron WHERE id= ? AND uid= ? LIMIT 1;", array(intval($id), $cuid));
}
@@ -123,8 +123,8 @@ class m_cron {
* @return boolean TRUE if the crontab has been edited
*/
private function _update_one($url, $user, $password, $email, $schedule, $id = null) {
- global $db, $err, $quota, $cuid;
- $err->log("cron", "update_one");
+ global $db, $msg, $quota, $cuid;
+ $msg->log("cron", "update_one");
if (empty($url) && !is_null($id)) {
return $this->delete_one($id);
@@ -132,7 +132,7 @@ class m_cron {
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
- $err->raise("cron", _("URL not valid"));
+ $msg->raise('Error', "cron", _("URL not valid"));
return false;
}
$url = urlencode($url);
@@ -144,7 +144,7 @@ class m_cron {
//@todo remove checkmail cf functions.php
if (!empty($email) && !checkmail($email) == 0) {
- $err->raise("cron", _("Email address is not valid"));
+ $msg->raise('Error', "cron", _("Email address is not valid"));
return false;
}
$email = urlencode($email);
@@ -155,7 +155,7 @@ class m_cron {
if (is_null($id)) { // if a new insert, quotacheck
$q = $quota->getquota("cron");
if ($q["u"] >= $q["t"]) {
- $err->raise("cron", _("You quota of cron entries is over. You cannot create more cron entries"));
+ $msg->raise('Error', "cron", _("You quota of cron entries is over. You cannot create more cron entries"));
return false;
}
} else { // if not a new insert, check the $cuid
@@ -163,8 +163,8 @@ class m_cron {
if (!$db->next_record()) {
return "false";
} // return false if pb
- if ($db->f('uid') != $cuid) {
- $err->raise("cron", _("Identity problem"));
+ if ($db->f('uid') != $cuid) {
+ $msg->raise('Error', "cron", _("Identity problem"));
return false;
}
}
@@ -196,8 +196,8 @@ class m_cron {
/** hook for quota computation
*/
function hook_quota_get() {
- global $cuid, $db, $err;
- $err->log("cron", "alternc_get_quota");
+ global $cuid, $db, $msg;
+ $msg->log("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()) {
diff --git a/bureau/class/m_err.php b/bureau/class/m_err.php
deleted file mode 100644
index e9c4d93a..00000000
--- a/bureau/class/m_err.php
+++ /dev/null
@@ -1,144 +0,0 @@
-Cette classe gère les erreurs qui peuvent apparaitre lors d'appels
- * à l'API d'AlternC. Ces erreurs sont stockées sous la forme de 2 nombres
- * (Classe ID et Numéro d'erreur) ainsi qu'un texte facultatif associé.
- * Des textes d'erreurs localisés sont aussi disponibles.
- *
Cette classe se charge aussi d'insérer les appels à l'API d'AlternC
- * dans les logs du système dans /var/log/alternc/bureau.log
- *
- * Copyleft {@link http://alternc.net/ AlternC Team}
- *
- * @copyright AlternC-Team 2002-11-01 http://alternc.net/
- */
-class m_err {
-
- /** Numero de classe d'erreur actuelle */
- var $clsid = 0;
-
- /** Dernière erreur enregistrée par la classe */
- var $error = 0;
-
- /** Paramètre chaine eventuellement associé à la dernière erreur */
- var $param = "";
-
- /** Emplacement du fichier de logs d'AlternC */
- var $logfile = "/var/log/alternc/bureau.log";
-
- /**
- * Leve une erreur, signale celle-ci dans les logs et stocke le code erreur
- *
- * Cette fonction lance une erreur, l'ajoute dans les logs d'AlternC,
- * et la met à disposition pour le bureau virtuel pour affichage ultérieur.
- *
- * @todo ne plus utiliser $error de façon numérique, nulle part
- *
- * @param integer $clsid Classe qui lève l'erreur
- * @param mixed $error Numéro de l'erreur ou chaîne décrivant l'erreur
- * @param string $param Paramètre chaine associé à l'erreur (facultatif)
- * @return boolean TRUE si l'erreur est connue, FALSE sinon.
- *
- */
- function raise($clsid, $error, $param = "") {
- /* Leve une exception. Si elle existe, sinon, stocke un message d'erreur sur erreur ... */
- if (_("err_" . $clsid . "_" . $error) != "err_" . $clsid . "_" . $error || is_string($error)) {
- $this->clsid = $clsid;
- $this->error = $error;
- $args = func_get_args();
- $this->param = array_slice($args, 2);
- $this->logerr();
- return true;
- } else {
- $this->clsid = "err";
- $this->error = 1;
- $this->param = "Error # $error in Class $clsid, Value is $param. (sorry, no text for this error in your language at the moment)";
- $this->logerr();
- return false;
- }
- }
-
- /**
- * Retourne la chaine d'erreur correspondant à la dernière erreur rencontrée
- *
- * Si la dernière erreur rencontrée est connue, retourne l'erreur en toute lettre
- * dans la langue actuellement sélectionnée, ou en anglais par défaut.
- * Si l'erreur n'est pas connue, retourne son numéro de classe et d'ereur.
- *
- * @return string Chaine d'erreur.
- *
- */
- function errstr() {
- if (is_string($this->error)) {
- // new way of handling errors: message directly in the class
- $str = $this->error . "\n";
- } else {
- // old way: message in the locales files (ugly)
- $str = _("err_" . $this->clsid . "_" . $this->error) . "\n";
- }
- $args = $this->param;
- if (is_array($args)) {
- array_unshift($args, $str);
- $msg = call_user_func_array("sprintf", $args);
- return $msg;
- } else {
- return $args;
- }
- }
-
- /**
- * Envoi un log d'erreur dans /var/log/alternc/bureau.log
- *
- * Cette fonction Loggue la dernière erreur dans /var/log sur la machine,
- * permettant ainsi aux admins de savoir ce qu'il se passe...
- * Elle est appelée automatiquement par error
- * @access private
- */
- function logerr() {
- global $mem;
- @file_put_contents($this->logfile, date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - ERROR - " . $mem->user["login"] . " - " . $this->errstr(), FILE_APPEND);
- }
-
- /**
- * Envoi un log d'appel d'API dans /var/log/alternc/bureau.log
- *
- * Cette fonction loggue dans /var/log l'appel à la fonction de l'API
- * d'AlternC.
- *
- * @param integer $clsid Numéro de la classe dont on a appelé une fonction
- * @param string $function Nom de la fonction appelée
- * @param string $param Paramètre (facultatif) passés à la fonction de l'API.
- * @return boolean TRUE si le log a été ajouté, FALSE sinon
- *
- */
- function log($clsid, $function, $param = "") {
- global $mem;
- return @file_put_contents($this->logfile, date("d/m/Y H:i:s") . " - " . get_remote_ip() . " - CALL - " . $mem->user["login"] . " - $clsid - $function - $param\n", FILE_APPEND);
- }
-
-}
-
-/* Classe m_err */
diff --git a/bureau/class/m_log.php b/bureau/class/m_log.php
index eabe4ad0..65eb3378 100644
--- a/bureau/class/m_log.php
+++ b/bureau/class/m_log.php
@@ -34,8 +34,8 @@ class m_log {
}
function list_logs_directory($dir) {
- global $cuid, $err;
- $err->log("log", "list_logs_directory");
+ global $cuid, $msg;
+ $msg->log("log", "list_logs_directory");
$c = array();
foreach (glob("${dir}/*log*") as $absfile) {
@@ -72,8 +72,8 @@ class m_log {
}
function list_logs_directory_all($dirs) {
- global $err;
- $err->log("log", "get_logs_directory_all");
+ global $msg;
+ $msg->log("log", "get_logs_directory_all");
$c = array();
foreach ($dirs as $dir => $val) {
$c[$dir] = $this->list_logs_directory($val);
@@ -82,8 +82,8 @@ class m_log {
}
function get_logs_directory() {
- global $cuid, $mem, $err;
- $err->log("log", "get_logs_directory");
+ global $cuid, $mem, $msg;
+ $msg->log("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"]);
@@ -94,8 +94,8 @@ class m_log {
}
function download_link($file) {
- global $err;
- $err->log("log", "download_link");
+ global $msg;
+ $msg->log("log", "download_link");
header("Content-Disposition: attachment; filename=" . $file . "");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
@@ -106,8 +106,8 @@ class m_log {
}
function tail($file, $lines = 20) {
- global $err;
- $err->log("log", "tail");
+ global $msg;
+ $msg->log("log", "tail");
$lines = intval($lines);
if ($lines <= 0) {
$lines = 20;
diff --git a/bureau/class/m_lxc.php b/bureau/class/m_lxc.php
index 27095129..ef97c0cf 100644
--- a/bureau/class/m_lxc.php
+++ b/bureau/class/m_lxc.php
@@ -69,8 +69,8 @@ class m_lxc implements vm {
* HOOK: remove VM history for AlternC account
*/
function hook_admin_del_member() {
- global $db, $err, $cuid;
- $err->log("lxc", "alternc_del_member");
+ global $db, $msg, $cuid;
+ $msg->log("lxc", "alternc_del_member");
$db->query("DELETE FROM vm_history WHERE uid= ?", array($cuid));
return true;
}
@@ -123,10 +123,10 @@ class m_lxc implements vm {
* for user $login having hashed password $pass and uid $uid
*/
public function start($login = FALSE, $pass = FALSE, $uid = FALSE) {
- global $mem, $db, $err, $mysql;
+ global $mem, $db, $msg, $mysql;
if ($this->getvm() !== FALSE) {
- $err->raise('lxc', _('VM already started'));
+ $msg->raise('Error', 'lxc', _('VM already started'));
return FALSE;
}
unset($this->error);
@@ -150,7 +150,7 @@ class m_lxc implements vm {
$uid = $mem->user['uid'];
if ($error != 0) {
- $err->raise('lxc', _($msg));
+ $msg->raise('Error', 'lxc', _($msg));
return FALSE;
}
$db->query("INSERT INTO vm_history (ip,date_start,uid,serialized_object) VALUES (?, ?, ?, ?);", array($hostname, $date_start, $uid, $res));
diff --git a/bureau/class/variables.php b/bureau/class/variables.php
index 43ab6d43..7aa67596 100644
--- a/bureau/class/variables.php
+++ b/bureau/class/variables.php
@@ -110,8 +110,8 @@ function variable_get($name, $default = null, $createit_comment = null) {
* of serialization as necessary.
*/
function variable_set($name, $value, $comment = null) {
- global $conf, $db, $err, $hooks;
- $err->log('variable', 'variable_set', '+' . serialize($value) . '+' . $comment . '+');
+ global $conf, $db, $msg, $hooks;
+ $msg->log('variable', 'variable_set', '+' . serialize($value) . '+' . $comment . '+');
variable_init_maybe();