Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fGenTCPTAB(){
- # This query pulls all the data necessary for TCPTAB
- # from multiple tables. Probably don't want to touch this.
- SQL="
- SELECT
- a.storename,
- INET_NTOA(a.ip) as eth0_ip,
- INET_NTOA('4294967232') as eth0_netmask,
- INET_NTOA(b.ip) as eth0_gateway,
- c.eth1_ip,c.eth1_netmask,c.eth1_gateway,c.additional
- FROM $devicetable AS a
- LEFT JOIN
- (
- SELECT storename,type,ip
- FROM $devicetable
- WHERE type='Router / FRAD' ORDER BY ip
- ) AS b
- ON a.storename=b.storename
- LEFT JOIN
- (
- SELECT
- storename,
- INET_NTOA(eth1_ip) as eth1_ip,
- INET_NTOA(eth1_netmask) as eth1_netmask,
- INET_NTOA(eth1_gateway) as eth1_gateway,
- additional
- FROM $addtable
- ) AS c
- ON a.storename=c.storename
- WHERE a.type='RxServer'
- GROUP BY a.storename
- "
- fRunQuery
- # Change IFS to NL
- IFS="
- "
- # For each line in the SQL result, split it apart.
- for entry in $(echo "$RESULT")
- do
- # Temporarily change IFS to default, and then read the line
- # into an array. Then restore IFS.
- OLDIFS=$IFS
- IFS=" "
- arr=( $entry )
- IFS=$OLDIFS
- # Get the number of columns in the array.
- colnums=${#arr[@]}
- # Split up the data into readable variables.
- storename=${arr[0]}
- eth0_ip=${arr[1]}
- eth0_netmask=${arr[2]}
- eth0_gateway=${arr[3]}
- eth1_ip=${arr[4]}
- eth1_netmask=${arr[5]}
- eth1_gateway=${arr[6]}
- # If we have more than 7 columns (remember, 0 counts)
- # and we have at least 10, this is extra routing information.
- # This will all be appended to a one variable for the
- # Extra field in TCPTAB.
- extra=''
- if [[ $colnums -ge 10 ]]
- then
- for (( i=7; i<${colnums}; i++));
- do
- extra="$extra ${arr[$i]}"
- done
- fi
- # The PHP code serverside requires that each of these fields
- # have either a string value or NULL (So we can accurately count them)
- # Change any NULL values to blank.
- # NOTE: At least 3 words must exist for the $extra column to populate.
- [[ $eth1_ip == "NULL" ]] && eth1_ip=''
- [[ $eth1_netmask == "NULL" ]] && eth1_netmask=''
- [[ $eth1_gateway == "NULL" ]] && eth1_gateway=''
- [[ $eth0_ip == "NULL" ]] && eth1_ip=''
- [[ $eth0_netmask == "NULL" ]] && eth1_netmask=''
- [[ $eth0_gateway == "NULL" ]] && eth1_gateway=''
- [[ $extra =~ NULL ]] && extra=''
- # Now setup printf to output the records.
- printf "%-15s %-15s %-15s %-15s | " $storename $eth0_ip $eth0_netmask $eth0_gateway >> $TCPTAB
- printf "%-15s %-15s %-15s | " $eth1_ip $eth1_netmask $eth1_gateway >> $TCPTAB
- printf "%-4s %-15s %-15s " $extra >> $TCPTAB
- printf "\n" >> $TCPTAB
- done
- } #end function
Add Comment
Please, Sign In to add comment