public function action_index() { $out = array('status' => 'ok', 'data' => array()); \Fuel\Core\Module::load('basic'); if ($_POST) { $val = \Validation::forge(); $val->add_field('eid', 'vps id', 'max_length[20]'); $val->add_field('val', 'ip address', 'required|min_length[1]|max_length[20]'); if ($val->run()) { $v = $val->validated('eid'); $ip = $val->validated('val'); $vps = \Basic\Model_Vps::find($v); foreach ($vps->device->network as $net) { //nope } if ($vps) { $i = \Basic\Model_Network_Ip::query()->where('ipv4', $ip)->get_one(); $ipv4 = new \Ipm\Ipv4object($ip); if (!$i) { $prop = array('networkID' => $net->id, 'nic_name' => '', 'ipv4' => $ip, 'ipv6' => '', 'conn_type' => 0, 'conn_speed' => 0, 'type' => 3, 'addrint' => $ipv4->toInt()); $netip = new \Basic\Model_Network_Ip($prop); $netip->save(); $vprop = array('vpsID' => $vps->id, 'portID' => $netip->id, 'type' => 1); $port = new \Basic\Model_Vps_Ports($vprop); $port->save(); $out['data'] = array('id' => $port->id, 'val' => $ip, 'vps' => $vps->id); $out['status'] = 'ok'; } } } } echo json_encode($out); }
public static function Device($model, $method) { if ($method == 'before_update') { //\Log::debug('device update'.$model->hostname); $old_data = \DB::select('rack', 'rack_pos')->from('device')->where('id', $model->id)->as_object()->execute(); if (count($old_data) > 0) { $rack = $old_data[0]->rack; $pos = $old_data[0]->rack_pos; if ($rack != $model->rack or $pos != $model->rack_pos) { \Log::debug('device update' . $model->hostname); $network = $model->network; foreach ($network as $net) { $ips = \Basic\Model_Network_Ip::find()->where('networkID', $net->id)->get(); foreach ($ips as $ip) { // \Log::debug('ip::'.print_r($ip,true)); $sub = \Ipm\Model_Subnet::find()->where('range_from', '<=', $ip->addrint)->where('range_to', '>=', $ip->addrint)->get_one(); if ($sub) { \Ipm\Observer::IsValidLocation($sub, $model, $ip); } } } } } } }
public function get_used($subnet, $count = false) { $ipv4 = new Ipv4($subnet); $data = $ipv4->get(); $query = \Basic\Model_Network_Ip::find()->where('addrint', '>=', 1)->where('addrint', '>=', $data['from'])->where('addrint', '<=', $data['to'])->order_by('addrint', 'asc'); if ($count) { return $query->count(); } return $query->get(); }
private function locate($sub) { $this->user = \Sentry::user()->get('id'); $ips = \Basic\Model_Network_Ip::find()->where('addrint', '<=', $sub['range_to'])->where('addrint', '>=', $sub['range_from'])->get(); foreach ($ips as $ip) { $device = $ip->network->device; if ($this->user == $device->meta_update_user) { $this->update_device($ip); } } }
private function updateIpv4() { \Fuel\Core\Module::load('basic', APPPATH . 'modules/basic/'); \Fuel\Core\Module::load('ipm', APPPATH . 'modules/ipm/'); //select * ip from database $ips = \Basic\Model_Network_Ip::find('all'); foreach ($ips as $ip) { if ($ip->ipv4 != '') { $subnet = $this->updateSubnet($ip); $this->update_location($subnet, $ip); $this->update_history($ip); } } //check if subnet exist // }
private function getDevicePort($dev, $num, $type) { $network = \Basic\Model_Device_Network::find()->where('deviceID', $dev->id)->get_one(); //echo $network->id; switch ($dev->cat) { case 2: //switch //switch case 8: //FC switch //FC switch case 3: //router $ports = \Basic\Model_Network_Mac::find()->where('networkID', $network->id)->offset($num - 1)->get_one(); break; case 5: $ext = array(); $int = array(); $ports = new \stdClass(); // get all device ports $ps = \Basic\Model_Network_Mac::find()->where('networkID', $network->id)->get(); // split utp and patch ports foreach ($ps as $port) { if ($port->type == 3) { array_push($ext, $port->id); } if ($port->type == 1) { array_push($int, $port->id); } } if ($type == 4) { $ports->id = $ext[$num - 1]; } if ($type == 1) { $ports->id = $int[$num - 1]; } break; default: $ports = \Basic\Model_Network_Ip::find()->where('networkID', $network->id)->offset($num - 1)->get_one(); break; } return $ports->id; }
private function parse_vps_address() { \Fuel\Core\Module::load('basic', APPPATH . 'modules/basic/'); \Fuel\Core\Module::load('ipm', APPPATH . 'modules/ipm/'); //select * ip from database $ips = \Basic\Model_Vps_Ip::find('all'); foreach ($ips as $ip) { $vps = \Basic\Model_Vps::find($ip->vpsID); $networks = $vps->device->network; foreach ($networks as $net) { } //print_r($net); $ipob = (object) array('ipv4' => $ip->data); if ($ip->data != '') { $ip_int = $this->___IPv4_dotquadA_to_intA($ipob); $ipvps = \Basic\Model_Network_Ip::find()->where('type', 3)->where('networkID', $net->id)->where('addrint', $ip_int)->get_one(); if (!$ipvps) { echo 'ok'; //make new ip input with type 3 $prop = array('networkID' => $net->id, 'nic_name' => 'vps', 'ipv4' => $ip->data, 'ipv6' => '', 'conn_type' => 0, 'conn_speed' => 0, 'type' => 3, 'addrint' => $ip_int); $ipv4 = new \Basic\Model_Network_Ip($prop); $ipv4->save(); $subnet = $this->updateSubnet($ipv4); $this->update_location($subnet, $ipv4); $this->update_history($ipv4); } } } //check if subnet exist // }
private function locate($model) { $this->user = \Sentry::user()->get('id'); $sub = $model->subnet; //\Log::debug('loc:[]'.$sub['id'].' >'.print_r($sub,true)); if ($sub) { $ips = \Basic\Model_Network_Ip::find()->where('addrint', '<=', $sub['range_to'])->where('addrint', '>=', $sub['range_from'])->get(); \Log::debug('ips:' . print_r($ips, true)); //$ips= \Basic\Model_Network_Ip::find()->where('addrint','<=',$sub['range_to'])->where('addrint','>=',$sub['range_from'])->get(); //only rack if ($model->rack > 0) { foreach ($ips as $ip) { $device = $ip->network->device; if ($this->user == $device->meta_update_user) { //check is device if ($device->rack == $model->rack) { if ($device->rack_pos >= $model->pos_from and $device->rack_pos <= $model->pos_to) { $this->update_device($ip); } } } } } else { //room if ($model->room > 0) { foreach ($ips as $ip) { $device = $ip->network->device; //check is device if ($this->user == $device->meta_update_user) { $room = $device->racks->rooms; if ($room->id == $model->room) { $this->update_device($ip); } } } } else { //floor if ($model->floor > 0) { foreach ($ips as $ip) { $device = $ip->network->device; if ($this->user == $device->meta_update_user) { //check is device $floor = $device->racks->rooms->floors; if ($floor->id == $model->floor) { $this->update_device($ip); } } } } else { //building foreach ($ips as $ip) { $device = $ip->network->device; //check is device if ($this->user == $device->meta_update_user) { $building = $device->racks->rooms->floors->buildings; if ($building->id == $model->building) { $this->update_device($ip); } } } } } } } }
public function action_index() { $this->limit = 30; $this->out = array('data' => array(), 'total' => 0, 'from' => 0, 'limit' => $this->limit); if ($this->id) { $val2 = \Validation::forge('data'); $val2->add_field('from', 'from', 'required|min_length[1]|max_length[50]'); $val2->add_field('type', 'type', 'required|min_length[1]|max_length[50]'); if ($val2->run()) { $this->offset = (int) $val2->validated('from') * $this->limit; $this->out['from'] = (int) $val2->validated('from'); switch ($val2->validated('type')) { case 0: //get all devices $devices = \DB::select()->from('device')->as_object()->execute(); $res = \DB::select()->from('device')->execute(); $this->out['total'] = count($res); $this->devices($devices, false); break; case 1: case 2: //get subnodes $devices = $this->get_ip_usage($this->id, true); //print_r($devices); $this->out['total'] = count($devices); //make limit offset $this->devices($devices); break; case 3: $this->subArray = array(); $sub = \Ipm\Model_Subnet::find($this->id); $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); } } $this->out['total'] = count($this->subArray); $this->devices($this->subArray); break; } } echo json_encode($this->out); } }