";
while( list( $var, $val ) = each( $vars ) )
{
echo "$pre$var = <$val>\n";
$pre = "
";
}
echo "
cmdline = <$cmdline>
\n"; system( $cmdline, $retcode ); if( $retcode != 0 ) { $error = "problem with htpasswd"; } } if( $error != "" ) { echo "" . "error setting password for $username: $error" . "
\n"; } return "user"; } function user_chpw( $username ) { ?>";
$users = user_getnames();
$n = count( $users );
$i = 0;
while( $i < $n )
{
$user = $users[$i];
if( $logname == "admin" || $logname == $user )
{
echo "$pre$user\n";
}
else
{
echo "$pre$user\n";
}
$pre = "
";
$i++;
}
if( $logname == "admin" )
{
echo "$pre
add new user\n";
}
echo "
" . "illegal group name '$groupname'" . "
\n"; } } $groups = $newgroups; } function dir_getresponse( &$dirgrps, $groups ) { $newdirgrps = array(); $groupnames = array( "*" ); while( list( $groupname, $tmp ) = each( $groups ) ) { $groupnames[] = $groupname; } $gn = count( $groupnames ); $i = 1; while( isset( $GLOBALS["_POST"]["g_".$i] ) ) { $grpnrs[$GLOBALS["_POST"]["g_".$i]] = $i; $i++; } $i = 1000; while( isset( $GLOBALS["_POST"]["d_".$i] ) ) { $dirnrs[$GLOBALS["_POST"]["d_".$i]] = $i; $i = $i + 1000; } while( list( $dir, $groups ) = each( $dirgrps ) ) { $dirnr = $dirnrs[$dir]; if( isset( $GLOBALS["_POST"]["keep_".$dirnr] ) || $dir == "/" ) { $groups = array(); $i = 0; while( $i < $gn ) { /* $selname = dir_makeselname( $dir, $groupnames[$i] ); */ $grpnr = $grpnrs[$groupnames[$i]]; $selname = "sel_" . ($dirnr + $grpnr); $access = $GLOBALS["_POST"][$selname]; if( $access == "r" || $access == "rw" || $access == "NA" ) { $groups[$groupnames[$i]] = $access; } $i++; } $newdirgrps[$dir] = $groups; } } $dir = $GLOBALS["_POST"]["newname"]; if( $dir != "" ) { $dirnames = split( "/", $dir ); $dirok = 1; $i = count( $dirnames ); while( $i > 0 ) { $i--; if( !ereg( "^[a-zA-z][a-zA-z0-9._-]*$", $dirnames[$i] ) ) { if( $i > 0 || $dirnames[$i] != "" ) { $dirok = 0; } } } if( $dirok == 1 ) { $groups = array(); $i = 0; while( $i < $gn ) { /* $selname = dir_makeselname( "newdir", $groupnames[$i] ); */ $selname = "sel_newdir_" . $grpnrs[$groupnames[$i]]; $access = $GLOBALS["_POST"][$selname]; if( $access == "r" || $access == "rw" || $access == "NA" ) { $groups[$groupnames[$i]] = $access; } $i++; } $newdirgrps[$dir] = $groups; } else { echo "" . "illegal directory name '$dir'" . "
\n"; } } $dirgrps = $newdirgrps; } function group_save( $cmd, $logname ) { $error = ""; $retcmd = ""; $isadmin = 0; if( $logname == "admin" ) { $users = user_getnames(); list( $groups, $grpdirs, $dirgrps ) = group_readgroupsfile(); switch( $cmd ) { case "group-save": group_getresponse( $groups, $users ); $retcmd = "group"; break; case "dir-save": dir_getresponse( $dirgrps, $groups ); $retcmd = "dir"; break; default: $error = "unknown command"; break; } $authzfile = $GLOBALS["AUTHZ_FILE"]; $newfile = $authzfile . ".new"; $tempfile = tempnam( $GLOBALS["AUTH_DIR"], "tmpgrp" ); if( $error == "" ) { $fp = fopen( $tempfile, "w" ); } else { $fp = false; } if( $fp ) { fwrite( $fp, "\n[groups]\n" ); while( list( $groupname, $userlist ) = each( $groups ) ) { $line = "$groupname ="; $pfx = " "; $i = 0; $un = count( $userlist ); while( $i < $un ) { $line .= $pfx . $userlist[$i]; $pfx = ", "; $i++; } fwrite( $fp, $line . "\n" ); } fwrite( $fp, "\n\n" ); while( list( $dir, $grp ) = each( $dirgrps ) ) { $accessline = ""; while( list( $group, $access ) = each( $grp ) ) { if( $group != "*" ) { $group = "@" . $group; } if( $access == "NA" ) { $access = ""; } $accessline .= "$group = $access\n"; } if( substr( $dir, 0, 1 ) == "/" ) { fwrite( $fp, "[$dir]\n$accessline\n\n" ); } else { fwrite( $fp, "[/trunk/$dir]\n$accessline\n" ); fwrite( $fp, "[/branches/$dir]\n$accessline\n" ); fwrite( $fp, "[/tags/$dir]\n$accessline\n\n" ); } } fclose( $fp ); if( rename( $tempfile, $newfile ) ) { /* */ if( !unlink( $authzfile ) ) { $error = "deleting group file failed"; } else if( !rename( $newfile, $authzfile ) ) { $error = "renaming group file failed"; } /* */ } else { unlink( $tempfile ); $error = "access conflict"; } } } else { $error = "permission denied"; } if( $error != "" ) { echo "" . "error setting groups: $error" . "
\n"; } return $retcmd; } function group_show( $logname ) { $isadmin = 0; if( $logname == "admin" ) { $isadmin = 1; } $users = user_getnames(); // $groups = group_readgroups(); list( $groups, $grpdirs, $dirgrps ) = group_readgroupsfile(); $un = count( $users ); if( $isadmin ) { echo "\n"; } } //============================================================================== // directories function dir_makeselname( $dir, $groupname ) { return "sel_" . $dir . "_" . $groupname; } function dir_show( $logname ) { if( $logname != "admin" ) { return; } list( $groups, $grpdirs, $dirgrps ) = group_readgroupsfile(); echo "\n"; } //============================================================================== // main code $cmd = check_referer( $_GET["cmd"] ); $logname = $_SERVER["PHP_AUTH_USER"]; $backurl = "."; switch( $cmd ) { case "user-save": $cmd = user_save( $logname, $_POST["username"], $_POST["password"] ); //$cmd = "showvars"; break; case "group-save": $cmd = group_save( $cmd, $logname ); //$cmd = "showvars"; break; case "dir-save": //showvars( "_POST", $_POST ); $cmd = group_save( $cmd, $logname ); //$cmd = "showvars"; break; default: break; } switch( $cmd ) { case "user": user_show( $logname ); break; case "user-add": user_add(); break; case "user-chpw": user_chpw( $_GET["username"] ); break; case "group": group_show( $logname ); break; case "dir": dir_show( $logname ); break; case "showvars": showvars( "GLOBALS", $GLOBALS ); showvars( "_GET", $_GET ); showvars( "_POST", $_POST ); showvars( "_COOKIE", $_COOKIE ); showvars( "_SERVER", $_SERVER ); showvars( "_ENV", $_ENV ); showvars( "_FILES", $_FILES ); showvars( "_REQUEST", $_REQUEST ); break; default: echo "