This software is released under the terms of the GNU license. Www PacKage loader 0.5 (WPK) ============================ Use this package to load files from your internal web server, avoid buying a second floppy drive or using 1680K diskettes and still get support for sshd as well as your other favorite tools while booting from a single standard 1440K floppy. WWW Package loader helps minimize the number of Thomas' files that you have to diff3 every time you upgrade your FloppyFW. Many thanks to Thomas Lundquist, Brad Wood, Kieth Keller, Uwe Dippel, Koen Vermeer, Ken Yap, Jos Heemskerk, Jim Murphy, Steve Parker, and the other folks at Newsgroup: floppyfw.general. WARNING: This system is only as secure as your web server. If your package web server is breached, your entire network can be breached. Loading anything that will be executed is somewhat unsafe, but web-loading login.bz2 is particularly unsafe as your passwords are stored there. In theory, you could load packages across the Internet right from Thomas' server... Please don't. I'm sure he doesn't pay his ISP so that you can pirate his bandwidth. Tested working with IIS 5, Apache 1.2/1.3 and microhttpd. PREREQUISITES ============= 1.9.20+: none 1.0.x: nc.bz2 OPTIONAL ======== mk2efs.bz2 Required to create a RAMdisk that is not 4MB on versions prior to 2.1.x INSTALL ======= 1) In A:\config, add WWW_PACKAGES= where is the URL to your filelist file on your web server. The URL can be abreviated by accepting my defaults or you can use a complete URL. The default port is 80 The default path is /PACKAGES/ The default document is filelist The default server is the local filesystem (read from file, not http. use this if you want to place the filelist on the floppy) Example: WWW_PACKAGES=http://www.myserver.org:8080/packagepath/customfilelist or WWW_PACKAGES=10.42.42.42 or (not implemented yet!) WWW_PACKAGES=/mnt/packages/filelist 2) Add post-wpk.ini to /packages on your floppy. 3) Put your filelist in /var/www/PACKAGES (served as http://your.server.com/PACKAGES/filelist) or in the path from WWW_PACKAGES= The filelist file contains filenames to be loaded and several commands: ====================================================================== Filenames can be simply the filename or the full URL If only a filename is given, it will be loaded from the most recent server, port and path used. .tar files will be extracted. .bz2 files will be decompressed and the .tar extracted. ** Note ** some packages (ssh) were made with tar's old -o compatiblity flag, -o is not implemented in busybox these packages need to be re-packaged. Some packaging/repackaging scripts also used -o. post-*.ini files will be executed immediately. post-*.ini files that are inside .tar or .bz2 files are not handled by this script. pre-*.ini files are NOT special, put them on the floppy. All other files will be transferred but not executed. Files and commands are transferred/executed in the order of your filelist. The commands are: ================= debug list commands, list some additional information and add -v to tar cd path change directory md path mkdir ln dest source create symbolic link chmod mode file set file permissions rm file remove file md5 (not implemented yet!) Make sure you've got chksum.bz2 on your floppy. ramdisk device mountpoint size create and mount ramdisk of size K. If your ramdisk is not 4096K, you've got to load mke2fs.bz2 first. As of 1.9.21, the max ramdisk size defaulted to 4096K unless you edit syslinux.cfg and put ramdisk_size= in K on the append line. Example filelist: ================= e3.bz2 ramdisk /dev/ram2 /usr 4096 md /usr/tmp sshd1.bz2 ssh-keygen1.bz2 md /opt ramdisk /dev/ram3 /opt 4096 cd /opt http://www.myserver.org/~me/packages/mytools.tar cd /bin halt chmod 755 /bin/halt ln /bin/halt /bin/reboot post-routes.ini post-sshd.ini post-login.ini Revision history 0.1 7/20/02 {BDF} Initial Alpha release for 1.9.20 and 1.9.21 0.2 8/13/02 {BDF} Added support for HTTP1.0, full URLs and 4M Jim Murphy style ramdisk, fixed microhttpd 0.3 9/13/02 {BDF} adjusted ramdisk(), added {Get() Url()} to save space (now <4K) 0.4 10/30/02 {BDF} more space savings, now at 3K. Completed optimizing ramdisk(). 0.5 01/07/03 {BDF} Doc fixes, Added HOST: header to support servers using name based virtual hosting. ToDo: Add support for local filelist (or 2.1.x config format???) Commented version of code: ========================== #!/bin/sh #post-wpk.ini Floppy firewall package loader #Version 0.5 Beta #Linuxboy #Url #Break URL into components and save to globals # Inputs # Http URL incuding Host, Port, Path and File # Inital Defaults # Port 80 # Path /PACKAGES/ # File filelist # Globals # Host # Port # Folder # the path # File # Note, the defaults are not reset between calls. # but the port defaults back to 80 if there is a # host given (without an new port) # If the URL does not begin with "HTTP://" it is assumed to # be a filename and optionally a path Url () { U=$1 #check for a protocol (like HTTP:) P=`expr "$U" : '\([a-zA-Z0-9][a-zA-Z0-9]*\):.*'` #if protocol, assume we have URL and not path/file if [ -z "$P" ] ; then #initialize defaults if Host was set in a prior call if [ -z "$Host" ] ; then Host=$U Port=80 Folder=/PACKAGES/ File=filelist else #no protocol found and not first call, assume path/file File=$U fi else #Strip protocol (assumed to be HTTP:) U=`expr "$U" : "$P:\(.*\)"` #Get everything after // but skipping forward to the last / File=`expr "$U" : "//[^/][^/]*.*/\(.*\)"` #Attempt to split Host and Port H=`expr "$U" : '//\([^/][^/]*\).*'` #If host found, set it. Either set port (if given) or clear it. if [ -n "$H" ] ; then Host=`expr "$H" : '\([^:][^:]*\).*'` #Host was present, either get port or clear the old value so #it can be set to 80 Port=`expr "$H" : '[^:][^:]*:\([0-9][0-9]*\).*'` U=`expr "$U" : "//[^/][^/]*\(.*\)/.*"` fi #Whatever is still left of the URL is the path. Folder=$U/ #if Port was cleared, set default. if [ -z "$Port" ] ; then Port=80 fi fi #Clear the temp variables unset H U P } #Get #Read the webpage, strip headers and send to standard out # Inputs # No parameters. # Globals (none changed) # Host # Port # Folder # the path # File #Note, Apache 1.3 virtual hosting required the Host: header Get () { echo -e "GET "$Folder""$File" HTTP/1.0\r\nHost: $Host\r\n\r" | nc "$Host" "$Port" | StripHeader } #StripHeader #Remove lines from stdin up to 1st blank line and #send remaining lines to stdout #Inputs # Data on stdin #Note, executed in subshell StripHeader () { ( IFS=`echo ""` cat "$@" | ( while read line do [ "$line" = "`echo -e -n "\r"`" ] && break done cat) ) } #Ramdisk4M #Create ramdisk without using mkfs # Inputs # Param1 # ramdisk device # Param2 # mountpoint #As of 1.9.21, there were 16 ramdisks but only 4 devices (0-3) set up in /dev Ramdisk4M () { #octal encoded ASCII version of binary 4M RAMdisk .bz2 file from Jim Murphy ( echo -en "BZh91AY&SY\30\275\350\362\0\0\30\177\367\376\335\300R\310\t@$\50\t\b\ \204\5E\216\20\303\377\340 \n \26@\2\42\1c\326\b\260\1\30$\64E2\0\0\0\0\0\3A\2404h\ \6\233P\343&M\30\206&\230\b\30\23L\21\202bi\246\200\14 \221E\47\223\324\231\32=M4\ \0\r\32\r\00024\0\64h\304\322\301\216\25\351\334\236\344\250\215IJ\264\1RhW]\255iG\ \17<\0\22I_hI$\222\22\315HbK*\2518\321\257HE\21\231\251\254\270\326\237re\242\347\ \351\207W_gm\333\335\326{\357\324\256\3530\317b\4\200\0\50i\n\303\rV\222,q\301-\ \366\bH\0\2N\320\351\265\6\1q\210\250\321+pI @\0N\355\263e\242G\214\nn.b\47\14MLu\ \134q\341\200/\347&\224e\7\331\240\4\361\b&Lg\364\325\31\0\314,\307\222 \300\330\ \310\306\270\16\304e0\1\267\325\256\315\232\322\315\335\341\0\16\206\2\216\361BB\b\ \306\47\24D\33R\227qN\221\4\217\216~J\305\223b%\346 H\0\2\312\21\201\245\313\5\211\ \344\377\27rE8P\220\30\275\350\362") | bzcat - > ${1} mount -t ext2 ${1} ${2} } #main() . /etc/config cd / echo "Checking for packages on ${WWW_PACKAGES} " IFS="`echo -e "\n\r"`" #Read url specified in /etc/config file WWW_PACKAGES setting #and process each line Url ${WWW_PACKAGES} && Get | for line in `cat` ; do unset IFS set `echo -n ${line}` [ "$dbg" = "v" ] && echo ":${line}:" 1>&2 case "${1}" in debug) dbg=v ;; md) mkdir ${2} ;; #symbolic link ln) ln -s -f ${2} ${3} ;; #delete rm) rm ${2} ;; #change permission flags chmod) chmod ${2} ${3} ;; #Set destination path #If a .tar or .bz2 has relative paths, they will be relative to here #Some packages did not use relative paths cd) cd ${2} ;; #Set up and mount a ramdisk, hopefully a 4MB one ramdisk) if [ `mount | grep ${2}` ]; then echo ${2} is already in use. else echo "${4}K RAM disk on ${2} at ${3}" if [ "$4" = "4096" ]; then Ramdisk4M ${2} ${3} ${4} else mke2fs -m0 ${2} ${4} || echo "Need mk2efs unless ramdisk is 4096K" mount -t ext2 ${2} ${3} fi fi ;; #I've never found a read error yet. md5) echo "md5 is not implemented yet" ;; #Everything else is a file. #.tar, .bz2 and post-*.ini files are handled specially #everything else is just placed in the current path *) echo -e "Getting ${1}" if [ `echo $1 | grep .*tar$` ]; then Url ${1} && Get | tar -x${debug} 1>&2 else #.bz2 is assumed to be a .tar inside a .bz2 file (AKA a FFW "package") if [ `echo $1 | grep .*bz2$` ]; then Url ${1} && Get | bzcat -f - | tar -x${debug} 1>&2 else if [ `echo $1 | grep ^post.*\.ini$` ]; then Url ${1} && Get | tr -d '\r' > /etc/${File} chmod 775 /etc/${File} /etc/${File} else Url ${1} && Get > ${File} fi fi fi ;; esac done