#!/usr/bin/env php $id, 'port_id' => $ports['port_id'], 'bill_port_autoadded' => '1' ); dbInsert($insert, 'bill_ports'); } return true; } /** Setup options: l - bill_name - bill glob c - circuit_id - interface glob s - sysName - device glob h - hostname - device glob f - flush - boolean **/ $options = getopt('b:s:h:i:f'); if (!empty($options['s'])) { $host_glob = str_replace('*', '%', mres($options['s'])); $nameType = "sysName"; } if (!empty($options['h'])) { $host_glob = str_replace('*', '%', mres($options['h'])); $nameType = "hostname"; } if (empty($options['s']) && empty($options['h'])) { echo "Please set -s or -h\n"; } elseif (!empty($options['s']) && !empty($options['h'])) { echo "Please set either -s or -h, not both\n"; } if (!empty($options['i']) && !empty($options['h'])) { echo "Please set -i\n"; } $bill_name = str_replace('*', '%', mres($options['b'])); $intf_glob = str_replace('*', '%', mres($options['i'])); if (empty($bill_name) or !(empty($options['h']) and empty($options['s']))) { echo "Usage:\n"; echo "-b Bill name to match\n"; echo "-s sysName to match (Cannot be used with -h)\n"; echo "-h Hostname to match (Cannot be used with -s)\n"; echo "-i Interface description to match\n"; echo "-f Flush all ports from a bill before adding adding ports\n"; echo "Example:\n"; echo "If I wanted to add all interfaces containing the description Telia to a bill called 'My Lovely Transit Provider'\n"; echo "php manage_bills.php -l 'My Lovely Transit Provider' -d all -c Telia"; echo "\n"; exit; } if ($bill_name == 'all') { $bill_name = '%'; } if ($intf_glob == 'all') { $intf_glob = '%'; } if ($host_glob == 'all') { $host_glob = '%'; } if (isset($options['f'])) { $flush = true; } else { $flush = false; } $id = list_bills($bill_name); $devices = get_devices($host_glob, $nameType); if (empty($devices)) { echo "No devices found\n"; exit(1); } if ($flush) { $flush_ret = flush_bill($id); } $ret = add_ports_to_bill($devices, $intf_glob, $id);