Skip to content

Commit c15d8ab

Browse files
committed
README
1 parent c65a4e2 commit c15d8ab

10 files changed

+35
-23
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ app/htadmin/config/config.ini
66
app/test/.htpasswd
77
app/test/.htmeta
88
app/test/.htaccess
9+
app/.htpasswd
10+
app/.htmeta
11+
app/.htaccess
912
app/index.html

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
HTAdmin
22
=======
33

4-
HTAdmin is a simple .htaccess and .htpasswd editor implemented in PHP with a nice frontend (based on bootstrap). It's intended to secure a folder of plain html files with multiple users. The admin has to create a user, but every user can change his password by himself using a self service area. It is also possible to send a password reset mail. You can use the .htpasswd with nginx and Apache, in the example we use nginx.
4+
HTAdmin is a simple htpasswd editor implemented in PHP with a nice frontend (based on bootstrap). It's intended to update and maintain users and password hashes in a .htpasswd file. The admin has to create a user, but every user can change his password by himself using a self service area. It is also possible to send a password reset mail. You can use the .htpasswd with nginx and Apache, in the example we use nginx.
55

66
It comes with a preconfigured docker-compose.yml, so you don't have to install a LAMP stack locally for testing but can use docker instead.
77

88
You find the application in `sites/html/htadmin`.
99

1010
![Screenshot](screenshot.png "Screenshot")
1111

12-
After cloning set the appropriate rights, change `user` with your user:
12+
Since both the nginx and the php-fpm run as the www-data user, change the group for the app folder and everything within:
1313

14-
`chown -R user:www-data app`
14+
`chgrp -R www-data app`
1515

1616
PHP needs write permission for the user www-data.
1717

app/htadmin/config/config.ini.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
app_title = HTAdmin
77

88
; Path to html files which have to be secured:
9-
secure_path = /app/test/
9+
secure_path = /app/
1010

1111
; Use metadata (necessary e.g. for password reset via mail):
1212
use_metadata = true

app/htadmin/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
$meta_model->user = $username;
2525
$meta_model->email = $_POST ['email'];
2626
$meta_model->name = $_POST ['name'];
27-
$meta_model->mailkey = random_password(8);
27+
$meta_model->mailkey = random_password(PASSWORD_LENGTH);
2828
}
2929

3030
if (! check_username ( $username ) || ! check_password_quality ( $passwd )) {

app/htadmin/tools/.htaccess

-3
This file was deleted.

app/htadmin/tools/htpasswd.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,10 @@ class htpasswd {
1919
const HTMETA_NAME = ".htmeta";
2020
function __construct($configpath, $use_metadata = false) {
2121
$path = realpath ( $configpath );
22-
$htaccessfile = $path . "/" . self::HTACCESS_NAME;
2322
$htpasswdfile = $path . "/" . self::HTPASSWD_NAME;
2423
@$this->use_metadata = $use_metadata;
25-
26-
if (! file_exists ( $htaccessfile )) {
27-
$could_write = $bdfp = fopen ( $htaccessfile, 'w' );
28-
$htaccess_content = "AuthType Basic\nAuthName \"Password Protected Area\"\nAuthUserFile \"" . $htpasswdfile . "\"\nRequire valid-user" . "\n<Files .ht*>\nOrder deny,allow\nDeny from all\n</Files>";
29-
if (! $could_write || !fwrite ( $bdfp, $htaccess_content )) {
30-
echo ("can not write to file " . $htaccessfile);
31-
}
32-
}
33-
3424

25+
3526
@$this->fp = @$this::open_or_create ( $htpasswdfile );
3627

3728
if ($this->fp == null) {
@@ -168,9 +159,11 @@ function user_update($username, $password) {
168159
$usernames = explode ( ":", $line = rtrim ( fgets ( $this->fp ) ) );
169160
trim ( $lusername = array_shift ( $usernames ) );
170161
if ($lusername == $username) {
171-
fseek ( $this->fp, (- 15 - strlen ( $username )), SEEK_CUR );
172-
fwrite ( $this->fp, $username . ':' . self::htcrypt ( $password ) . "\n" );
173-
return true;
162+
fseek ( $this->fp, (- 1 - strlen($line)), SEEK_CUR );
163+
self::delete($this->fp, $username, $this->filename, false);
164+
file_put_contents ( $this->filename,
165+
$username . ':' . self::htcrypt ( $password ) . "\n" ,
166+
FILE_APPEND | LOCK_EX);
174167
}
175168
}
176169
return false;

app/htadmin/tools/util.php

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function check_username($username) {
2525

2626
}
2727

28+
// default password / mailkey length:
29+
const PASSWORD_LENGTH = 18;
30+
2831
function random_password($length) {
2932
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ1234567890';
3033
$pass = array(); //remember to declare $pass as an array

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
version: '3'
22
services:
33
web:
4-
image: nginx:1.21
4+
build:
5+
context: .
6+
dockerfile: nginx.dockerfile
57
ports:
68
- "80:80"
79
volumes:

nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ http {
1616

1717
location /test {
1818
auth_basic "Secured by htadmin";
19-
auth_basic_user_file /app/test/.htpasswd;
19+
auth_basic_user_file /app/.htpasswd;
2020
}
2121

2222
location /htadmin/config {

nginx.dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM nginx:1.21
2+
3+
4+
# Customization of the nginx user and group ids in the image. It's 101:101 in
5+
# the base image. Here we use 33 which is the user id and group id for www-data
6+
# on Ubuntu, Debian, etc.
7+
ARG nginx_uid=33
8+
ARG nginx_gid=33
9+
10+
# The worker processes in the nginx image run as the user nginx with group
11+
# nginx. This is where we override their respective uid and guid to something
12+
# else that lines up better with file permissions.
13+
# The -o switch allows reusing an existing user id
14+
RUN usermod -u $nginx_uid -o nginx && groupmod -g $nginx_gid -o nginx

0 commit comments

Comments
 (0)