Ejemplo n.º 1
0
 /**
  * 
  * Update database update mac/conn device/ vlan/ configdata
  */
 public function action_index()
 {
     if (isset($this->field)) {
         $out['status'] = 'ok';
         $val = \Validation::forge();
         $val->add_field('act', 'action id', 'required|min_length[1]|max_length[20]');
         $val->add_field('val', 'value', 'required|min_length[1]');
         $val->add_field('mid', 'mac port id', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             $new_val = $val->validated('val');
             if ($this->tmpl) {
                 $macport = Model_Device_Template_Network_Mac::find($val->validated('mid'));
             } else {
                 $macport = Model_Network_Mac::find($val->validated('mid'));
             }
             if ($macport) {
                 switch ($val->validated('act')) {
                     case 'macset':
                         if ($this->isValidMAC($new_val)) {
                             $macport->mac_address = $new_val;
                         } else {
                             $out['old'] = $macport->mac_address;
                             $out['status'] = 'no';
                         }
                         break;
                     case 'connect':
                         $dev = Model_Device::find($new_val);
                         if ($dev) {
                             $macport->conn_device = $dev->id;
                         }
                         break;
                     case 'disconnect':
                         $macport->conn_device = 0;
                         break;
                     case 'vlanset':
                         if ($new_val == 0) {
                             $macport->vlan = 0;
                         } else {
                             if ($this->tmpl) {
                                 $vlan = Model_Device_Template_Network_Vlan::find($new_val);
                             } else {
                                 $vlan = Model_Network_Vlan::find($new_val);
                             }
                             $macport->vlan = $vlan->id;
                         }
                         break;
                 }
                 $macport->save();
             }
         }
         echo json_encode($out);
     }
 }
Ejemplo n.º 2
0
 /**
  * 
  * Update database update mac/conn device/ vlan/ configdata
  */
 public function action_index()
 {
     if (isset($this->field)) {
         $out['status'] = 'ok';
         $val = \Validation::forge();
         $val->add_field('act', 'action id', 'required|min_length[1]|max_length[20]');
         $val->add_field('val', 'value', 'required|min_length[1]');
         if ($val->run()) {
             $new_val = $val->validated('val');
             switch ($val->validated('act')) {
                 case 'add':
                     if (!$this->tmpl) {
                         $prop = array('name' => $new_val, 'networkID' => $this->field->network->id);
                         $vlan = new Model_Network_Vlan($prop);
                     } else {
                         $prop = array('name' => $new_val, 'tempnetID' => $this->field->network->id);
                         $vlan = new Model_Device_Template_Network_Vlan($prop);
                     }
                     $vlan->save();
                     break;
                 case 'rem':
                     if (!$this->tmpl) {
                         $vlan = Model_Network_Vlan::find($new_val);
                     } else {
                         $vlan = Model_Device_Template_Network_Vlan::find($new_val);
                     }
                     if ($vlan) {
                         $vlan->delete();
                     }
                     break;
                 case 'ren':
                     break;
             }
             $data = $this->data();
             return \Response::forge(\View::forge('network/vlans', $data));
         }
         echo json_encode($out);
     }
 }
Ejemplo n.º 3
0
 public function data()
 {
     $data = array('net_type' => $this->net_type, 'con_type' => $this->con_type, 'net' => $this->field->network);
     if ($this->net_type == 1) {
         $data['conn'] = $this->connection_data();
         if ($this->tmpl) {
             $data['ips'] = Model_Device_Template_Network_Ip::find()->where('tempnetID', $this->field->network->id)->order_by('type', 'asc')->order_by('id', 'asc')->get();
         } else {
             $data['ips'] = Model_Network_Ip::find()->where('networkID', $this->field->network->id)->order_by('type', 'asc')->order_by('id', 'asc')->get();
         }
     }
     if ($this->net_type == 2) {
         $data['conn'] = $this->connection_data();
         if ($this->tmpl) {
             $data['ips'] = Model_Device_Template_Network_Ip::find()->where('tempnetID', $this->field->network->id)->order_by('type', 'asc')->order_by('id', 'asc')->get();
             $data['macs'] = Model_Device_Template_Network_Mac::find()->where('tempnetID', $this->field->network->id)->order_by('id', 'asc')->get();
             $data['vlans'] = Model_Device_Template_Network_Vlan::find()->where('tempnetID', $this->field->network->id)->order_by('id', 'asc')->get();
         } else {
             $data['ips'] = Model_Network_Ip::find()->where('networkID', $this->field->network->id)->order_by('type', 'asc')->order_by('id', 'asc')->get();
             $data['macs'] = Model_Network_Mac::find()->where('networkID', $this->field->network->id)->order_by('id', 'asc')->get();
             $data['vlans'] = Model_Network_Vlan::find()->where('networkID', $this->field->network->id)->order_by('id', 'asc')->get();
         }
     }
     if ($this->net_type == 3) {
         $data['conn'] = $this->connection_data();
         if ($this->tmpl) {
             $data['ips'] = Model_Device_Template_Network_Ip::find()->where('tempnetID', $this->field->network->id)->order_by('type', 'asc')->order_by('id', 'asc')->get();
             $data['macs'] = Model_Device_Template_Network_Mac::find()->where('tempnetID', $this->field->network->id)->order_by('id', 'asc')->get();
             $data['vlans'] = Model_Device_Template_Network_Vlan::find()->where('tempnetID', $this->field->network->id)->order_by('id', 'asc')->get();
         } else {
             $data['ips'] = Model_Network_Ip::find()->where('networkID', $this->field->network->id)->order_by('type', 'asc')->order_by('id', 'asc')->get();
             $data['macs'] = Model_Network_Mac::find()->where('networkID', $this->field->network->id)->order_by('id', 'asc')->get();
             $data['vlans'] = Model_Network_Vlan::find()->where('networkID', $this->field->network->id)->order_by('id', 'asc')->get();
         }
     }
     if ($this->tmpl) {
         $data['cables'] = array();
         //Model_Cable::find()->where('dev1',$this->field->templateID)->or_where('dev2',$this->field->templateID)->get();
     } else {
         $data['cables'] = Model_Cable::find()->where('dev1', $this->field->deviceID)->or_where('dev2', $this->field->deviceID)->get();
     }
     return $data;
 }
