Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 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
     //
 }