/** * 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 ($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 ($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; } }
/** * Method to add or replace the network metadata. * Editable attributes: * - left * - name * - top * - type * 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['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'][30003]); } 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'])) { $this->name = htmlentities($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'][30004]); } else { if (isset($p['top'])) { $this->top = $p['top']; $modified = True; } } } if (isset($p['type']) && !checkNetworkType($p['type'])) { // Type is not valid, ignored error_log(date('M d H:i:s ') . 'WARNING: ' . $GLOBALS['messages'][30005]); } else { if (isset($p['type'])) { $this->type = $p['type']; $modified = True; } } if ($modified) { // At least an attribute is changed return 0; } else { // No attribute has been changed error_log(date('M d H:i:s ') . 'ERROR: ' . $GLOBALS['messages'][30006]); return 30006; } }
function checkPosition($widgetID) { $curUser = new DashboardUsers($_SESSION['userid']); $userWidgets = $curUser->get_users_widgets(); $curWidPosX = $curUser->get_position_x($widgetID); $curWidPosY = $curUser->get_position_y($widgetID); foreach ($userWidgets as $widgetID2 => $userID2) { if ($widgetID != $widgetID2) { $compWidPosX = $curUser->get_position_x($widgetID2); $compWidPosY = $curUser->get_position_y($widgetID2); if ($curWidPosX == $compWidPosX && $curWidPosY == $compWidPosY) { $curUser->set_widget_id($widgetID2); $newX = $compWidPosX + 1; $newY = $compWidPosY; if ($newX >= 3) { $newX = 0; $newY++; } $curUser->set_position_x($newX); $curUser->set_position_y($newY); $curUser->update_widget(); checkPosition($widgetID2); } } } }