File "edit.php"
Full Path: /home/analogde/www/filetypes/htpasswd/edit.php
File size: 6.9 KB
MIME-type: text/x-php
Charset: utf-8
<?php
/***************************************************************
* Copyright notice
*
* (c) 2003-2004 Tobias Bender (tobias@phpXplorer.org)
* All rights reserved
*
* This script is part of the phpXplorer project. The phpXplorer project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
$acronym = basename(dirname(__FILE__));
require(dirname(__FILE__) . "/../defaultActionHead.php");
$fileName = getRequestVar("fileName");
if(!(strpos($fileName, "..") === FALSE))
die($PXP_languages[$PXP_language]['accessDenied'] . " (804)");
$pInfo = checkFilePermissions($fileName, false);
if(!$pInfo["allowOpen"] or !$pInfo["allowEdit"])
die($PXP_languages[$PXP_language]["accessDenied"] . " (809)");
if(isset($HTTP_POST_VARS["users"])){
require(dirname(__FILE__) . "/../../authentication/htaccess_editor.php");
$htEditor = new htaccessEditor(dirname(dirname(dirname(__FILE__))) . "/.htpasswd");
$rowActions = explode("<|>", $HTTP_POST_VARS["rowActions"]);
$users = explode("<|>", $HTTP_POST_VARS["users"]);
$passwords = explode("<|>", $HTTP_POST_VARS["passwords"]);
$pxuf = $currentDir . "/" . $fileName;
$passwdFileContent = "";
foreach($users as $index => $user){
if($rowActions[$index] == "d"){
$htEditor->deleteUser($user);
continue;
}
if($passwords[$index] != "{__EMPTY__}")
$htEditor->addUser($user, $passwords[$index]);
}
$htEditor->writeFile();
die();
}
$caption = $PXP_languages[$PXP_language]['filetype.' . $acronym] . " - " . str_replace($PXP_basedir, "", $currentDir) . "/" . $fileName;
$users = Array();
$lines = file($currentDir . "/" . $fileName);
foreach($lines as $line){
$values = explode(":", $line);
array_push($users, trim($values[0]));
}
# build strings from arrays
$strUsers = sizeof($users) > 0 ? "'" . implode("','", $users) . "',null" : "null";
?>
<html>
<head><title><?php echo $caption ?></title>
<script src="<?php echo $GC_webGridClient_URL ?>/webGrid.js" type="text/javascript" language="JavaScript"></script>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
httpParameter=new Array()
httpParameter['http_user']=''
wGB205116740640f36a8f95b953 = new gridBox("wGB205116740640f36a8f95b953")
var b=wGB205116740640f36a8f95b953
b.wgURL="<?php echo $GC_webGridClient_URL ?>"
//]]>
</script>
<script src="<?php echo $GC_webGridClient_URL ?>/cache/columnTemplates.js" type="text/javascript" language="JavaScript"></script>
<script src="<?php echo $GC_webGridClient_URL ?>/cache/validations.js" type="text/javascript" language="JavaScript"></script>
<script src="<?php echo $GC_webGridClient_URL ?>/getJSDefinition.php?id=wGB205116740640f36a8f95b953" type="text/javascript" language="JavaScript"></script>
<style type="text/css">
/*<![CDATA[*/
body{margin:0px}
/*]]>*/
</style>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
function save(){
var f = document.frm1
if(!b.onSync())
return false
var arrRA = new Array()
for(var y in htpasswd.rows)
arrRA[arrRA.length] = htpasswd.gRS(htpasswd.rows[y])
f.rowActions.value = arrRA.join("<|>")
f.users.value = htpasswd.aCols['username'].vs.join("<|>");
f.passwords.value = htpasswd.aCols['password'].vs.join("<|>");
f.submit()
}
<?php
$nullValues = Array();
for($i = 0; $i < sizeof($users) + 1; $i++)
array_push($nullValues, "'{__EMPTY__}'");
$strNullValues = implode(",", $nullValues);
?>//javascript
var confirmPasswordOfUser = "<?php echo $PXP_languages[$PXP_language]['confirmPasswordOfUser'] ?>"
var doesNotMatch = "<?php echo $PXP_languages[$PXP_language]['doesNotMatch'] ?>"
var passwordOfUser = "<?php echo $PXP_languages[$PXP_language]['passwordOfUser'] ?>"
var shouldNotEmpty = "<?php echo $PXP_languages[$PXP_language]['shouldNotEmpty'] ?>"
function init(){
var g = htpasswd;
g.rC = <?php echo sizeof($users) ?>
g.aCols['username'].vs = Array(<?php echo $strUsers ?>)
g.aCols['password'].vs = Array(<?php echo $strNullValues ?>)
g.aCols['passwordConfirm'].vs = Array(<?php echo $strNullValues ?>)
g.title = "<?php echo $PXP_languages[$PXP_language]['user'] ?>"
g.aCols['username'].title = "<?php echo $PXP_languages[$PXP_language]['user'] ?>"
g.aCols['password'].title = "<?php echo $PXP_languages[$PXP_language]['password'] ?>"
g.aCols['passwordConfirm'].title = "<?php echo $PXP_languages[$PXP_language]['passwordConfirm'] ?>"
b.render(window.frames['wGB205116740640f36a8f95b953Content'])
b.resize()
window.setInterval('wGB205116740640f36a8f95b953.resize()', 444)
}
//]]>
</script>
</head>
<body onLoad="init()">
<form name="frm1" action="./edit.php" method="post" target="frmSave">
<input type="hidden" name="rowActions" value="">
<input type="hidden" name="users" value="">
<input type="hidden" name="passwords" value="">
<input type="hidden" name="currentDir" value="<?php echo $currentDir ?>">
<input type="hidden" name="shareId" value="<?php echo $shareId ?>">
<input type="hidden" name="fileName" value="<?php echo $fileName ?>">
<input type="hidden" name="actionType" value="">
<input type="hidden" name="keyGenList" value="">
<table style="background-color:#DDDDDD" cellspacing="0" cellpadding="1" width="100%">
<tr>
<td>
<iframe scrolling="auto" id="wGB205116740640f36a8f95b953Content" name="wGB205116740640f36a8f95b953Content" width="100%" height="480px" frameborder="0"></iframe>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="height:1px" colspan="4"></td>
</tr>
<tr>
<td height="28">
<input type="button" value="<?php echo $PXP_languages[$PXP_language]['add'] ?>" onClick="wGB205116740640f36a8f95b953.addRow()">
</td>
<td height="28">
<input type="button" value="<?php echo $PXP_languages[$PXP_language]['insert'] ?>" onClick="wGB205116740640f36a8f95b953.insRow()">
</td>
<td height="28">
<input type="button" value="<?php echo $PXP_languages[$PXP_language]['delete'] ?>" onClick="wGB205116740640f36a8f95b953.delRow()">
</td>
<td height="28">
<input type="button" value="<?php echo $PXP_languages[$PXP_language]['save'] ?>" onClick="save()">
</td>
<td height="28">
<input type="button" value="<?php echo $PXP_languages[$PXP_language]['cancel'] ?>" onClick="window.close()">
</td>
</tr>
</table>
</td>
</tr>
</table>
<iframe name="frmSave" style="display:none"></iframe>
</form>
</body>
</html>