Advertisement
Guest User

sophos-config.sh

a guest
Jul 2nd, 2014
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.10 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## Sophos Batch Configuration Script
  4. # @author: Darin Webb
  5. # @file: sophos-config.sh
  6. # Functions for modifying the configuration of many remote Sophos UTM devices.
  7. # Requires the public ssh key of executing system to be loaded in every target UTM for root user, SSH must be turned on and root login allowed with public key.
  8.  
  9. ### Parameters
  10. # verbose : set to true for additional logging
  11. # hostsfile : default is ./inventory/hosts
  12. verbose=true
  13. hostsfile="./inventory/hosts"
  14.  
  15. # List hosts we're going to try to connect to, skipping blank lines and # comments
  16. hosts=( `grep -vE '^(\s*$|#)' $hostsfile`)
  17.  
  18. ### Functions
  19.  
  20. #### checkin : Check In
  21. # Usage: checkin $hosts
  22. # 1. $hosts : a list of target UTMs
  23. function checkin {
  24.     for host in "${$1[@]}"; do
  25.         printf "Checking in with $host : "
  26.         ssh root@$host hostname
  27.     done
  28. }
  29.  
  30. #### resetAdminPw : Reset Admin Password
  31. # Usage: resetAdminPw $hosts $password
  32. # 1. $hosts : a list of target UTMs
  33. # 2. $password : the new password
  34. function resetAdminPw {
  35.     for host in "${$1[@]}"; do
  36.         printf "Resetting Admin password on $host\n"
  37.         ssh root@$host cc passwd $2
  38.         printf "Password reset on $host\n"
  39.     done
  40. }
  41.  
  42. #### resetUserPw : Reset WebAdmin User Password
  43. # Usage: resetAdminPw $hosts $user $password
  44. # 1. $hosts : a list of target UTMs
  45. # 2. $user : the name of the WebAdmin user to modify
  46. # 3. $password : the new password
  47. function resetUserPw {
  48.     for host in "${$1[@]}"; do
  49.         printf "Resetting $2 password on $host\n"
  50.         ssh root@$host 'confd-client.plx change_object `confd-client.plx get_objects_filtered "\\$_->{data}->{name} eq \"$2\"" | pcregrep -o REF_AaaUse[A-Za-z]*` md4hash `printf "$3" | iconv -f ASCII -t UTF-16LE | openssl dgst -md4 | cut -f 2 -d \ `'
  51.         printf "Password reset for $2 on $host\n"
  52.     done
  53. }
  54.  
  55. ### Do Stuff
  56. checkin $hosts
  57. read -n1 -r -p "Enter a new password for the Admin user: " newAdminPw
  58. resetAdminPw $hosts $newAdminPw
  59. read -n1 -r -p "Enter a new password for the TestAdmin user: " newTestAdminPw
  60. resetUserPw $hosts "TestAdmin" $newTestAdminPw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement