Ejemplo n.º 1
0
 private function update_history($ip)
 {
     //insert disconnect state
     $ipv4 = new \Ipm\Ipv4object($ip->ipv4);
     $ipv4Int = $ipv4->toInt();
     if ($ipv4Int > 0) {
         $q = array('ip_dotted' => $ip->ipv4, 'ip_int' => $ipv4Int, 'time' => time(), 'device' => 0, 'user' => $this->user);
         $history = new \Ipm\Model_History($q);
         $history->save();
     }
 }
Ejemplo n.º 2
0
 private function update_history($ip)
 {
     $ipv4 = new \Ipm\Ipv4object($ip->ipv4);
     $ipv4Int = $ipv4->toInt();
     $device = $ip->network->device;
     if (strlen($ip->ipv4) > 0) {
         $q = array('ip_dotted' => $ip->ipv4, 'ip_int' => $ipv4Int, 'time' => time(), 'device' => $device->id, 'devname' => $device->hostname, 'user' => 1);
         $history = new \Ipm\Model_History($q);
         $history->save();
     }
 }
Ejemplo n.º 3
0
 public static function Network_Ip($model, $method)
 {
     $ipm_history = \DBUtil::checkIfExist('ipm_history');
     if ($ipm_history) {
         if ($method == 'before_delete') {
             $ipv4 = new Ipv4object($model->ipv4);
             $ipv4Int = $ipv4->toInt();
             if ($ipv4Int > 0) {
                 $q = array('ip_dotted' => $model->ipv4, 'ip_int' => $ipv4Int, 'time' => time(), 'device' => 0, 'devname' => '', 'user' => 1);
                 $history = new \Ipm\Model_History($q);
                 $history->save();
             }
         }
         if ($method == 'before_save') {
             $oldipv4 = '';
             $old_data = \DB::select('ipv4')->from('network_ip_ports')->where('id', $model->id)->as_object()->execute();
             if (count($old_data) > 0) {
                 $oldipv4 = $old_data[0]->ipv4;
             }
             if (strlen($model->ipv4) > 0) {
                 $ipv4 = new Ipv4object($model->ipv4);
                 $ipv4Int = $ipv4->toInt();
                 $device = $model->network->device->id;
                 $hist = \Ipm\Model_History::find('last');
                 $up = true;
                 if ($hist) {
                     if ($hist['ip_int'] == $ipv4Int and $hist['device'] == $device) {
                         $up = false;
                     }
                 }
                 //update new location for ip
                 if ($up) {
                     $q = array('ip_dotted' => $model->ipv4, 'ip_int' => $ipv4Int, 'time' => time(), 'device' => $device, 'devname' => $model->network->device->hostname, 'user' => 1);
                     $history = new \Ipm\Model_History($q);
                     $history->save();
                 }
                 if (strlen($oldipv4) > 0) {
                     //set old ip to undefined(device = 0)
                     if ($oldipv4 != $model->ipv4) {
                         $ipv42 = new Ipv4object($oldipv4);
                         $ipv4Int2 = $ipv42->toInt();
                         $q = array('ip_dotted' => $oldipv4, 'ip_int' => $ipv4Int2, 'time' => time(), 'device' => 0, 'devname' => '', 'user' => 1);
                         $history2 = new \Ipm\Model_History($q);
                         $history2->save();
                     }
                 }
             }
         }
     }
 }