Ejemplo n.º 4
0
 private function insert_template_to_device_data($field, $new_field)
 {
     #hdd element data
     #####################################################################################
     if ($field->type == 'hdd') {
         //get raid data
         $old_raid = Model_Raid::find()->where('tempfieldID', $field->id)->get_one();
         $hdd = Model_Raid::find()->where('fieldsetID', $new_field->id)->get_one();
         //create new hardware_raid
         $hdd->raid_type = $old_raid->raid_type;
         $hdd->size = $old_raid->size;
         $hdd->total = $old_raid->total;
         $hdd->meta_update_time = time();
         $hdd->meta_update_user = $this->user;
         //$hdd=new Model_Raid($prop);
         $hdd->save();
         //get all discs from array
         foreach ($old_raid->rows as $disc) {
             $m = array('model' => $disc->model, 'size' => $disc->size, 'vport' => $disc->vport, 'serial_number' => $disc->serial_number, 'hardware_raid' => $hdd->id, 'meta_update_time' => time(), 'meta_update_user' => $this->user);
             $discs = new Model_Raid_Data($m);
             $discs->save();
         }
     }
     //ram
     #####################################################################################
     if ($field->type == 'ram') {
         //get ram data
         $old_ram = Model_Ram::find()->where('tempfieldID', $field->id)->get_one();
         $ram = Model_Ram::find()->where('fieldsetID', $new_field->id)->get_one();
         //create new hardware_ram
         $ram->ram_type = $old_ram->ram_type;
         $ram->size = $old_ram->size;
         $ram->total = $old_ram->total;
         $ram->meta_update_time = time();
         $ram->meta_update_user = $this->user;
         $ram->save();
         //get all modules from array
         foreach ($old_ram->rows as $modul) {
             $m = array('hardware_ram' => $ram->id, 'meta_update_time' => time(), 'meta_update_user' => $this->user, 'model' => $modul->model, 'size' => $modul->size, 'port' => $modul->port, 'serial_number' => $modul->serial_number);
             $rams = new Model_Ram_Data($m);
             $rams->save();
         }
     }
     //images
     #####################################################################################
     if ($field->type == 'img') {
         //get field images
         $temp_imags = Model_Device_Template_Image::find()->where('elementID', $field->id)->get();
         foreach ($temp_imags as $img) {
             $props = array('name' => $img->name, 'elementID' => $new_field->id, 'type' => $img->type, 'width' => $img->width, 'height' => $img->height);
             $imgs = new Model_Image($props);
             $imgs->save();
             copy(DOCROOT . 'images/temp' . $img->id . '.png', DOCROOT . 'images/' . $imgs->id . '.png');
             copy(DOCROOT . 'images/tumb/temp' . $img->id . '.png', DOCROOT . 'images/tumb/' . $imgs->id . '.png');
         }
     }
     //power out (PDU,ATS,UPS)
     #####################################################################################
     if ($field->type == 'power_out') {
         //power is set automatic as field saved
         $power = Model_Device_Power::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->power;
         if ($new_field->device->meta_default_data > 0) {
             $max = 42;
         } else {
             $max = 24;
         }
         if ($extra->output > $max) {
             $extra->output = $max;
         }
         //update default data with template power data
         $power->input = $extra->input;
         $power->output = $extra->output;
         $power->type = $extra->type;
         $power->current = $extra->current;
         if ($power->ru == 0) {
             $power->ru = $extra->ru;
             $power->pos = $extra->pos;
         }
         $power->save();
         //delete any default socket
         $defsockets = Model_Device_Power_Socket::find()->where('powerID', $power->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         $n = 1;
         foreach ($field->power->socket as $socket) {
             if ($n > $max) {
                 break;
             }
             $prop = array('powerID' => $power->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Power_Socket($prop);
             $newsocket->save();
             if ($socket->type == 2) {
                 $n++;
             }
         }
     }
     //power in (Server,Switch,Router,...)
     #####################################################################################
     if ($field->type == 'power_in') {
         //power is set automatic as field saved
         $power = Model_Device_Power::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->power;
         //update default data with template power data
         $power->input = $extra->input;
         $power->output = $extra->output;
         $power->type = $extra->type;
         $power->current = $extra->current;
         $power->ru = $extra->ru;
         $power->pos = $extra->pos;
         $power->save();
         //delete any default socket
         $defsockets = Model_Device_Power_Socket::find()->where('powerID', $power->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         foreach ($field->power->socket as $socket) {
             $prop = array('powerID' => $power->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Power_Socket($prop);
             $newsocket->save();
         }
     }
     //kvm out (KVM switch)
     #####################################################################################
     if ($field->type == 'kvm_out') {
         //power is set automatic as field saved
         $kvm = Model_Device_Kvm::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->kvm;
         //update default data with template power data
         $kvm->input = $extra->input;
         $kvm->output = $extra->output;
         $kvm->type = $extra->type;
         $kvm->save();
         //delete any default socket
         $defsockets = Model_Device_Kvm_Socket::find()->where('kvmID', $kvm->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         foreach ($field->kvm->socket as $socket) {
             $prop = array('kvmID' => $kvm->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Kvm_Socket($prop);
             $newsocket->save();
         }
     }
     //KVM in (Server,Switch,Router,...)
     #####################################################################################
     if ($field->type == 'kvm_in') {
         //kvm is set automatic as field saved
         $kvm = Model_Device_Kvm::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->kvm;
         //update default data with template kvm data
         $kvm->input = $extra->input;
         $kvm->output = $extra->output;
         $kvm->type = $extra->type;
         $kvm->save();
         //delete any default socket
         $defsockets = Model_Device_Kvm_Socket::find()->where('kvmID', $kvm->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         foreach ($field->kvm->socket as $socket) {
             $prop = array('kvmID' => $kvm->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Kvm_Socket($prop);
             $newsocket->save();
         }
     }
     //network
     #####################################################################################
     if ($field->type == 'network') {
         //newtwork is set automatic as field saved
         $network = Model_Device_Network::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->network;
         //update default data with  template network data
         $network->type = $extra->type;
         $network->nics = $extra->nics;
         $network->vports = $extra->vports;
         $network->ports = $extra->ports;
         $network->uplinks = $extra->uplinks;
         $network->save();
         switch ($network->type) {
             case 1:
                 //IP addresses
                 foreach ($field->network->ip as $ip) {
                     $prop = array('networkID' => $network->id, 'nic_name' => $ip->nic_name, 'ipv4' => $ip->ipv4, 'ipv6' => $ip->ipv6, 'conn_type' => $ip->conn_type, 'conn_speed' => $ip->conn_speed, 'type' => $ip->type);
                     $ips = new Model_Network_Ip($prop);
                     $ips->save();
                 }
                 break;
                 //MAC and VLAN
             //MAC and VLAN
             case 2:
                 $vlan2port = array();
                 //if no vlan is set to mac
                 $vlan2port[0] = 0;
                 foreach ($field->network->vlan as $vlan) {
                     $prop = array('networkID' => $network->id, 'name' => $vlan->name);
                     $vlans = new Model_Network_Vlan($prop);
                     $vlans->save();
                     $vlan2port[$vlan->id] = $vlans->id;
                 }
                 foreach ($field->network->mac as $mac) {
                     $prop = array('networkID' => $network->id, 'mac_address' => $mac->mac_address, 'conn_device' => $mac->conn_device, 'vlan' => $vlan2port[$mac->vlan], 'type' => $mac->type);
                     $macs = new Model_Network_Mac($prop);
                     $macs->save();
                 }
                 break;
             case 3:
                 foreach ($field->network->mac as $mac) {
                     $prop = array('networkID' => $network->id, 'mac_address' => $mac->mac_address, 'conn_device' => $mac->conn_device, 'vlan' => $mac->vlan, 'type' => $mac->type);
                     $macs = new Model_Network_Mac($prop);
                     $macs->save();
                 }
                 break;
         }
     }
 }