39 $this->srv_name =
variable_get(
'ftp_human_name',
'%%FQDN%%',
'Human name for FTP server', array(array(
'desc'=>
'Name',
'type'=>
'string')));
48 return array(
"ftp"=>
"FTP accounts");
53 $q = $quota->getquota(
"ftp");
56 'title' => _(
"FTP accounts"),
57 'ico' =>
'images/ftp.png',
63 if ( $quota->cancreate(
"ftp") ) {
66 'ico' =>
'images/new.png',
67 'txt' => _(
"Create a new ftp account"),
68 'url' =>
"ftp_edit.php?create=1",
76 'txt' => _(
"FTP accounts list"),
77 'url' =>
"ftp_list.php"
93 if (empty($tt) || !is_array($tt))
return $c;
95 $c[
'values'][$v[
'id']]=$v[
'login'];
105 $err->raise(
'ftp', _(
"This account do not exist or is not of this account"));
108 if ( $status == null ){
109 if ($jj[0][
'enabled'] ==
true ) { $status=0;}
114 $status = ($status?
'true':
'false');
116 if ( ! $db->query(
"UPDATE ftpusers SET enabled = $status WHERE uid = '$cuid' AND id = '$id' ;") ) {
117 $err->raise(
'ftp', _(
"Error during update"));
136 $err->log(
"ftp",
"get_list");
138 $db->query(
"SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' ORDER BY name;");
139 if ($db->num_rows()) {
140 while ($db->next_record()) {
143 "login"=>$db->f(
"name"),
144 "enabled"=>$db->f(
"enabled"),
146 "dir"=>$db->f(
"homedir")
151 $err->raise(
"ftp",_(
"No FTP account found"));
164 $err->log(
"ftp",
"get_ftp_details",$id);
166 $db->query(
"SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' AND id='$id';");
167 if ($db->num_rows()) {
170 $regexp=
"/^".preg_quote(
getuserpath(),
"/").
"\/(.*)$/";
171 $tr=preg_match($regexp, $db->f(
"homedir"),$match);
173 $lg=explode(
"_",$db->f(
"name"));
174 if ((!is_array($lg)) || (count($lg)!=2)) {
175 $lg[0]=$db->f(
"name");
183 "enabled"=>$db->f(
"enabled")
187 $err->raise(
"ftp",_(
"This FTP account does not exist"));
200 $r[]=$mem->user[
"login"];
201 $db->query(
"SELECT domaine FROM domaines WHERE compte='$cuid' ORDER BY domaine;");
202 while ($db->next_record()) {
203 $r[]=$db->f(
"domaine");
214 $vv = array(
'_'=>
'1',
' '=>0);
215 foreach ($vv as $k=>$n) {
216 if (substr_count($l, $k) > $n ) {
217 $err->raise(
'ftp', sprintf(_(
"FTP login is incorrect: too many '%s'"), $k));
223 if ( ! preg_match(
"/^[A-Za-z0-9_\.\-]+$/", $l) ) {
224 $err->raise(
'ftp', _(
"FTP login is incorrect"));
241 if ($current==
$val)
$c=
" selected=\"selected\"";
else $c=
"";
242 echo
"<option$c>$val</option>";
258 $err->log(
"ftp",
"put_ftp_details",$id);
259 $db->query(
"SELECT count(*) AS cnt FROM ftpusers WHERE id='$id' and uid='$cuid';");
261 if (!$db->f(
"cnt")) {
262 $err->raise(
"ftp",_(
"This FTP account does not exist"));
265 $dir=$bro->convertabsolute($dir);
266 if (substr($dir,0,1)==
"/") {
270 if (!in_array($prefixe,
$r)) {
271 $err->raise(
"ftp",_(
"The chosen prefix is not allowed"));
274 $lo=$mem->user[
"login"];
276 $full_login=$prefixe;
277 if ($login) $full_login.=
"_".$login;
278 if (! $this->
check_login($full_login) )
return false;
279 $db->query(
"SELECT COUNT(*) AS cnt FROM ftpusers WHERE id!='$id' AND name='$full_login';");
282 $err->raise(
"ftp",_(
"This FTP account already exists"));
286 if (!file_exists($absolute)) {
287 system(
"/bin/mkdir -p $absolute");
289 if (!is_dir($absolute)) {
290 $err->raise(
"ftp",_(
"The directory cannot be created"));
296 if (is_callable(array($admin,
"checkPolicy"))) {
297 if (!$admin->checkPolicy(
"ftp",$prefixe.$login,$pass)) {
301 $encrypted_password =
_md5cr($pass,strrev(microtime(
true)));
302 $db->query(
"UPDATE ftpusers SET name='".$full_login.
"', password='', encrypted_password='$encrypted_password', homedir='$absolute', uid='$cuid' WHERE id='$id';");
304 $db->query(
"UPDATE ftpusers SET name='".$full_login.
"', homedir='$absolute', uid='$cuid' WHERE id='$id';");
317 $err->log(
"ftp",
"delete_ftp",$id);
318 $db->query(
"SELECT name FROM ftpusers WHERE id='$id' and uid='$cuid';");
320 $name=$db->f(
"name");
322 $err->raise(
"ftp",_(
"This FTP account does not exist"));
325 $db->query(
"DELETE FROM ftpusers WHERE id='$id'");
338 function add_ftp($prefixe,$login,$pass,$dir) {
340 $err->log(
"ftp",
"add_ftp",$prefixe.
"_".$login);
341 $dir=$bro->convertabsolute($dir);
342 if (substr($dir,0,1)==
"/") {
347 $err->raise(
"ftp",_(
"Password can't be empty"));
350 if (!in_array($prefixe,
$r) || $prefixe==
"") {
351 $err->raise(
"ftp",_(
"The chosen prefix is not allowed"));
354 $full_login=$prefixe;
355 if ($login) $full_login.=
"_".$login;
356 if ( !$this->
check_login($full_login) )
return false;
357 $db->query(
"SELECT count(*) AS cnt FROM ftpusers WHERE name='".$full_login.
"'");
360 $err->raise(
"ftp",_(
"This FTP account already exists"));
363 $db->query(
"SELECT login FROM membres WHERE uid='$cuid';");
368 if (!file_exists($absolute)) {
369 system(
"/bin/mkdir -p $absolute");
371 if (!is_dir($absolute)) {
372 $err->raise(
"ftp",_(
"The directory cannot be created"));
377 if (is_callable(array($admin,
"checkPolicy"))) {
378 if (!$admin->checkPolicy(
"ftp",$full_login,$pass)) {
383 if ($quota->cancreate(
"ftp")) {
384 $encrypted_password =
_md5cr($pass,strrev(microtime(
true)));
385 $db->query(
"INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ('".$full_login.
"', '', '$encrypted_password', '$absolute', '$cuid')");
388 $err->raise(
"ftp",_(
"Your FTP account quota is over. You cannot create more ftp accounts"));
400 $err->log(
"ftp",
"is_ftp",$dir);
401 $lo=$mem->user[
"login"];
403 if (substr($dir,0,1)==
"/") $dir=substr($dir,1);
404 $db->query(
"SELECT id FROM ftpusers WHERE homedir='".
getuserpath().
"/$dir';");
405 if ($db->num_rows()) {
420 $err->log(
"ftp",
"alternc_del_domain",
$dom);
421 $db->query(
"DELETE FROM ftpusers WHERE uid='$cuid' AND ( name LIKE '$dom\_%' OR name LIKE '$dom') ");
432 $err->log(
"ftp",
"alternc_del_member");
433 $db->query(
"DELETE FROM ftpusers WHERE uid='$cuid'");
446 $err->log(
"ftp",
"getquota");
447 $q=Array(
"name"=>
"ftp",
"description"=>_(
"FTP accounts"),
"used"=>0);
448 $db->query(
"SELECT COUNT(*) AS cnt FROM ftpusers WHERE uid='$cuid'");
449 if ($db->next_record()) {
450 $q[
'used']=$db->f(
"cnt");
464 $err->log(
"ftp",
"export");
467 foreach ($f as
$d=>$v) {
468 $str.=
" <login>".($v[
"login"]).
"</login>\n";
469 $str.=
" <password>".($v[
"encrypted_password"]).
"</password>\n";
470 $str.=
" <directory>".($v[
"dir"]).
"<directory>\n";
485 "ftp" => array(
"port" => 21,
"protocol" =>
"tcp",
"mandatory" => 1),