From 8d5953f1c4559fcc2ac3b968ab8ed1f886aafbbe Mon Sep 17 00:00:00 2001 From: quenenni Date: Tue, 15 Aug 2017 20:05:02 +0200 Subject: [PATCH] =?UTF-8?q?classe=20ftp=20+=20fichiers=20section=20admin?= =?UTF-8?q?=20associ=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bureau/admin/ftp_del.php | 11 ++--- bureau/admin/ftp_doedit.php | 21 +++----- bureau/admin/ftp_edit.php | 24 +++++---- bureau/admin/ftp_list.php | 29 +++++------ bureau/admin/ftp_switch_enable.php | 7 ++- bureau/class/m_ftp.php | 78 +++++++++++++++--------------- 6 files changed, 78 insertions(+), 92 deletions(-) diff --git a/bureau/admin/ftp_del.php b/bureau/admin/ftp_del.php index 7843791a..65253a86 100755 --- a/bureau/admin/ftp_del.php +++ b/bureau/admin/ftp_del.php @@ -29,7 +29,6 @@ */ require_once("../class/config.php"); -$error=""; // On parcours les POST_VARS et on repere les del_. reset($_POST); $lst_todel=array(); @@ -54,10 +53,9 @@ getFields($fields); if(!empty($confirm_del)) { foreach($lst_todel as $v) { $r=$ftp->delete_ftp($v); - if (!$r) { - $error.=$err->errstr()."
"; - } else { - $error.=sprintf(_("The ftp account %s has been successfully deleted"),$r)."
"; + if ($r) { + $success=true; + $msg->raise("Ok", "ftp", _("The ftp account %s has been successfully deleted"),$r); } } include("ftp_list.php"); @@ -71,7 +69,7 @@ if(!empty($confirm_del)) { @@ -87,7 +85,6 @@ if(!empty($confirm_del)) { diff --git a/bureau/admin/ftp_doedit.php b/bureau/admin/ftp_doedit.php index 4cee5a72..2c270484 100755 --- a/bureau/admin/ftp_doedit.php +++ b/bureau/admin/ftp_doedit.php @@ -39,16 +39,8 @@ $fields = array ( ); getFields($fields); -if ($pass != $passconf) { - $error = _("Passwords do not match"); - include_once("head.php"); - echo "

"._("Create a FTP account")."

$error

"; - include("foot.php"); - exit(); -} - if (! $id && !$create) { //not a creation and not an edit - $error=_("Error: neither a creation nor an edition"); + $msg->raise("Error", "ftp", _("Error: neither a creation nor an edition")); include("ftp_list.php"); exit(); } @@ -60,7 +52,6 @@ if (! $id ) { //create } if (!$r) { - $error=$err->errstr(); $is_include=true; $rr[0]["prefixe"]=$prefixe; $rr[0]["login"]=$login; @@ -68,11 +59,11 @@ if (!$r) { include_once("ftp_edit.php"); exit(); } else { -if ($create) { - $error=_("The ftp account has been successfully created"); -} else { - $error=_("The ftp account has been successfully saved"); -} + if ($create) + $msg->raise("Ok", "ftp", _("The ftp account has been successfully created")); + else + $msg->raise("Ok", "ftp", _("The ftp account has been successfully saved")); + include("ftp_list.php"); exit(); } diff --git a/bureau/admin/ftp_edit.php b/bureau/admin/ftp_edit.php index 8925f45a..d5999827 100755 --- a/bureau/admin/ftp_edit.php +++ b/bureau/admin/ftp_edit.php @@ -40,29 +40,27 @@ if ( !isset($is_include) ) { } if (!$id && !$create) { - $error=_("Neither a creation nor a edition"); + $msg->raise("Error", "ftp", _("Neither a creation nor a edition")); echo "

"._("Create a FTP account")."

"; - echo "

$error

"; + echo $msg->msg_html_all(); include_once("foot.php"); exit(); } if (!$id && $create) { //creation echo "

