Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network/darkhttpd: added rc script, config file, and default page #9630

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions network/darkhttpd/README
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ Security:
Limitations:

* Only serves static content -- no CGI.

Configuration:

You need to configue the darkhttpd using the file

/etc/default/darkhttpd

Them can start add rc.darkhttpd into rc.local

# Start the darkhttpd server:
if [ -x /etc/rc.d/rc.darkhttpd ]; then
/etc/rc.d/rc.darkhttpd start
fi

23 changes: 19 additions & 4 deletions network/darkhttpd/darkhttpd.SlackBuild
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=darkhttpd
VERSION=${VERSION:-1.16}
BUILD=${BUILD:-1}
BUILD=${BUILD:-2}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

Expand Down Expand Up @@ -59,10 +59,10 @@ elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
SLKCFLAGS="-O2 -fPIE"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
SLKCFLAGS="-O2 -fPIE"
LIBDIRSUFFIX=""
fi

Expand All @@ -81,22 +81,37 @@ find -L . \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

make
CFLAGS="$SLKCFLAGS" LDFLAGS="-pie" make

mkdir -p $PKG/usr/bin
install -m755 darkhttpd $PKG/usr/bin/

find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true

# Install init script:
mkdir -p $PKG/etc/rc.d
cat $CWD/rc.darkhttpd > $PKG/etc/rc.d/rc.darkhttpd.new
chmod 644 $PKG/etc/rc.d/rc.darkhttpd.new

# Install default options file for darkhttpd:
mkdir -p $PKG/etc/default
cat $CWD/default.darkhttpd > $PKG/etc/default/darkhttpd.new

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a README* $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

# Install simple index.html
mkdir -p $PKG/srv/static
cat $CWD/index.html > $PKG/srv/static/index.html
chown apache:apache $PKG/srv/static/index.html

# Install license (from Arch Linux' PKGBUILD)
head -n 18 darkhttpd.c > $PKG/usr/doc/$PRGNAM-$VERSION/LICENSE

mkdir -p $PKG/install
cat $CWD/doinst.sh > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
Expand Down
13 changes: 13 additions & 0 deletions network/darkhttpd/default.darkhttpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Path to the darkhttpd binary. Ensure this points to the correct location of the darkhttpd executable.
DARKHTTPD_BIN="/usr/bin/darkhttpd"

# The root directory to serve files from. This should be set to the path where your web files are stored.
# For example, use "/var/www/html" or "/path/to/your/files".
DARKHTTPD_ROOT="/srv/static"

# Additional flags for darkhttpd. Run `darkhttpd --help` or check its documentation to determine which flags
# you might need, such as:
# --chroot : Run darkhttpd in a chroot jail for added security.
# --port <num> : Specify the port number to serve content on (default is 80).
# --daemon : Run darkhttpd as a background process (daemon mode).
DARKHTTPD_FLAGS="--uid apache --gid apache --chroot --daemon"
23 changes: 23 additions & 0 deletions network/darkhttpd/doinst.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
config() {
NEW="$1"
OLD="`dirname $NEW`/`basename $NEW .new`"
# If there's no config file by that name, mv it over:
if [ ! -r $OLD ]; then
mv $NEW $OLD
elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
rm $NEW
fi
# Otherwise, we leave the .new copy for the admin to consider...
}

# Keep same perms on rc.darkhttpd.new:
if [ -e etc/rc.d/rc.darkhttpd ]; then
cp -a etc/rc.d/rc.darkhttpd etc/rc.d/rc.darkhttpd.new.incoming
cat etc/rc.d/rc.darkhttpd.new > etc/rc.d/rc.darkhttpd.new.incoming
mv etc/rc.d/rc.darkhttpd.new.incoming etc/rc.d/rc.darkhttpd.new
fi

config etc/default/darkhttpd.new
config etc/rc.d/rc.darkhttpd.new

68 changes: 68 additions & 0 deletions network/darkhttpd/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to darkhttpd</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
color: #333;
}
header {
background-color: #333;
color: #fff;
padding: 1rem;
text-align: center;
}
main {
padding: 2rem;
max-width: 800px;
margin: 0 auto;
}
h1 {
font-size: 2rem;
margin-bottom: 1rem;
}
p {
line-height: 1.6;
}
footer {
text-align: center;
padding: 1rem;
background-color: #333;
color: #fff;
position: fixed;
bottom: 0;
width: 100%;
}
a {
color: #007BFF;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<header>
<h1>Welcome to darkhttpd</h1>
</header>
<main>
<h1>Hello!</h1>
<p>Welcome to the default page served by <strong>darkhttpd</strong>. Your web server is running correctly.</p>
<p>You can replace this file with your own <code>index.html</code> to serve your content.</p>
<p>For documentation or support, visit the <a href="https://unix4lyfe.org/darkhttpd/" target="_blank">official darkhttpd page</a>.</p>
<h2>Directory Listing</h2>
<p>If enabled, darkhttpd will automatically list the contents of directories when no <code>index.html</code> file is present.</p>
</main>
<footer>
<p>&copy; 2025 darkhttpd. All rights reserved.</p>
</footer>
</body>
</html>

68 changes: 68 additions & 0 deletions network/darkhttpd/rc.darkhttpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh
#
# rc.darkhttpd: Start/Stop the darkhttpd web server
#
# This script assumes you have darkhttpd installed and available in the PATH.
# Configuration can be placed in /etc/defaults/darkhttpd

# config file /etc/default/darkhttpd:
CONFIG_FILE="/etc/default/darkhttpd"

# Load options from /etc/default/darkhttpd:
# Source the configuration file if it exists
if [ -f "$CONFIG_FILE" ]; then
. "$CONFIG_FILE"
fi

# Function to start darkhttpd
start() {
if pgrep -x darkhttpd > /dev/null; then
echo "darkhttpd is already running."
else
echo "Starting darkhttpd..."
$DARKHTTPD_BIN $DARKHTTPD_ROOT $DARKHTTPD_FLAGS
if [ $? -eq 0 ]; then
echo "darkhttpd started."
else
echo "Failed to start darkhttpd."
fi
fi
}

# Function to stop darkhttpd
stop() {
echo "Stopping darkhttpd..."
pkill -x darkhttpd
if [ $? -eq 0 ]; then
echo "darkhttpd stopped."
else
echo "Failed to stop darkhttpd or it was not running."
fi
}

# Function to restart darkhttpd
restart() {
stop
sleep 1
start
}

# Check for input argument
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

exit 0