Permet d'activer/désactiver un compte FTP

Fix #1421
This commit is contained in:
Alan Garcia 2013-03-01 07:52:50 +00:00
parent 93728f99ae
commit 89920d549f
6 changed files with 80 additions and 4 deletions

1
.gitattributes vendored
View File

@ -150,6 +150,7 @@ bureau/admin/ftp_del.php -text
bureau/admin/ftp_doedit.php -text
bureau/admin/ftp_edit.php -text
bureau/admin/ftp_list.php -text
bureau/admin/ftp_switch_enable.php -text
bureau/admin/head.php -text
bureau/admin/hippo_bleue.gif -text
bureau/admin/hta_add.php -text

View File

@ -69,7 +69,7 @@ if (isset($error) && $error && !$noftp) {
<form method="post" action="ftp_del.php">
<table class="tlist">
<tr><th colspan="2"> </th><th><?php __("Username"); ?></th><th><?php __("Folder"); ?></th></tr>
<tr><th colspan="2"> </th><th><?php __("Enabled"); ?></th><th><?php __("Username"); ?></th><th><?php __("Folder"); ?></th></tr>
<?php
reset($r);
$col=1;
@ -81,6 +81,15 @@ while (list($key,$val)=each($r))
<td align="center"><input type="checkbox" class="inc" id="del_<?php echo $val["id"]; ?>" name="del_<?php echo $val["id"]; ?>" value="<?php echo $val["id"]; ?>" /></td>
<td><div class="ina"><a href="ftp_edit.php?id=<?php echo $val["id"] ?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div></td>
<td><a href='ftp_switch_enable.php?id=<?php echo $val['id'].'&status='.( ($val['enabled'])?'0':'1' ) ;?>' onClick='return confirm("<?php __("Are you sure you want to change his status?"); ?>");'><?php
if ( $val['enabled']) {
echo "<img src='images/check_ok.png' alt=\""._("Enabled")."\"/>";
} else {
echo "<img src='images/check_no.png' alt=\""._("Disabled")."\"/>";
}
?></a></td>
<td><label for="del_<?php echo $val["id"]; ?>"><?php echo $val["login"] ?></label>
<input type='hidden' name='names[<?php echo $val['id'];?>]' value='<?php echo $val["login"] ?>' >
</td>

View File

@ -0,0 +1,36 @@
<?php
/*
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2000-2012 by the AlternC Development Team.
https://alternc.org/
----------------------------------------------------------------------
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
*/
require_once("../class/config.php");
$fields = array (
"id" =>array ("get","integer",""),
"status" =>array ("get","integer",null),
);
getFields($fields);
$ftp->switch_enabled($id,$status);
require_once('ftp_list.php');

View File

@ -98,6 +98,30 @@ class m_ftp {
return $c;
}
// Switch enabled status of an account
function switch_enabled($id,$status=null) {
global $cuid, $db, $err;
if (! $jj = $this->get_ftp_details($id)) {
$err->raise('ftp', _("This account do not exist or is not of this account"));
return false;
}
if ( $status == null ){
if ($jj[0]['enabled'] == true ) { $status=0;}
else { $status=1; }
}
// Be sure what is in $status, in case of it was a parameter
$status = ($status?'true':'false');
if ( ! $db->query("UPDATE ftpusers SET enabled = $status WHERE uid = '$cuid' AND id = '$id' ;") ) {
$err->raise('ftp', _("Error during update"));
return false;
} else {
return true ;
}
}
/* ----------------------------------------------------------------- */
/** Retourne la liste des comptes FTP du compte hébergé
* Retourne la liste des comptes FTP sous forme de tableau indexé de
@ -112,12 +136,13 @@ class m_ftp {
global $db,$err,$cuid, $bro;
$err->log("ftp","get_list");
$r=array();
$db->query("SELECT id, name, homedir FROM ftpusers WHERE uid='$cuid' ORDER BY name;");
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' ORDER BY name;");
if ($db->num_rows()) {
while ($db->next_record()) {
$r[]=array(
"id"=>$db->f("id"),
"login"=>$db->f("name"),
"enabled"=>$db->f("enabled"),
//"dir"=>$match[1]
"dir"=>$db->f("homedir")
);
@ -139,7 +164,7 @@ class m_ftp {
global $db,$err,$cuid;
$err->log("ftp","get_ftp_details",$id);
$r=array();
$db->query("SELECT id, name, homedir FROM ftpusers WHERE uid='$cuid' AND id='$id';");
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' AND id='$id';");
if ($db->num_rows()) {
$db->next_record();
@ -155,7 +180,8 @@ class m_ftp {
"id"=>$db->f("id"),
"prefixe"=> $lg[0],
"login"=>$lg[1],
"dir"=>$match[1]
"dir"=>$match[1],
"enabled"=>$db->f("enabled")
);
return $r;
} else {

View File

@ -80,6 +80,7 @@ AuthPAM off
# - check that the user's ip is in an allowed range
# - add the IP range who are defined as "always from everyone" (uid=0. Not uid=2000, because we could want to have some limitation for the root account)
SQLUserWhereClause " \
enabled = true and \
true in ( \
select if(count(*)>0,false,(select value from variable where name='auth_ip_ftp_default_yes')) \
from authorised_ip_affected aia, ftpusers f \

View File

@ -12,3 +12,6 @@ CREATE TABLE IF NOT EXISTS `db_servers` (
-- Alter table membres to add
ALTER TABLE `membres` ADD db_server_id int(10) DEFAULT NULL;
-- Alter table FTP to add 'enabled'
ALTER TABLE `ftpusers` ADD `enabled` boolean NOT NULL DEFAULT TRUE ;