home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 August - Disc 1 / PCNET_CD_2006_08_1.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / betaftpd-cc < prev    next >
Encoding:
Text File  |  2005-07-03  |  9.7 KB  |  314 lines

  1. #!/bin/sh
  2. # (c) papaschtroumpf 2005 for puppy linux
  3. # this "control center" interacts with the BetaFTPD FTP server program
  4. # which runs in the background
  5. #
  6. # This script is designed to run with a version of betaftpd that I
  7. # modified to accept a command line argument "-restrict" to restrict
  8. # upload to the anonymous account.
  9. # Note that there is no way to determine the restricted state of the 
  10. # server at run time, so if the server was started manually, the state
  11. # of the semaphore file (/ect/betaftpd.restricted) may be wrong!
  12. # If in doubt click the button to force the desired state
  13. #
  14.  
  15. VERSIONNUMBER="0.0.8pre17-pup-4"
  16. INSTALLDIR="/usr/sbin"
  17. RUNOPTIONS="-contain"
  18. SEMAPHOREFILE="/etc/betaftpd.restricted"
  19. HELPDIR="/usr/share/doc/"
  20. ANONUSER="ftp"
  21. BGCOLOR="#e0ffe0"
  22. ERRORCOLOR="#ffe0e0"
  23.  
  24. # The BetaFTPD package for puppy provides a deny_sh "fake shell"
  25. # that can be used to prevent users created for FTP purpose only to
  26. # be able to have shell access
  27. # We will use this for the "ftp" user
  28. DENYSHELL="/usr/bin/deny_sh"
  29.  
  30.  
  31. while true
  32. do 
  33.  
  34.   ANONSTATUS="Anonymous FTP access is disabled"
  35.   ANONBUTTON="Enable Anon:15,"
  36.   ANONDIR=""
  37.   RESTRICTEDSTATUS=""
  38.   RESTRICTEDBUTTON=""
  39.   grep "$ANONUSER:" /etc/passwd
  40.   if [ $? -eq 0 ] ; then
  41.     if [ -d /root/ftp ] ; then
  42.       ANONDIR=`grep "$ANONUSER:" /etc/passwd | cut -f 6 -d":"`
  43.       ANONSTATUS="Anonymous FTP access is available for $ANONDIR"
  44.       ANONBUTTON="Disable Anon:14,"
  45.       if [ -f $SEMAPHOREFILE ] ; then
  46.         RESTRICTEDSTATUS="Download-only"
  47.         RESTRICTEDBUTTON="Full Access:16,"
  48.       else
  49.         RESTRICTEDSTATUS="FULL"
  50.         RESTRICTEDBUTTON="Download Only:17,"
  51.       fi
  52.     fi
  53.   fi
  54.  
  55.  
  56.   if [ -f /var/log/xferlog ]
  57.   then
  58.     LOGSTATUS="ENABLED"
  59.     LOGBUTTON="Disable Logging:12,"
  60.     VIEWBUTTON="View Xfer Log:13,"
  61.   else
  62.     LOGSTATUS="DISABLED"
  63.     LOGBUTTON="Enable Logging:12,"
  64.     VIEWBUTTON=""
  65.   fi
  66.  
  67.   
  68.   ps | egrep "[SR] +$INSTALLDIR/betaftpd" >/dev/null
  69.   if [ $? -eq "0" ]
  70.   then
  71.     RUNSTATUS="RUNNING"
  72.     RUNBUTTON="Stop FTP Server:11,"
  73.   else
  74.     RUNSTATUS="STOPPED"
  75.     RUNBUTTON="Start FTP Server:10,"
  76.   fi
  77.  
  78. BUTTONS="${LOADSAVEBUTTONS}$RUNBUTTON$ANONBUTTON$RESTRICTEDBUTTON$LOGBUTTON$VIEWBUTTON Help:21,EXIT:19"
  79.  
  80.   xmessage -bg "$BGCOLOR" -center -name "BetaFTPD" -title "BetaFTPD Control Center" -buttons "$BUTTONS" -file -<<MSG1
  81. --- This is the BetaFTPD Control Center ---
  82. BetaFTPD is a single threaded fast and efficient FTP server
  83.  
  84. * This is betaftpd-$VERSIONNUMBER
  85. * BetaFTPD is currently $RUNSTATUS
  86. * BetaFTPD log (/var/log/xferlog) is currently $LOGSTATUS
  87. * $RESTRICTEDSTATUS $ANONSTATUS
  88. * Users with a password on their account have full access 
  89.   to their home directory by logging in as themselves.
  90.  
  91. Changing options may restart the server.
  92. MSG1
  93.  
  94.   RETVALUE=$?
  95.  
  96.   ##################################################################
  97.   #  Start Server
  98.   #
  99.   if [ $RETVALUE -eq 10 ];then
  100.     if [ -f $SEMAPHOREFILE ] ; then
  101.       $INSTALLDIR/betaftpd -restrict $RUNOPTIONS
  102.     else
  103.       $INSTALLDIR/betaftpd $RUNOPTIONS
  104.     fi
  105.     continue
  106.   fi
  107.  
  108.  
  109.   ##################################################################
  110.   #  Stop Server
  111.   #
  112.   if [ $RETVALUE -eq 11 ];then 
  113.     THEPID=`ps | egrep -e"[SR] +/usr/sbin/betaftpd" | sed -e "s/^ \+//" | cut -f1 -d" "`
  114.     kill -sTerm $THEPID
  115.     continue
  116.   fi
  117.  
  118.  
  119.  
  120.   ##################################################################
  121.   #  Toggle logging
  122.   #
  123.   if [ $RETVALUE -eq 12 ];then
  124.     # not sure what the server will do if the logging file disappears 
  125.     # from under it, and it will not discover the file has been created
  126.     # until a restart, so always restart it if it was started
  127.     if [ $RUNSTATUS = "RUNNING" ] ; then
  128.       THEPID=`ps | egrep -e"[SR] +/usr/sbin/betaftpd" | sed -e "s/^ \+//" | cut -f1 -d" "`
  129.       kill -sTerm $THEPID
  130.       sleep 2
  131.     fi
  132.     if [ "$LOGSTATUS" = "DISABLED" ];then
  133.       # creating the log file enables logging
  134.       echo "# This is the BetaFTPD transfer log" >/var/log/xferlog
  135.       echo "# Format: <date> <xfer time> <IP address> <xfer size> <filename> b _ <iNPUT/oUTPUT> a <owner> ftp 0 *" >>/var/log/xferlog
  136.     else
  137.       rm -f /var/log/xferlog
  138.       xmessage -bg "$BGCOLOR" -center -name "BetaFTPD" -title "BetaFTPD Control Center" "The log file has been reset"
  139.     fi
  140.     sync
  141.     if [ $RUNSTATUS = "RUNNING" ] ; then
  142.       if [ -f $SEMAPHOREFILE ] ; then
  143.         $INSTALLDIR/betaftpd -restrict $RUNOPTIONS
  144.       else
  145.         $INSTALLDIR/betaftpd $RUNOPTIONS
  146.       fi
  147.     fi
  148.     continue
  149.   fi
  150.  
  151.  
  152.   ##################################################################
  153.   #  View Transfer Log
  154.   #
  155.   if [ $RETVALUE -eq 13 ];then
  156.     if [ -f /var/log/xferlog ] ; then
  157.       sync
  158.       leafpad /var/log/xferlog &
  159.     else
  160.       xmessage -bg "$ERRORCOLOR" -center -name "BetaFTPD" -title "BetaFTPD Control Center" "BetaFTPD logging is not enabled"
  161.     fi
  162.     continue
  163.   fi
  164.  
  165.  
  166.   ##################################################################
  167.   #  Disable Anonymous
  168.   #
  169.   if [ $RETVALUE -eq 14 ];then
  170.     if [ $RUNSTATUS = "RUNNING" ] ; then
  171.       THEPID=`ps | egrep -e"[SR] +/usr/sbin/betaftpd" | sed -e "s/^ \+//" | cut -f1 -d" "`
  172.       kill -sTerm $THEPID
  173.       sleep 1
  174.     fi
  175.     deluser $ANONUSER >/dev/null
  176.     # I think this is safe: clean up the group file since it fills in a new entry whenever we
  177.     # create a new instance of the "ftp" user
  178.     sed -i.bak '/^[0-9]\+:x:[0-9]\+:ftp *$/ d' /etc/group
  179.     grep "$ANONUSER:" /etc/passwd >/dev/null
  180.     if [ $? -eq 0 ] ; then
  181.       xmessage -bg "$ERRCOLOR" -center -name "BetaFTPD" -title "BetaFTPD Control Center" -file -<<MSG3
  182. Could not remove the "$ANONUSER" user!
  183. You should delete the user manually (try the deluser command)
  184. or at least rename/remove the $ANONDIR directory.
  185. Until you do this, Anonymous FTP is STILL ENABLED!
  186. The server has been stopped.
  187. MSG3
  188.     else
  189.       xmessage -bg "$BGCOLOR" -center -name "BetaFTPD" -title "BetaFTPD Control Center" -file -<<MSG4
  190. The user "$ANONUSER" was removed to prevent Anonymous FTP
  191. The shared directory $ANONDIR was not touched however.
  192. The server will be restarted if it was running.
  193. MSG4
  194.       if [ $RUNSTATUS = "RUNNING" ] ; then
  195.         $INSTALLDIR/betaftpd -restrict $RUNOPTIONS 
  196.       fi
  197.     fi
  198.     continue
  199.   fi
  200.  
  201.  
  202.   ##################################################################
  203.   #  Enable Anonymous
  204.   #
  205.   if [ $RETVALUE -eq 15 ];then
  206.     if [ $RUNSTATUS = "RUNNING" ] ; then
  207.       THEPID=`ps | egrep -e"[SR] +/usr/sbin/betaftpd" | sed -e "s/^ \+//" | cut -f1 -d" "`
  208.       kill -sTerm $THEPID
  209.       sleep 1
  210.     fi
  211.     echo "echo --- Creating the \"$ANONUSER\" user for Anonymous FTP access" > /tmp/betaftd-cc.tmp
  212.     echo "echo For security reasons, the user \"ftp\" will not have shell access" >> /tmp/betaftd-cc.tmp
  213.     echo "echo however sure the password you enter below in NOT BLANK" >> /tmp/betaftd-cc.tmp
  214.  
  215.     echo "echo \" \"" >> /tmp/betaftd-cc.tmp
  216.     echo "adduser -h /root/$ANONUSER -s $DENYSHELL $ANONUSER " >> /tmp/betaftd-cc.tmp
  217.     chmod +x /tmp/betaftd-cc.tmp
  218.     rxvt -bg Yellow3 -e "/tmp/betaftd-cc.tmp"
  219.     rm -f /tmp/betaftd-cc.tmp
  220.     if [ -f $SEMAPHOREFILE ] ; then
  221.       RESTRICTEDSTATUS="Download-only"
  222.     else
  223.       RESTRICTEDSTATUS="FULL upload/delete"
  224.     fi
  225.     grep "$ANONUSER:" /etc/passwd >/dev/null
  226.     if [ $? -eq 0 ] ; then
  227.       echo "Anonymous FTP directory" >/root/$ANONUSER/betaftpd.anon.readme
  228.       xmessage -bg "$BGCOLOR" -center -name "BetaFTPD" -button "Show Dir:10,Okay:11" -title "BetaFTPD Control Center" -file -<<MSG6
  229. The user "$ANONUSER" was properly created.
  230. Anonymous FTP is now available for directory: /root/$ANONUSER
  231. Anonymous users have $RESTRICTEDSTATUS access to that directory.
  232. If the directory already existed, all files that were in it are now shared!
  233. You may want to check the contents of the directory (click "Show Dir").
  234. The server will be restarted if it was running.
  235. MSG6
  236.       if [ $? -eq 10 ] ; then
  237.         rox -d /root/$ANONUSER
  238.       fi
  239.     else
  240.       xmessage -bg "$ERRCOLOR" -center -name "BetaFTPD" -title "BetaFTPD Control Center" -file -<<MSG5
  241. Could not create the "$ANONUSER" user!
  242. You can try and create the user manually (try the adduser command)
  243. Until you do this, Anonymous FTP is NOT ENABLED!
  244. MSG5
  245.     fi
  246.     if [ $RUNSTATUS = "RUNNING" ] ; then
  247.       if [ -f $SEMAPHOREFILE ] ; then
  248.         $INSTALLDIR/betaftpd -restrict $RUNOPTIONS
  249.       else
  250.         $INSTALLDIR/betaftpd $RUNOPTIONS
  251.       fi
  252.     fi
  253.     continue
  254.   fi
  255.  
  256.  
  257.  
  258.   ##################################################################
  259.   #  Enable full access
  260.   #
  261.   if [ $RETVALUE -eq 16 ];then
  262.     if [ $RUNSTATUS = "RUNNING" ] ; then
  263.       THEPID=`ps | egrep -e"[SR] +/usr/sbin/betaftpd" | sed -e "s/^ \+//" | cut -f1 -d" "`
  264.       kill -sTerm $THEPID
  265.       sleep 1
  266.     fi
  267.     # remove the semaphore file
  268.     rm -f $SEMAPHOREFILE
  269.     sync
  270.     if [ $RUNSTATUS = "RUNNING" ] ; then
  271.       $INSTALLDIR/betaftpd $RUNOPTIONS
  272.     fi
  273.     xmessage -bg "$BGCOLOR" -center -name "BetaFTPD" -title "BetaFTPD Control Center" "Everyone can now upload or delete files in $ANONDIR!"
  274.     continue
  275.   fi
  276.  
  277.  
  278.  
  279.   ##################################################################
  280.   #  Enable download only access
  281.   #
  282.   if [ $RETVALUE -eq 17 ];then
  283.     if [ $RUNSTATUS = "RUNNING" ] ; then
  284.       THEPID=`ps | egrep -e"[SR] +/usr/sbin/betaftpd" | sed -e "s/^ \+//" | cut -f1 -d" "`
  285.       kill -sTerm $THEPID
  286.       sleep 1
  287.     fi
  288.     # create the semaphore file
  289.     echo "BetaFTPD semaphore file - DO NOT REMOVE!"> $SEMAPHOREFILE
  290.     sync
  291.     if [ $RUNSTATUS = "RUNNING" ] ; then
  292.       $INSTALLDIR/betaftpd -restrict $RUNOPTIONS
  293.     fi
  294.     continue
  295.   fi
  296.  
  297.  
  298.  
  299.   ##################################################################
  300.   #  Help
  301.   #
  302.   if [ $RETVALUE -eq 21 ];then 
  303.     dillo $HELPDIR/betaftpd.htm &
  304.     continue
  305.   fi
  306.  
  307.  
  308.   ##################################################################
  309.   #  Exit
  310.   #
  311.   if [ $RETVALUE -eq 19 ];then 
  312.     exit
  313.   fi
  314. done