From 4ade8ccfc6cb761adec205285f1866c8265e57e2 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 21 May 2008 14:01:23 +0000 Subject: release 1.5. added setup-alpine-web --- Makefile | 3 +- setup-alpine-web | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup-webconf | 36 ++++++++++++------------ 3 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 setup-alpine-web diff --git a/Makefile b/Makefile index b13c885..0a33a11 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -V=1.4.1 +V=1.5 P=alpine-conf PV=$(P)-$(V) APKF=$(PV).apk @@ -11,6 +11,7 @@ SBIN_FILES=albootstrap\ lbu\ setup-ads\ setup-alpine\ + setup-alpine-web\ setup-cryptswap\ setup-dns\ setup-hostname\ diff --git a/setup-alpine-web b/setup-alpine-web new file mode 100644 index 0000000..a24ca12 --- /dev/null +++ b/setup-alpine-web @@ -0,0 +1,83 @@ +#!/bin/sh + +BRNUM=0 +CNET="10.$BRNUM.0" +IFACE_LIST=/tmp/interfaces + +get_interfaces() { + [ -f "$IFACE_LIST" ] || tail -n +3 /proc/net/dev \ + | awk -F: '$1 !~ /lo/ { print $1 }' > "$IFACE_LIST" + cat "$IFACE_LIST" +} + +make_dhcp_subnet() { + local num=$1 + local iface=$2 + local network="$CNET.$num" + local netmask=255.255.255.240 + local router="$CNET.$(( $num + 1 ))" + local poolstart="$CNET.$(( $num + 2 ))" + local poolend="$CNET.$(( $num + 14 ))" + echo "subnet $network netmask $netmask {" + echo " range $poolstart $poolend;" + echo " option routers $router;" + echo "}" + echo "" + ip addr add $router/28 dev $iface || echo "Failed to set address $router/28 on $iface" >&2 + ip link set dev $iface up + iptables -t nat -A PREROUTING -i $iface -j DNAT --to-destination $router +} + +make_dhcp_global() { + echo "option domain-name \"bootstrap.invalid\";" + echo "option domain-name-servers $CNET.1;" + echo "ddns-update-style none;" + echo "" +} + +# parse args +while getopts "b:" opts; do + case "$opts" in + b) BRNUM="$OPTARG";; + h) usage;; + esac +done +shift $(( $OPTIND - 1 )) + +hostname alpine + +# install needed packages +apk_add dhcp iptables tinydns acf-apk "$@" + +# config dhcp server +make_dhcp_global > /etc/dhcp/dhcpd.conf +count=0 +for i in $(get_interfaces); do + # maximum 16 network interfaces + [ $count -ge 16 ] && break + make_dhcp_subnet $(( $count * 16 )) $i >> /etc/dhcp/dhcpd.conf + count=$(( $count + 1 )) +done + +/etc/init.d/syslog start +/etc/init.d/dhcpd start +FORCE_SETUP_WEBCONF=yes setup-webconf apk "$@" + +# set up http listener/forwarder +mkdir -p /var/www/redirect +cat </var/www/redirect/index.html + + + + + + + +EOF +httpd -h /var/www/redirect + +# dummy dns +echo "* $CNET.1" > /etc/dnsd.conf +/etc/init.d/dnsd start + +exit 0 diff --git a/setup-webconf b/setup-webconf index aba6223..1776577 100644 --- a/setup-webconf +++ b/setup-webconf @@ -28,23 +28,24 @@ while [ $# -gt 0 ]; do shift done -# issue warning so user knows what he is doing -echo "!!!" -echo "!!! WARNING !!! WARNING !!! WARNING !!!" -echo "!!!" -echo "!!! The webinterface is in alpha stage and will give *anyone* on the" -echo "!!! network access to your box. The web interface is only for testing" -echo "!!! purposes and should only be used in isolated secure networks." -echo "!!!" -echo "!!! Please send suggestions and patches to acf@lists.alpinelinux.org" -echo "!!!" - - -echon "Are you sure you want continue? (y/n) [n] " -default_read imsure n -if [ "$imsure" != y ]; then - echo "Aborting." - exit +if [ "$FORCE_SETUP_WEBCONF" != yes ]; then + # issue warning so user knows what he is doing + echo "!!!" + echo "!!! WARNING !!! WARNING !!! WARNING !!!" + echo "!!!" + echo "!!! The webinterface is in alpha stage and will give *anyone* on the" + echo "!!! network access to your box. The web interface is only for testing" + echo "!!! purposes and should only be used in isolated secure networks." + echo "!!!" + echo "!!! Please send suggestions and patches to acf@lists.alpinelinux.org" + echo "!!!" + + echon "Are you sure you want continue? (y/n) [n] " + default_read imsure n + if [ "$imsure" != y ]; then + echo "Aborting." + exit + fi fi # install packages @@ -53,6 +54,7 @@ apk_add mini_httpd $pkgs || exit 1 # setup mini_httpd and start it mkdir -p /var/www/localhost/ ln -s /usr/share/acf/www/ /var/www/localhost/htdocs +lbu add /var/www/localhost/htdocs SSLDIR=/etc/ssl/mini_httpd -- cgit v1.2.3