Browse Source

Small bugfixes, beautify

Stefan Ostermann 8 years ago
parent
commit
8989ab1ba9

+ 2 - 2
sites/html/htadmin/delete.php

@@ -2,13 +2,13 @@
 session_start();
 include_once("tools/util.php");
 if (!check_login()) {
-	echo "error";
+	echo "unauthorized";
 	die();
 }
 include_once ('tools/htpasswd.php');
 $ini = read_config();
 
-$htpasswd = new htpasswd ( $ini ['secure_path'] . ".htpasswd" );
+$htpasswd = new htpasswd ( $ini ['secure_path'] );
 
 if (isset ( $_POST['user'] )) {
 	$user = $_POST['user'];

+ 2 - 2
sites/html/htadmin/includes/nav.php

@@ -13,7 +13,7 @@ if (check_login ()) {
 				</a>
 				<li><a href="adminpwd.php">Admin password</a></li>
 				<li><a href="logout.php">Logout</a></li>
-				<li><a href="selfservice.php">Change my password</a></li>
+				<li><a href="selfservice.php">User Self Service</a></li>
 			</ul>
 		</div>
 	</div>
@@ -33,7 +33,7 @@ if (check_login ()) {
 	?>
 				</a>
 				<li><a href="login.php">Login</a></li>
-				<li><a href="login.php">Change my password</a></li>
+				<li><a href="login.php">User Self Service</a></li>
 			</ul>
 		</div>
 	</div>

+ 1 - 1
sites/html/htadmin/index.php

@@ -4,7 +4,7 @@ include_once ('tools/htpasswd.php');
 include_once ('includes/head.php');
 include_once ('includes/nav.php');
 
-$htpasswd = new htpasswd ( $ini ['secure_path'] . ".htpasswd" ); // path to your .htpasswd file
+$htpasswd = new htpasswd ( $ini ['secure_path'] );
 
 ?>
 

+ 2 - 1
sites/html/htadmin/selfservice.php

@@ -1,9 +1,10 @@
 <?php
+session_start();
 include_once ('tools/htpasswd.php');
 include_once ('includes/head.php');
 include_once ('includes/nav.php');
 
-$htpasswd = new htpasswd ( $ini ['secure_path'] . ".htpasswd" );
+$htpasswd = new htpasswd ( $ini ['secure_path'] );
 
 ?>
 

+ 18 - 13
sites/html/htadmin/tools/htpasswd.php

@@ -9,26 +9,31 @@ class htpasswd {
 	var $fp;
 	var $filename;
 	
-	const HTACCESS_CONTENT = "AuthType Basic\nAuthName \"Password Protected Area\"\nAuthUserFile XXX\nRequire valid-user";
+	const HTPASSWD_NAME = ".htpasswd";
+	const HTACCESS_NAME = ".htaccess";
+
 	
-	function htpasswd($filename) {
-		$basedir = realpath(dirname($filename));
-		$htaccessdir = $basedir . "/.htaccess";
+	function htpasswd($configpath) {
+		$path = realpath($configpath);
+		$htaccessfile = $path . "/" . self::HTACCESS_NAME;
+		$htpasswdfile = $path . "/" . self::HTPASSWD_NAME;
+		
+		if (!file_exists($htaccessfile)) {
+			$bdfp = fopen($htaccessfile, 'w');
+			$htaccess_content = "AuthType Basic\nAuthName \"Password Protected Area\"\nAuthUserFile \"" . $htpasswdfile . "\"\nRequire valid-user";
+			fwrite($bdfp,$htaccess_content);
+		}
 
-		if (!file_exists($filename)) {
-			@$this->fp = fopen ( $filename, 'w' );
+		if (!file_exists($htpasswdfile)) {
+			@$this->fp = fopen ( $htpasswdfile, 'w+' );
 		} else {
-			@$this->fp = fopen ( $filename, 'r+' ) or die ( 'Invalid file name' );
+			@$this->fp = fopen ( $htpasswdfile, 'r+' ) or die ( 'Invalid file name' );
 		}
 		
-		if (!file_exists($htaccessdir)) {
-			$bdfp = fopen($htaccessdir, 'w');
-			$htaccess_content = str_replace("XXX",realpath($filename),self::HTACCESS_CONTENT);
-			fwrite($bdfp,$htaccess_content);
-		}
+
 		
 		
-		$this->filename = $filename;
+		$this->filename = $htpasswdfile;
 	}
 	function user_exists($username) {
 		rewind ( $this->fp );