Merge branch 'master' of alternc.org:alternc

This commit is contained in:
Benjamin Sonntag 2014-03-27 16:56:17 +01:00
commit 9489d4f77c
32 changed files with 638 additions and 510 deletions

3
.gitattributes vendored
View File

@ -605,6 +605,7 @@ nightlybuild/READMEFIRST -text
nightlybuild/build.sh -text nightlybuild/build.sh -text
nightlybuild/mchroot.sh -text nightlybuild/mchroot.sh -text
nightlybuild/nightly.key -text nightlybuild/nightly.key -text
phpunit/tests/_datasets/domaines.yml -text
po/alternc-admintools.pot -text po/alternc-admintools.pot -text
po/fr/LC_MESSAGES/.svnignore -text po/fr/LC_MESSAGES/.svnignore -text
po/fr/LC_MESSAGES/alternc-admintools.po -text po/fr/LC_MESSAGES/alternc-admintools.po -text
@ -614,7 +615,6 @@ roundcube/class/m_roundcube.php -text
roundcube/roundcube-install -text roundcube/roundcube-install -text
roundcube/roundcube_alternc_logo.png -text roundcube/roundcube_alternc_logo.png -text
roundcube/templates/apache2/roundcube.conf -text roundcube/templates/apache2/roundcube.conf -text
roundcube/templates/logrotate.d/roundcube-core -text
roundcube/templates/roundcube/main.inc.php -text roundcube/templates/roundcube/main.inc.php -text
roundcube/templates/roundcube/plugins/managesieve/config.inc.php -text roundcube/templates/roundcube/plugins/managesieve/config.inc.php -text
roundcube/templates/roundcube/plugins/password/config.inc.php -text roundcube/templates/roundcube/plugins/password/config.inc.php -text
@ -663,6 +663,7 @@ src/quota-warning.sh -text
src/quota_delete -text src/quota_delete -text
src/quota_edit -text src/quota_edit -text
src/quota_get -text src/quota_get -text
src/quota_get_all -text
src/quota_init -text src/quota_init -text
src/rebuild_all_webconf.sh -text src/rebuild_all_webconf.sh -text
src/sendmail -text src/sendmail -text

View File

