private function defualtNode() { $m = Model_Node::find()->where('name', 'Detected')->get_one(); if ($m) { return $m->id; } $q = array('name' => 'Detected', 'parent' => 0, 'meta_update_user' => 1); $n = new Model_Node($q); $n->save(); return $n->id; }
public function populate_nodes($node) { $nodes = Model_Node::find($node); $subnets = Model_Subnet::find()->where('parent', $nodes->id)->order_by('size', 'desc')->get(); foreach ($subnets as $sub) { array_push($this->subArray, array('id' => $sub->id, 'subnet' => $sub->subnet, 'size' => $sub->size, 'used' => $this->get_used($sub->subnet, true), 'reserved' => '0')); } $subs = Model_Node::find()->where('parent', $nodes->id)->get(); foreach ($subs as $sub) { $this->populate_nodes($sub->id); } }
public function action_index() { if ($this->id) { $val = \Validation::forge('add'); $val->add_field('name', 'subnet id', 'required|min_length[1]|max_length[20]'); if ($this->type == 0) { $this->id = 0; } if ($val->run()) { //check if exist already $m = Model_Node::find()->where('name', $val->validated('name'))->where('parent', $this->id)->get(); if (!$m) { $q = array('name' => $val->validated('name'), 'parent' => $this->id, 'meta_update_user' => $this->user); $n = new Model_Node($q); $n->save(); echo json_encode(array('id' => $n->id, 'name' => $n->name, 'status' => 'valid')); } else { echo json_encode(array('id' => $m->id, 'name' => $m->name, 'status' => 'taken')); } } } }
public function populate_hist_nodes($node) { $subnets = Model_Subnet::find()->where('parent', $node)->order_by('size', 'desc')->get(); foreach ($subnets as $sub) { $from_pos = $sub['range_from']; $to_pos = $sub['range_to']; $ips = Model_History::find()->where('ip_int', '>=', $from_pos)->where('ip_int', '<=', $to_pos)->get(); foreach ($ips as $ip) { $device = $ip->dev; // print_r($device); array_push($this->subArray, array('id' => $ip->id, 'ip' => $ip->ip_dotted, 'date' => date('d/m/Y H:i:s', $ip->time), 'device' => array('id' => $ip->device, 'name' => $ip->devname, 'erased' => 0))); } } $subs = Model_Node::find()->where('parent', $node)->get(); foreach ($subs as $sub) { $this->populate_hist_nodes($sub->id); } }
public function populate_nodes($node) { $nodes = Model_Node::find($node); $subnets = Model_Subnet::find()->where('parent', $nodes->id)->order_by('size', 'desc')->get(); foreach ($subnets as $sub) { $ips = \Basic\Model_Network_Ip::find()->where('addrint', '>=', $sub->range_from)->where('addrint', '<=', $sub->range_to)->get(); foreach ($ips as $ip) { $dev = $ip->network->device; if (!in_array($dev->id, $this->subArray)) { array_push($this->subArray, $dev->id); } } } $subs = Model_Node::find()->where('parent', $nodes->id)->get(); foreach ($subs as $sub) { $this->populate_nodes($sub->id); } }
/** * * Building tree */ public function action_index() { if ($_POST) { $val = \Validation::forge(); $val->add_field('id', 'node id', 'required|min_length[1]|max_length[20]'); $val->add_field('rel', 'node type', 'required|min_length[1]|max_length[20]'); if ($val->run()) { switch ($this->gettype($val->validated('rel'))) { //root case 0: echo '[{"attr":{"id":"main_1","rel":"main"},"data":"My company","state":"closed"}]'; break; //main //main case 1: $data['nodes'] = Model_Node::find()->where('parent', 0)->get(); return \Response::forge(\View::forge('nodes/main', $data)); break; //submain //submain case 2: $data['nodes'] = Model_Node::find()->where('parent', $val->validated('id'))->get(); $data['subnets'] = Model_Subnet::find()->where('parent', $val->validated('id'))->get(); return \Response::forge(\View::forge('nodes/subnode', $data)); break; //subnets //subnets case 3: $data['subnets'] = Model_Subnet::find()->where('parent', $val->validated('id'))->get(); return \Response::forge(\View::forge('nodes/subnet', $data)); break; //subnet //subnet case 3: echo '{:P}'; break; } //echo $val->validated('id'); } } }
public function action_index() { if ($this->id) { $val = \Validation::forge('add'); $val->add_field('name', 'subnet id', 'required|min_length[1]|max_length[20]'); if ($this->type == 0) { $this->id = 0; } if ($val->run()) { //check if exist already $m = Model_Node::find($this->id); if ($m) { $m->name = $val->validated('name'); $m->save(); echo json_encode(array('id' => $m->id, 'name' => $m->name, 'status' => 'valid')); } else { echo json_encode(array('status' => 'false')); } } } }
public function structure() { $o = array(); switch ($this->type) { case 1: $nodes = Model_Node::find()->where('parent', $this->id)->get(); foreach ($nodes as $node) { $o = array_merge($o, $this->getParentData($node->id)); } $o = array_merge($o, $this->getParentData($this->id)); //get subnets //get child folder subnets break; case 2: $o = $this->getParentData($this->id); //$o = array_merge($o,$this->getData($this->id)); // $o=Array($p,$a); break; case 3: $o = $this->getData($this->id); break; } return $o; }
public function action_index() { if ($this->type >= 0) { switch ($this->type) { default: echo json_encode(array('nop' => 'ok')); break; break; case 0: //get all $this->get_ip_usage('all'); break; case 1: case 2: //get subnodes $this->get_ip_usage($this->id); break; //subnets //subnets case 3: $this->subnet = Model_Subnet::find($this->id); if ($this->subnet) { $used = $this->get_used($this->subnet['subnet']); $parent = Model_Node::find($this->subnet->parent); $ip_used = array(); foreach ($used as $ip) { $device = $ip->network->device; array_push($ip_used, array('id' => $ip['id'], 'ip' => $ip['ipv4'], 'device' => $device->hostname, 'did' => $device->id, 'vps' => $this->isVPS($ip))); } echo json_encode(array('used' => $ip_used, 'parent' => $parent['name'])); } break; //reserved ip-s } } }
public function action_index() { if ($this->id) { $val = \Validation::forge('add'); $val->add_field('name', 'subnet id', 'required|min_length[1]|max_length[20]'); if ($this->type == 0) { $this->id = 0; } if ($val->run()) { //check if exist already $m = Model_Node::find($this->id); if ($m) { $nodes = \Ipm\Model_Node::find()->where('parent', $this->id)->get(); foreach ($nodes as $n) { $n->delete(); } $m->delete(); echo json_encode(array('status' => 'valid')); } else { echo json_encode(array('status' => 'none')); } } } }