home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / languard / languardnss7.exe / securityversion.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2004-12-17  |  6.6 KB  |  184 lines

  1. #!/bin/bash
  2.  
  3. appfile=applications
  4.  
  5. #below is a list of applications and their version, please note that the application name and version are
  6. #seperated by the "~" symbol 
  7. #if you wish to check for other applications simply add the entry you wish belowno further changes will be necessary
  8. #records below use the following structure:
  9. #<RPM Package name>~<Major release>~<Latest security update version>~<Latest application update version>
  10. #<Major release> is used by the script below to differenciate between major release of packages. 
  11. #the system works by matching the value of <Major release> with the first corresponding number of characters of the actually version.
  12.  
  13. #data file starting below
  14. cat << EOF > applications 
  15. apache2~2.0~2.0.52~2.0.52
  16. apache~1.3~1.3.33~1.3.33
  17. bash~2~2.05c~2.05c
  18. bash~1~1.14.7~1.14.7
  19. kernel-smp~2.6~2.6.9~2.6.9
  20. kernel~2.6~2.6.9~2.6.9
  21. kernel-smp~2.4~2.4.28~2.4.28
  22. kernel~2.4~2.4.28~2.4.28
  23. kernel-smp~2.2~2.2.26~2.2.26
  24. kernel~2.2~2.2.26~2.2.26
  25. kernel-smp~2.0~2.0.40~2.0.40
  26. kernel~2.0~2.0.40~2.0.40
  27. openssh~3~3.9p1~3.9p1
  28. samba~3~3.0.9~3.0.9
  29. openssl~0.9~0.9.7e~0.9.7e
  30. bind~9~9.3.0~9.3.0
  31. bind~8~8.4.5~8.4.5
  32. bind~4~4.9.11~4.9.11
  33. dhcp~3~3.0.2rc3~3.0.2rc3
  34. gcc-c++~3~3.4.3~3.4.3
  35. sudo~1~1.6.8p2~1.6.8.p5
  36. gcc~3~3.4.3~3.4.3
  37. iptables~1.2~1.2.11~1.2.11
  38. sendmail~8~8.12.10~8.13.1
  39. mysql-shared~4.0~4.0.22~4.0.22
  40. mysql-shared~4.1~4.1.7~4.1.7
  41. mysql-shared~5.0~5.0.2~5.0.2
  42. mysql~4.0~4.0.22~4.0.22
  43. mysql~4.1~4.1.7~4.1.7
  44. mysql~5.0~5.0.2~5.0.2
  45. postgresql~7~7.4.6~7.4.6
  46. cvs~1.11~1.11.18~1.11.18
  47. cvs~1.12~1.12.11~1.12.11
  48. net-snmp~5~5.2~5.2
  49. postfix~2.1~2.1.5-4~2.1.5-4
  50. EOF
  51. #data file finished
  52. #anything below here should not require any editing. Unless there's a need to change the script's functionality ofcourse.
  53.  
  54. declare -a apps
  55. filestore=`date --iso-8601`_apps 
  56.  
  57. if [ ! -e "$filestore" ]
  58. then
  59.     rpm -qa --qf '%{NAME}~%{VERSION}\n' > "$filestore"
  60.     filetodelete=`cat filestorever`
  61.     rm -f `echo $filetodelete`
  62.     echo "$filestore" > filestorever
  63.  
  64. fi
  65. oldversions=FALSE
  66. apps=(` cat "$filestore" | tr '\n' ' '`)
  67. count=${#apps[*]}
  68. echo "" > installedapps
  69. for ap in ${apps[@]}
  70. do
  71.     echo $ap >> installedapps
  72. done
  73. #echo ${apps[@]} > installedapps
  74. declare -a applist
  75. applist=( `cat "$appfile" | tr '\n' ' '`)
  76. appcount=${#applist[*]}
  77.  
  78. for AppToTest in ${applist[@]}
  79. do
  80.     appname=`echo $AppToTest | awk -F~ ' { print $1 } '`
  81.     appmajorrelease=`echo $AppToTest | awk -F~ ' { print $2 } '`
  82.     appfullversec=`echo $AppToTest | awk -F~ ' { print $3 } '`
  83.     appmajor1sec=`echo $appfullversec | awk -F. ' { print $1 } '`
  84.     appmajor2sec=`echo $appfullversec | awk -F. ' { print $2 } '`
  85.     appminorsec=`echo $appfullversec | awk -F. ' { print $3 } '`
  86.     matchapps=`grep -i $appname installedapps`
  87.     for AppRecord in ${matchapps[@]}
  88.     do
  89.         StAppName=`echo $AppRecord | awk -F~ ' { print $1 } '`
  90.         if [ "$StAppName" == "$appname" ]
  91.         then
  92.             len=`echo $appmajorrelease | awk ' { print length } '`
  93.             tempapp=`echo $AppRecord~$len`
  94.             stmajorrelease=`echo $tempapp | awk -F~ ' { print substr($2,1,$3) } '`
  95.             stappfullver=`echo $tempapp | awk -F~ ' { print $2 } '`
  96.             stappfullversec=`echo $AppRecord | awk -F~ ' { print $3 } '`
  97.             stappfullverapp=`echo $AppRecord | awk -F~ ' { print $4 } '`
  98.                 stappmajor1=`echo $stappfullver | awk -F. ' { print $1 } '`
  99.                 stappmajor2=`echo $stappfullver | awk -F. ' { print $2 } '`
  100.                 stappminor=`echo $stappfullver | awk -F. ' { print $3 } '`
  101.             if [ "$stmajorrelease" == "$appmajorrelease" ]
  102.             then
  103.  
  104.                 #substitution for version which include RC
  105.                 stappmajor1=`echo $stappmajor1 |  sed s/rc/./`
  106.                 stappmajor2=`echo $stappmajor2 | sed s/rc/./`
  107.                 stappminor=`echo $stappminor | sed s/rc/./`
  108.                 appmajor1sec=`echo $appmajor1sec | sed s/rc/./`
  109.                             appmajor2sec=`echo $appmajor2sec | sed s/rc/./`
  110.                             appminorsec=`echo $appminorsec | sed s/rc/./`
  111.                             #substitution for version which include p
  112.                 stappmajor1=`echo $stappmajor1 |  sed s/p/./`
  113.                 stappmajor2=`echo $stappmajor2 | sed s/p/./`
  114.                 stappminor=`echo $stappminor | sed s/p/./`
  115.                 appmajor1sec=`echo $appmajor1sec | sed s/p/./`
  116.                             appmajor2sec=`echo $appmajor2sec | sed s/p/./`
  117.                             appminorsec=`echo $appminorsec | sed s/p/./`
  118.                             
  119.                             stappmajor1=`echo $stappmajor1 | sed 's/[a-f]/.&/'`
  120.                                 stappmajor2=`echo $stappmajor2 | sed 's/[a-f]/.&/'`
  121.                                 stappminor=`echo $stappminor | sed 's/[a-f]/.&/'`
  122.                                 appmajor1sec=`echo $appmajor1sec |  sed 's/[a-f]/.&/'`
  123.                                 appmajor2sec=`echo $appmajor2sec |  sed 's/[a-f]/.&/'`
  124.                                 appminorsec=`echo $appminorsec |  sed 's/[a-f]/.&/'`
  125.  
  126.                 stappmajor1=`echo $stappmajor1 |  tr [a-f] [1-6]`
  127.                             stappmajor2=`echo $stappmajor2 | tr [a-f] [1-6]`
  128.                             stappminor=`echo $stappminor |  tr [a-f] [1-6]`
  129.                             appmajor1sec=`echo $appmajor1sec | tr [a-f] [1-6]` 
  130.                             appmajor2sec=`echo $appmajor2sec | tr [a-f] [1-6]` 
  131.                             appminorsec=`echo $appminorsec | tr [a-f] [1-6]`
  132.  
  133.                 if [ "$appmajor2sec" == "" ]
  134.                             then
  135.                                     appmajor2sec=0
  136.                             fi
  137.                             if [ "$stappmajor2" == "" ]
  138.                             then
  139.                                     stappmajor2=0
  140.                             fi
  141.     
  142.                 if [ "$appminorsec" == "" ]
  143.                 then
  144.                     appminorsec=0
  145.                 fi
  146.  
  147.                 if [ "$stappminor" == "" ]
  148.                             then
  149.                                     stappminor=0
  150.                             fi
  151.  
  152.     
  153.                             temp=`echo "$appmajor1sec $appmajor2sec $appminorsec"`
  154.                                 procappversec=`echo $temp | awk '{ print $1 * 10000 + $2 * 100 + $3 }'`
  155.                                 temp=`echo "$stappmajor1 $stappmajor2 $stappminor"`
  156.                                 procstappver=`echo $temp | awk ' { print $1 * 10000 + $2 * 100 + $3 }'`
  157.         
  158.                 if [ $procstappver \< $procappversec ]
  159.                 then    
  160.                     if [ "$oldversions" == FALSE ]
  161.                     then
  162.                         echo "TRUE:"
  163.                         oldversions=TRUE
  164.                     fi
  165.                     
  166.                     app=`echo $AppToTest | awk -F~ ' { print $1 } '` 
  167.                     echo "AddListItem([[[]]],[[[Application: $app current version is: $stappfullver. The latest version with security fixes is: $appfullversec]]])"
  168.                 fi
  169.  
  170.  
  171.  
  172.             fi
  173.         fi
  174.     done
  175. done
  176. if [ "$oldversions" == FALSE ]
  177. then
  178.     echo "FALSE:"
  179. fi
  180.  
  181. rm -f applications
  182. rm -f installedapps
  183. echo "!!SCRIPT_FINISHED!!"
  184.