@ -35,24 +35,18 @@ if (!$admin->enabled) {
} }
$fields = array ( $fields = array (
"d" => array ("request", "array", array()), "accountList" => array ("request", "array", array()),
"del_confirm" => array("request", "string", ""), "del_confirm" => array("request", "string", ""),
); );
getFields($fields); getFields($fields);
if($del_confirm == "y"){ if($del_confirm == "y"){
if (!is_array($accountList)) { $error = "";
$accountList[] = $accountList; foreach ($accountList as $key => $val) {
}
reset($accountList);
while (list($key,$val)=each($accountList)) {
if (!$admin->checkcreator($val)) { if (!$admin->checkcreator($val)) {
__("This page is restricted to authorized staff"); __("This page is restricted to authorized staff");
exit(); exit();
} }
$error = "";
if (!($u=$admin->get($val)) || !$admin->del_mem($val)) { if (!($u=$admin->get($val)) || !$admin->del_mem($val)) {
$error .= sprintf(_("Member '%s' does not exist"),$val)."<br />"; $error .= sprintf(_("Member '%s' does not exist"),$val)."<br />";
} else { } else {
@ -77,12 +71,14 @@ if($del_confirm == "y"){
<input type="hidden" name="del_confirm" value="y" /> <input type="hidden" name="del_confirm" value="y" />
<p class="alert alert-warning"><?php __("WARNING : Confirm the deletion of the users"); ?></p> <p class="alert alert-warning"><?php __("WARNING : Confirm the deletion of the users"); ?></p>
<p> <p>
<?php <ul>
foreach($accountList as $userid){ <?php
$membre = $admin->get($userid); foreach($accountList as $userid){
echo "<input type=\"hidden\" name=\"d[]\" value=\"$userid\" />".$membre['login']."<br/>"; $membre = $admin->get($userid);
} echo "<li><input type=\"hidden\" name=\"accountList[]\" value=\"$userid\" />".$membre['login']."</li>";
?> }
?>
</ul>
</p> </p>
<blockquote> <blockquote>
<input type="submit" class="inb ok" name="confirm" value="<?php __("Yes, delete those accounts"); ?>" />&nbsp;&nbsp; <input type="submit" class="inb ok" name="confirm" value="<?php __("Yes, delete those accounts"); ?>" />&nbsp;&nbsp;

View File

@ -174,7 +174,7 @@ if (!is_array($accountList) || empty($accountList)) {
<?php if ($val["su"]) { ?> <?php if ($val["su"]) { ?>
<td id="user_<?php echo $val["uid"]; ?>">&nbsp;</td> <td id="user_<?php echo $val["uid"]; ?>">&nbsp;</td>
<?php } else { ?> <?php } else { ?>
<td><input type="checkbox" class="inc" name="d[]" id="user_<?php echo $val["uid"]; ?>" value="<?php echo $val["uid"]; ?>" /></td> <td><input type="checkbox" class="inc" name="accountList[]" id="user_<?php echo $val["uid"]; ?>" value="<?php echo $val["uid"]; ?>" /></td>
<?php } // val['su'] ?> <?php } // val['su'] ?>
<td <?php if ($val["su"]) echo 'style="color: red"'; ?>><label for="user_<?php echo $val["uid"]; ?>"><b><?php echo $val["login"] ?></b></label></td> <td <?php if ($val["su"]) echo 'style="color: red"'; ?>><label for="user_<?php echo $val["uid"]; ?>"><b><?php echo $val["login"] ?></b></label></td>
<td><a title="<?php __("Send an email"); ?>" href="mailto:<?php echo $val["mail"]; ?>"><?php echo $val["nom"] . " " . $val["prenom"] ?></a>&nbsp;</td> <td><a title="<?php __("Send an email"); ?>" href="mailto:<?php echo $val["mail"]; ?>"><?php echo $val["nom"] . " " . $val["prenom"] ?></a>&nbsp;</td>
@ -250,7 +250,7 @@ if ($mem->user["admlist"] == 1) { // SHORT MODE
if ($val["su"]) { if ($val["su"]) {
echo '<td>&nbsp;</td>'; echo '<td>&nbsp;</td>';
} else { } else {
echo '<td align="center"><input type="checkbox" class="inc" name="d[]" value="' . $val["uid"] . '" id="id_c_' . $val["uid"] . '" /></td>'; echo '<td align="center"><input type="checkbox" class="inc" name="accountList[]" value="' . $val["uid"] . '" id="id_c_' . $val["uid"] . '" /></td>';
} // if $val["su"] } // if $val["su"]
?> ?>
<td align="center"> <td align="center">

View File

@ -51,7 +51,7 @@ if ($newlogin) {
// Add an account // Add an account
if ($mail->add_slave_account($newlogin,$newpass)) { if ($mail->add_slave_account($newlogin,$newpass)) {
$error=_("The requested account address has been created. It is now allowed."); $error=_("The requested account address has been created. It is now allowed.");
$newlogin=false;$newpass=false; $newlogin='';$newpass='';
} }
} }

View File

@ -138,7 +138,7 @@ function var_input($infotype, $name, $value='') {
break; break;
case "boolean": case "boolean":
echo "<input type='hidden' name='$name' value='0' />"; // This way, there is allways something send, even if checkbox is unchecked echo "<input type='hidden' name='$name' value='0' />"; // This way, there is allways something send, even if checkbox is unchecked
echo "<input type='checkbox' id='add_$id' name='$name' value='1' ";cbox($value);echo " />"; echo "<input type='checkbox' id='add_$id' name='$name' value='1' ";cbox((bool)$value);echo " />";
break; break;
default: default:
echo "WTF ? Dunno what to do with a ".$infotype['type']; echo "WTF ? Dunno what to do with a ".$infotype['type'];
@ -251,7 +251,7 @@ foreach ( $variables->strata_order as $strata) {
foreach ($allvars['FQDN_CREATOR'] as $ttk => $ttv ) { foreach ($allvars['FQDN_CREATOR'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) { if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; "; echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>"; echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
edit_var($ttv[$var]); edit_var($ttv[$var]);
} }
echo "<br/>"; echo "<br/>";
@ -267,7 +267,7 @@ foreach ( $variables->strata_order as $strata) {
foreach ($allvars['FQDN'] as $ttk => $ttv ) { foreach ($allvars['FQDN'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) { if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $panel_url[$ttk])." &rarr; "; echo sprintf(_("Overwritted by %s"), $panel_url[$ttk])." &rarr; ";
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>"; echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
edit_var($ttv[$var]); edit_var($ttv[$var]);
} }
echo "<br/>"; echo "<br/>";
@ -283,7 +283,7 @@ foreach ( $variables->strata_order as $strata) {
foreach ($allvars['CREATOR'] as $ttk => $ttv ) { foreach ($allvars['CREATOR'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) { if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; "; echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>"; echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
edit_var($ttv[$var]); edit_var($ttv[$var]);
} }
echo "<br/>"; echo "<br/>";
@ -299,7 +299,7 @@ foreach ( $variables->strata_order as $strata) {
foreach ($allvars['MEMBER'] as $ttk => $ttv ) { foreach ($allvars['MEMBER'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) { if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; "; echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>"; echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
edit_var($ttv[$var]); edit_var($ttv[$var]);
} }
echo "<br/>"; echo "<br/>";

View File

@ -92,7 +92,7 @@ echo _("See the vars for the account")." ";
echo "<select name='member_id'>";eoption($ml, $member_id);echo "</select>"; echo "<select name='member_id'>";eoption($ml, $member_id);echo "</select>";
echo " "._("logged via")." "; echo " "._("logged via")." ";
echo "<select name='fqdn_id'>";eoption($dom->get_panel_url_list(), $fqdn_id );echo "</select> "; echo "<select name='fqdn_id'>";eoption($dom->get_panel_url_list(), $fqdn_id );echo "</select> ";
echo "<input type='submit' class='ina' value=\""; echo ehe(_("View")); echo "\" />"; echo "<input type='submit' class='ina' value=\""; ehe(_("View")); echo "\" />";
?> ?>
</form> </form>

View File

@ -37,14 +37,17 @@ if (!isset($charset) || ! $charset) $charset="UTF-8";
if (file_exists("styles/style-custom.css") ) { if (file_exists("styles/style-custom.css") ) {
echo '<link rel="stylesheet" href="styles/style-custom.css" type="text/css" />'; echo '<link rel="stylesheet" href="styles/style-custom.css" type="text/css" />';
} }
$favicon = variable_get('favicon', 'favicon.ico' ,'You can specify a favicon, for example /images/my_logo.ico', array(array('desc'=>'URL','type'=>'string')));
?> ?>
<link rel="stylesheet" href="styles/style-empty.css" type="text/css" title="Default - Desktop TNG"/> <link rel="stylesheet" href="styles/style-empty.css" type="text/css" title="Default - Desktop TNG"/>
<link rel="alternate stylesheet" href="styles/style-bluedesktop10.css" type="text/css" title="Blue Desktop 1.0" /> <link rel="alternate stylesheet" href="styles/style-bluedesktop10.css" type="text/css" title="Blue Desktop 1.0" />
<link rel="alternate stylesheet" href="styles/style-hw.css" type="text/css" title="Halloween" /> <link rel="alternate stylesheet" href="styles/style-hw.css" type="text/css" title="Halloween" />
<link rel="Shortcut Icon" href="favicon.ico" type="image/ico" /> <link rel="Shortcut Icon" href="<?php echo $favicon;?>" type="image/ico" />
<link rel="icon" href="favicon.ico" type="image/ico" /> <link rel="icon" href="<?php echo $favicon;?>" type="image/ico" />
<script src="js/alternc.js" type="text/javascript" ></script> <script src="js/alternc.js" type="text/javascript" ></script>
<script src="js/jquery.min_embedded.js" type="text/javascript"></script> <script src="js/jquery.min_embedded.js" type="text/javascript"></script>

View File

@ -35,11 +35,12 @@ reset($_POST);
while (list($key,$val)=each($_POST)) { while (list($key,$val)=each($_POST)) {
if (substr($key,0,4)=="del_") { if (substr($key,0,4)=="del_") {
// Effacement du dossier $val // Effacement du dossier $val
$r=$hta->DelDir($val); // $r=$hta->DelDir($val);
if (!$r) { $return = $hta->DelDir($val);
$error.=$err->errstr()."<br />"; if (!$return) {
$error.= $err->errstr()."<br />";
} else { } else {
$error.=sprintf(_("The protected folder %s has been successfully unprotected"),$val)."<br />"; $error.= sprintf(_("The protected folder %s has been successfully unprotected"),$val)."<br />";
} }
} }
} }

View File

@ -143,7 +143,7 @@ class system_bind {
* *
* @global m_dom $dom * @global m_dom $dom
* @param string $domain * @param string $domain
* @return string * @return array
*/ */
function get_domain_summary($domain=false) { function get_domain_summary($domain=false) {
global $dom; global $dom;

View File

@ -44,7 +44,7 @@ function fl($str) { return str_replace("<","&lt;",str_replace("\"","&quot;",$str
* @param struing $type * @param struing $type
* @return mixed * @return mixed
*/ */
function variable_get($name, $default = null, $createit_comment = null, $type=null) { function variable_get($name, $default = null, $createit_comment = null, $type = null) {
global $variables; global $variables;
return $variables->variable_get($name, $default, $createit_comment, $type); return $variables->variable_get($name, $default, $createit_comment, $type);
} }
@ -66,16 +66,16 @@ function variable_get($name, $default = null, $createit_comment = null, $type=nu
*/ */
function checkhostallow($domain,$dns) { function checkhostallow($domain,$dns) {
global $L_NS1,$L_NS2,$db,$dom; global $L_NS1,$L_NS2,$db,$dom;
$sizefound=0; $sizefound = 0;
$found=""; $found = "";
$db->query("SELECT tld,mode FROM tld;"); $db->query("SELECT tld,mode FROM tld;");
while ($db->next_record()) { while ($db->next_record()) {
list($key,$val)=$db->Record; list($key,$val) = $db->Record;
if (substr($domain,-1-strlen($key))==".".$key) { if (substr($domain,-1-strlen($key))==".".$key) {
if ($sizefound<strlen($key)) { if ($sizefound<strlen($key)) {
$sizefound=strlen($key); $sizefound = strlen($key);
$found=$key; $found = $key;
$fmode=$val; $fmode = $val;
} }
} }
} }
@ -88,10 +88,10 @@ function checkhostallow($domain,$dns) {
return -2; return -2;
if ($fmode>2) // OK, in the case 3 4 5 if ($fmode>2) // OK, in the case 3 4 5
return $found; return $found;
$n1=false; $n2=false; $n1 = false; $n2 = false;
for ($i=0;$i<count($dns);$i++) { for ($i = 0;$i<count($dns);$i++) {
if (strtolower($dns[$i])==strtolower($L_NS1)) $n1=true; if (strtolower($dns[$i])==strtolower($L_NS1)) $n1 = true;
if (strtolower($dns[$i])==strtolower($L_NS2)) $n2=true; if (strtolower($dns[$i])==strtolower($L_NS2)) $n2 = true;
} }
if ($fmode==1 && $n1) // OK if ($fmode==1 && $n1) // OK
return $found; return $found;
@ -109,16 +109,16 @@ function checkhostallow($domain,$dns) {
*/ */
function checkhostallow_nodns($domain) { function checkhostallow_nodns($domain) {
global $db; global $db;
$sizefound=0; $sizefound = 0;
$found=""; $found = "";
$db->query("SELECT tld,mode FROM tld;"); $db->query("SELECT tld,mode FROM tld;");
while ($db->next_record()) { while ($db->next_record()) {
list($key,$val)=$db->Record; list($key,$val) = $db->Record;
if (substr($domain,-1-strlen($key))==".".$key) { if (substr($domain,-1-strlen($key))==".".$key) {
if ($sizefound<strlen($key)) { if ($sizefound<strlen($key)) {
$sizefound=strlen($key); $sizefound = strlen($key);
$found=$key; $found = $key;
$fmode=$val; $fmode = $val;
} }
} }
} }
@ -149,12 +149,12 @@ function get_remote_ip() {
function checkurl($url) { function checkurl($url) {
// TODO : add a path/file check // TODO : add a path/file check
if (substr($url,0,7)!="http://" && substr($url,0,8)!="https://" && substr($url,0,6)!="ftp://") return false; if (substr($url,0,7)!="http://" && substr($url,0,8)!="https://" && substr($url,0,6)!="ftp://") return false;
if (substr($url,0,7)=="http://" ) $fq=substr($url,7); if (substr($url,0,7)=="http://" ) $fq = substr($url,7);
if (substr($url,0,8)=="https://") $fq=substr($url,8); if (substr($url,0,8)=="https://") $fq = substr($url,8);
if (substr($url,0,6)=="ftp://" ) $fq=substr($url,6); if (substr($url,0,6)=="ftp://" ) $fq = substr($url,6);
$f=explode("/",$fq); $f = explode("/",$fq);
if (!is_array($f)) $f=array($f); if (!is_array($f)) $f = array($f);
$t=checkfqdn($f[0]); $t = checkfqdn($f[0]);
if ($t) return false; if ($t) return false;
return true; return true;
} }
@ -235,8 +235,8 @@ function checkfqdn($fqdn) {
// 4. Le fqdn ne fait qu'un seul membre (il n'est donc pas fq...) // 4. Le fqdn ne fait qu'un seul membre (il n'est donc pas fq...)
if (strlen($fqdn)>255) if (strlen($fqdn)>255)
return 1; return 1;
$members=explode(".", $fqdn); $members = explode(".", $fqdn);
if (count($members)>1) $ret=0; else $ret=4; if (count($members)>1) $ret = 0; else $ret = 4;
reset($members); reset($members);
while (list ($key, $val) = each ($members)) { while (list ($key, $val) = each ($members)) {
if (strlen($val)>63) if (strlen($val)>63)
@ -262,10 +262,10 @@ function checkfqdn($fqdn) {
*/ */
function checkuserpath($path) { function checkuserpath($path) {
global $mem; global $mem;
$user=$mem->user["login"]; $user = $mem->user["login"];
$usar=substr($user,0,1); $usar = substr($user,0,1);
if (substr($path,0,1)!="/") if (substr($path,0,1)!="/")
$path="/".$path; $path = "/".$path;
$rpath = realpath(ALTERNC_HTML."/$usar/$user$path"); $rpath = realpath(ALTERNC_HTML."/$usar/$user$path");
if (!$rpath) { // if file or directory does not exist if (!$rpath) { // if file or directory does not exist
@ -310,7 +310,7 @@ function cbox($test, $echo = TRUE) {
if ($test) { if ($test) {
$return = " checked=\"checked\""; $return = " checked=\"checked\"";
} else { } else {
$return=''; $return = '';
} }
if( $echo ){ if( $echo ){
echo $return; echo $return;
@ -331,7 +331,7 @@ function selected($bool, $echo = TRUE) {
if ($bool) { if ($bool) {
$return = " selected=\"selected\""; $return = " selected=\"selected\"";
} else { } else {
$return=''; $return = '';
} }
if( $echo ){ if( $echo ){
echo $return; echo $return;
@ -347,7 +347,7 @@ function selected($bool, $echo = TRUE) {
* @param integer $affiche * @param integer $affiche
* @return string * @return string
*/ */
function ecif($test,$tr,$fa="",$affiche=1) { function ecif($test,$tr,$fa = "",$affiche = 1) {
if ($test){ if ($test){
$retour = $tr; $retour = $tr;
} }
@ -375,7 +375,7 @@ function __($str) {
* @param string $fa * @param string $fa
* @return string * @return string
*/ */
function ife($test,$tr,$fa="") { function ife($test,$tr,$fa = "") {
if ($test){ if ($test){
return $tr; return $tr;
} }
@ -388,33 +388,33 @@ function ife($test,$tr,$fa="") {
* @param integer $html * @param integer $html
* @return string * @return string
*/ */
function format_size($size,$html=0) { function format_size($size,$html = 0) {
// Retourne une taille formatt<74>e en Octets, Kilo-octets, M<>ga-octets ou Giga-Octets, avec 2 d<>cimales. // Retourne une taille formatt<74>e en Octets, Kilo-octets, M<>ga-octets ou Giga-Octets, avec 2 d<>cimales.
if ("-" == $size) { if ("-" == $size) {
return $size; return $size;
} }
$size=(float)$size; $size = (float)$size;
if ($size<1024) { if ($size<1024) {
$r=$size; $r = $size;
if ($size!=1) { if ($size!=1) {
$r.=" "._("Bytes"); $r.=" "._("Bytes");
} else { } else {
$r.=" "._("Byte"); $r.=" "._("Byte");
} }
} else { } else {
$size=$size/1024; $size = $size/1024;
if ($size<1024) { if ($size<1024) {
$r=round($size,2)." "._("Kb"); $r = round($size,2)." "._("Kb");
} else { } else {
$size=$size/1024; $size = $size/1024;
if ($size<1024) { if ($size<1024) {
$r=round($size,2)." "._("Mb"); $r = round($size,2)." "._("Mb");
} else { } else {
$size=$size/1024; $size = $size/1024;
if ($size<1024) { if ($size<1024) {
$r=round($size,2)." "._("Gb"); $r = round($size,2)." "._("Gb");
} else { } else {
$r=round($size/1024,2)." "._("Tb"); $r = round($size/1024,2)." "._("Tb");
} }
} }
} }
@ -448,17 +448,17 @@ function linkhelp($hid) {
* @return string * @return string
*/ */
function format_date($format,$date) { function format_date($format,$date) {
$d=substr($date,8,2); $d = substr($date,8,2);
$m=substr($date,5,2); $m = substr($date,5,2);
$y=substr($date,0,4); $y = substr($date,0,4);
$h=substr($date,11,2); $h = substr($date,11,2);
$i=substr($date,14,2); $i = substr($date,14,2);
if ($h>12) { if ($h>12) {
$hh=$h-12; $hh = $h-12;
$am="pm"; $am = "pm";
} else { } else {
$hh=$h; $hh = $h;
$am="am"; $am = "am";
} }
return sprintf($format,$d,$m,$y,$h,$i,$hh,$am); return sprintf($format,$d,$m,$y,$h,$i,$hh,$am);
} }
@ -482,13 +482,13 @@ function ssla($str) {
* @return string Retourne le mot de passe crypt<EFBFBD> * @return string Retourne le mot de passe crypt<EFBFBD>
* @access private * @access private
*/ */
function _md5cr($pass,$salt="") { function _md5cr($pass,$salt = "") {
if (!$salt) { if (!$salt) {
$chars="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $chars = "./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for ($i=0;$i<12;$i++) { for ($i = 0;$i<12;$i++) {
$salt.=substr($chars,(mt_rand(0,strlen($chars))),1); $salt.=substr($chars,(mt_rand(0,strlen($chars))),1);
} }
$salt="$1$".$salt; $salt = "$1$".$salt;
} }
return crypt($pass,$salt); return crypt($pass,$salt);
} }
@ -536,7 +536,7 @@ function pretty_months($months) {
* @return string Code html pour le drop-down * @return string Code html pour le drop-down
* @access private * @access private
*/ */
function duration_list($name, $selected=0) { function duration_list($name, $selected = 0) {
$res = "<select name=\"$name\" id=\"$name\" class=\"inl\">"; $res = "<select name=\"$name\" id=\"$name\" class=\"inl\">";
foreach(array(0, 1, 2, 3, 4, 6, 12, 24) as $dur) { foreach(array(0, 1, 2, 3, 4, 6, 12, 24) as $dur) {
@ -568,10 +568,10 @@ function duration_list($name, $selected=0) {
* @param string $cur * @param string $cur
* @param boolean $onedim * @param boolean $onedim
*/ */
function eoption($values,$cur,$onedim=false) { function eoption($values,$cur,$onedim = false) {
if (is_array($values)) { if (is_array($values)) {
foreach ($values as $k=>$v) { foreach ($values as $k=>$v) {
if ( $onedim ) $k=$v; if ( $onedim ) $k = $v;
echo "<option value=\"$k\""; echo "<option value=\"$k\"";
if ($k==$cur) echo " selected=\"selected\""; if ($k==$cur) echo " selected=\"selected\"";
echo ">".$v."</option>"; echo ">".$v."</option>";
@ -697,15 +697,15 @@ function list_properties_order($a, $b) {
* @param boolean $echo * @param boolean $echo
* @return string * @return string
*/ */
function pager($offset,$count,$total,$url,$before="",$after="",$echo = TRUE) { function pager($offset,$count,$total,$url,$before = "",$after = "",$echo = TRUE) {
$return = ""; $return = "";
$offset=intval($offset); $offset = intval($offset);
$count=intval($count); $count = intval($count);
$total=intval($total); $total = intval($total);
if ($offset<=0) $offset="0"; if ($offset<=0) $offset = "0";
if ($count<=1) $count="1"; if ($count<=1) $count = "1";
if ($total<=0) $total="0"; if ($total<=0) $total = "0";
if ($total<$offset) $offset=max(0,$total-$count); if ($total<$offset) $offset = max(0,$total-$count);
if ($total<=$count) { // When there is less element than 1 complete page, just don't do anything :-D if ($total<=$count) { // When there is less element than 1 complete page, just don't do anything :-D
return true; return true;
@ -722,17 +722,17 @@ function pager($offset,$count,$total,$url,$before="",$after="",$echo = TRUE) {
if ($total>(2*$count)) { // On n'affiche le pager central (0 1 2 ...) s'il y a au moins 2 pages. if ($total>(2*$count)) { // On n'affiche le pager central (0 1 2 ...) s'il y a au moins 2 pages.
$return .= " - "; $return .= " - ";
if (($total<($count*10)) && ($total>$count)) { // moins de 10 pages : if (($total<($count*10)) && ($total>$count)) { // moins de 10 pages :
for($i=0;$i<$total/$count;$i++) { for($i = 0;$i<$total/$count;$i++) {
$o=$i*$count; $o = $i*$count;
if ($offset==$o) { if ($offset==$o) {
$return .= $i." "; $return .= $i." ";
} else { } else {
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> "; $return .= "<a href = \"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
} }
} }
} else { // Plus de 10 pages, on affiche 0 1 2 , 2 avant et 2 apr<70>s la page courante, et les 3 dernieres } else { // Plus de 10 pages, on affiche 0 1 2 , 2 avant et 2 apr<70>s la page courante, et les 3 dernieres
for($i=0;$i<=2;$i++) { for($i = 0;$i<=2;$i++) {
$o=$i*$count; $o = $i*$count;
if ($offset==$o) { if ($offset==$o) {
$return .= $i." "; $return .= $i." ";
} else { } else {
@ -741,11 +741,11 @@ function pager($offset,$count,$total,$url,$before="",$after="",$echo = TRUE) {
} }
if ($offset>=$count && $offset<($total-2*$count)) { // On est entre les milieux ... if ($offset>=$count && $offset<($total-2*$count)) { // On est entre les milieux ...
// On affiche 2 avant jusque 2 apr<70>s l'offset courant mais sans d<>border sur les indices affich<63>s autour // On affiche 2 avant jusque 2 apr<70>s l'offset courant mais sans d<>border sur les indices affich<63>s autour
$start=max(3,intval($offset/$count)-2); $start = max(3,intval($offset/$count)-2);
$end=min(intval($offset/$count)+3,intval($total/$count)-3); $end = min(intval($offset/$count)+3,intval($total/$count)-3);
if ($start!=3) $return .= " ... "; if ($start!=3) $return .= " ... ";
for($i=$start;$i<$end;$i++) { for($i = $start;$i<$end;$i++) {
$o=$i*$count; $o = $i*$count;
if ($offset==$o) { if ($offset==$o) {
$return .= $i." "; $return .= $i." ";
} else { } else {
@ -756,8 +756,8 @@ function pager($offset,$count,$total,$url,$before="",$after="",$echo = TRUE) {
} else { } else {
$return .= " ... "; $return .= " ... ";
} }
for($i=intval($total/$count)-3;$i<$total/$count;$i++) { for($i = intval($total/$count)-3;$i<$total/$count;$i++) {
$o=$i*$count; $o = $i*$count;
if ($offset==$o) { if ($offset==$o) {
$return .= $i." "; $return .= $i." ";
} else { } else {
@ -769,7 +769,7 @@ function pager($offset,$count,$total,$url,$before="",$after="",$echo = TRUE) {
} }
// Shall-we show the next page link ? // Shall-we show the next page link ?
if ($offset+$count<$total) { if ($offset+$count<$total) {
$o=$offset+$count; $o = $offset+$count;
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-s)\" title=\"(Alt-s)\" accesskey=\"s\">"._("Next Page")."</a> "; $return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-s)\" title=\"(Alt-s)\" accesskey=\"s\">"._("Next Page")."</a> ";
} else { } else {
$return .= _("Next Page")." "; $return .= _("Next Page")." ";
@ -808,8 +808,8 @@ function create_pass($length = 8){
* @param string $fields_to_fill2 * @param string $fields_to_fill2
* @return int * @return int
*/ */
function display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_fill1="", $fields_to_fill2="") { function display_div_generate_password($pass_size = DEFAULT_PASS_SIZE, $fields_to_fill1 = "", $fields_to_fill2 = "") {
$id=rand(1,1000); $id = rand(1,1000);
echo "<div id='z$id' style='display:none;'><a href=\"javascript:generate_password_html('$id',$pass_size,'$fields_to_fill1','$fields_to_fill2');\">"; echo "<div id='z$id' style='display:none;'><a href=\"javascript:generate_password_html('$id',$pass_size,'$fields_to_fill1','$fields_to_fill2');\">";
__("Clic here to generate a password"); __("Clic here to generate a password");
echo "</a></div>"; echo "</a></div>";
@ -825,9 +825,9 @@ function display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_
* @param int $width * @param int $width
* @param int $height * @param int $height
*/ */
function display_browser($dir="", $caller="main.dir", $width=350, $height=450) { function display_browser($dir = "", $caller = "main.dir", $width = 350, $height = 450) {
// Browser id // Browser id
$bid="b".rand(1,1000); $bid = "b".rand(1,1000);
echo "<script type=\"text/javascript\"> echo "<script type=\"text/javascript\">
<!-- <!--
$(function() { $(function() {
@ -863,27 +863,6 @@ function display_browser($dir="", $caller="main.dir", $width=350, $height=450) {
} }
/**
* Insere un $wrap_string tous les $max caracteres dans $message
*
* @param string $message
* @param int $max
* @param string $wrap_string
* @return string
*/
function auto_wrap($message="",$max=10,$wrap_string="<wbr/>") {
$cpt = 0;
$mot = split(" ",$message);
while (isset($mot[$cpt]) && ($mot[$cpt] != "")){
if(@strlen($mot[$cpt]) > $max){
$nvmot = chunk_split ($mot[$cpt], $max, $wrap_string );
$message = str_replace($mot[$cpt], $nvmot, $message);
}
$cpt++;
}
return $message;
}
/** /**
* Converts HSV to RGB values * Converts HSV to RGB values
* ----------------------------------------------------- * -----------------------------------------------------
@ -959,9 +938,9 @@ function hexa($hex)
* @param int $p * @param int $p
* @return string * @return string
*/ */
function PercentToColor($p=0) { function PercentToColor($p = 0) {
if ($p>100) $p=100; if ($p>100) $p = 100;
if ($p<0) $p=0; if ($p<0) $p = 0;
// Pour aller de vert a rouge en passant par jaune et orange // Pour aller de vert a rouge en passant par jaune et orange
$h = 1+((100-$p)*130/100); $h = 1+((100-$p)*130/100);

View File

@ -50,7 +50,7 @@ class m_action {
function do_action() { function do_action() {
global $err, $L_INOTIFY_DO_ACTION; global $err, $L_INOTIFY_DO_ACTION;
$err->log("action", "do_action"); $err->log("action", "do_action");
if( ! touch($L_INOTIFY_DO_ACTION) ){ if( ! @touch($L_INOTIFY_DO_ACTION) ){
return FALSE; return FALSE;
} }
return TRUE; return TRUE;

View File

@ -569,11 +569,11 @@ class m_admin {
* @param int $duration * @param int $duration
* @param string $notes * @param string $notes
* @param integer $force * @param integer $force
* @param boolean $create_dom * @param string $create_dom
* @param int $db_server_id * @param int $db_server_id
* @return boolean Returns FALSE if an error occurs, TRUE if not. * @return boolean Returns FALSE if an error occurs, TRUE if not.
*/ */
function add_mem($login, $pass, $nom, $prenom, $mail, $canpass=1, $type='default', $duration=0, $notes = "", $force=0, $create_dom=false, $db_server_id) { function add_mem($login, $pass, $nom, $prenom, $mail, $canpass=1, $type='default', $duration=0, $notes = "", $force=0, $create_dom='', $db_server_id) {
global $err,$quota,$classes,$cuid,$mem,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN,$hooks,$action; global $err,$quota,$classes,$cuid,$mem,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN,$hooks,$action;
$err->log("admin","add_mem",$login."/".$mail); $err->log("admin","add_mem",$login."/".$mail);
if (!$this->enabled) { if (!$this->enabled) {
@ -1135,7 +1135,7 @@ EOF;
function checkalldom() { function checkalldom() {
global $db,$L_NS1,$L_NS2,$L_MX,$L_PUBLIC_IP; global $db,$L_NS1,$L_NS2,$L_MX,$L_PUBLIC_IP;
$checked=array(); $checked=array();
$r=$db->query("SELECT * FROM domaines ORDER BY domaine;"); $db->query("SELECT * FROM domaines ORDER BY domaine;");
$dl=array(); $dl=array();
while ($db->next_record()) { while ($db->next_record()) {
$dl[$db->Record["domaine"]]=$db->Record; $dl[$db->Record["domaine"]]=$db->Record;
@ -1179,10 +1179,14 @@ EOF;
// Check the IP: // Check the IP:
$out=array(); $out=array();
exec("dig +short A ".escapeshellarg($d["sub"].(($d["sub"]!="")?".":"").$c["domaine"]),$out); exec("dig +short A ".escapeshellarg($d["sub"].(($d["sub"]!="")?".":"").$c["domaine"]),$out);
if (!in_array($L_PUBLIC_IP,$out)) { if (! is_array($out)) { // exec dig can fail
$errstr.="subdomain '".$d["sub"]."' don't point to $L_PUBLIC_IP but to ".implode(",",$out)."\n"; $errno=1; $errstr.="Fail to get the DNS information. Try again.\n";
$errno=1; } else {
} if (!in_array($L_PUBLIC_IP,$out)) {
$errstr.="subdomain '".$d["sub"]."' don't point to $L_PUBLIC_IP but to ".implode(",",$out)."\n";
$errno=1;
}
}
} }
} }
} }
@ -1362,7 +1366,6 @@ EOF;
global $db,$classes,$hooks; global $db,$classes,$hooks;
$tmp1=array(); $tmp1=array();
$tmp2=array(); $tmp2=array();
$tmp3=array();
$policies=array(); $policies=array();
$db->query("SELECT * FROM policy;"); $db->query("SELECT * FROM policy;");
while ($db->next_record()) { while ($db->next_record()) {

View File

@ -46,34 +46,34 @@ class m_bro {
/** internal cache /** internal cache
*/ */
var $mime_desc=array(); var $mime_desc = array();
/** internal cache /** internal cache
*/ */
var $mime_icon=array(); var $mime_icon = array();
/** internal cache /** internal cache
*/ */
var $mime_type=array(); var $mime_type = array();
/** Internal cache for viewurl /** Internal cache for viewurl
*/ */
var $cacheurl=array(); var $cacheurl = array();
/** Font choice in the editor */ /** Font choice in the editor */
var $l_editor_font=array("Arial, Helvetica, Sans-serif","Times, Bookman, Serif","Courier New, Courier, Fixed"); var $l_editor_font = array("Arial, Helvetica, Sans-serif","Times, Bookman, Serif","Courier New, Courier, Fixed");
/** font size in the editor */ /** font size in the editor */
var $l_editor_size=array("18px","14px","12px","10px","8px","0.8em","0.9em","1em","1.1em","1.2em"); var $l_editor_size = array("18px","14px","12px","10px","8px","0.8em","0.9em","1em","1.1em","1.2em");
/** /**
* Constructor * Constructor
**/ **/
function m_bro() { function m_bro() {
$this->l_mode=array( 0=>_("1 column, detailed"), 1=>_("2 columns, short"), 2=>_("3 columns, short") ); $this->l_mode = array( 0=>_("1 column, detailed"), 1=>_("2 columns, short"), 2=>_("3 columns, short") );
$this->l_tgz=array( 0=>_("tgz (Linux)"), 1=>_("tar.bz2 (Linux)"), 2=>_("zip (Windows/Dos)"), 3=>_("tar.Z (Unix)") ); $this->l_tgz = array( 0=>_("tgz (Linux)"), 1=>_("tar.bz2 (Linux)"), 2=>_("zip (Windows/Dos)"), 3=>_("tar.Z (Unix)") );
$this->l_icons=array( 0=>_("No"), 1=>_("Yes") ); $this->l_icons = array( 0=>_("No"), 1=>_("Yes") );
$this->l_createfile=array( 0=>_("Go back to the file manager"), 1=>_("Edit the newly created file") ); $this->l_createfile = array( 0=>_("Go back to the file manager"), 1=>_("Edit the newly created file") );
} }
/** /**
@ -81,7 +81,7 @@ class m_bro {
* @return array * @return array
*/ */
function hook_menu() { function hook_menu() {
$obj = array( $obj = array(
'title' => _("File browser"), 'title' => _("File browser"),
'ico' => 'images/folder.png', 'ico' => 'images/folder.png',
'link' => 'bro_main.php', 'link' => 'bro_main.php',
@ -96,32 +96,32 @@ class m_bro {
/** /**
* Verifie un dossier relatif au dossier de l'utilisateur courant * Verifie un dossier relatif au dossier de l'utilisateur courant
* *
* @param string $dir * @param string $dir
* @global m_mem $mem * @global m_mem $mem
* @param string $dir Dossier absolu que l'on souhaite vérifier * @param string $dir Dossier absolu que l'on souhaite vérifier
* @param integer $strip * @param integer $strip
* @return false|string Retourne le nom du dossier vrifi, relatif au * @return false|string Retourne le nom du dossier vérifié, relatif au
* dossier de l'utilisateur courant, ventuellement corrig. * dossier de l'utilisateur courant, éventuellement corrigé.
* ou FALSE si le dossier n'est pas dans le dossier de l'utilisateur. * ou FALSE si le dossier n'est pas dans le dossier de l'utilisateur.
*/ */
function convertabsolute($dir,$strip=1) { function convertabsolute($dir,$strip = 1) {
global $mem; global $mem;
$root=$this->get_user_root($mem->user["login"]); $root = $this->get_user_root($mem->user["login"]);
// Sauvegarde du chemin de base. // Sauvegarde du chemin de base.
$root_alternc = $root ; $root_alternc = $root ;
// Passage du root en chemin rel (diffrent avec un lien) // Passage du root en chemin rel (diffrent avec un lien)
$root=realpath($root) ; $root = realpath($root) ;
// separer le chemin entre le repertoire et le fichier // separer le chemin entre le repertoire et le fichier
$file = basename($dir); $file = basename($dir);
$dir = dirname($dir); $dir = dirname($dir);
$dir=realpath($root."/".$dir); $dir = realpath($root."/".$dir);
// verifier que le repertoire est dans le home de l'usager // verifier que le repertoire est dans le home de l'usager
if (substr($dir,0,strlen($root))!=$root) { if (substr($dir,0,strlen($root)) != $root) {
return false; return false;
} }
// recomposer le chemin // recomposer le chemin
$dir = $dir . '/' . $file; $dir = $dir . '/' . $file;
# Si on tente de mettre un '..' alors erreur # Si on tente de mettre un '..' alors erreur
if ( preg_match("/\/\.\.\//", $dir) || preg_match("/\/\.\.$/", $dir) ) { if ( preg_match("/\/\.\.\//", $dir) || preg_match("/\/\.\.$/", $dir) ) {
@ -129,14 +129,14 @@ class m_bro {
} }
if ($strip) { if ($strip) {
$dir=substr($dir,strlen($root)); $dir = substr($dir,strlen($root));
} else { } else {
// si on ne strip pas, il faut enlever le chemin rel // si on ne strip pas, il faut enlever le chemin rel
// et mettre la racine d'alternc pour viter les // et mettre la racine d'alternc pour viter les
// problmes de lien depuis /var /alternc ! // problmes de lien depuis /var /alternc !
$dir=$root_alternc . substr($dir,strlen($root)); $dir = $root_alternc . substr($dir,strlen($root));
} }
if (substr($dir,-1)=="/") { if (substr($dir,-1) == "/") {
return substr($dir,0,strlen($dir)-1); return substr($dir,0,strlen($dir)-1);
} else } else
return $dir; return $dir;
@ -171,10 +171,10 @@ class m_bro {
function get_userid_root($uid) { function get_userid_root($uid) {
global $admin; global $admin;
$old_enabled = $admin->enabled; $old_enabled = $admin->enabled;
$admin->enabled = true; $admin->enabled = true;
$member = $admin->get($uid); $member = $admin->get($uid);
$admin->enabled = $old_enabled; $admin->enabled = $old_enabled;
return $this->get_user_root($member['login']); return $this->get_user_root($member['login']);
} }
@ -185,10 +185,10 @@ class m_bro {
* *
* Ce tableau contient tous les paramtres des fichiers du dossier courant * Ce tableau contient tous les paramtres des fichiers du dossier courant
* sous la forme d'un tableau index de tableaux associatifs comme suit : * sous la forme d'un tableau index de tableaux associatifs comme suit :
* $a["name"]=nom du fichier / dossier * $a["name"] = nom du fichier / dossier
* $a["size"]=Taille totale du fichier / dossier + sous-dossier * $a["size"] = Taille totale du fichier / dossier + sous-dossier
* $a["date"]=Date de dernire modification * $a["date"] = Date de dernire modification
* $a["type"]=Type du fichier (1 pour fichier, 0 pour dossier) * $a["type"] = Type du fichier (1 pour fichier, 0 pour dossier)
* *
* @global m_mysql $db * @global m_mysql $db
* @global int $cuid * @global int $cuid
@ -197,19 +197,19 @@ class m_bro {
* @param boolean $showdirsize * @param boolean $showdirsize
* @return array Le tableau contenant les fichiers de $dir, et * @return array Le tableau contenant les fichiers de $dir, et
*/ */
function filelist($dir="", $showdirsize = false) { function filelist($dir = "", $showdirsize = false) {
global $db,$cuid,$err; global $db,$cuid,$err;
$db->query("UPDATE browser SET lastdir='$dir' WHERE uid='$cuid';"); $db->query("UPDATE browser SET lastdir = '$dir' WHERE uid = '$cuid';");
$absolute=$this->convertabsolute($dir,0); $absolute = $this->convertabsolute($dir,0);
if (!$absolute || !file_exists($absolute)) { if (!$absolute || !file_exists($absolute)) {
$err->raise('bro',_("This directory do not exist")); $err->raise('bro',_("This directory do not exist"));
return false; return false;
} }
$c=array(); $c = array();
if ($dir = @opendir($absolute)) { if ($dir = @opendir($absolute)) {
while (($file = readdir($dir)) !== false) { while (($file = readdir($dir)) !== false) {
if ($file!="." && $file!="..") { if ($file!="." && $file!="..") {
$c[]=array("name"=>$file, "size"=>$this->fsize($absolute."/".$file, $showdirsize), "date"=>filemtime($absolute."/".$file), "type"=> (!is_dir($absolute."/".$file)) ); $c[] = array("name"=>$file, "size"=>$this->fsize($absolute."/".$file, $showdirsize), "date"=>filemtime($absolute."/".$file), "type"=> (!is_dir($absolute."/".$file)) );
} }
} }
closedir($dir); closedir($dir);
@ -231,10 +231,10 @@ class m_bro {
*/ */
function GetPrefs() { function GetPrefs() {
global $db,$cuid; global $db,$cuid;
$db->query("SELECT * FROM browser WHERE uid='$cuid';"); $db->query("SELECT * FROM browser WHERE uid = '$cuid';");
if ($db->num_rows()==0) { if ($db->num_rows() == 0) {
$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');"); $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');");
$db->query("SELECT * FROM browser WHERE uid='$cuid';"); $db->query("SELECT * FROM browser WHERE uid = '$cuid';");
} }
$db->next_record(); $db->next_record();
return $db->Record; return $db->Record;
@ -260,15 +260,19 @@ class m_bro {
*/ */
function SetPrefs($editsizex, $editsizey, $listmode, $showicons, $downfmt, $createfile, $showtype, $editor_font, $editor_size, $golastdir) { function SetPrefs($editsizex, $editsizey, $listmode, $showicons, $downfmt, $createfile, $showtype, $editor_font, $editor_size, $golastdir) {
global $db,$cuid; global $db,$cuid;
$editsizex=intval($editsizex); $editsizey=intval($editsizey); $editsizex = intval($editsizex);
$listmode=intval($listmode); $showicons=intval($showicons); $editsizey = intval($editsizey);
$showtype=intval($showtype); $downfmt=intval($downfmt); $listmode = intval($listmode);
$createfile=intval($createfile); $golastdir=intval($golastdir); $showicons = intval($showicons);
$db->query("SELECT * FROM browser WHERE uid='".intval($cuid)."';"); $showtype = intval($showtype);
if ($db->num_rows()==0) { $downfmt = intval($downfmt);
$createfile = intval($createfile);
$golastdir = intval($golastdir);
$db->query("SELECT * FROM browser WHERE uid = '".intval($cuid)."';");
if ($db->num_rows() == 0) {
$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, '".intval($cuid)."','Arial, Helvetica, Sans-serif','12px',1);"); $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, '".intval($cuid)."','Arial, Helvetica, Sans-serif','12px',1);");
} }
$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='".intval($cuid)."';"); $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 = '".intval($cuid)."';");
return true; return true;
} }
@ -286,11 +290,11 @@ class m_bro {
if (!strpos($file,".") && substr($file,0,1)!=".") { if (!strpos($file,".") && substr($file,0,1)!=".") {
return "file.png"; return "file.png";
} }
$t=explode(".",$file); $t = explode(".",$file);
if (!is_array($t)) if (!is_array($t))
$ext=$t; $ext = $t;
else else
$ext=$t[count($t)-1]; $ext = $t[count($t)-1];
// Now seek the extension // Now seek the extension
if (!isset($bro_icon[$ext]) || ! $bro_icon[$ext]) { if (!isset($bro_icon[$ext]) || ! $bro_icon[$ext]) {
return "file.png"; return "file.png";
@ -314,11 +318,11 @@ class m_bro {
if (!strpos($file,".") && substr($file,0,1)!=".") { if (!strpos($file,".") && substr($file,0,1)!=".") {
return "File"; return "File";
} }
$t=explode(".",$file); $t = explode(".",$file);
if (!is_array($t)) if (!is_array($t))
$ext=$t; $ext = $t;
else else
$ext=$t[count($t)-1]; $ext = $t[count($t)-1];
// Now seek the extension // Now seek the extension
if (empty($bro_type[$ext])) { if (empty($bro_type[$ext])) {
return "File"; return "File";
@ -358,11 +362,11 @@ class m_bro {
* @return integer The total size in bytes. * @return integer The total size in bytes.
*/ */
function dirsize($dir) { function dirsize($dir) {
$totalsize = 0; $totalsize = 0;
if ($handle = opendir($dir)) { if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
$nextpath = $dir . '/' . $file; $nextpath = $dir . '/' . $file;
if ($file != '.' && $file != '..' && !is_link($nextpath)) { if ($file != '.' && $file != '..' && !is_link($nextpath)) {
if (is_dir($nextpath)) { if (is_dir($nextpath)) {
@ -390,15 +394,15 @@ class m_bro {
*/ */
function CreateDir($dir,$file) { function CreateDir($dir,$file) {
global $db,$cuid,$err; global $db,$cuid,$err;
$file=ssla($file); $file = ssla($file);
$absolute=$this->convertabsolute($dir."/".$file,0); $absolute = $this->convertabsolute($dir."/".$file,0);
#echo "$absolute"; #echo "$absolute";
if ($absolute && (!file_exists($absolute))) { if ($absolute && (!file_exists($absolute))) {
if (!mkdir($absolute,00777,true)) { if (!mkdir($absolute,00777,true)) {
$err->raise("bro",_("Cannot create the requested directory. Please check the permissions")); $err->raise("bro",_("Cannot create the requested directory. Please check the permissions"));
return false; return false;
} }
$db->query("UPDATE browser SET crff=1 WHERE uid='$cuid';"); $db->query("UPDATE browser SET crff = 1 WHERE uid = '$cuid';");
return true; return true;
} else { } else {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
@ -419,8 +423,8 @@ class m_bro {
*/ */
function CreateFile($dir,$file) { function CreateFile($dir,$file) {
global $db,$err,$cuid; global $db,$err,$cuid;
$file=ssla($file); $file = ssla($file);
$absolute=$this->convertabsolute($dir."/".$file,0); $absolute = $this->convertabsolute($dir."/".$file,0);
if (!$absolute || file_exists($absolute)) { if (!$absolute || file_exists($absolute)) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
@ -431,7 +435,7 @@ class m_bro {
return false; return false;
} }
} }
$db->query("UPDATE browser SET crff=0 WHERE uid='$cuid';"); $db->query("UPDATE browser SET crff = 0 WHERE uid = '$cuid';");
return true; return true;
} }
@ -447,14 +451,14 @@ class m_bro {
*/ */
function DeleteFile($file_list,$R) { function DeleteFile($file_list,$R) {
global $err, $mem; global $err, $mem;
$root=realpath(getuserpath()); $root = realpath(getuserpath());
$absolute=$this->convertabsolute($R,0); $absolute = $this->convertabsolute($R,0);
if (!$absolute && strpos($root,$absolute) === 0 && strlen($absolute) > (strlen($root)+1) ) { if (!$absolute && strpos($root,$absolute) === 0 && strlen($absolute) > (strlen($root)+1) ) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
} }
for ($i=0;$i<count($file_list);$i++) { for ($i = 0;$i<count($file_list);$i++) {
$file_list[$i]=ssla($file_list[$i]); $file_list[$i] = ssla($file_list[$i]);
if (!strpos($file_list[$i],"/") && file_exists($absolute."/".$file_list[$i])) { // Character / forbidden in a FILE name if (!strpos($file_list[$i],"/") && file_exists($absolute."/".$file_list[$i])) { // Character / forbidden in a FILE name
$this->_delete($absolute."/".$file_list[$i]); $this->_delete($absolute."/".$file_list[$i]);
} }
@ -474,20 +478,20 @@ class m_bro {
*/ */
function RenameFile($R,$old,$new) { function RenameFile($R,$old,$new) {
global $err; global $err;
$absolute=$this->convertabsolute($R,0); $absolute = $this->convertabsolute($R,0);
if (!$absolute) { if (!$absolute) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
} }
$alea=".".time().rand(1000,9999); $alea = ".".time().rand(1000,9999);
for ($i=0;$i<count($old);$i++) { for ($i = 0;$i<count($old);$i++) {
$old[$i]=ssla($old[$i]); // strip slashes if needed $old[$i] = ssla($old[$i]); // strip slashes if needed
$new[$i]=ssla($new[$i]); $new[$i] = ssla($new[$i]);
if (!strpos($old[$i],"/") && !strpos($new[$i],"/")) { // caractre / interdit dans old ET dans new... if (!strpos($old[$i],"/") && !strpos($new[$i],"/")) { // caractre / interdit dans old ET dans new...
@rename($absolute."/".$old[$i],$absolute."/".$old[$i].$alea); @rename($absolute."/".$old[$i],$absolute."/".$old[$i].$alea);
} }
} }
for ($i=0;$i<count($old);$i++) { for ($i = 0;$i<count($old);$i++) {
if (!strpos($old[$i],"/") && !strpos($new[$i],"/")) { // caractre / interdit dans old ET dans new... if (!strpos($old[$i],"/") && !strpos($new[$i],"/")) { // caractre / interdit dans old ET dans new...
@rename($absolute."/".$old[$i].$alea,$absolute."/".$new[$i]); @rename($absolute."/".$old[$i].$alea,$absolute."/".$new[$i]);
} }
@ -508,27 +512,27 @@ class m_bro {
*/ */
function MoveFile($d,$old,$new) { function MoveFile($d,$old,$new) {
global $err; global $err;
$old=$this->convertabsolute($old,0); $old = $this->convertabsolute($old,0);
if (!$old) { if (!$old) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
} }
if ($new[0] != '/') { if ($new[0] != '/') {
$new = $old . '/' . $new; $new = $old . '/' . $new;
} }
$new = $this->convertabsolute($new,0); $new = $this->convertabsolute($new,0);
if (!$new) { if (!$new) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
} }
if ($old==$new) { if ($old == $new) {
$err->raise("bro",_("You cannot move or copy a file to the same folder")); $err->raise("bro",_("You cannot move or copy a file to the same folder"));
return false; return false;
} }
for ($i=0;$i<count($d);$i++) { for ($i = 0;$i<count($d);$i++) {
$d[$i]=ssla($d[$i]); // strip slashes if needed $d[$i] = ssla($d[$i]); // strip slashes if needed
if (!strpos($d[$i],"/") && file_exists($old."/".$d[$i]) && !file_exists($new."/".$d[$i])) { if (!strpos($d[$i],"/") && file_exists($old."/".$d[$i]) && !file_exists($new."/".$d[$i])) {
if (!rename($old."/".$d[$i],$new."/".$d[$i])) if (!rename($old."/".$d[$i],$new."/".$d[$i]))
$err->raise("bro", "error renaming $old/$d[$i] -> $new/$d[$i]"); $err->raise("bro", "error renaming $old/$d[$i] -> $new/$d[$i]");
@ -546,22 +550,22 @@ class m_bro {
* @param boolean $verbose Shall we 'echo' what we did ? * @param boolean $verbose Shall we 'echo' what we did ?
* @return boolean TRUE Si les fichiers ont t renomms, FALSE si une erreur s'est produite. * @return boolean TRUE Si les fichiers ont t renomms, FALSE si une erreur s'est produite.
*/ */
function ChangePermissions($R,$d,$perm,$verbose=false) { function ChangePermissions($R,$d,$perm,$verbose = false) {
global $err; global $err;
$absolute=$this->convertabsolute($R,0); $absolute = $this->convertabsolute($R,0);
if (!$absolute) { if (!$absolute) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
} }
for ($i=0;$i<count($d);$i++) { for ($i = 0;$i<count($d);$i++) {
$d[$i]=ssla($d[$i]); // strip slashes if needed $d[$i] = ssla($d[$i]); // strip slashes if needed
if (!strpos($d[$i],"/")) { // caractre / interdit dans le nom du fichier if (!strpos($d[$i],"/")) { // caractre / interdit dans le nom du fichier
$m = fileperms($absolute."/". $d[$i]); $m = fileperms($absolute."/". $d[$i]);
// pour l'instant on se limite a "write" pour owner, puisque c'est le seul // pour l'instant on se limite a "write" pour owner, puisque c'est le seul
// cas interessant compte tenu de la conf de Apache pour AlternC.. // cas interessant compte tenu de la conf de Apache pour AlternC..
if ($perm[$i]['w']) { if ($perm[$i]['w']) {
$m = $m | 0220; // ug+w $m = $m | 0220; // ug+w
} else { } else {
$m = $m ^ 0222; // ugo-w $m = $m ^ 0222; // ugo-w
} }
@ -591,7 +595,7 @@ class m_bro {
*/ */
function UploadFile($R) { function UploadFile($R) {
global $_FILES,$err,$cuid,$action; global $_FILES,$err,$cuid,$action;
$absolute=$this->convertabsolute($R,0); $absolute = $this->convertabsolute($R,0);
if (!$absolute) { if (!$absolute) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
@ -613,7 +617,7 @@ class m_bro {
$err->log("bro","uploadfile","Problem when uploading a file"); $err->log("bro","uploadfile","Problem when uploading a file");
switch ( $_FILES['userfile']['error'] ) { switch ( $_FILES['userfile']['error'] ) {
case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_INI_SIZE:
$erstr=_("The uploaded file exceeds the max file size allowed"); $erstr = _("The uploaded file exceeds the max file size allowed");
break; break;
case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_FORM_SIZE:
case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_PARTIAL:
@ -622,7 +626,7 @@ class m_bro {
case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_CANT_WRITE:
case UPLOAD_ERR_EXTENSION: case UPLOAD_ERR_EXTENSION:
default: default:
$erstr=_("Undefined error ").$_FILES['userfile']['error']; $erstr = _("Undefined error ").$_FILES['userfile']['error'];
break; break;
} }
$err->raise("bro",_("Error during the upload of the file: ").$erstr); $err->raise("bro",_("Error during the upload of the file: ").$erstr);
@ -645,22 +649,22 @@ class m_bro {
* same directory as the archive by default * same directory as the archive by default
* @return integer|null != 0 on error * @return integer|null != 0 on error
*/ */
function ExtractFile($file, $dest=null) { function ExtractFile($file, $dest = null) {
global $err,$cuid,$mem,$action; global $err,$cuid,$mem,$action;
$file = $this->convertabsolute($file,0); $file = $this->convertabsolute($file,0);
if (is_null($dest)) { if (is_null($dest)) {
$dest = dirname($file); $dest = dirname($file);
} else { } else {
$dest = $this->convertabsolute($dest,0); $dest = $this->convertabsolute($dest,0);
} }
if (!$file || !$dest) { if (!$file || !$dest) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return 1; return 1;
} }
$file = escapeshellarg($file); $file = escapeshellarg($file);
$dest_to_fix = $dest; $dest_to_fix = $dest;
$dest = escapeshellarg($dest); $dest = escapeshellarg($dest);
#$dest_to_fix=str_replace(getuserpath(),'',$dest); #$dest_to_fix = str_replace(getuserpath(),'',$dest);
// TODO new version of tar supports `tar xf ...` so there is no // TODO new version of tar supports `tar xf ...` so there is no
// need to specify the compression format // need to specify the compression format
@ -669,11 +673,11 @@ class m_bro {
exec("tar -xjf $file -C $dest", $void, $ret); exec("tar -xjf $file -C $dest", $void, $ret);
} }
if ($ret) { if ($ret) {
$cmd = "unzip -o $file -d $dest"; $cmd = "unzip -o $file -d $dest";
exec($cmd, $void, $ret); exec($cmd, $void, $ret);
} }
if ($ret) { if ($ret) {
$cmd = "gunzip $file"; $cmd = "gunzip $file";
exec($cmd, $void, $ret); exec($cmd, $void, $ret);
} }
if ($ret) { if ($ret) {
@ -696,22 +700,22 @@ class m_bro {
*/ */
function CopyFile($d,$old,$new) { function CopyFile($d,$old,$new) {
global $err; global $err;
$old=$this->convertabsolute($old,0); $old = $this->convertabsolute($old,0);
if (!$old) { if (!$old) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
} }
$new=$this->convertabsolute($new,0); $new = $this->convertabsolute($new,0);
if (!$new) { if (!$new) {
$err->raise("bro",_("File or folder name is incorrect")); $err->raise("bro",_("File or folder name is incorrect"));
return false; return false;
} }
if ($old==$new) { if ($old == $new) {
$err->raise("bro",_("You cannot move or copy a file to the same folder")); $err->raise("bro",_("You cannot move or copy a file to the same folder"));
return false; return false;
} }
for ($i=0;$i<count($d);$i++) { for ($i = 0;$i<count($d);$i++) {
$d[$i]=ssla($d[$i]); // strip slashes if needed $d[$i] = ssla($d[$i]); // strip slashes if needed
if (!strpos($d[$i],"/") && file_exists($old."/".$d[$i]) && !file_exists($new."/".$d[$i])) { if (!strpos($d[$i],"/") && file_exists($old."/".$d[$i]) && !file_exists($new."/".$d[$i])) {
$this->CopyOneFile($old."/".$d[$i],$new); $this->CopyOneFile($old."/".$d[$i],$new);
} }
@ -734,8 +738,8 @@ class m_bro {
*/ */
function CopyOneFile($src, $dest) { function CopyOneFile($src, $dest) {
global $err; global $err;
$src = escapeshellarg($src); $src = escapeshellarg($src);
$dest = escapeshellarg($dest); $dest = escapeshellarg($dest);
exec("cp -Rpf $src $dest", $void, $ret); exec("cp -Rpf $src $dest", $void, $ret);
if ($ret) { if ($ret) {
$err->raise("bro","Errors happened while copying the source to destination. cp return value: %d", $ret); $err->raise("bro","Errors happened while copying the source to destination. cp return value: %d", $ret);
@ -749,26 +753,26 @@ class m_bro {
* Affiche le chemin et les liens de la racine au dossier $path * Affiche le chemin et les liens de la racine au dossier $path
* Affiche autant de liens HTML (anchor) que le chemin $path contient de * Affiche autant de liens HTML (anchor) que le chemin $path contient de
* niveaux de dossier. Chaque lien est associ la page web $action * niveaux de dossier. Chaque lien est associ la page web $action
* laquelle on ajoute le paramtre R=+Le nom du dossier courant. * laquelle on ajoute le paramtre R = +Le nom du dossier courant.
* *
* @param string $path Dossier vers lequel on trace le chemin * @param string $path Dossier vers lequel on trace le chemin
* @param string $action Page web de destination des liens * @param string $action Page web de destination des liens
* @param boolean $justparent * @param boolean $justparent
* @return string Le code HTML ainsi obtenu. * @return string Le code HTML ainsi obtenu.
*/ */
function PathList($path,$action, $justparent=false) { function PathList($path,$action, $justparent = false) {
$path=$this->convertabsolute($path,1); $path = $this->convertabsolute($path,1);
$a=explode("/",$path); $a = explode("/",$path);
if (!is_array($a)) $a=array($a); if (!is_array($a)) $a = array($a);
$c=''; $c = '';
$R=''; $R = '';
if ($justparent) { if ($justparent) {
return "<a href=\"$action?R=".urlencode($a[count($a)-2].'/')."\">&uarr;</a>"; return "<a href = \"$action?R = ".urlencode($a[count($a)-2].'/')."\">&uarr;</a>";
} }
for($i=0;$i<count($a);$i++) { for($i = 0;$i<count($a);$i++) {
if ($a[$i]) { if ($a[$i]) {
$R.=$a[$i]."/"; $R .= $a[$i]."/";
$c.="<a href=\"$action?R=".urlencode($R)."\">".$a[$i]."</a>&nbsp;/&nbsp;"; $c .= "<a href = \"$action?R = ".urlencode($R)."\">".$a[$i]."</a>&nbsp;/&nbsp;";
} }
} }
return $c; return $c;
@ -789,11 +793,11 @@ class m_bro {
*/ */
function content($R,$file) { function content($R,$file) {
global $err; global $err;
$absolute=$this->convertabsolute($R,0); $absolute = $this->convertabsolute($R,0);
if (!strpos($file,"/")) { if (!strpos($file,"/")) {
$absolute.="/".$file; $absolute .= "/".$file;
if (file_exists($absolute)) { if (file_exists($absolute)) {
$std=str_replace("<","&lt;",str_replace("&","&amp;",file_get_contents($absolute))); $std = str_replace("<","&lt;",str_replace("&","&amp;",file_get_contents($absolute)));
return $std; return $std;
} else { } else {
$err->raise("bro",_("Cannot read the requested file. Please check the permissions")); $err->raise("bro",_("Cannot read the requested file. Please check the permissions"));
@ -825,32 +829,32 @@ class m_bro {
function viewurl($dir,$name) { function viewurl($dir,$name) {
global $db,$cuid; global $db,$cuid;
// Is it in cache ? // Is it in cache ?
if (substr($dir,0,1)=="/") $dir=substr($dir,1); if (substr($dir,0,1) == "/") $dir = substr($dir,1);
if (substr($dir,-1)=="/") $dir=substr($dir,0,-1); if (substr($dir,-1) == "/") $dir = substr($dir,0,-1);
$dir=str_replace("%2F", "/", urlencode($dir)); $dir = str_replace("%2F", "/", urlencode($dir));
$name=urlencode($name); $name = urlencode($name);
if (!@$this->cacheurl["d".$dir]) { if (!@$this->cacheurl["d".$dir]) {
// On parcours $dir en remontant les / // On parcours $dir en remontant les /
$end=""; $beg=$dir; $tofind=true; $end = ""; $beg = $dir; $tofind = true;
while ($tofind) { while ($tofind) {
$db->query("SELECT sub,domaine FROM sub_domaines WHERE compte='$cuid' $db->query("SELECT sub,domaine FROM sub_domaines WHERE compte = '$cuid'
AND type=0 AND (valeur='/$beg/' or valeur='/$beg');"); AND type = 0 AND (valeur = '/$beg/' or valeur = '/$beg');");
$db->next_record(); $db->next_record();
if ($db->num_rows()) { if ($db->num_rows()) {
$tofind=false; $tofind = false;
$this->cacheurl["d".$dir]="http://".$db->f("sub").ife($db->f("sub"),".").$db->f("domaine").$end; $this->cacheurl["d".$dir] = "http://".$db->f("sub").ife($db->f("sub"),".").$db->f("domaine").$end;
} }
if (!$beg && $tofind) { if (!$beg && $tofind) {
$tofind=false; $tofind = false;
$this->cacheurl["d".$dir]="-"; $this->cacheurl["d".$dir] = "-";
// We did not find it ;( // We did not find it ;(
} }
if (($tt=strrpos($beg,"/"))!==false) { if (($tt = strrpos($beg,"/"))!==false) {
$end=substr($beg,$tt).$end; // = /topdir$end so $end starts AND ends with / $end = substr($beg,$tt).$end; // = /topdir$end so $end starts AND ends with /
$beg=substr($beg,0,$tt); $beg = substr($beg,0,$tt);
} else { } else {
$end="/".$beg.$end; $end = "/".$beg.$end;
$beg="/"; $beg = "/";
} }
} }
} }
@ -871,16 +875,16 @@ class m_bro {
*/ */
function can_edit($dir,$name) { function can_edit($dir,$name) {
global $mem,$err; global $mem,$err;
$absolute="$dir/$name"; $absolute = "$dir/$name";
$absolute=$this->convertabsolute($absolute,0); $absolute = $this->convertabsolute($absolute,0);
if (!$absolute) { if (!$absolute) {
$err->raise('bro',_("File not in authorized directory")); $err->raise('bro',_("File not in authorized directory"));
include('foot.php'); include('foot.php');
exit; exit;
} }
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo,$absolute); $mime = finfo_file($finfo,$absolute);
if ( substr($mime,0,5)=="text/" || $mime == "application/x-empty" || $mime == "inode/x-empty") { if ( substr($mime,0,5) == "text/" || $mime == "application/x-empty" || $mime == "inode/x-empty") {
return true; return true;
} }
return false; return false;
@ -896,7 +900,7 @@ class m_bro {
*/ */
function is_extractable($dir,$name) { function is_extractable($dir,$name) {
if ($parts = explode(".", $name)) { if ($parts = explode(".", $name)) {
$ext = array_pop($parts); $ext = array_pop($parts);
switch ($ext) { switch ($ext) {
case "gz": case "gz":
case "bz": case "bz":
@ -927,9 +931,9 @@ class m_bro {
*/ */
function is_sqlfile($dir,$name) { function is_sqlfile($dir,$name) {
if ($parts = explode(".", $name)) { if ($parts = explode(".", $name)) {
$ext = array_pop($parts); $ext = array_pop($parts);
$ext2 = array_pop($parts) . '.'.$ext; $ext2 = array_pop($parts) . '.'.$ext;
if ( $ext=='sql' or $ext2=='sql.gz') return true; if ( $ext == 'sql' or $ext2 == 'sql.gz') return true;
} }
return false; return false;
} }
@ -943,7 +947,7 @@ class m_bro {
function download_link($dir,$file){ function download_link($dir,$file){
global $err; global $err;
$err->log("bro","download_link"); $err->log("bro","download_link");
header("Content-Disposition: attachment; filename=$file"); header("Content-Disposition: attachment; filename = $file");
header("Content-Type: application/force-download"); header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
$this->content_send($dir,$file); $this->content_send($dir,$file);
@ -960,9 +964,9 @@ class m_bro {
*/ */
function content_send($R,$file) { function content_send($R,$file) {
global $err; global $err;
$absolute=$this->convertabsolute($R,0); $absolute = $this->convertabsolute($R,0);
if (!strpos($file,"/")) { if (!strpos($file,"/")) {
$absolute.="/".$file; $absolute .= "/".$file;
if (file_exists($absolute)) { if (file_exists($absolute)) {
readfile($absolute); readfile($absolute);
} }
@ -987,9 +991,9 @@ class m_bro {
*/ */
function save($file,$R,$texte) { function save($file,$R,$texte) {
global $err; global $err;
$absolute=$this->convertabsolute($R,0); $absolute = $this->convertabsolute($R,0);
if (!strpos($file,"/")) { if (!strpos($file,"/")) {
$absolute.="/".$file; $absolute .= "/".$file;
if (file_exists($absolute)) { if (file_exists($absolute)) {
if (! file_put_contents($absolute, $texte ) ) { if (! file_put_contents($absolute, $texte ) ) {
$err->raise("bro",_("Cannot edit the requested file. Please check the permissions")); $err->raise("bro",_("Cannot edit the requested file. Please check the permissions"));
@ -1010,12 +1014,12 @@ class m_bro {
* @param string $dir Dossier à dumper, relatif la racine du compte du membre. * @param string $dir Dossier à dumper, relatif la racine du compte du membre.
* @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs * @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs
*/ */
function DownloadZ($dir="") { function DownloadZ($dir = "") {
global $mem; global $mem;
header("Content-Disposition: attachment; filename=".$mem->user["login"].".Z"); header("Content-Disposition: attachment; filename = ".$mem->user["login"].".Z");
header("Content-Type: application/x-Z"); header("Content-Type: application/x-Z");
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
$d=escapeshellarg(".".$this->convertabsolute($dir,1)); $d = escapeshellarg(".".$this->convertabsolute($dir,1));
set_time_limit(0); set_time_limit(0);
passthru("/bin/tar -cZ -C ".getuserpath()."/".$mem->user["login"]."/ $d"); passthru("/bin/tar -cZ -C ".getuserpath()."/".$mem->user["login"]."/ $d");
} }
@ -1028,12 +1032,12 @@ class m_bro {
* @param string $dir Dossier à dumper, relatif la racine du compte du membre. * @param string $dir Dossier à dumper, relatif la racine du compte du membre.
* @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs * @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs
*/ */
function DownloadTGZ($dir="") { function DownloadTGZ($dir = "") {
global $mem; global $mem;
header("Content-Disposition: attachment; filename=".$mem->user["login"].".tgz"); header("Content-Disposition: attachment; filename = ".$mem->user["login"].".tgz");
header("Content-Type: application/x-tgz"); header("Content-Type: application/x-tgz");
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
$d=escapeshellarg(".".$this->convertabsolute($dir,1)); $d = escapeshellarg(".".$this->convertabsolute($dir,1));
set_time_limit(0); set_time_limit(0);
passthru("/bin/tar -cz -C ".getuserpath()."/ $d"); passthru("/bin/tar -cz -C ".getuserpath()."/ $d");
} }
@ -1046,12 +1050,12 @@ class m_bro {
* @param string $dir Dossier à dumper, relatif la racine du compte du membre. * @param string $dir Dossier à dumper, relatif la racine du compte du membre.
* @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs * @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs
*/ */
function DownloadTBZ($dir="") { function DownloadTBZ($dir = "") {
global $mem; global $mem;
header("Content-Disposition: attachment; filename=".$mem->user["login"].".tar.bz2"); header("Content-Disposition: attachment; filename = ".$mem->user["login"].".tar.bz2");
header("Content-Type: application/x-bzip2"); header("Content-Type: application/x-bzip2");
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
$d=escapeshellarg(".".$this->convertabsolute($dir,1)); $d = escapeshellarg(".".$this->convertabsolute($dir,1));
set_time_limit(0); set_time_limit(0);
passthru("/bin/tar -cj -C ".getuserpath()."/ $d"); passthru("/bin/tar -cj -C ".getuserpath()."/ $d");
} }
@ -1065,12 +1069,12 @@ class m_bro {
* @param string $dir Dossier à dumper, relatif la racine du compte du membre. * @param string $dir Dossier à dumper, relatif la racine du compte du membre.
* @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs * @return void NE RETOURNE RIEN, et il faut Quitter le script immdiatement aprs
*/ */
function DownloadZIP($dir="") { function DownloadZIP($dir = "") {
global $mem; global $mem;
header("Content-Disposition: attachment; filename=".$mem->user["login"].".zip"); header("Content-Disposition: attachment; filename = ".$mem->user["login"].".zip");
header("Content-Type: application/x-zip"); header("Content-Type: application/x-zip");
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
$d=escapeshellarg($this->convertabsolute($dir,false)); $d = escapeshellarg($this->convertabsolute($dir,false));
set_time_limit(0); set_time_limit(0);
passthru("/usr/bin/zip -r - $d"); passthru("/usr/bin/zip -r - $d");
} }
@ -1102,7 +1106,7 @@ class m_bro {
@set_time_limit(0); @set_time_limit(0);
//chmod($file,0777); //chmod($file,0777);
if (is_dir($file)) { if (is_dir($file)) {
$handle = opendir($file); $handle = opendir($file);
while($filename = readdir($handle)) { while($filename = readdir($handle)) {
if ($filename != "." && $filename != "..") { if ($filename != "." && $filename != "..") {
$this->_delete($file."/".$filename); $this->_delete($file."/".$filename);
@ -1127,18 +1131,18 @@ class m_bro {
function alternc_export_conf() { function alternc_export_conf() {
global $db,$err; global $db,$err;
$err->log("bro","export_conf"); $err->log("bro","export_conf");
$str="<table border=\"1\"><caption> Browser </caption>\n"; $str = "<table border = \"1\"><caption> Browser </caption>\n";
$str.=" <browser>\n"; $str .= " <browser>\n";
$pref=$this->GetPrefs(); $pref = $this->GetPrefs();
$i=1; $i = 1;
foreach ($pref as $k=>$v) { foreach ($pref as $k=>$v) {
if (($i % 2)==0){ if (($i % 2) == 0){
$str.=" <$k>$v</$k>\n"; $str .= " <$k>$v</$k>\n";
} }
$i++; $i++;
} }
$str.=" </browser>\n"; $str .= " </browser>\n";
return $str; return $str;
} }
@ -1155,12 +1159,12 @@ class m_bro {
function alternc_export_data($dir){ function alternc_export_data($dir){
global $mem,$err; global $mem,$err;
$err->log("bro","export_data"); $err->log("bro","export_data");
$dir.="html/"; $dir .= "html/";
if(!is_dir($dir)){ if(!is_dir($dir)){
if(!mkdir($dir)) if(!mkdir($dir))
$err->raise("bro",_("Cannot create the requested directory. Please check the permissions")); $err->raise("bro",_("Cannot create the requested directory. Please check the permissions"));
} }
$timestamp=date("H:i:s"); $timestamp = date("H:i:s");
// relacher le lock global sinon ce download va geler alternc pour // relacher le lock global sinon ce download va geler alternc pour
// tout le monde // tout le monde

View File

@ -435,7 +435,7 @@ class m_dom {
$this->lock(); $this->lock();
// function add_domain($domain,$dns,$noerase=0,$force=0,$isslave=0,$slavedom="") // function add_domain($domain,$dns,$noerase=0,$force=0,$isslave=0,$slavedom="")
if (! $this->add_domain($domain, true, false, 1) ) { if (! $this->add_domain($domain, true, false, true) ) {
$err->raise('dom', "Error adding domain"); $err->raise('dom', "Error adding domain");
return false; return false;
} }
@ -646,13 +646,13 @@ class m_dom {
* appellée lors de l'installation d'un nouveau domaine.</p> * appellée lors de l'installation d'un nouveau domaine.</p>
* *
* @param string $dom nom fqdn du domaine à installer * @param string $dom nom fqdn du domaine à installer
* @param integer $dns 1 ou 0 pour héberger le DNS du domaine ou pas. * @param boolean $dns 1 ou 0 pour héberger le DNS du domaine ou pas.
* @param integer $noerase 1 ou 0 pour rendre le domaine inamovible ou non * @param boolean $noerase 1 ou 0 pour rendre le domaine inamovible ou non
* @param integer $force 1 ou 0, si 1, n'effectue pas les tests de DNS. * @param boolean $force 1 ou 0, si 1, n'effectue pas les tests de DNS.
* force ne devrait être utilisé que par le super-admin. * force ne devrait être utilisé que par le super-admin.
$ @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. $ @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
*/ */
function add_domain($domain,$dns,$noerase=0,$force=0,$isslave=0,$slavedom="") { function add_domain($domain,$dns,$noerase=false,$force=false,$isslave=false,$slavedom="") {
global $db,$err,$quota,$classes,$L_MX,$L_FQDN,$tld,$cuid,$bro,$hooks; global $db,$err,$quota,$classes,$L_MX,$L_FQDN,$tld,$cuid,$bro,$hooks;
$err->log("dom","add_domain",$domain); $err->log("dom","add_domain",$domain);
@ -1608,6 +1608,10 @@ class m_dom {
return $res; return $res;
} }
/**
*
* @return array
*/
function get_domain_all_summary() { function get_domain_all_summary() {
global $db,$err; global $db,$err;
$res=array(); $res=array();

View File

@ -40,21 +40,26 @@
class m_hta { class m_hta {
/*---------------------------------------------------------------------------*/ /**
/** * Constructor
* Constructor */
*/
function m_webaccess() { function m_webaccess() {
} }
/** /**
* Password kind used in this class (hook for admin class) * Password kind used in this class (hook for admin class)
*
* @return array
*/ */
function alternc_password_policy() { function alternc_password_policy() {
return array("hta"=>"Protected folders passwords"); return array("hta"=>"Protected folders passwords");
} }
/**
*
* @return array
*/
function hook_menu() { function hook_menu() {
$obj = array( $obj = array(
'title' => _("Protected folders"), 'title' => _("Protected folders"),
@ -67,16 +72,21 @@ class m_hta {
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Create a protected folder (.htaccess et .htpasswd) * Create a protected folder (.htaccess et .htpasswd)
* @param string $dir Folder to protect (relative to user root) * @param string $dir Folder to protect (relative to user root)
* @return boolean TRUE if the folder has been protected, or FALSE if an error occurred * @return boolean TRUE if the folder has been protected, or FALSE if an error occurred
*
* @global m_mem $mem
* @global m_bro $bro
* @global m_err $err
* @param string $dir
* @return boolean
*/ */
function CreateDir($dir) { function CreateDir($dir) {
global $mem,$bro,$err; global $mem,$bro,$err;
$err->log("hta","createdir",$dir); $err->log("hta","createdir",$dir);
$absolute=$bro->convertabsolute($dir,0); $absolute = $bro->convertabsolute($dir,0);
if (!$absolute) { if (!$absolute) {
$err->raise("hta",printf(_("The folder '%s' does not exist"),$dir)); $err->raise("hta",printf(_("The folder '%s' does not exist"),$dir));
return false; return false;
@ -95,7 +105,7 @@ class m_hta {
return false; return false;
} }
fseek($file,0); fseek($file,0);
$param="AuthUserFile \"$absolute/.htpasswd\"\nAuthName \""._("Restricted area")."\"\nAuthType Basic\nrequire valid-user\n"; $param = "AuthUserFile \"$absolute/.htpasswd\"\nAuthName \""._("Restricted area")."\"\nAuthType Basic\nrequire valid-user\n";
fwrite($file, $param); fwrite($file, $param);
fclose($file); fclose($file);
} }
@ -110,43 +120,46 @@ class m_hta {
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Returns the list of all user folder currently protected by a .htpasswd file * Returns the list of all user folder currently protected by a .htpasswd file
* @return array Array containing user folder list *
* @global m_err $err
* @global m_mem $mem
* @return array Array containing user folder list
*/ */
function ListDir(){ function ListDir(){
global$err,$mem; global$err,$mem;
$err->log("hta","listdir"); $err->log("hta","listdir");
$sortie=array(); $sortie = array();
$absolute=ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"]; $absolute = ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"];
exec("find $absolute -name .htpasswd|sort",$sortie); exec("find $absolute -name .htpasswd|sort",$sortie);
if(!count($sortie)){ if(!count($sortie)){
$err->raise("hta",_("No protected folder")); $err->raise("hta",_("No protected folder"));
return false; return false;
} }
$pattern="/^".preg_quote(ALTERNC_HTML,"/")."\/.\/[^\/]*\/(.*)\/\.htpasswd/"; $pattern = "/^".preg_quote(ALTERNC_HTML,"/")."\/.\/[^\/]*\/(.*)\/\.htpasswd/";
$r=array(); $r = array();
for($i=0;$i<count($sortie);$i++){ for($i = 0;$i<count($sortie);$i++){
preg_match($pattern,$sortie[$i],$matches); preg_match($pattern,$sortie[$i],$matches);
$tmpm=isset($matches[1])?'/'.$matches[1]:''; $tmpm = isset($matches[1])?'/'.$matches[1]:'';
$r[$i]=$tmpm."/"; $r[$i] = $tmpm."/";
} }
return $r; return $r;
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Tells if a folder is protected. * Tells if a folder is protected.
* @param string $dir Folder to check *
* @return boolean if the folder is protected, or FALSE if it is not * @global m_mem $mem
* @global m_err $err
* @param string $dir Folder to check
* @return boolean If the folder is protected, or FALSE if it is not
*/ */
function is_protected($dir){ function is_protected($dir){
global $mem,$err; global $mem,$err;
$err->log("hta","is_protected",$dir); $err->log("hta","is_protected",$dir);
$absolute=ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir"; $absolute = ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir";
if (file_exists("$absolute/.htpasswd")){ if (file_exists("$absolute/.htpasswd")){
return true; return true;
} else { } else {
@ -155,34 +168,36 @@ class m_hta {
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Returns the list of login for a protected folder. * Returns the list of login for a protected folder.
* @param string $dir The folder to lookup (relative to user root) *
* @return array An array containing the list of logins from the .htpasswd file, or FALSE * @global m_mem $mem
* @global m_err $err
* @param string $dir The folder to lookup (relative to user root)
* @return array An array containing the list of logins from the .htpasswd file, or FALSE
*/ */
function get_hta_detail($dir) { function get_hta_detail($dir) {
global $mem,$err; global $mem,$err;
$err->log("hta","get_hta_detail"); $err->log("hta","get_hta_detail");
$absolute=ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir"; $absolute = ALTERNC_HTML."/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir";
if (file_exists("$absolute/.htaccess")) { if (file_exists("$absolute/.htaccess")) {
/* if (!_reading_htaccess($absolute)) { /* if (!_reading_htaccess($absolute)) {
return false; return false;
} }
*/ } */ }
$file = @fopen("$absolute/.htpasswd","r"); $file = @fopen("$absolute/.htpasswd","r");
$i=0; $i = 0;
$res=array(); $res = array();
if (!$file) { if (!$file) {
return false; return false;
} }
// TODO: Tester la validit<EFBFBD> du .htpasswd // TODO: Tester la validité du .htpasswd
while (!feof($file)) { while (!feof($file)) {
$s=fgets($file,1024); $s = fgets($file,1024);
$t=explode(":",$s); $t = explode(":",$s);
if ($t[0]!=$s) { if ($t[0]!=$s) {
$res[$i]=$t[0]; $res[$i] = $t[0];
$i=$i+1; $i = $i+1;
} }
} }
fclose($file); fclose($file);
@ -190,38 +205,82 @@ class m_hta {
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Unprotect a folder * Unprotect a folder
* @param string $dir Folder to unprotect, relative to user root *
* @return boolean TRUE if the folder has been unprotected, or FALSE if an error occurred * @global m_mem $mem
* @global m_bro $bro
* @global m_err $err
* @param string $dir Folder to unprotect, relative to user root
* @param boolean $skip For testing purpose mainly, skips the full user path search
* @return boolean TRUE if the folder has been unprotected, or FALSE if an error occurred
*/ */
function DelDir($dir) { function DelDir($dir,$skip = 0) {
global $mem,$bro,$err; global $mem,$bro,$err;
$err->log("hta","deldir",$dir); $err->log("hta","deldir",$dir);
$dir=$bro->convertabsolute($dir,0); $dir = $bro->convertabsolute($dir,$skip);
if (!$dir) { if (!$dir) {
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir)); $err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
return false; return false;
} }
if (!@unlink("$dir/.htaccess")) { $htaccess_file = "$dir/.htaccess";
$err->raise("hta",printf(_("I cannot delete the file '%s/.htaccess'"),$dir)); if( !is_readable($htaccess_file)){
return false; $err->raise("hta",printf(_("I cannot read the file '%s'"),$htaccess_file));
} }
if (!@unlink("$dir/.htpasswd")) { $fileLines = file($htaccess_file);
$err->raise("hta",printf(_("I cannot delete the file '%s/.htpasswd'"),$dir)); $patternList = array(
return false; "AuthUserFile.*$",
"AuthName.*$",
"AuthType Basic.*$",
"require valid-user.*$"
);
$count_lines = 0;
foreach($fileLines as $key => $line){
foreach ($patternList as $pattern) {
if(preg_match("/".$pattern."/", $line)){
$count_lines++;
unset($fileLines[$key]);
}
}
} }
// If no changes
if( ! $count_lines ){
$err->raise("hta",printf(_("Unexpected: No changes made to '%s'"),$htaccess_file));
}
// If file is empty, remove it
if( !count($fileLines)){
if( ! unlink( $htaccess_file)){
$err->raise("hta",printf(_("I could not delete the file '%s'"),$htaccess_file));
}
}else{
file_put_contents($htaccess_file, implode("\n",$fileLines));
}
$htpasswd_file = "$dir/.htpasswd";
$perms = substr(sprintf('%o', fileperms($dir)), -4);
if( ! is_writable($htpasswd_file)){
$err->raise("hta",printf(_("I cannot read the file '%s'"),$htpasswd_file));
}
else if ( ! unlink($htpasswd_file)) {
$err->raise("hta",printf(_("I cannot delete the file '%s/.htpasswd'"),$dir));
return false;
}
return true; return true;
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Add a user to a protected folder * Add a user to a protected folder
* @param string $password The password to add (cleartext) *
* @param string $dir The folder we add it to (relative to user root). * @global m_err $err
* @return boolean TRUE if the user has been added, or FALSE if an error occurred * @global m_bro $bro
* @global m_admin $admin
* @param string $user
* @param string $password
* @param string $dir
* @param string $password The password to add (cleartext)
* @param string $dir The folder we add it to (relative to user root).
* @return boolean TRUE if the user has been added, or FALSE if an error occurred
*/ */
function add_user($user,$password,$dir) { function add_user($user,$password,$dir) {
global $err, $bro, $admin; global $err, $bro, $admin;
@ -234,7 +293,7 @@ class m_hta {
$err->raise('hta',_("Please enter a password")); $err->raise('hta',_("Please enter a password"));
return false; return false;
} }
$absolute=$bro->convertabsolute($dir,0); $absolute = $bro->convertabsolute($dir,0);
if (!file_exists($absolute)) { if (!file_exists($absolute)) {
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir)); $err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
return false; return false;
@ -255,8 +314,8 @@ class m_hta {
} }
fseek($file,0); fseek($file,0);
while (!feof($file)) { while (!feof($file)) {
$s=fgets($file,1024); $s = fgets($file,1024);
$t=explode(":",$s); $t = explode(":",$s);
if ($t[0]==$user) { if ($t[0]==$user) {
$err->raise("hta",_("The user '%s' already exist for this folder"),$user); $err->raise("hta",_("The user '%s' already exist for this folder"),$user);
return false; return false;
@ -276,17 +335,21 @@ class m_hta {
} }
/*---------------------------------------------------------------------------*/ /**
*/
/** /**
* Delete a user from a protected folder. * Delete a user from a protected folder.
* @param array $lst An array with login to delete. *
* @param string $dir The folder, relative to user root, where we want to delete users. * @global m_bro $bro
* @return boolean TRUE if users has been deleted, or FALSE if an error occurred. * @global m_err $err
* @param array $lst An array with login to delete.
* @param string $dir The folder, relative to user root, where we want to delete users.
* @return boolean TRUE if users has been deleted, or FALSE if an error occurred.
*/ */
function del_user($lst,$dir) { function del_user($lst,$dir) {
global $bro,$err; global $bro,$err;
$err->log("hta","del_user",$lst."/".$dir); $err->log("hta","del_user",$lst."/".$dir);
$absolute=$bro->convertabsolute($dir,0); $absolute = $bro->convertabsolute($dir,0);
if (!file_exists($absolute)) { if (!file_exists($absolute)) {
$err->raise("hta",printf(_("The folder '%s' does not exist"),$dir)); $err->raise("hta",printf(_("The folder '%s' does not exist"),$dir));
return false; return false;
@ -301,8 +364,8 @@ class m_hta {
reset($lst); reset($lst);
fseek($file,0); fseek($file,0);
while (!feof($file)) { while (!feof($file)) {
$s=fgets($file,1024); $s = fgets($file,1024);
$t=explode(":",$s); $t = explode(":",$s);
if (!in_array($t[0],$lst) && ($t[0]!="\n")) { if (!in_array($t[0],$lst) && ($t[0]!="\n")) {
fseek($newf,0); fseek($newf,0);
fwrite($newf, "$s"); fwrite($newf, "$s");
@ -316,18 +379,27 @@ class m_hta {
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Change the password of a user in a protected folder
* @param string $user The users whose password should be changed * @param string $user The users whose password should be changed
* @param string $newpass The new password of this user * @param string $newpass The new password of this user
* @param string $dir The folder, relative to user root, in which we will change a password * @param string $dir The folder, relative to user root, in which we will change a password
* @return boolean TRUE if the password has been changed, or FALSE if an error occurred * @return boolean TRUE if the password has been changed, or FALSE if an error occurred
*/ */
/**
* Change the password of a user in a protected folder
*
* @global m_bro $bro
* @global m_err $err
* @global m_admin $admin
* @param string $user
* @param string $newpass
* @param string $dir
* @return boolean
*/
function change_pass($user,$newpass,$dir) { function change_pass($user,$newpass,$dir) {
global $bro,$err,$admin; global $bro,$err,$admin;
$err->log("hta","change_pass",$user."/".$dir); $err->log("hta","change_pass",$user."/".$dir);
$absolute=$bro->convertabsolute($dir,0); $absolute = $bro->convertabsolute($dir,0);
if (!file_exists($absolute)) { if (!file_exists($absolute)) {
$err->raise("hta",printf(_("The folder '%s' does not exist"),$dir)); $err->raise("hta",printf(_("The folder '%s' does not exist"),$dir));
return false; return false;
@ -348,8 +420,8 @@ class m_hta {
return false; return false;
} }
while (!feof($file)) { while (!feof($file)) {
$s=fgets($file,1024); $s = fgets($file,1024);
$t=explode(":",$s); $t = explode(":",$s);
if ($t[0]!=$user) { if ($t[0]!=$user) {
fwrite($newf, "$s"); fwrite($newf, "$s");
} }
@ -363,38 +435,39 @@ class m_hta {
} }
/*---------------------------------------------------------------------------*/ /**
/**
* Check that a .htaccess file is valid (for authentication) * Check that a .htaccess file is valid (for authentication)
* @param string $absolute Folder we want to check (relative to user root) *
* @return boolean TRUE is the .htaccess is protecting this folder, or FALSE else * @global m_err $err
* @access private * @param type $absolute
* @param string $absolute Folder we want to check (relative to user root)
* @return boolean TRUE is the .htaccess is protecting this folder, or FALSE else
*/ */
function _reading_htaccess($absolute) { private function _reading_htaccess($absolute) {
global $err; global $err;
$err->log("hta","_reading_htaccess",$absolute); $err->log("hta","_reading_htaccess",$absolute);
$file = fopen("$absolute/.htaccess","r+"); $file = fopen("$absolute/.htaccess","r+");
$lignes=array(1,1,1); $lignes = array(1,1,1);
$errr=0; $errr = 0;
if (!$file) { if (!$file) {
return false; return false;
} }
while (!feof($file) && !$errr) { while (!feof($file) && !$errr) {
$s=fgets($file,1024); $s = fgets($file,1024);
if (substr($s,0,12)!="RewriteCond " && substr($s,0,14)!="ErrorDocument " && substr($s,0,12)!="RewriteRule " && substr($s,0,14)!="RewriteEngine " && trim($s)!="") { if (substr($s,0,12)!="RewriteCond " && substr($s,0,14)!="ErrorDocument " && substr($s,0,12)!="RewriteRule " && substr($s,0,14)!="RewriteEngine " && trim($s)!="") {
$errr=1; $errr = 1;
} }
if (strtolower(trim($s))==strtolower("authuserfile $absolute/.htpasswd")) { if (strtolower(trim($s))==strtolower("authuserfile $absolute/.htpasswd")) {
$lignes[0]=0; $lignes[0] = 0;
$errr=0; $errr = 0;
} // authuserfile } // authuserfile
if (strtolower(trim($s))=="require valid-user") { if (strtolower(trim($s))=="require valid-user") {
$lignes[1]=0; $lignes[1] = 0;
$errr=0; $errr = 0;
} //require } //require
if (strtolower(trim($s))=="authtype basic") { if (strtolower(trim($s))=="authtype basic") {
$lignes[2]=0; $lignes[2] = 0;
$errr=0; $errr = 0;
} //authtype } //authtype
} // Reading config file } // Reading config file
fclose($file); fclose($file);

View File

@ -669,6 +669,7 @@ ORDER BY
$db->query("UPDATE mailbox SET quota=".intval($quotamb)." WHERE address_id=".$mail_id.";"); $db->query("UPDATE mailbox SET quota=".intval($quotamb)." WHERE address_id=".$mail_id.";");
} }
$recipients=preg_replace('/[\r\t\s]/', "\n", $recipients); // Handle space AND new line
$r=explode("\n",$recipients); $r=explode("\n",$recipients);
$red=""; $red="";
foreach($r as $m) { foreach($r as $m) {

View File

@ -134,7 +134,7 @@ class m_variables {
case 'DEFAULT': case 'DEFAULT':
// $variables = $this->variable_merge(array(),$arr_var['DEFAULT'][NULL]); // $variables = $this->variable_merge(array(),$arr_var['DEFAULT'][NULL]);
$variablesList = current($arr_var["DEFAULT"]); $variablesList = current($arr_var["DEFAULT"]);
$variables = $this->variable_merge(array(),$variablesList); $variables = $this->variable_merge(array(),$variablesList);
break; break;
case 'GLOBAL': case 'GLOBAL':
@ -372,7 +372,7 @@ class m_variables {
$output = ""; $output = "";
if (isset($tab[$strata][$id][$varname]['value'])) { if (isset($tab[$strata][$id][$varname]['value'])) {
$v = $tab[$strata][$id][$varname]['value']; $v = $tab[$strata][$id][$varname]['value'];
$output .= $this->display_valueraw_html($v, $varname); $output .= $this->display_valueraw_html($v, $varname, false);
} else { } else {
$output .= "<em>"._("None defined")."</em>"; $output .= "<em>"._("None defined")."</em>";
} }

View File

@ -1,2 +1,2 @@
alterncpanel ALL = NOPASSWD : /usr/bin/quota, /usr/sbin/setquota, /usr/lib/alternc/fixperms.sh, /usr/lib/alternc/mem_add, /usr/lib/alternc/mem_del, /usr/lib/alternc/quota_edit, /usr/lib/alternc/quota_get, /usr/lib/alternc/du.pl, /usr/lib/alternc/update_mails.sh alterncpanel ALL = NOPASSWD : /usr/bin/quota, /usr/sbin/setquota, /usr/lib/alternc/fixperms.sh, /usr/lib/alternc/mem_add, /usr/lib/alternc/mem_del, /usr/lib/alternc/quota_edit, /usr/lib/alternc/quota_get, /usr/lib/alternc/du.pl, /usr/lib/alternc/update_mails.sh, /usr/sbin/repquota
vmail ALL = NOPASSWD : /usr/lib/dovecot/deliver vmail ALL = NOPASSWD : /usr/lib/dovecot/deliver

View File

@ -216,14 +216,13 @@ CREATE TABLE IF NOT EXISTS sub_domaines (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT, id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
compte int(10) unsigned NOT NULL default '0', compte int(10) unsigned NOT NULL default '0',
domaine varchar(255) NOT NULL default '', domaine varchar(255) NOT NULL default '',
sub varchar(100) NOT NULL default '', sub varchar(255) NOT NULL default '',
valeur varchar(255) default NULL, valeur varchar(255) default NULL,
type varchar(30) NOT NULL default 'LOCAL', type varchar(30) NOT NULL default 'LOCAL',
web_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE', web_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE',
web_result varchar(255) not null default '', web_result varchar(255) not null default '',
enable enum ('ENABLED', 'ENABLE', 'DISABLED', 'DISABLE') NOT NULL DEFAULT 'ENABLED', enable enum ('ENABLED', 'ENABLE', 'DISABLED', 'DISABLE') NOT NULL DEFAULT 'ENABLED',
PRIMARY KEY (id), PRIMARY KEY (id)
UNIQUE (compte,domaine,sub,type,valeur)
-- ,FOREIGN KEY (type) REFERENCES (domaines_type) -- ,FOREIGN KEY (type) REFERENCES (domaines_type)
) ENGINE=MyISAM; ) ENGINE=MyISAM;
@ -716,8 +715,7 @@ CREATE TABLE IF NOT EXISTS `default_subdomains` (
`domain_type_parameter` varchar(255) NOT NULL, `domain_type_parameter` varchar(255) NOT NULL,
`concerned` enum('BOTH','MAIN','SLAVE') NOT NULL DEFAULT 'MAIN', `concerned` enum('BOTH','MAIN','SLAVE') NOT NULL DEFAULT 'MAIN',
`enabled` boolean not null default true, `enabled` boolean not null default true,
PRIMARY KEY (`id`), PRIMARY KEY (`id`)
UNIQUE KEY `unique_row` (`sub`,`domain_type`,`domain_type_parameter`,`concerned`)
) ENGINE=MyISAM COMMENT='Contains the defaults subdomains created on domains creation'; ) ENGINE=MyISAM COMMENT='Contains the defaults subdomains created on domains creation';
INSERT IGNORE INTO `default_subdomains` (`sub`, `domain_type`, `domain_type_parameter`, `concerned`) VALUES INSERT IGNORE INTO `default_subdomains` (`sub`, `domain_type`, `domain_type_parameter`, `concerned`) VALUES

View File

@ -156,4 +156,4 @@ $mem = new \m_mem();
$err = new \m_err(); $err = new \m_err();
$authip = new \m_authip(); $authip = new \m_authip();
$hooks = new \m_hooks(); $hooks = new \m_hooks();
$bro = new \m_bro();

View File

@ -21,16 +21,27 @@ abstract class AlterncTest extends PHPUnit_Extensions_Database_TestCase
* @return \PHPUnit_Extensions_Database_DataSet_YamlDataSet * @return \PHPUnit_Extensions_Database_DataSet_YamlDataSet
* @throws \Exception * @throws \Exception
*/ */
public function loadDataSet($file_name) public function loadDataSet($fileList)
{ {
$file = PHPUNIT_DATASETS_PATH."/$file_name"; if (empty($fileList)) {
if( !is_file($file) ){ throw new \Exception("No files specified");
throw new \Exception("missing $file");
} }
$dataSet = new PHPUnit_Extensions_Database_DataSet_YamlDataSet($file); if( !is_array($fileList)){
$fileList = array($fileList);
}
$datasetList = array();
foreach ($fileList as $file_name) {
$file = PHPUNIT_DATASETS_PATH."/$file_name";
if( !is_file($file) ){
throw new \Exception("missing $file");
}
$dataSet = new PHPUnit_Extensions_Database_DataSet_YamlDataSet($file);
$datasetList[] = $dataSet;
}
$compositeDataSet = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet($datasetList);
return $dataSet; return $dataSet;
} }
} }

View File

@ -0,0 +1,11 @@
domaines:
-
id : 1
compte : 2001
domaine : example.tld
gesdns : 1
gesmx : 1
noerase : 0
dns_action : OK
dns_result : 0
zonettl : 86400

View File

@ -1,6 +1,6 @@
membres: membres:
- -
uid : 0 uid : 2000
login : admin login : admin
pass : admin pass : admin
enabled : 1 enabled : 1
@ -11,6 +11,7 @@ membres:
lastfail : 0 lastfail : 0
lastip : 127.0.0.1 lastip : 127.0.0.1
- -
uid : 2001
login : phpunit login : phpunit
pass : phpunit pass : phpunit
enabled : 1 enabled : 1
@ -19,4 +20,4 @@ membres:
show_help : 1 show_help : 1
lastlogin : 2014-01-01 00:00:00 lastlogin : 2014-01-01 00:00:00
lastfail : 0 lastfail : 0
lastip : 127.0.0.1 lastip : 127.0.0.1

View File

@ -9,6 +9,9 @@ class m_htaTest extends PHPUnit_Framework_TestCase
*/ */
protected $object; protected $object;
const PATH_HTACCESS = "/tmp/.htaccess";
const PATH_HTPASSWD = "/tmp/.htpasswd";
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed. * This method is called before a test is executed.
@ -16,6 +19,10 @@ class m_htaTest extends PHPUnit_Framework_TestCase
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
touch(self::PATH_HTACCESS);
touch(self::PATH_HTPASSWD);
$file_content = "AuthUserFile \"/tmp/.htpasswd\"\nAuthName \"Restricted area\"\nAuthType Basic\nrequire valid-user\n";
file_put_contents(self::PATH_HTACCESS,$file_content);
$this->object = new m_hta; $this->object = new m_hta;
} }
@ -26,6 +33,12 @@ class m_htaTest extends PHPUnit_Framework_TestCase
protected function tearDown() protected function tearDown()
{ {
parent::tearDown(); parent::tearDown();
if(file_exists(self::PATH_HTACCESS)){
unlink (self::PATH_HTACCESS);
}
if(file_exists(self::PATH_HTPASSWD)){
unlink (self::PATH_HTPASSWD);
}
} }
/** /**
@ -114,14 +127,26 @@ class m_htaTest extends PHPUnit_Framework_TestCase
/** /**
* @covers m_hta::DelDir * @covers m_hta::DelDir
* @todo Implement testDelDir().
*/ */
public function testDelDir() public function testDelDir()
{ {
// Remove the following lines when you implement this test. $result = $this->object->DelDir("/tmp",TRUE);
$this->markTestIncomplete( $this->assertTrue($result);
'This test has not been implemented yet.' $this->assertFileNotExists(self::PATH_HTACCESS);
); $this->assertFileNotExists(self::PATH_HTPASSWD);
}
/**
* @covers m_hta::DelDir
*/
public function testDelDirNotEmpty()
{
file_put_contents(self::PATH_HTACCESS, "\nphpunit", FILE_APPEND);
$result = $this->object->DelDir("/tmp",TRUE);
$this->assertTrue($result);
$this->assertFileExists(self::PATH_HTACCESS);
$this->assertFileNotExists(self::PATH_HTPASSWD);
$this->assertTrue("phpunit" == trim(file_get_contents(self::PATH_HTACCESS)));
} }
/** /**

View File

@ -2,7 +2,7 @@
/** /**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58. * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58.
*/ */
class m_mailTest extends PHPUnit_Framework_TestCase class m_mailTest extends AlterncTest
{ {
/** /**
* @var m_mail * @var m_mail
@ -19,6 +19,15 @@ class m_mailTest extends PHPUnit_Framework_TestCase
$this->object = new m_mail; $this->object = new m_mail;
} }
/**
* @return PHPUnit_Extensions_Database_DataSet_IDataSet
*/
public function getDataSet()
{
return parent::loadDataSet("domaines.yml");
}
/** /**
* Tears down the fixture, for example, closes a network connection. * Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed. * This method is called after a test is executed.
@ -310,10 +319,7 @@ class m_mailTest extends PHPUnit_Framework_TestCase
*/ */
public function testCreate_alias() public function testCreate_alias()
{ {
// Remove the following lines when you implement this test. // Test #1580
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
} }
/** /**

View File

@ -28,7 +28,7 @@ then
# cp -f /etc/alternc/templates/roundcube/avelsieve-config.php /etc/alternc/templates/roundcube/apache.conf /etc/roundcube/ # cp -f /etc/alternc/templates/roundcube/avelsieve-config.php /etc/alternc/templates/roundcube/apache.conf /etc/roundcube/
# cp -f /etc/alternc/templates/javascript-common/javascript-common.conf /etc/javascript-common/ # cp -f /etc/alternc/templates/javascript-common/javascript-common.conf /etc/javascript-common/
LOGIN="2000_roundcube" LOGIN="0000_roundcube"
PASSWORD="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..10)'`" PASSWORD="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..10)'`"
DESKEY="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..24)'`" DESKEY="`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..24)'`"
@ -40,7 +40,6 @@ then
# Configuration template location # Configuration template location
TEMPLATE_DIR="/etc/alternc/templates" TEMPLATE_DIR="/etc/alternc/templates"
CONFIG_FILES="etc/roundcube/main.inc.php etc/roundcube/plugins/password/config.inc.php etc/roundcube/plugins/managesieve/config.inc.php" CONFIG_FILES="etc/roundcube/main.inc.php etc/roundcube/plugins/password/config.inc.php etc/roundcube/plugins/managesieve/config.inc.php"
LOGROTATE_FILES="etc/logrotate.d/roundcube-core"
cat > $SED_SCRIPT <<EOF cat > $SED_SCRIPT <<EOF
s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\; s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
@ -62,14 +61,6 @@ EOF
echo " Done" echo " Done"
for file in $LOGROTATE_FILES; do
TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
echo -n " $file"
if [ -f "$TEMPLATE" ]; then
cat $TEMPLATE > /$file
fi
done
echo " Done" echo " Done"
. /usr/lib/alternc/functions.sh . /usr/lib/alternc/functions.sh
@ -99,10 +90,3 @@ EOF
fi fi
#This is necessary because upgrading roundcube from 7.1 to 7.2 changes this setting
if [ "$1" = "end" ]; then
chown alternc-roundcube:root /etc/roundcube/main.inc.php
fi

View File

@ -1,46 +1,46 @@
<VirtualHost *:80> <VirtualHost *:80>
ServerName %%fqdn%% ServerName %%fqdn%%
AssignUserId alternc-roundcube nogroup AssignUserId www-data www-data
SetEnv LOGIN "%%UID%%-%%LOGIN%%" SetEnv LOGIN "0000-roundcube"
DocumentRoot /var/lib/roundcube DocumentRoot /var/lib/roundcube
# Access to tinymce files # Access to tinymce files
<Directory "/usr/share/tinymce/www/"> <Directory "/usr/share/tinymce/www/">
Options Indexes MultiViews FollowSymLinks Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /var/lib/roundcube/>
Options +FollowSymLinks
# This is needed to parse /var/lib/roundcube/.htaccess. See its
# content before setting AllowOverride to None.
AllowOverride All
order allow,deny
allow from all
</Directory>
# Protecting basic directories:
<Directory /var/lib/roundcube/config>
Options -FollowSymLinks
AllowOverride None AllowOverride None
</Directory> Order allow,deny
allow from all
</Directory>
<Directory /var/lib/roundcube/temp> <Directory /var/lib/roundcube/>
Options -FollowSymLinks Options +FollowSymLinks
AllowOverride None # This is needed to parse /var/lib/roundcube/.htaccess. See its
Order allow,deny # content before setting AllowOverride to None.
Deny from all AllowOverride All
</Directory> order allow,deny
allow from all
</Directory>
<Directory /var/lib/roundcube/logs> # Protecting basic directories:
Options -FollowSymLinks <Directory /var/lib/roundcube/config>
AllowOverride None Options -FollowSymLinks
Order allow,deny AllowOverride None
Deny from all </Directory>
</Directory>
<Directory /var/lib/roundcube/temp>
Options -FollowSymLinks
AllowOverride None
Order allow,deny
Deny from all
</Directory>
<Directory /var/lib/roundcube/logs>
Options -FollowSymLinks
AllowOverride None
Order allow,deny
Deny from all
</Directory>
Alias /javascript /usr/share/javascript/ Alias /javascript /usr/share/javascript/

View File

@ -1,15 +0,0 @@
######
# Configuration file of Roundcube's logrotate for AlternC
#
# /!\ WARNING /!\ Do not edit this file, edit the one in
# /etc/alternc/templates/logrotate.d/ and launch alternc.install again.
######
/var/log/roundcube/password /var/log/roundcube/errors /var/log/roundcube/sendmail /var/log/roundcube/userlogins {
create 0640 alternc-roundcube root
compress
missingok
notifempty
rotate 52
weekly
}

View File

@ -25,6 +25,8 @@ if ( $nb != 1 ){
} }
#we check that for that type only one option is specified #we check that for that type only one option is specified
# FIXME je doute que ca fasse un truc pertinent ce morceau
$nb2=0;
foreach($options as $opt => $val){ foreach($options as $opt => $val){
$nb2=count($options[$opt]); $nb2=count($options[$opt]);
} }
@ -61,6 +63,7 @@ function FixQuotaDovecot($conditions){
} }
#We construct a sql query to get the mailbox root based on the option. #We construct a sql query to get the mailbox root based on the option.
// FIXME where does $opt come from ??
switch($opt){ switch($opt){
case "m": case "m":
if (!filter_var($val,FILTER_VALIDATE_EMAIL)) { if (!filter_var($val,FILTER_VALIDATE_EMAIL)) {

29
src/quota_get_all Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# List quotas of all users in 3 columns :
# id used quota
source /etc/alternc/local.sh
#checking if quotas are installed
command -v /usr/sbin/repquota >/dev/null || { echo "Quotas uninstalled"; exit 0; }
get_quota() {
quotadir="$1"
if [ "$quotadir" = "/" ] ; then
sudo repquota -g -v -n -p "$quotadir" 2>/dev/null || (echo "Error: can't get quota"; exit 1)
else
sudo repquota -g -v -n -p "$quotadir" 2>/dev/null || get_quota "$(dirname $quotadir)"
fi
}
# Some help : this is what we must parse
# Block limits File limits
#Group used soft hard grace used soft hard grace
#----------------------------------------------------------------------
#root -- 1612116 0 0 96181 0 0
#adm -- 14532 0 0 226 0 0
get_quota "$ALTERNC_HTML" | egrep "^\#[0-9]+"|while read gid blank bused bsoft bhard bgrace fused fsoft fhard fgrace ; do
echo ${gid/\#/} $bused $bhard
done

View File

@ -6,12 +6,22 @@ require_once("/usr/share/alternc/panel/class/config_nochk.php");
global $db; global $db;
echo "\n---------------------------\n Generating size-cache for web accounts\n\n"; echo "\n---------------------------\n Generating size-cache for web accounts\n\n";
$r=mysql_query("SELECT uid,login FROM membres;"); exec("/usr/lib/alternc/quota_get_all", $list_quota_tmp);
while ($c=mysql_fetch_array($r)) { $list_quota=array();
echo $c["login"]; flush(); foreach ($list_quota_tmp as $qt) {
$size=exec("sudo /usr/lib/alternc/du.pl ".ALTERNC_HTML."/".substr($c["login"],0,1)."/".$c["login"]); $qt = explode(" ", $qt);
$db->query("REPLACE INTO size_web SET uid='".$c["uid"]."',size='$size';"); $list_quota[$qt[0]] = array('used'=>$qt[1], 'quota'=>$qt[2]);
echo " done ($size KB) \n"; flush(); }
if ($db->query("SELECT uid,login FROM membres;")) {
$db2 = new DB_system();
while ($db->next_record()) {
if (isset($list_quota[$db->f('uid')])) {
$qu=$list_quota[$db->f('uid')];
$db2->query("INSERT OR REPLACE INTO size_web SET uid='".intval($db->f('uid'))."',size='".intval($qu['used'])."';");
echo $db->f('login')." (".$qu['used']." B)\n";
}
}
} }
echo "\n---------------------------\n Generating size-cache for MySQL databases\n\n"; echo "\n---------------------------\n Generating size-cache for MySQL databases\n\n";