- added possibility to customize authname of directory-protection, fixes #345

This commit is contained in:
Michael Kaufmann (d00p)
2010-08-11 07:48:56 +00:00
parent db286077f8
commit 040f151d65
11 changed files with 58 additions and 16 deletions

View File

@@ -49,7 +49,7 @@ elseif($page == 'htpasswds')
'path' => $lng['panel']['path']
);
$paging = new paging($userinfo, $db, TABLE_PANEL_HTPASSWDS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']);
$result = $db->query("SELECT `id`, `username`, `path` FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' " . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
$result = $db->query("SELECT * FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' " . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
$paging->setEntries($db->num_rows($result));
$sortcode = $paging->getHtmlSortCode($lng);
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
@@ -81,7 +81,7 @@ elseif($page == 'htpasswds')
elseif($action == 'delete'
&& $id != 0)
{
$result = $db->query_first("SELECT `id`, `customerid`, `username`, `path` FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
$result = $db->query_first("SELECT * FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
if(isset($result['username'])
&& $result['username'] != '')
@@ -114,6 +114,7 @@ elseif($page == 'htpasswds')
$userpath = $path;
$path = makeCorrectDir($userinfo['documentroot'] . '/' . $path);
$username = validate($_POST['username'], 'username', '/^[a-zA-Z0-9][a-zA-Z0-9\-_]+\$?$/');
$authname = validate($_POST['directory_authname'], 'directory_authname', '/^[a-zA-Z0-9][a-zA-Z0-9\-_ ]+\$?$/');
validate($_POST['directory_password'], 'password');
$username_path_check = $db->query_first("SELECT `id`, `username`, `path` FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `username`='" . $db->escape($username) . "' AND `path`='" . $db->escape($path) . "' AND `customerid`='" . (int)$userinfo['customerid'] . "'");
@@ -151,7 +152,7 @@ elseif($page == 'htpasswds')
}
else
{
$db->query("INSERT INTO `" . TABLE_PANEL_HTPASSWDS . "` (`customerid`, `username`, `password`, `path`) VALUES ('" . (int)$userinfo['customerid'] . "', '" . $db->escape($username) . "', '" . $db->escape($password) . "', '" . $db->escape($path) . "')");
$db->query("INSERT INTO `" . TABLE_PANEL_HTPASSWDS . "` (`customerid`, `username`, `password`, `path`, `authname`) VALUES ('" . (int)$userinfo['customerid'] . "', '" . $db->escape($username) . "', '" . $db->escape($password) . "', '" . $db->escape($path) . "', '" . $db->escape($authname) . "')");
$log->logAction(USR_ACTION, LOG_INFO, "added htpasswd for '" . $username . " (" . $path . ")'");
inserttask('1');
redirectTo($filename, Array('page' => $page, 's' => $s));
@@ -166,7 +167,7 @@ elseif($page == 'htpasswds')
elseif($action == 'edit'
&& $id != 0)
{
$result = $db->query_first("SELECT `id`, `username`, `path` FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
$result = $db->query_first("SELECT * FROM `" . TABLE_PANEL_HTPASSWDS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
if(isset($result['username'])
&& $result['username'] != '')
@@ -175,6 +176,7 @@ elseif($page == 'htpasswds')
&& $_POST['send'] == 'send')
{
validate($_POST['directory_password'], 'password');
$authname = validate($_POST['directory_authname'], 'directory_authname', '/^[a-zA-Z0-9][a-zA-Z0-9\-_ ]+\$?$/');
if(CRYPT_STD_DES == 1)
{
@@ -186,13 +188,25 @@ elseif($page == 'htpasswds')
$password = crypt($_POST['directory_password']);
}
if($_POST['directory_password'] == '')
$pwd_sql = '';
if($_POST['directory_password'] != '')
{
standard_error(array('stringisempty', 'mypassword'));
$pwd_sql = "`password`='" . $db->escape($password) . "' ";
}
else
$auth_sql = '';
if($authname != $result['authname'])
{
$db->query("UPDATE `" . TABLE_PANEL_HTPASSWDS . "` SET `password`='" . $db->escape($password) . "' WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
$auth_sql = "`authname`='" . $db->escape($authname) . "' ";
}
if($pwd_sql != '' || $auth_sql != '')
{
if($pwd_sql !='' && $auth_sql != '') {
$pwd_sql.= ', ';
}
$db->query("UPDATE `" . TABLE_PANEL_HTPASSWDS . "` SET ".$pwd_sql.$auth_sql." WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
$log->logAction(USR_ACTION, LOG_INFO, "edited htpasswd for '" . $result['username'] . " (" . $result['path'] . ")'");
inserttask('1');
redirectTo($filename, Array('page' => $page, 's' => $s));

View File

@@ -380,6 +380,7 @@ CREATE TABLE `panel_htpasswds` (
`path` varchar(255) NOT NULL default '',
`username` varchar(255) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`authname` varchar(255) NOT NULL default 'Restricted Area',
PRIMARY KEY (`id`),
KEY `customerid` (`customerid`)
) TYPE=MyISAM ;
@@ -455,7 +456,7 @@ INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) V
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (18, 'system', 'vmail_homedir', '/var/customers/mail/');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (19, 'system', 'bindconf_directory', '/etc/bind/');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (20, 'system', 'bindreload_command', '/etc/init.d/bind9 reload');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.12-svn5');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.12-svn6');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (23, 'system', 'hostname', 'SERVERNAME');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (24, 'login', 'maxloginattempts', '3');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (25, 'login', 'deactivatetime', '900');

View File

@@ -1008,3 +1008,14 @@ if(isFroxlorVersion('0.9.12-svn4'))
updateToVersion('0.9.12-svn5');
}
if(isFroxlorVersion('0.9.12-svn5'))
{
showUpdateStep("Updating from 0.9.12-svn5 to 0.9.12-svn6", false);
showUpdateStep("Adding new field to table 'panel_htpasswds'");
$db->query("ALTER TABLE `".TABLE_PANEL_HTPASSWDS."` ADD `authname` varchar(255) NOT NULL default 'Restricted Area' AFTER `password`;");
lastStepStatus(0);
updateToVersion('0.9.12-svn6');
}

View File

@@ -72,7 +72,7 @@ define('PACKAGE_ENABLED', 2);
// VERSION INFO
$version = '0.9.12-svn5';
$version = '0.9.12-svn6';
$dbversion = '2';
$branding = '';

View File

@@ -1490,4 +1490,8 @@ $lng['admin']['templates']['USR_PATH'] = 'FTP homedir (relative to customer-docr
// ADDED IN FROXLOR 0.9.12-svn4
$lng['serversettings']['awstats_awstatspath'] = 'Path to AWStats \'awstats.pl\'';
// ADDED IN FROXLOR 0.9.12-svn6
$lng['extras']['htpasswdauthname'] = 'Authentication reason (AuthName)';
$lng['extras']['directoryprotection_edit'] = 'edit directory protection';
?>

View File

@@ -1473,4 +1473,8 @@ $lng['admin']['templates']['USR_PATH'] = 'FTP Heimatverzeichnis (relativ zum Kun
// ADDED IN FROXLOR 0.9.12-svn4
$lng['serversettings']['awstats_awstatspath'] = 'Pfad zu AWStats \'awstats.pl\'';
// ADDED IN FROXLOR 0.9.12-svn6
$lng['extras']['htpasswdauthname'] = 'Authentifizierungs-Grund (AuthName)';
$lng['extras']['directoryprotection_edit'] = 'Verzeichnisschutz bearbeiten';
?>

View File

@@ -965,7 +965,7 @@ class apache
}
$this->diroptions_data[$diroptions_filename].= ' AuthType Basic' . "\n";
$this->diroptions_data[$diroptions_filename].= ' AuthName "Restricted Area"' . "\n";
$this->diroptions_data[$diroptions_filename].= ' AuthName "'.$row_htpasswd['authname'].'"' . "\n";
$this->diroptions_data[$diroptions_filename].= ' AuthUserFile ' . $htpasswd_filename . "\n";
$this->diroptions_data[$diroptions_filename].= ' require valid-user' . "\n";
}

View File

@@ -219,7 +219,7 @@ class lighttpd
$htaccess_text.= ' "' . $htaccess_path . '" =>' . "\n";
$htaccess_text.= ' (' . "\n";
$htaccess_text.= ' "method" => "basic",' . "\n";
$htaccess_text.= ' "realm" => "Restricted Area",' . "\n";
$htaccess_text.= ' "realm" => "'.$row_htpasswds['authname'].'",' . "\n";
$htaccess_text.= ' "require" => "valid-user"' . "\n";
$htaccess_text.= ' )' . "\n";
$htaccess_text.= ' )' . "\n";
@@ -606,7 +606,7 @@ class lighttpd
$diroption_text.= '"' . $row_htpasswds['path'] . '" =>' . "\n";
$diroption_text.= '(' . "\n";
$diroption_text.= ' "method" => "basic",' . "\n";
$diroption_text.= ' "realm" => "Restricted Area",' . "\n";
$diroption_text.= ' "realm" => "'.$row_htpasswds['authname'].'",' . "\n";
$diroption_text.= ' "require" => "valid-user"' . "\n";
$diroption_text.= ')' . "\n";

View File

@@ -22,6 +22,10 @@ $header
<td class="main_field_name">{$lng['login']['password']}:</td>
<td class="main_field_display" nowrap="nowrap"><input type="password" name="directory_password" size="30" /></td>
</tr>
<tr>
<td class="main_field_name">{$lng['extras']['htpasswdauthname']}:</td>
<td class="main_field_display" nowrap="nowrap"><input type="text" name="directory_authname" size="30" /></td>
</tr>
<tr>
<td class="main_field_confirm" colspan="2"><input type="hidden" name="send" value="send" /><input type="submit" class="bottom" value="{$lng['extras']['directoryprotection_add']}" /></td>
</tr>

View File

@@ -6,7 +6,7 @@ $header
<input type="hidden" name="id" value="$id" />
<table cellpadding="5" cellspacing="4" border="0" align="center" class="maintable_60">
<tr>
<td class="maintitle" colspan="2"><b><img src="images/title.gif" alt="" />&nbsp;{$lng['menue']['main']['changepassword']}</b></td>
<td class="maintitle" colspan="2"><b><img src="images/title.gif" alt="" />&nbsp;{$lng['extras']['directoryprotection_edit']}</b></td>
</tr>
<tr>
<td class="main_field_name">{$lng['panel']['path']}:</td>
@@ -21,7 +21,11 @@ $header
<td class="main_field_display" nowrap="nowrap"><input type="password" name="directory_password" maxlength="50" /></td>
</tr>
<tr>
<td class="main_field_confirm" colspan="2"><input type="hidden" name="send" value="send" /><input type="submit" class="bottom" value="{$lng['menue']['main']['changepassword']}" /></td>
<td class="main_field_name">{$lng['extras']['htpasswdauthname']}:</td>
<td class="main_field_display" nowrap="nowrap"><input type="text" name="directory_authname" value="{$result['authname']}" /></td>
</tr>
<tr>
<td class="main_field_confirm" colspan="2"><input type="hidden" name="send" value="send" /><input type="submit" class="bottom" value="{$lng['extras']['directoryprotection_edit']}" /></td>
</tr>
</table>
</form>

View File

@@ -1,6 +1,6 @@
<tr class="" onmouseover="this.className='RowOverSelected';" onmouseout="this.className='';">
<td class="field_name_border_left">{$row['username']}</td>
<td class="field_name">{$row['path']}</td>
<td class="field_name"><a href="$filename?page=htpasswds&amp;action=edit&amp;id={$row['id']}&amp;s=$s">{$lng['menue']['main']['changepassword']}</a></td>
<td class="field_name"><a href="$filename?page=htpasswds&amp;action=edit&amp;id={$row['id']}&amp;s=$s">{$lng['panel']['edit']}</a></td>
<td class="field_name"><a href="$filename?page=htpasswds&amp;action=delete&amp;id={$row['id']}&amp;s=$s">{$lng['panel']['delete']}</a></td>
</tr>