crude implementation of permission change in the file browser

Contributed by: Mathieu Lutfy
Sponsored by: Koumbit
This commit is contained in:
Antoine Beaupré 2008-04-10 18:40:08 +00:00
parent 9517d27d78
commit c8f477c3ec
3 changed files with 83 additions and 0 deletions

View File

@ -107,6 +107,11 @@ if ($formu) {
print $err->errstr();
}
break;
case 7: // Changement de permissions [ML]
if (!$bro->ChangePermissions($R, $d, $perm)) {
print $err->errstr();
}
break;
}
}
@ -173,6 +178,46 @@ if ($formu==2 && $actrename && count($d)) {
echo "<hr />\n";
}
/* [ML] Changer les permissions : */
if ($formu==2 && $_REQUEST['actperms'] && count($d)) {
echo "<form action=\"bro_main.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"R\" value=\"$R\" />\n";
echo "<input type=\"hidden\" name=\"formu\" value=\"7\" />\n";
echo "<p>"._("Permissions")."</p>";
$tmp_absdir = $bro->convertabsolute($R,0);
echo "<table border=\"1\">"; // FIXME, marco, ajouter classe css?
echo "<tr>";
// echo "<th>" . 'File' . "</th><th>&nbsp;</th><th>Owner</th><th>Group</th><th>Other</th>"; // FIXME , i18n
echo "<th>" . 'File' . "</th><th>Permissions</th>"; // FIXME, i18n
echo "</tr>";
for ($i=0;$i<count($d);$i++) {
$d[$i]=ssla($d[$i]);
$stats = stat($tmp_absdir . '/' . $d[$i]);
$modes = $stats[2];
echo "<tr>";
echo "<td>".$d[$i]."</td>";
// Owner
echo "<td>";
echo "<input type=\"hidden\" name=\"d[$i]\" value=\"".$d[$i]."\" />";
// echo "<label>read <input type=\"checkbox\" name=\"perm[$i][r]\" value=\"1\" ". (($modes & 0000400) ? 'checked="checked"' : '') ." />";
echo "<label>write <input type=\"checkbox\" name=\"perm[$i][w]\" value=\"1\" ". (($modes & 0000200) ? 'checked="checked"' : '') ." />";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<p><input type=\"submit\" class=\"inb\" name=\"submit\" value=\""._("Change permissions")."\" /></p>";
echo "</form>\n";
echo "<hr />\n";
}
/* We draw the file list and button bar only if there is files here ! */
if (count($c)) {
@ -189,6 +234,7 @@ document.write("<input type=\"button\" value=\"<?php __("all/none"); ?>\" class=
<input type="submit" class="inb" name="actdel" value="<?php __("Delete"); ?>" />
<input type="submit" class="inb" name="actrename" value="<?php __("Rename"); ?>" />
<input type="submit" class="inb" name="actperms" value="<?php __("Permissions"); ?>" /> <!-- [ML] -->
&nbsp;&nbsp;&nbsp;
<input type="submit" class="inb" name="actcopy" value="<?php __("Copy to"); ?>" />

View File

@ -385,6 +385,42 @@ class m_bro {
return true;
}
/* ----------------------------------------------------------------- */
/** Change les droits d'acces aux fichier de $d du dossier $R en $p
* @param string $R dossier dans lequel se trouve les fichiers à renommer.
* @param array of string $old Ancien nom des fichiers
* @param array of string $new Nouveau nom des fichiers
* @return boolean TRUE si les fichiers ont été renommés, FALSE si une erreur s'est produite.
*/
function ChangePermissions($R,$d,$perm) {
global $err;
$absolute=$this->convertabsolute($R,0);
if (!$absolute) {
$err->raise("bro",1);
return false;
}
for ($i=0;$i<count($d);$i++) {
$d[$i]=ssla($d[$i]); // strip slashes if needed
if (!strpos($d[$i],"/")) { // caractère / interdit dans le nom du fichier
// @rename($absolute."/".$old[$i],$absolute."/".$old[$i].$alea);
$m = fileperms($absolute."/". $d[$i]);
// 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..
if ($perm[$i]['w']) {
$m = $m | 128;
} else {
$m = $m ^ 128;
}
$m = $m | ($perm[$i]['w'] ? 128 : 0); // 0600
chmod($absolute."/".$d[$i], $m);
echo "chmod " . sprintf('%o', $m) . " file, was " . sprintf('%o', fileperms($absolute."/". $d[$i])). " -- " . $perm[$i]['w'];
}
}
return true;
}
/* ----------------------------------------------------------------- */
/** Recoit un champ file upload (Global) et le stocke dans le dossier $R
* Le champ file-upload originel doit s'appeler "userfile" et doit

1
debian/changelog vendored
View File

@ -3,6 +3,7 @@ alternc (0.9.7+dev) stable; urgency=low UNRELEASED
* standardisation of the web interface, along with some esthetic changes, by
Marc Angles, sponsored by Koumbit
* styles can now be changed locally in admin/styles/base.css
* crude implementation of a permission change interface in the file browser
-- Antoine Beaupré <anarcat@koumbit.org> Thu, 10 Apr 2008 13:56:22 -0400