aboutsummaryrefslogblamecommitdiff
path: root/sysutils/bsdstats/files/300.statistics
blob: 0bc1cd2b07b6a250a83701aec772ea607a49798d (plain) (tree)
1
2
3
4
5
6
7

           
                                                                                                                 



                                                             








                                     


















                                                                  




             


                                                    























                                                                       








                                                                            


















                           
                                                                    


 


                                    
                             
                              
                            

                                                                          
                                                             
                                                  














                                                                                         
        
       


                                                                          



              
#!/bin/sh -
#
# $FreeBSD: /tmp/pcvs/ports/sysutils/bsdstats/files/Attic/300.statistics,v 1.12 2006-08-14 13:08:01 scrappy Exp $
#

# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/periodic.conf ]
then
    . /etc/defaults/periodic.conf
    source_periodic_confs
fi

oldmask=$(umask)
umask 066

checkin_server="bsdstats.org";
id_token_file='/var/db/bsdstats'

IFS="
"

send_devices () {
    for line in `/usr/sbin/pciconf -l | /usr/bin/grep -v none`
    do
      DRIVER=`echo $line | awk -F\@ '{print $1}'`
      DEV=`echo $line | awk '{print $4}' | cut -c8-15`
      CLASS=`echo $line | awk '{print $2}' | cut -c9-14`
      query_string=$query_string`echo \&dev[]=$DRIVER:$DEV:$CLASS`
    done

    do_fetch report_devices.php?key=$KEY$query_string
}

get_id_token () {
    local IFS

    IFS='=
'

    if [ ! -f $id_token_file ] ;
    then
       IDTOKEN=$( /usr/bin/openssl rand -base64 16 )
       
       idf=$( mktemp "$id_token_file.XXXXXX" )   && \
       /usr/sbin/chown root:wheel $id_token_file && \
       /bin/chmod 600 $id_token_file             && \    

       /usr/bin/fetch -qo - \
	   "http://$checkin_server/scripts/getid.php?key=$IDTOKEN" | { 
	   while read var val 
	     do  
	     case $var in
		 KEY)
                     echo "KEY=$val"
		 ;;
		 TOKEN)
                     echo "TOKEN=$val"
		 ;;
		 *)
                 ;;
		 esac
	   done
       } > $idf                                  && \

       mv $idf $id_token_file

       echo "To protect against abuse, the initial challenge/response phase"
       echo "contains a 15 minute pause.  Please be patient while this time"
       echo "limit elapses"
       sleep 900
    fi
    . $id_token_file
    KEY=$( uri_escape $KEY )
}

# RFC 2396
uri_escape () {
    echo ${1+$@} | sed -e '
        s/%/%25/g
        s/;/%3b/g
        s,/,%2f,g
        s/?/%3f/g
        s/:/%3a/g
        s/@/%40/g
        s/&/%26/g
        s/=/%3d/g
        s/+/%2b/g
        s/\$/%24/g
        s/,/%2c/g
        s/ /%20/g
        '
}

do_fetch () {
    /usr/bin/fetch -qo /dev/null "http://$checkin_server/scripts/$1"
}


case "$monthly_statistics_enable" in
    [Yy][Ee][Ss])
      HN=`/bin/hostname`
      REL=`/usr/bin/uname -r`
      ARCH=`/usr/bin/uname -m`
      OS=`/usr/bin/uname -s`
      get_id_token
      do_fetch report_system.php?key=$KEY\&rel=$REL\&arch=$ARCH\&opsys=$OS
      echo "Posting monthly OS statistics to $checkin_server"
      case "$monthly_statistics_report_devices" in
          [Yy][Ee][Ss])
              send_devices
              echo "Posting monthly device statistics to $checkin_server"
              line=$( sysctl -n hw.model )
              VEN=$( echo $line | cut -d ' ' -f 1 )
              DEV=$( uri_escape $( echo $line | cut -d ' ' -f 2- ) )
              count=$( sysctl -n hw.ncpu )
              do_fetch report_cpu.php?key=$KEY\&cpus=$count\&vendor=$VEN\&cpu_type=$DEV
              echo "Posting monthly CPU statistics to $checkin_server"
             ;;
          *) 
             echo "Posting monthly device/CPU statistics disabled"
             echo '    set monthly_statistics_report_devices="YES" in /etc/periodic.conf'
             ;;
      esac
      ;;
    *) 
      echo "Posting monthly OS statistics disabled"
      echo '    set monthly_statistics_enable="YES" in /etc/periodic.conf'
    ;;
esac

umask $oldmask
exit $rc