Mike Noyes assured me that my message would not bounce.  So I am
including the whole checkdisk weblet script.  

I added one more thing to search for and that is floppy drives. 
Ideally, I don't think you'd want to leave your media mounted. (crack
could be run on the shadow password file because the msdos packages are
mounted world readable.  Yeah Yeah, if your firewall is compromised.) In
a normal start of DCD your floppy(s) or CD-ROM media are not left
mounted. That's why I thought it was relevant to only search for
/dev/ram* at first.  However, the web page message of checkdisk sounds
like its talking about checking your floppies for room to back up
packages.  If you have a floppy that meets the weblet error message
criteria, then the web page will display an error.  The check of
floppies may be useful then.

This solution still seems lame because it doesn't take care of all the
other media types.  However, the solution probably takes care of most of
the problems.

Test with a floppy at 98% full and cdrom mounted:

Fri Apr 12 19:59:55 UTC 2002

myrouter Disk Status: error 

<snip>

Details:

Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/ram0                12155      3367      8788  28% /
/dev/ram1                 4049        44      4005   1% /var/log
/dev/hda                 19368     19368         0 100% /mnt/cdrom
/dev/fd0                  1424      1402        22  98% /mnt/floppy

Test with a floppy that has more available space mounted:

Fri Apr 12 20:19:22 UTC 2002

myrouter Disk Status: ok 

<snip>

Details:

Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/ram0                12155      3368      8787  28% /
/dev/ram1                 4049        44      4005   1% /var/log
/dev/hda                 19368     19368         0 100% /mnt/cdrom
/dev/fd0                  1424       805       619  57% /mnt/floppy

Test with /dev/ram1 at 100 percent capacity:

Fri Apr 12 20:24:38 UTC 2002

myrouter Disk Status: error 

<snip>

Details:

Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/ram0                12155      3368      8787  28% /
/dev/ram1                 4049      4049         0 100% /var/log
/dev/hda                 19368     19368         0 100% /mnt/cdrom
/dev/fd0                  1424       805       619  57% /mnt/floppy

The new code with a few more comments:

#!/bin/sh

. /etc/weblet.conf

func=$1

setwarn() {
        case $level in
        warn|error) 
                ;;
        *)
                level=warn
                bkg='BGCOLOR="#ffff33"'
                ;;
        esac
}

seterror() {
        level=error
        bkg='BGCOLOR="#ff3333"'
}

OIFS=$IFS
IFS='
'
level=ok
bkg='BGCOLOR="#33ff33"'

for line in `df | grep /dev/` ; do
   # Look at the greped line returned from df.
   # Error reporting is only concerned about shortage of space 
   # on both floppy drives and ram drives.
   # All other mounted media is presumed to be some sort of
   # readonly boot media.  The default case statement, *) 
   # will ignore readonly media especially cdroms.
   case $line in
     # Search for /dev/fd* and /dev/ram* lines to calculate
     # drive capacity ratios.
   *fd*|*ram*)
        IFS=$OIFS
        set -- $line

        DEV=${1#/dev/}
        
        used=${5%\%}
        used=${used:-100}

        free=${4:-0}
        pcnt=$(( ${free} * 100 / ${2:-1} ))

        eval WRN_PCNT=\$WRN_DISK_${DEV}_PCNT
        eval WRN_K=\$WRN_DISK_${DEV}_K
        eval ERR_PCNT=\$ERR_DISK_${DEV}_PCNT
        eval ERR_K=\$ERR_DISK_${DEV}_K

        WRN_PCNT=${WRN_PCNT:-$WRN_DISK_PCNT}
        WRN_K=${WRN_K:-$WRN_DISK_K}
        ERR_PCNT=${ERR_PCNT:-$ERR_DISK_PCNT}
        ERR_K=${ERR_K:-$ERR_DISK_K}

        [ "$pcnt" -le "${WRN_PCNT}" ] && setwarn
        [ "$free" -le "${WRN_K}" ] && setwarn
        [ "$pcnt" -le "${ERR_PCNT}" ] && seterror
        [ "$free" -le "${ERR_K}" ] && seterror
        ;;
   *) 
        continue
        ;;
   esac
done