"._("Create a FTP account")."

"; - $rr=false; + if ( !isset($is_include) ) + $rr=false; } else { - echo "

"._("Editing a FTP account")."

"; + echo "

"._("Editing a FTP account")."

"; $rr=$ftp->get_ftp_details($id); - if (!$rr) { - $error=$err->errstr(); - } } -?> -$error

"; -} +echo $msg->msg_html_all(); + +$c=$admin->listPasswordPolicies(); +$passwd_classcount = $c['ftp']['classcount']; + ?>
@@ -88,7 +86,7 @@ if (isset($error) && $error) { - + diff --git a/bureau/admin/ftp_list.php b/bureau/admin/ftp_list.php index b950ce3d..b4faa115 100755 --- a/bureau/admin/ftp_list.php +++ b/bureau/admin/ftp_list.php @@ -38,7 +38,6 @@ getFields($fields); $noftp=false; if (!$r=$ftp->get_list($domain)) { $noftp=true; - $error=$err->errstr(); } ?> @@ -47,24 +46,20 @@ if (!$r=$ftp->get_list($domain)) {
-

- +echo $msg->msg_html_all(); -cancreate("ftp")) { ?> -

+if ($quota->cancreate("ftp")) { ?> +

-

- +

+ - show_help("ftp_list_no"); ?> -show_help("ftp_list_no"); + include_once("foot.php"); + exit; +} ?> @@ -80,7 +75,7 @@ while (list($key,$val)=each($r)) { ?> " name="del_" value="" /> - ' onClick='return confirm("");'>' onClick='return confirm("");'>"; echo "ENABLED"; // for tablesorter diff --git a/bureau/admin/ftp_switch_enable.php b/bureau/admin/ftp_switch_enable.php index a0ba0ef4..5b77d1a0 100644 --- a/bureau/admin/ftp_switch_enable.php +++ b/bureau/admin/ftp_switch_enable.php @@ -31,6 +31,11 @@ $fields = array ( getFields($fields); -$ftp->switch_enabled($id,$status); +if ($ftp->switch_enabled($id,$status)) { + if ($status) + $msg->raise("Ok", "ftp", _("The ftp account is enabled")); + else + $msg->raise("Ok", "ftp", _("The ftp account is disabled")); +} require_once('ftp_list.php'); diff --git a/bureau/class/m_ftp.php b/bureau/class/m_ftp.php index ac7b9337..ed119c67 100644 --- a/bureau/class/m_ftp.php +++ b/bureau/class/m_ftp.php @@ -102,9 +102,9 @@ class m_ftp { // Switch enabled status of an account function switch_enabled($id, $status = null) { - global $cuid, $db, $err; + global $cuid, $db, $msg; if (!$jj = $this->get_ftp_details($id)) { - $err->raise('ftp', _("This account do not exist or is not of this account")); + $msg->raise('Error', 'ftp', _("This account do not exist or is not of this account")); return false; } if ($status == null) { @@ -116,10 +116,10 @@ class m_ftp { } // Be sure what is in $status, in case of it was a parameter - $status = ($status ? 'true' : 'false'); + $status = ($status ? 1 : 0); if (!$db->query("UPDATE ftpusers SET enabled = ? WHERE uid = ? AND id = ? ;", array($status, $cuid, $id))) { - $err->raise('ftp', _("Error during update")); + $msg->raise('Error', 'ftp', _("Error during update")); return false; } else { return true; @@ -137,8 +137,8 @@ class m_ftp { * @return array Retourne le tableau des comptes */ function get_list() { - global $db, $err, $cuid; - $err->log("ftp", "get_list"); + global $db, $msg, $cuid; + $msg->log("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()) { @@ -153,7 +153,7 @@ class m_ftp { } return $r; } else { - $err->raise("ftp", _("No FTP account found")); + $msg->raise('Info', "ftp", _("No FTP account found")); return array(); } } @@ -166,8 +166,8 @@ class m_ftp { * @return array Tableau associatif contenant les infos du comptes ftp */ function get_ftp_details($id) { - global $db, $err, $cuid; - $err->log("ftp", "get_ftp_details", $id); + global $db, $msg, $cuid; + $msg->log("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()) { @@ -191,7 +191,7 @@ class m_ftp { ); return $r; } else { - $err->raise("ftp", _("This FTP account does not exist")); + $msg->raise('Error', "ftp", _("This FTP account does not exist")); return false; } } @@ -219,21 +219,21 @@ class m_ftp { * @param string $l */ function check_login($l) { - global $err; + global $msg; // special chars and the max numbers of them allowed // to be able to give a specific error $vv = array('_' => '1', ' ' => 0); foreach ($vv as $k => $n) { if (substr_count($l, $k) > $n) { // if there is more than $n $k - $err->raise('ftp', sprintf(_("FTP login is incorrect: too many '%s'"), $k)); + $msg->raise('Error', 'ftp', sprintf(_("FTP login is incorrect: too many '%s'"), $k)); return false; } } // Explicitly look for only allowed chars if (!preg_match("/^[A-Za-z0-9]+[A-Za-z0-9_\.\-]*$/", $l)) { - $err->raise('ftp', _("FTP login is incorrect")); + $msg->raise('Error', 'ftp', _("FTP login is incorrect")); return false; } return true; @@ -272,12 +272,12 @@ class m_ftp { * @return boolean TRUE si le compte a �t� modifi�, FALSE si une erreur est survenue. */ function put_ftp_details($id, $prefixe, $login, $pass, $dir) { - global $db, $err, $bro, $cuid, $admin; - $err->log("ftp", "put_ftp_details", $id); + global $db, $msg, $bro, $cuid, $admin; + $msg->log("ftp", "put_ftp_details", $id); $db->query("SELECT count(*) AS cnt FROM ftpusers WHERE id= ? and uid= ?;", array($id, $cuid)); $db->next_record(); if (!$db->f("cnt")) { - $err->raise("ftp", _("This FTP account does not exist")); + $msg->raise('Error', "ftp", _("This FTP account does not exist")); return false; } $dir = $bro->convertabsolute($dir); @@ -286,7 +286,7 @@ class m_ftp { } $r = $this->prefix_list(); if (!in_array($prefixe, $r)) { - $err->raise("ftp", _("The chosen prefix is not allowed")); + $msg->raise('Error', "ftp", _("The chosen prefix is not allowed")); return false; } @@ -300,7 +300,7 @@ class m_ftp { $db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE id!= ? AND name= ?;", array($id, $full_login)); $db->next_record(); if ($db->f("cnt")) { - $err->raise("ftp", _("This FTP account already exists")); + $msg->raise('Error', "ftp", _("This FTP account already exists")); return false; } $absolute = getuserpath() . "/$dir"; @@ -308,7 +308,7 @@ class m_ftp { system("/bin/mkdir -p $absolute"); } if (!is_dir($absolute)) { - $err->raise("ftp", _("The directory cannot be created")); + $msg->raise('Error', "ftp", _("The directory cannot be created")); return false; } if (trim($pass)) { @@ -334,13 +334,13 @@ class m_ftp { * @return boolean TRUE si le compte a ete efface, FALSE sinon. */ function delete_ftp($id) { - global $db, $err, $cuid; - $err->log("ftp", "delete_ftp", $id); + global $db, $msg, $cuid; + $msg->log("ftp", "delete_ftp", $id); $db->query("SELECT name FROM ftpusers WHERE id= ? and uid= ? ;", array($id, $cuid)); $db->next_record(); $name = $db->f("name"); if (!$name) { - $err->raise("ftp", _("This FTP account does not exist")); + $msg->raise('Error', "ftp", _("This FTP account does not exist")); return false; } $db->query("DELETE FROM ftpusers WHERE id= ? ;", array($id)); @@ -358,19 +358,19 @@ class m_ftp { * */ function add_ftp($prefixe, $login, $pass, $dir) { - global $db, $err, $quota, $bro, $cuid, $admin; - $err->log("ftp", "add_ftp", $prefixe . "_" . $login); + global $db, $msg, $quota, $bro, $cuid, $admin; + $msg->log("ftp", "add_ftp", $prefixe . "_" . $login); $dir = $bro->convertabsolute($dir); if (substr($dir, 0, 1) == "/") { $dir = substr($dir, 1); } $r = $this->prefix_list(); if (empty($pass)) { - $err->raise("ftp", _("Password can't be empty")); + $msg->raise('Error', "ftp", _("Password can't be empty")); return false; } if (!in_array($prefixe, $r) || $prefixe == "") { - $err->raise("ftp", _("The chosen prefix is not allowed")); + $msg->raise('Error', "ftp", _("The chosen prefix is not allowed")); return false; } $full_login = $prefixe; @@ -383,7 +383,7 @@ class m_ftp { $db->query("SELECT count(*) AS cnt FROM ftpusers WHERE name= ? ;", array($full_login)); $db->next_record(); if ($db->f("cnt")) { - $err->raise("ftp", _("This FTP account already exists")); + $msg->raise('Error', "ftp", _("This FTP account already exists")); return false; } $db->query("SELECT login FROM membres WHERE uid= ? ;", array($cuid)); @@ -393,7 +393,7 @@ class m_ftp { system("/bin/mkdir -p $absolute"); // FIXME replace with action } if (!is_dir($absolute)) { - $err->raise("ftp", _("The directory cannot be created")); + $msg->raise('Error', "ftp", _("The directory cannot be created")); return false; } @@ -409,7 +409,7 @@ class m_ftp { $db->query("INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ( ?, '', ?, ?, ?)", array($full_login, $encrypted_password, $absolute, $cuid)); return true; } else { - $err->raise("ftp", _("Your FTP account quota is over. You cannot create more ftp accounts")); + $msg->raise('Error', "ftp", _("Your FTP account quota is over. You cannot create more ftp accounts")); return false; } } @@ -421,8 +421,8 @@ class m_ftp { * @return boolean retourne TRUE si $dir a un compte FTP, FALSE sinon. */ function is_ftp($dir) { - global $db, $err; - $err->log("ftp", "is_ftp", $dir); + global $db, $msg; + $msg->log("ftp", "is_ftp", $dir); if (substr($dir, 0, 1) == "/") { $dir = substr($dir, 1); } @@ -442,8 +442,8 @@ class m_ftp { * @access private */ function alternc_del_domain($dom) { - global $db, $err, $cuid; - $err->log("ftp", "alternc_del_domain", $dom); + global $db, $msg, $cuid; + $msg->log("ftp", "alternc_del_domain", $dom); $db->query("DELETE FROM ftpusers WHERE uid= ? AND ( name LIKE ? OR name LIKE ?) ", array($cuid, $dom."\_%", $dom)); return true; } @@ -454,8 +454,8 @@ class m_ftp { * @access private */ function alternc_del_member() { - global $db, $err, $cuid; - $err->log("ftp", "alternc_del_member"); + global $db, $msg, $cuid; + $msg->log("ftp", "alternc_del_member"); $db->query("DELETE FROM ftpusers WHERE uid= ?", array($cuid)); return true; } @@ -469,8 +469,8 @@ class m_ftp { * @access private */ function hook_quota_get() { - global $db, $err, $cuid; - $err->log("ftp", "getquota"); + global $db, $msg, $cuid; + $msg->log("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()) { @@ -487,8 +487,8 @@ class m_ftp { * EXPERIMENTAL 'sid' function ;) */ function alternc_export_conf() { - global $db, $err; - $err->log("ftp", "export"); + global $db, $msg; + $msg->log("ftp", "export"); $f = $this->get_list(); $str = " "; foreach ($f as $d => $v) {