Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## Sophos Batch Configuration Script
- # @author: Darin Webb
- # @file: sophos-config.sh
- # Functions for modifying the configuration of many remote Sophos UTM devices.
- # 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.
- ### Parameters
- # verbose : set to true for additional logging
- # hostsfile : default is ./inventory/hosts
- verbose=true
- hostsfile="./inventory/hosts"
- # List hosts we're going to try to connect to, skipping blank lines and # comments
- hosts=( `grep -vE '^(\s*$|#)' $hostsfile`)
- ### Functions
- #### checkin : Check In
- # Usage: checkin $hosts
- # 1. $hosts : a list of target UTMs
- function checkin {
- for host in "${$1[@]}"; do
- printf "Checking in with $host : "
- ssh root@$host hostname
- done
- }
- #### resetAdminPw : Reset Admin Password
- # Usage: resetAdminPw $hosts $password
- # 1. $hosts : a list of target UTMs
- # 2. $password : the new password
- function resetAdminPw {
- for host in "${$1[@]}"; do
- printf "Resetting Admin password on $host\n"
- ssh root@$host cc passwd $2
- printf "Password reset on $host\n"
- done
- }
- #### resetUserPw : Reset WebAdmin User Password
- # Usage: resetAdminPw $hosts $user $password
- # 1. $hosts : a list of target UTMs
- # 2. $user : the name of the WebAdmin user to modify
- # 3. $password : the new password
- function resetUserPw {
- for host in "${$1[@]}"; do
- printf "Resetting $2 password on $host\n"
- 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 \ `'
- printf "Password reset for $2 on $host\n"
- done
- }
- ### Do Stuff
- checkin $hosts
- read -n1 -r -p "Enter a new password for the Admin user: " newAdminPw
- resetAdminPw $hosts $newAdminPw
- read -n1 -r -p "Enter a new password for the TestAdmin user: " newTestAdminPw
- resetUserPw $hosts "TestAdmin" $newTestAdminPw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement