require_once("config.inc"); require_once("util.inc"); require_once("service-utils.inc"); function usage() { echo "Usage: playback static_list \n"; echo "or\n"; echo "Usage: playback static_list \n"; echo "or\n"; echo "Usage: playback static_list \n"; } global $g, $config, $argv, $command_split; if (is_array($command_split)) { $args = array_slice($command_split, 2); } else { $args = array_slice($argv, 3); } if (empty($args[0])) { usage(); } $action = $args[0]; $interface = $args[1]; $ip = $args[2]; $mac = $args[3]; $hostname = $args[4]; $description = $args[5]; $mac = strtolower($mac); preg_match('/^(add|del)$/', $action) or die(usage()); preg_match('/^[A-z0-9]+$/', $interface) or die(usage()); preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $ip) or die(usage()); preg_match('/^[a-f0-9]{2}\:[a-f0-9]{2}\:[a-f0-9]{2}\:[a-f0-9]{2}\:[a-f0-9]{2}\:[a-f0-9]{2}$/', $mac) or die(usage()); if(!empty($hostname)) preg_match('/^[A-z0-9\_]+$/', $hostname) or die(usage()); if(!strcmp($action, 'add')) { $arr_size = count($config['dhcpd'][$interface]['staticmap']); for($i = 0; $i < $arr_size; $i++) { if(!strcasecmp($config['dhcpd'][$interface]['staticmap'][$i]['mac'], $mac)) { die; } } $config['dhcpd'][$interface]['staticmap'][] = array ( 'mac' => $mac, 'ipaddr' => $ip, 'hostname' => $hostname, 'descr' => $description, 'arp_table_static_entry' => '', 'filename' => '', 'rootpath' => '', 'defaultleasetime' => '', 'maxleasetime' => '', 'gateway' => '', 'domain' => '', 'domainsearchlist' => '', 'ddnsdomain' => '', 'ddnsdomainprimary' => '', 'ddnsdomainsecondary' => '', 'ddnsdomainkeyname' => '', 'ddnsdomainkeyalgorithm' => '', 'ddnsdomainkey' => '', 'tftp' => '', 'ldap' => '', 'nextserver' => '', 'filename32' => '', 'filename64' => '', 'filename32arm' => '', 'filename64arm' => '', 'uefihttpboot' => '', 'numberoptions' => '' ); system("/usr/sbin/arp -S " . escapeshellarg($ip) . " " . escapeshellarg($mac)); } if(!strcmp($action, 'del')) { $arr_size = count($config['dhcpd'][$interface]['staticmap']); for($i = 0; $i < $arr_size; $i++) { if(!strcmp($config['dhcpd'][$interface]['staticmap'][$i]['ipaddr'], $ip) and !strcasecmp($config['dhcpd'][$interface]['staticmap'][$i]['mac'], $mac)) { unset($config['dhcpd'][$interface]['staticmap'][$i]); system("/usr/sbin/arp -d " . escapeshellarg($ip)); break; } } } parse_config(true); write_config();