} $fp = popen("tail -F {$pdbSyslog} -n0 2>&1", 'r'); while (is_resource($fp)) { $line = fgets($fp); $pdbConfig = parse_ini_file($pdbConfigFile, true); // reread config file. // Nov 10 07:43:46 raspberrypi hostapd: wlan0: STA 10:ae:60:4f:44:83 IEEE 802.11: authenticated $Interface = "/hostapd: wlan0:/"; $authenticated = "/IEEE 802.11: authenticated/"; if (preg_match($Interface, $line) and preg_match($authenticated, $line)) { $items = explode(' ', $line); if (!isValidMac($items[7])) { $validMac = false; if (!isValidMac($items[6])) { $validMac = false; if (!isValidMac($items[8])) { $validMac = false; } else { $validMac = 8; } } else { $validMac = 6; } } else { $validMac = 7; } if ($validMac !== false) { $macAddress = strtoupper($items[$validMac]); if ($pdbConfig['General']['debug'] == 1) { echo "MAC:{$macAddress}\n"; }
/** * Method to add or replace the node metadata. * Editable attributes: * - config * - cpu * - delay * - ethernet * - icon * - idlepc * - image * - left * - name * - nvram * - ram * - serial * - slots * - top * If an attribute is set and is valid, then it will be used. If an * attribute is not set, then the original is maintained. If in attribute * is set and empty '', then the current one is deleted. * * @param Array $p Parameters * @return int 0 means ok */ public function edit($p) { $modified = False; if (isset($p['config']) && $p['config'] === '') { // Config is empty, unset the current one unset($this->config); $modified = True; } else { if (isset($p['config']) && !checkNodeConfig($p['config'])) { // Config is invalid, ingored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40003]); } else { if (isset($p['config'])) { $this->config = $p['config']; $modified = True; } } } if (isset($p['delay']) && $p['delay'] === '') { // Delay is empty, unset the current one unset($this->delay); $modified = True; } else { if (isset($p['delay']) && (int) $p['delay'] < 0) { // Delay is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40004]); } else { if (isset($p['delay'])) { $this->delay = (int) $p['delay']; } } } if (isset($p['icon']) && $p['icon'] === '') { // Icon is empty, unset the current one unset($this->icon); $modified = True; } else { if (isset($p['icon']) && !checkNodeIcon($p['icon'])) { // Icon is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40005]); } else { if (isset($p['icon'])) { $this->icon = $p['icon']; } } } if (isset($p['image']) && ($p['image'] === '' || !checkNodeImage($p['image'], $p['type'], $p['template']))) { // Image is not valid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40006]); } else { if (isset($p['image'])) { $this->image = $p['image']; $modified = True; } } if (isset($p['left']) && $p['left'] === '') { // Left is empty, unset the current one unset($this->left); $modified = True; } else { if (isset($p['left']) && !checkPosition($p['left'])) { // Left is not valid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40007]); } else { if (isset($p['left'])) { $this->left = $p['left']; $modified = True; } } } if (isset($p['name']) && $p['name'] === '') { // Name is empty, unset the current one unset($this->name); $modified = True; } else { if (isset($p['name']) && !checkNodeName($p['name'])) { // Name is not valid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40008]); } else { if (isset($p['name'])) { $this->name = $p['name']; $modified = True; } } } if (isset($p['top']) && $p['top'] === '') { // Top is empty, unset the current one unset($this->top); $modified = True; } else { if (isset($p['top']) && !checkPosition($p['top'])) { // Top is not valid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40010]); } else { if (isset($p['top'])) { $this->top = $p['top']; $modified = True; } } } // Specific parameters if ($this->type == 'iol') { if (isset($p['ethernet']) && $p['ethernet'] === '') { // Ethernet interfaces is empty, unset the current one unset($p['ethernet']); $modified = True; } else { if (isset($p['ethernet']) && (int) $p['ethernet'] < 0) { // Ethernet interfaces is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40012]); } else { if (isset($p['ethernet']) && $this->ethernet != (int) $p['ethernet']) { // New Ethernet value $this->ethernet = (int) $p['ethernet']; $modified = True; } } } if (isset($p['nvram']) && $p['nvram'] === '') { // NVRAM is empty, unset the current one unset($p['nvram']); $modified = True; } else { if (isset($p['nvram']) && (int) $p['nvram'] <= 0) { // NVRAM is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40011]); } else { if (isset($p['nvram'])) { $this->nvram = (int) $p['nvram']; } } } if (isset($p['ram']) && $p['ram'] === '') { // RAM is empty, unset the current one unset($p['ram']); $modified = True; } else { if (isset($p['ram']) && (int) $p['ram'] <= 0) { // RAM is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40009]); } else { if (isset($p['ram'])) { $this->ram = (int) $p['ram']; } } } if (isset($p['serial']) && $p['serial'] === '') { // Serial interfaces is empty, unset the current one unset($p['serial']); $modified = True; } else { if (isset($p['serial']) && (int) $p['serial'] < 0) { // Serial interfaces is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40013]); } else { if (isset($p['serial']) && $this->serial != (int) $p['serial']) { // New Serial value $this->serial = (int) $p['serial']; $modified = True; } } } } if ($this->type == 'dynamips') { if (isset($p['idlepc']) && $p['idlepc'] === '') { // Idle PC is empty, unset the current one unset($p['idlepc']); $modified = True; } else { if (isset($p['idlepc']) && !checkNodeIdlepc($p['idlepc'])) { // Idle PC is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40014]); } else { if (isset($p['idlepc'])) { $this->idlepc = $p['idlepc']; } } } if (isset($p['nvram']) && $p['nvram'] === '') { // NVRAM is empty, unset the current one unset($p['nvram']); $modified = True; } else { if (isset($p['nvram']) && (int) $p['nvram'] <= 0) { // NVRAM is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40011]); } else { if (isset($p['nvram'])) { $this->nvram = (int) $p['nvram']; } } } if (isset($p['ram']) && $p['ram'] === '') { // RAM is empty, unset the current one unset($p['ram']); $modified = True; } else { if (isset($p['ram']) && (int) $p['ram'] <= 0) { // RAM is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40009]); } else { if (isset($p['ram'])) { $this->ram = (int) $p['ram']; } } } // Loading slots foreach ($p as $key => $module) { if (preg_match('/^slot[0-9]+$/', $key)) { // Found a slot $slot_id = substr($key, 4); if ($module == '') { // Slot is empty, unset the current one unset($this->slots[$slot_id]); $modified = True; } else { if (!isset($this->slots[$slot_id]) || $this->slots[$slot_id] != $module) { // Need to set the slot (previous was empty or different module) $this->setSlot($slot_id, $module); $modified = True; } } } } } if ($this->type == 'qemu') { // TODO check if == vnc or telnet (checkConsole) if (isset($p['console']) && $p['console'] === '') { // Console is empty, unset the current one unset($p['console']); $modified = True; } else { if (isset($p['console'])) { $this->console = htmlentities($p['console']); $modified = True; } } if (isset($p['cpu']) && $p['cpu'] === '') { // Configured CPUs is empty, unset the current one unset($p['cpu']); $modified = True; } else { if (isset($p['cpu']) && (int) $p['cpu'] <= 0) { // Configured CPUs is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40011]); } else { if (isset($p['cpu'])) { $this->cpu = (int) $p['cpu']; } } } if (isset($p['ram']) && $p['ram'] === '') { // RAM is empty, unset the current one unset($p['ram']); $modified = True; } else { if (isset($p['ram']) && (int) $p['ram'] <= 0) { // RAM is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40009]); } else { if (isset($p['ram'])) { $this->ram = (int) $p['ram']; } } } if (isset($p['ethernet']) && $p['ethernet'] === '') { // Ethernet interfaces is empty, unset the current one unset($p['ethernet']); $modified = True; } else { if (isset($p['ethernet']) && (int) $p['ethernet'] <= 0) { // Ethernet interfaces is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40012]); } else { if (isset($p['ethernet']) && $this->ethernet != (int) $p['ethernet']) { // New Ethernet value $this->ethernet = (int) $p['ethernet']; $modified = True; } } } if (isset($p['uuid']) && $p['uuid'] === '') { // UUID is empty, unset the current one unset($this->uuid); $modified = True; } else { if (isset($p['uuid']) && !checkUuid($p['uuid'])) { // UUID is not valid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40026]); } else { if (isset($p['uuid'])) { $this->uuid = $p['uuid']; $modified = True; } } } if (isset($p['firstmac']) && !isValidMac($p['firstmac'])) { $this->firstmac = '00:50:' . sprintf('%02x', $this->tenant) . ':' . sprintf('%02x', $this->id / 512) . ':' . sprintf('%02x', $this->id % 512) . ':00'; $modified = True; } else { if (isset($p['firstmac']) && isValidMac($p['firstmac'])) { $this->firstmac = (string) $p['firstmac']; } } } if ($this->type == 'docker') { if (isset($p['ram']) && $p['ram'] === '') { // RAM is empty, unset the current one unset($p['ram']); $modified = True; } else { if (isset($p['ram']) && (int) $p['ram'] <= 0) { // RAM is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40009]); } else { if (isset($p['ram'])) { $this->ram = (int) $p['ram']; } } } if (isset($p['ethernet']) && $p['ethernet'] === '') { // Ethernet interfaces is empty, unset the current one unset($p['ethernet']); $modified = True; } else { if (isset($p['ethernet']) && (int) $p['ethernet'] <= 0) { // Ethernet interfaces is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40012]); } else { if (isset($p['ethernet']) && $this->ethernet != (int) $p['ethernet']) { // New Ethernet value $this->ethernet = (int) $p['ethernet']; $modified = True; } } } } if ($this->type == 'vpcs') { if (isset($p['ethernet']) && $p['ethernet'] === '') { // Ethernet interfaces is empty, unset the current one unset($p['ethernet']); $modified = True; } else { if (isset($p['ethernet']) && (int) $p['ethernet'] <= 0) { // Ethernet interfaces is invalid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][40012]); } else { if (isset($p['ethernet']) && $this->ethernet != (int) $p['ethernet']) { // New Ethernet value $this->ethernet = (int) $p['ethernet']; $modified = True; } } } } if ($modified) { // At least an attribute is changed // Set interface name if (isset($p['ethernet'])) { $this->setEthernets(); } if (isset($p['serial']) && $this->type == 'iol') { $this->setSerials(); } return 0; } else { // No attribute has been changed error_log(date('M d H:i:s ') . 'ERROR: ' . $GLOBALS['messages'][40016]); return 40016; } }