60 var
$l_editor_font=array(
"Arial, Helvetica, Sans-serif",
"Times, Bookman, Serif",
"Courier New, Courier, Fixed");
63 var
$l_editor_size=array(
"18px",
"14px",
"12px",
"10px",
"8px",
"0.8em",
"0.9em",
"1em",
"1.1em",
"1.2em");
68 $this->l_mode=array( 0=>_(
"1 column, detailed"), 1=>_(
"2 columns, short"), 2=>_(
"3 columns, short") );
69 $this->l_tgz=array( 0=>_(
"tgz (Linux)"), 1=>_(
"tar.bz2 (Linux)"), 2=>_(
"zip (Windows/Dos)"), 3=>_(
"tar.Z (Unix)") );
70 $this->l_icons=array( 0=>_(
"No"), 1=>_(
"Yes") );
71 $this->l_createfile=array( 0=>_(
"Go back to the file manager"), 1=>_(
"Edit the newly created file") );
76 'title' => _(
"File browser"),
77 'ico' =>
'images/folder.png',
78 'link' =>
'bro_main.php',
99 $root_alternc =
$root ;
103 $file = basename($dir);
104 $dir = dirname($dir);
105 $dir=realpath(
$root.
"/".$dir);
112 $dir = $dir .
'/' . $file;
114 # Si on tente de mettre un '..' alors erreur
115 if ( preg_match(
"/\/\.\.\//", $dir) || preg_match(
"/\/\.\.$/", $dir) ) {
120 $dir=substr($dir,strlen(
$root));
125 $dir=$root_alternc . substr($dir,strlen(
$root));
127 if (substr($dir,-1)==
"/") {
128 return substr($dir,0,strlen($dir)-1);
160 $old_enabled = $admin->enabled;
161 $admin->enabled =
true;
162 $member = $admin->get(
$uid);
163 $admin->enabled = $old_enabled;
183 $db->query(
"UPDATE browser SET lastdir='$dir' WHERE uid='$cuid';");
185 if (! file_exists($absolute)) {
186 $err->raise(
'bro',_(
"This directory do not exist"));
189 if ($dir = @opendir($absolute)) {
190 while (($file = readdir($dir)) !==
false) {
191 if ($file!=
"." && $file!=
"..") {
192 $c[]=array(
"name"=>$file,
"size"=>$this->
fsize($absolute.
"/".$file, $showdirsize),
"date"=>filemtime($absolute.
"/".$file),
"type"=> (!is_dir($absolute.
"/".$file)) );
198 usort (
$c, array(
"m_bro",
"_sort_filelist_name"));
214 $db->query(
"SELECT * FROM browser WHERE uid='$cuid';");
215 if ($db->num_rows()==0) {
216 $db->query(
"INSERT INTO browser (editsizex, editsizey, listmode, showicons, downfmt, createfile, showtype, uid, editor_font, editor_size) VALUES (70, 21, 0, 0, 0, 0, 0, '$cuid','Arial, Helvetica, Sans-serif','12px');");
217 $db->query(
"SELECT * FROM browser WHERE uid='$cuid';");
239 function SetPrefs($editsizex, $editsizey, $listmode, $showicons, $downfmt, $createfile, $showtype, $editor_font, $editor_size, $golastdir) {
241 $editsizex=intval($editsizex); $editsizey=intval($editsizey);
242 $listmode=intval($listmode); $showicons=intval($showicons);
243 $showtype=intval($showtype); $downfmt=intval($downfmt);
244 $createfile=intval($createfile); $golastdir=intval($golastdir);
245 $db->query(
"SELECT * FROM browser WHERE uid='$cuid';");
246 if ($db->num_rows()==0) {
247 $db->query(
"INSERT INTO browser (editsizex, editsizey, listmode, showicons, downfmt, createfile, showtype, uid, editor_font, editor_size, golastdir) VALUES (70, 21, 0, 0, 0, 0, 0, '".$this->uid.
"','Arial, Helvetica, Sans-serif','12px',1);");
249 $db->query(
"UPDATE browser SET editsizex='$editsizex', editsizey='$editsizey', listmode='$listmode', showicons='$showicons', downfmt='$downfmt', createfile='$createfile', showtype='$showtype', editor_font='$editor_font', editor_size='$editor_size', golastdir='$golastdir' WHERE uid='$cuid';");
262 if (!strpos($file,
".") && substr($file,0,1)!=
".") {
265 $t=explode(
".",$file);
269 $ext=
$t[count(
$t)-1];
271 if (!
isset($bro_icon[$ext]) || ! $bro_icon[$ext]) {
274 return $bro_icon[$ext].
".png";
288 if (!strpos($file,
".") && substr($file,0,1)!=
".") {
291 $t=explode(
".",$file);
295 $ext=
$t[count(
$t)-1];
297 if (empty($bro_type[$ext])) {
300 return $bro_type[$ext];
313 function fsize($file, $showdirsize =
false) {
321 return filesize($file);
334 if ($handle = opendir($dir)) {
335 while (
false !== ($file = readdir($handle))) {
336 $nextpath = $dir .
'/' . $file;
338 if ($file !=
'.' && $file !=
'..' && !is_link($nextpath)) {
339 if (is_dir($nextpath)) {
340 $totalsize += $this->
dirsize($nextpath);
341 } elseif (is_file ($nextpath)) {
342 $totalsize += filesize($nextpath);
363 if ($absolute && (!file_exists($absolute))) {
364 if (!mkdir($absolute,00777,
true)) {
365 $err->raise(
"bro",_(
"Cannot create the requested directory. Please check the permissions"));
368 $db->query(
"UPDATE browser SET crff=1 WHERE uid='$cuid';");
371 $err->raise(
"bro",_(
"File or folder name is incorrect"));
387 if (!$absolute || file_exists($absolute)) {
388 $err->raise(
"bro",_(
"File or folder name is incorrect"));
391 if (!file_exists($absolute)) {
392 if (!@touch($absolute)) {
393 $err->raise(
"bro",_(
"Cannot create the requested file. Please check the permissions"));
397 $db->query(
"UPDATE browser SET crff=0 WHERE uid='$cuid';");
412 if (!$absolute && strpos(
$root,$absolute) === 0 && strlen($absolute) > (strlen(
$root)+1) ) {
413 $err->raise(
"bro",_(
"File or folder name is incorrect"));
416 for (
$i=0;
$i<count($file_list);
$i++) {
417 $file_list[
$i]=
ssla($file_list[
$i]);
418 if (!strpos($file_list[$i],
"/") && file_exists($absolute.
"/".$file_list[$i])) {
419 $this->
_delete($absolute.
"/".$file_list[$i]);
437 $err->raise(
"bro",_(
"File or folder name is incorrect"));
440 $alea=
".".time().rand(1000,9999);
441 for (
$i=0;
$i<count($old);
$i++) {
444 if (!strpos($old[$i],
"/") && !strpos($new[$i],
"/")) {
445 @rename($absolute.
"/".$old[$i],$absolute.
"/".$old[$i].$alea);
448 for (
$i=0;
$i<count($old);
$i++) {
449 if (!strpos($old[
$i],
"/") && !strpos($new[$i],
"/")) {
450 @rename($absolute.
"/".$old[$i].$alea,$absolute.
"/".$new[$i]);
469 $err->raise(
"bro",_(
"File or folder name is incorrect"));
473 if ($new[0] !=
'/') {
474 $new = $old .
'/' . $new;
479 $err->raise(
"bro",_(
"File or folder name is incorrect"));
483 $err->raise(
"bro",_(
"You cannot move or copy a file to the same folder"));
488 if (!strpos(
$d[$i],
"/") && file_exists($old.
"/".
$d[$i]) && !file_exists($new.
"/".
$d[$i])) {
489 if (!rename($old.
"/".
$d[$i],$new.
"/".
$d[$i]))
490 $err->raise(
"bro",
"error renaming $old/$d[$i] -> $new/$d[$i]");
509 $err->raise(
"bro",_(
"File or folder name is incorrect"));
514 if (!strpos(
$d[$i],
"/")) {
515 $m = fileperms($absolute.
"/".
$d[$i]);
519 if ($perm[$i][
'w']) {
524 chmod($absolute.
"/".
$d[$i], $m);
526 echo
"chmod " . sprintf(
'%o', $m) .
" file, was " . sprintf(
'%o', fileperms($absolute.
"/".
$d[$i])).
" -- " . $perm[
$i][
'w'];
546 $err->raise(
"bro",_(
"File or folder name is incorrect"));
549 if (!strpos($_FILES[
'userfile'][
'name'],
"/")) {
550 if ($_FILES[
'userfile'][
'error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES[
'userfile'][
'tmp_name'])) {
551 if (!file_exists($absolute.
"/".$_FILES[
'userfile'][
'name'])) {
552 @touch($absolute.
"/".$_FILES[
'userfile'][
'name']);
554 if (@move_uploaded_file($_FILES[
'userfile'][
'tmp_name'], $absolute.
"/".$_FILES[
'userfile'][
'name'])) {
555 $action->fix_file($absolute.
"/".$_FILES[
'userfile'][
'name']);
556 return $absolute.
"/".$_FILES[
'userfile'][
'name'];
558 $err->raise(
"bro",_(
"Cannot create the requested file. Please check the permissions"));
563 $err->log(
"bro",
"uploadfile",
"Problem when uploading a file");
564 switch ( $_FILES[
'userfile'][
'error'] ) {
565 case UPLOAD_ERR_INI_SIZE:
566 $erstr=_(
"The uploaded file exceeds the max file size allowed");
568 case UPLOAD_ERR_FORM_SIZE:
569 case UPLOAD_ERR_PARTIAL:
570 case UPLOAD_ERR_NO_FILE:
571 case UPLOAD_ERR_NO_TMP_DIR:
572 case UPLOAD_ERR_CANT_WRITE:
573 case UPLOAD_ERR_EXTENSION:
575 $erstr=_(
"Undefined error ").$_FILES[
'userfile'][
'error'];
578 $err->raise(
"bro",_(
"Error during the upload of the file: ").$erstr);
582 return $absolute.
"/".$_FILES[
'userfile'][
'name'];
597 if (is_null($dest)) {
598 $dest = dirname($file);
602 if (!$file || !$dest) {
603 $err->raise(
"bro",_(
"File or folder name is incorrect"));
606 $file = escapeshellarg($file);
607 $dest_to_fix = $dest;
608 $dest = escapeshellarg($dest);
609 #$dest_to_fix=str_replace(getuserpath(),'',$dest);
613 exec(
"tar -xf $file -C $dest", $void, $ret);
615 exec(
"tar -xjf $file -C $dest", $void, $ret);
618 $cmd =
"unzip -o $file -d $dest";
619 exec($cmd, $void, $ret);
622 $cmd =
"gunzip $file";
623 exec($cmd, $void, $ret);
626 $err->raise(
"bro",_(
"I cannot find a way to extract the file %s, it is an unsupported compressed format"), $file);
629 $action->fix_dir($dest_to_fix);
641 $err->raise(
"bro",_(
"File or folder name is incorrect"));
646 $err->raise(
"bro",_(
"File or folder name is incorrect"));
650 $err->raise(
"bro",_(
"You cannot move or copy a file to the same folder"));
655 if (!strpos(
$d[$i],
"/") && file_exists($old.
"/".
$d[$i]) && !file_exists($new.
"/".
$d[$i])) {
676 $src = escapeshellarg($src);
677 $dest = escapeshellarg($dest);
678 exec(
"cp -Rpf $src $dest", $void, $ret);
680 $err->raise(
"bro",
"Errors happened while copying the source to destination. cp return value: %d", $ret);
696 function PathList($path,$action, $justparent=
false) {
698 $a=explode(
"/",$path);
699 if (!is_array($a)) $a=array($a);
703 return "<a href=\"$action?R=".urlencode($a[count($a)-2].
'/').
"\">↑</a>";
705 for(
$i=0;
$i<count($a);
$i++) {
708 $c.=
"<a href=\"$action?R=".urlencode(
$R).
"\">".$a[
$i].
"</a> / ";
728 if (!strpos($file,
"/")) {
729 $absolute.=
"/".$file;
730 if (file_exists($absolute)) {
731 $std=str_replace(
"<",
"<",str_replace(
"&",
"&",file_get_contents($absolute)));
733 $err->raise(
"bro",_(
"Cannot read the requested file. Please check the permissions"));
737 $err->raise(
"bro",_(
"File or folder name is incorrect"));
763 if (substr($dir,0,1)==
"/") $dir=substr($dir,1);
764 if (substr($dir,-1)==
"/") $dir=substr($dir,0,-1);
765 $dir=str_replace(
"%2F",
"/", urlencode($dir));
766 $name=urlencode($name);
767 if (!@$this->cacheurl[
"d".$dir]) {
769 $end=
""; $beg=$dir; $tofind=
true;
771 $db->query(
"SELECT sub,domaine FROM sub_domaines WHERE compte='$cuid'
772 AND type=0 AND (valeur='/$beg/' or valeur='/$beg');");
774 if ($db->num_rows()) {
776 $this->cacheurl[
"d".$dir]=
"http://".$db->f(
"sub").ife($db->f(
"sub"),
".").$db->f(
"domaine").$end;
778 if (!$beg && $tofind) {
780 $this->cacheurl[
"d".$dir]=
"-";
783 if (($tt=strrpos($beg,
"/"))!==
false) {
784 $end=substr($beg,$tt).$end;
785 $beg=substr($beg,0,$tt);
792 if ($this->cacheurl[
"d".$dir] && $this->cacheurl[
"d".$dir]!=
"-") {
793 return $this->cacheurl[
"d".$dir].
"/".$name;
805 $absolute=
"$dir/$name";
808 $err->raise(
'bro',_(
"File not in authorized directory"));
812 $finfo = finfo_open(FILEINFO_MIME_TYPE);
813 $mime = finfo_file($finfo,$absolute);
814 if ( substr($mime,0,5)==
"text/" || $mime ==
"application/x-empty" || $mime ==
"inode/x-empty") {
825 if ($parts = explode(
".", $name)) {
826 $ext = array_pop($parts);
831 $ext = array_pop($parts) . $ext;
850 if ($parts = explode(
".", $name)) {
851 $ext = array_pop($parts);
852 $ext2 = array_pop($parts) .
'.'.$ext;
853 if ( $ext==
'sql' or $ext2==
'sql.gz')
return true;
864 $err->log(
"bro",
"download_link");
865 header(
"Content-Disposition: attachment; filename=$file");
866 header(
"Content-Type: application/force-download");
867 header(
"Content-Transfer-Encoding: binary");
878 if (!strpos($file,
"/")) {
879 $absolute.=
"/".$file;
880 if (file_exists($absolute)) {
884 $err->raise(
"bro",_(
"File or folder name is incorrect"));
903 if (!strpos($file,
"/")) {
904 $absolute.=
"/".$file;
905 if (file_exists($absolute)) {
906 if (! file_put_contents($absolute,
$texte ) ) {
907 $err->raise(
"bro",_(
"Cannot edit the requested file. Please check the permissions"));
912 $err->raise(
"bro",_(
"File or folder name is incorrect"));
925 header(
"Content-Disposition: attachment; filename=".$mem->user[
"login"].
".Z");
926 header(
"Content-Type: application/x-Z");
927 header(
"Content-Transfer-Encoding: binary");
930 passthru(
"/bin/tar -cZ -C ".
getuserpath().
"/".$mem->user[
"login"].
"/ $d");
941 header(
"Content-Disposition: attachment; filename=".$mem->user[
"login"].
".tgz");
942 header(
"Content-Type: application/x-tgz");
943 header(
"Content-Transfer-Encoding: binary");
957 header(
"Content-Disposition: attachment; filename=".$mem->user[
"login"].
".tar.bz2");
958 header(
"Content-Type: application/x-bzip2");
959 header(
"Content-Transfer-Encoding: binary");
973 header(
"Content-Disposition: attachment; filename=".$mem->user[
"login"].
".zip");
974 header(
"Content-Type: application/x-zip");
975 header(
"Content-Transfer-Encoding: binary");
978 passthru(
"/usr/bin/zip -r - $d");
987 if ($a[
"type"] && !$b[
"type"])
return 1;
988 if ($b[
"type"] && !$a[
"type"])
return -1;
989 return $a[
"name"]>$b[
"name"];
1003 if (is_dir($file)) {
1004 $handle = opendir($file);
1005 while($filename = readdir($handle)) {
1006 if ($filename !=
"." && $filename !=
"..") {
1007 $this->
_delete($file.
"/".$filename);
1024 $err->log(
"bro",
"export_conf");
1025 $str=
"<table border=\"1\"><caption> Browser </caption>\n";
1026 $str=
" <browser>\n";
1030 foreach ($pref as $k=>$v) {
1032 $str.=
" <$k>$v</$k>\n";
1036 $str.=
" </browser>\n";
1048 $err->log(
"bro",
"export_data");
1052 $err->raise(
"bro",_(
"Cannot create the requested directory. Please check the permissions"));
1054 $timestamp=date(
"H:i:s");
1059 if(exec(
"/bin/tar cvf - ".
getuserpath().
"/ | gzip -9c > ".$dir.
"/".$mem->user[
'login'].
"_html_".$timestamp.
".tar.gz")){
1060 $err->log(
"bro",
"export_data_succes");
1062 $err->log(
"bro",
"export_data_failed");
1069 return min(ini_get(
'post_max_size'), ini_get(
'upload_max_filesize'));