case $func in
verbose)
        cat <<- /HTML-DATA
        Content-type: text/html
        
        <HTML><HEAD><TITLE>${0##*/}</TITLE></HEAD>
        $(cat cgi.include)
        <BODY>
        <script language="JavaScript">b_head();</script>
        <script language="JavaScript">t_head("Firewall Status");</script>
        <tr><td><div>
        <p>$(date)</p>
        <table><tr><td>$(hostname) Disk Status:</td>
        <td ${bkg}><b>${level}</b></td></tr></table>
        <p><b>NOTE:</b> If you have less than about 750K free disk
        space, you need to be very careful backing up large packages,
        like root.  You could run out of disk space and corrupt your
        LRP disk image, making it unusable. It is always a good idea
        to verify the current and new package sizes before writing
        the new package to the disk.</p>
        <p><b>Details:</b></p>
        <pre>$(df)</pre>
        </div></td></tr>
        <script language="JavaScript">t_foot();</script>
        <script language="JavaScript">b_foot();</script>
        </BODY></HTML>
        /HTML-DATA
        ;;
img)
        case $level in
        ok|warn|error) 
                echo "Content-type: image/gif"
                echo "Expires: Thu,  7 Mar 1968 00:00:00 GMT"
                echo ""
                cat "../images/${level}.gif"
                ;;
        *) 
                echo "Status: 400 Bad Request"
                echo ""
                ;;
        esac
        ;;
*)
        echo "Content-type: text/html"
        echo "Status: 400 Bad Request"
        echo ""
        echo "<HTML><HEAD><TITLE>ERROR</TITLE></HEAD>"
        echo "<BODY BGCOLOR=\"#cc9999\"><H2>400 Bad Request</H2>"
        echo "Unknown response format: $1"
        count=1
        while [ ${count} -le 5 ] ; do
                echo "<!-- Padding to override IE 'friendly error pages' -->"
                echo "<!-- Response must be longer than 0x200 bytes -->"
                count=$(( $count + 1 ))
        done
        echo "</BODY></HTML>"
        exit 1
        ;;
esac


Greg Morgan


Greg Morgan wrote:
> 
> Charles Steinkuehler wrote:
> >
> > > > - Alter weblet disk-checking script to ignore CD-ROM (always 100% full)
> > >
> > > I am not following the weblet CD-ROM issue.  I am running weblet 1.2.0
> > > off of DCD 1.0.2.  I've clicked all around on the weblet web pages and I
> > > do not see where the CD-ROM is reported at all.
> >
> > If you mount the CD-ROM, the weblet disk-check script will report an error.
> > This only occurs when the CD-ROM is actually mounted (ie it shows up in the
> > output of df).  The disk monitoring script should probably be modified to
> > ignore read-only media.
> >
> ahhhhhh.  I see the problem now after I mounted the cdrom.  I didn't
> save the original file to do a diff on it, but a weblet checkdisk
> solution is listed below.  I am not posting all of it because my message
> would get bounced because of html content.  I simply added a case
> statement and ignored all lines that are not /dev/ram?  Four lines of
> comments explain my rational in the code below.
> 
> I hope this helps,
> Greg Morgan
> 
> for line in `df | grep /dev/` ; do
>    # Look at the greped line returned from df.
>    # We are only concerned about shortage of space on the ram drives.
>    # All other mounted media is presumed to be some sort of boot media.
>    # The default case statement will ignore it especially cdroms.
>    case $line in
>    *ram*)
>         IFS=$OIFS
>         set -- $line
> 
>         DEV=${1#/dev/}
> 
>         used=${5%\%}
>         used=${used:-100}
> 
>         free=${4:-0}
>         pcnt=$(( ${free} * 100 / ${2:-1} ))
> 
>         eval WRN_PCNT=\$WRN_DISK_${DEV}_PCNT
>         eval WRN_K=\$WRN_DISK_${DEV}_K
>         eval ERR_PCNT=\$ERR_DISK_${DEV}_PCNT
>         eval ERR_K=\$ERR_DISK_${DEV}_K
> 
>         WRN_PCNT=${WRN_PCNT:-$WRN_DISK_PCNT}
>         WRN_K=${WRN_K:-$WRN_DISK_K}
>         ERR_PCNT=${ERR_PCNT:-$ERR_DISK_PCNT}
>         ERR_K=${ERR_K:-$ERR_DISK_K}
> 
>         [ "$pcnt" -le "${WRN_PCNT}" ] && setwarn
>         [ "$free" -le "${WRN_K}" ] && setwarn
>         [ "$pcnt" -le "${ERR_PCNT}" ] && seterror
>         [ "$free" -le "${ERR_K}" ] && seterror
>         ;;
>    *)
>         continue
>         ;;
>    esac
> done

_______________________________________________
Leaf-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user

Reply via email to