Пример #1
0
 public function getSubnets()
 {
     $device = \Basic\Model_Device::find($this->id);
     $rack = $device->racks;
     $room = $rack->rooms;
     $floor = $room->floors;
     $building = $floor->buildings;
     $location = Model_Location_Extra::find()->where('building', $building->id)->get();
     $valid = array();
     foreach ($location as $sub) {
         //distinct rack
         if ($sub['rack'] == $rack->id) {
             array_push($valid, $sub);
         }
         //same room
         if ($sub['rack'] == 0 and $sub['room'] == $room->id) {
             array_push($valid, $sub);
         }
         //same floor
         if ($sub['rack'] == 0 and $sub['room'] == 0 and $sub['floor'] == $floor->id) {
             array_push($valid, $sub);
         }
         //same building
         if ($sub['rack'] == 0 and $sub['room'] == 0 and $sub['floor'] == 0 and $sub['building'] == $building->id) {
             array_push($valid, $sub);
         }
     }
     return $valid;
 }
Пример #2
0
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('room', 'Room id', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             \Fuel\Core\Module::load('basic');
             $room = \Basic\Model_Room::find($val->validated('room'));
             if ($room) {
                 $query = \DB::query('select distinct cables.id  from cables, rack, device where rack.room=' . $room->id . ' and device.rack=rack.id and (device.id=cables.dev1 or device.id=cables.dev2)');
                 $cables = $query->as_object()->execute();
                 $cabledata = array();
                 foreach ($cables as $c) {
                     $cab = \Basic\Model_Cable::find($c->id);
                     $dev1 = \Basic\Model_Device::find($cab->dev1);
                     $dev2 = \Basic\Model_Device::find($cab->dev2);
                     array_push($cabledata, array('id' => $cab->id, 'dev1' => $cab->dev1, 'port1' => $cab->port1, 'dev2' => $cab->dev2, 'port2' => $cab->port2, 'name1' => $cab->name1, 'name2' => $cab->name2, 'type' => $cab->type, 'hostname1' => $dev1->hostname, 'hostname2' => $dev2->hostname));
                 }
                 $data['cabledata'] = $cabledata;
                 $data['room'] = $room;
                 return \Response::forge(\View::forge('rack', $data));
             }
         }
     }
 }
Пример #3
0
 private function devices($devs, $keyset = true)
 {
     $n = 0;
     $u = 0;
     foreach ($devs as $dev) {
         if ($keyset) {
             $dev = \Basic\Model_Device::find($dev);
         }
         if ($n >= $this->offset and $u < $this->limit) {
             array_push($this->out['data'], array('id' => $dev->id, 'name' => $dev->hostname, 'data' => $this->getPorts($dev->id), 'vps' => $this->getVps($dev->id)));
             $u++;
         }
         $n++;
     }
 }
Пример #4
0
 public function action_index()
 {
     if ($this->id) {
         $out = array('type' => $this->type, 'data' => array());
         switch ($this->type) {
             case 'build':
                 array_push($out['data'], array('name' => 'All', 'id' => 'all'));
                 //return floors
                 $building = \Basic\Model_Building::find($this->id);
                 foreach ($building->floor as $floor) {
                     array_push($out['data'], array('name' => $floor['name'], 'id' => $floor['id']));
                 }
                 break;
             case 'floor':
                 array_push($out['data'], array('name' => 'All', 'id' => 'all'));
                 //return rooms
                 $data = \Basic\Model_Floor::find($this->id);
                 foreach ($data->room as $room) {
                     array_push($out['data'], array('name' => $room['name'], 'id' => $room['id']));
                 }
                 break;
             case 'room':
                 array_push($out['data'], array('name' => 'All', 'id' => 'all'));
                 //return racks
                 $data = \Basic\Model_Room::find($this->id);
                 foreach ($data->rack as $rack) {
                     array_push($out['data'], array('name' => $rack['name'], 'id' => $rack['id'], 'size' => $rack['size']));
                 }
                 break;
             case 'rack':
                 array_push($out['data'], array('name' => 'All', 'id' => 'all'));
                 //return panels
                 $data = \Basic\Model_Rack::find($this->id);
                 if (count($data->device)) {
                     foreach ($data->device as $device) {
                         if ($device['cat'] == 5) {
                             array_push($out['data'], array('name' => $device['hostname'], 'id' => $device['id'], 'size' => $device['size']));
                         }
                     }
                 }
                 break;
             case 'rack2':
                 array_push($out['data'], array('name' => 'All', 'id' => 'all'));
                 //return panels
                 $data = \Basic\Model_Rack::find($this->id);
                 if (count($data->device)) {
                     foreach ($data->device as $device) {
                         array_push($out['data'], array('name' => $device['hostname'], 'id' => $device['id'], 'size' => $device['size']));
                     }
                 }
                 break;
             case 'panel_int':
                 //cable
                 $cab = \Basic\Model_Cable::find($_POST['cab']);
                 if ($cab->port1 == $this->id) {
                     $did = $cab->dev2;
                 } else {
                     $did = $cab->dev1;
                 }
                 $device = \Basic\Model_Device::find()->where('id', $did)->get_one();
                 $devices = \Basic\Model_Device::find()->where('rack', $device->rack)->get();
                 $rack = \Basic\Model_Rack::find($device->rack);
                 $racks = \Basic\Model_Rack::find()->where('room', $rack->room)->get();
                 $data = array('racks' => array(), 'devices' => array());
                 foreach ($devices as $device) {
                     array_push($data['devices'], array('id' => $device->id, 'name' => $device->hostname));
                 }
                 foreach ($racks as $rack) {
                     array_push($data['racks'], array('id' => $rack->id, 'name' => $rack->name));
                 }
                 array_push($out['data'], $data);
                 break;
             case 'panel_ext':
                 //cable
                 $cab = \Basic\Model_Cable::find($_POST['cab']);
                 if ($cab->port1 == $this->id) {
                     $did = $cab->dev2;
                 } else {
                     $did = $cab->dev1;
                 }
                 // devices
                 $device = \Basic\Model_Device::find()->where('id', $did)->get_one();
                 $devices = \Basic\Model_Device::find()->where('rack', $device->rack)->get();
                 // rack
                 $rack = \Basic\Model_Rack::find($device->rack);
                 $racks = \Basic\Model_Rack::find()->where('room', $rack->room)->get();
                 // room
                 $room = \Basic\Model_Room::find($rack->room);
                 $rooms = \Basic\Model_Room::find()->where('floor', $room->floor)->get();
                 // floor
                 $floor = \Basic\Model_Floor::find($room->floor);
                 $floors = \Basic\Model_Floor::find()->where('building', $floor->building)->get();
                 // building
                 $buildings = \Basic\Model_Building::find('all');
                 $data = array('buildings' => array(), 'floors' => array(), 'rooms' => array(), 'racks' => array(), 'devices' => array());
                 foreach ($devices as $device) {
                     array_push($data['devices'], array('id' => $device->id, 'name' => $device->hostname));
                 }
                 foreach ($racks as $rack) {
                     array_push($data['racks'], array('id' => $rack->id, 'name' => $rack->name));
                 }
                 foreach ($rooms as $room) {
                     array_push($data['rooms'], array('id' => $room->id, 'name' => $room->name));
                 }
                 foreach ($floors as $floor) {
                     array_push($data['floors'], array('id' => $floor->id, 'name' => $floor->name));
                 }
                 foreach ($buildings as $building) {
                     array_push($data['buildings'], array('id' => $building->id, 'name' => $building->name));
                 }
                 array_push($out['data'], $data);
                 break;
         }
         echo json_encode($out);
     }
 }
Пример #5
0
 public function init($graph, $dev, $port, $sourceID)
 {
     //$graph=Model_Graphing_Cacti::find()->where('graphID',$id)->where('deviceID',$dev);
     $this->port = $port;
     ob_start();
     $this->device = \Basic\Model_Device::find($dev);
     $this->heightlimit = 750;
     $this->_setTitle();
     $this->_AddPage();
     $this->zoom = 0.75;
     $source = Model_Source::find($sourceID);
     if ($source) {
         $this->cacti = new \Cacti($source->content);
         $code = $this->cacti->authentication($source->user, $source->pass);
         if ($code == 200) {
             $this->angle = 0;
             $this->SetFont('Verdana', '', 12);
             $this->SetTextColor(0, 0, 0);
             $this->_graph($graph, 5, 1, 20);
             ///$this->Ln(-180);
             $this->Rotate(90);
             $this->text(-80, 72, 'Daily');
             $this->Rotate(0);
             $this->_graph($graph, 5, 2, 205);
             $this->Rotate(90);
             $this->text(-265, 72, 'Weekly');
             $this->Rotate(0);
             $this->_graph($graph, 5, 3, 390);
             $this->Rotate(90);
             $this->text(-450, 72, 'Monthly');
             $this->Rotate(0);
             $this->_graph($graph, 5, 4, 575);
             $this->Rotate(90);
             $this->text(-635, 72, 'Yearly');
             $this->Rotate(0);
         }
     }
     /*
     		$this->setTypeOfDevice();
     		
     		$this->rack=Model_Rack::find($this->device->rack);
     		
     		$this->template=Model_Device_Template::find($this->device->get('type'));
     		
     		$this->heightlimit=750;
     			
     		$this->_setTitle();
     
     		$this->_AddPage();
     		$this->zoom=0.75;
     		
     		$this->rack_set(90,50,$this->rack->size);
     
     
     $this->device_general();
     		
     		if($this->action[0]==1)
     		$this->device_hardware();
     		
     		if($this->action[1]==1)
     		$this->device_network();
     		
     		if($this->action[2]==1)
     		$this->device_notes();
     		
     		$this->device_power();
     */
 }
Пример #6
0
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('dev1', 'dev1', 'required|min_length[1]|max_length[20]');
         $val->add_field('dev2', 'dev2', 'required|min_length[1]|max_length[20]');
         $val->add_field('name1', 'name1', 'required|min_length[1]|max_length[200]');
         $val->add_field('name2', 'name2', 'required|min_length[1]|max_length[200]');
         $val->add_field('port1', 'name1', 'required|min_length[1]|max_length[200]');
         $val->add_field('port2', 'name2', 'required|min_length[1]|max_length[200]');
         $val->add_field('type', 'type', 'required|min_length[1]|max_length[3]');
         $val->add_field('act', 'action', 'required|min_length[1]|max_length[30]');
         $val->add_field('cab', 'action', 'max_length[30]');
         //print_r($_POST);
         if ($val->run()) {
             \Log::debug("port1 " . $val->validated('port1'));
             \Log::debug("port2 " . $val->validated('port2'));
             $device1 = \Basic\Model_Device::find($val->validated('dev1'));
             $device2 = \Basic\Model_Device::find($val->validated('dev2'));
             switch ($val->validated('type')) {
                 //network
                 case 1:
                 case 4:
                     //if()
                     $port1 = $this->getDevicePort($device1, $val->validated('name1'), $val->validated('type'));
                     $port2 = $this->getDevicePort($device2, $val->validated('name2'), $val->validated('type'));
                     break;
                 case 2:
                 case 3:
                     $port1 = $val->validated('port1');
                     $port2 = $val->validated('port2');
                     break;
             }
             //$cable->save();
             switch ($val->validated('act')) {
                 case 'connect':
                     $props = array('dev1' => $val->validated('dev1'), 'port1' => $port1, 'dev2' => $val->validated('dev2'), 'port2' => $port2, 'name1' => $val->validated('name1'), 'name2' => $val->validated('name2'), 'type' => $val->validated('type'), 'meta_update_time' => time(), 'meta_update_user' => $this->user);
                     $cable = new Model_Cable($props);
                     $cable->save();
                     $m = array('id' => $cable->id, 'dev1' => $cable->dev1, 'port1' => $cable->port1, 'port2' => $cable->port2, 'dev2' => $cable->dev2, 'name1' => $cable->name1, 'name2' => $cable->name2, 'type' => $cable->type, 'hostname1' => $device1->hostname, 'hostname2' => $device2->hostname);
                     echo json_encode(array('cable' => $m));
                     break;
                 case 'move':
                     //print_r($_POST);
                     $cable = Model_Cable::find($val->validated('cab'));
                     if ($cable) {
                         $cable->dev1 = $val->validated('dev1');
                         $cable->port1 = $port1;
                         $cable->dev2 = $val->validated('dev2');
                         $cable->port2 = $port2;
                         $cable->name1 = $val->validated('name1');
                         $cable->name2 = $val->validated('name2');
                         $cable->meta_update_time = time();
                         $cable->save();
                         $m = array('id' => $cable->id, 'dev1' => $cable->dev1, 'port1' => $cable->port1, 'port2' => $cable->port2, 'dev2' => $cable->dev2, 'name1' => $cable->name1, 'name2' => $cable->name2, 'type' => $cable->type, 'hostname1' => $device1->hostname, 'hostname2' => $device2->hostname);
                         echo json_encode(array('cable' => $m));
                     }
                     break;
             }
             /*
             				$room=Model_Room::find($val->validated('room'));
             		
             		if($room){
             			
             			$query = DB::query('select distinct cables.* from cables, rack, device where rack.room='.$room->id.' and device.rack=rack.id and (device.id=cables.dev1 or device.id=cables.dev2)');
             		
             			$cables=$query->as_object()->execute();
             			
             			$cabledata=Array();
             				foreach($cables as $cab){
             					array_push($cabledata,Array(
             				 				'id'=>$cab->id,
             				 				'dev1'=>$cab->dev1,
             				 				'port1'=>$cab->port1,
             				 				'dev2'=>$cab->dev2,
             				 				'port2'=>$cab->port2,
             				 				'name1'=>$cab->name1,
             				 				'name2'=>$cab->name2,
             								'type'=>$cab->type
             				
             					));
             				
             				}
             				
             			
             			
             			$data['cabledata']=$cabledata;
             			$data['room']=$room;
             			return \Response::forge(View::forge('cables/rack',$data));
             		}
             */
         }
     }
 }
Пример #7
0
            array_push($vlandata, $dd);
        }
        $data = array(array('title' => 'General', 'items' => array(array('act' => 'act3', 'field' => 'Number of ports', 'value' => $net->ports, 'element' => 'select', 'min' => 0, 'max' => 48, 'width' => 135, 'class' => 'port_select'), array('act' => 'act4', 'field' => 'Number of uplink ports', 'element' => 'select', 'value' => $net->uplinks, 'min' => 0, 'max' => 4, 'width' => 135, 'class' => 'port_select'), array('act' => 'act2', 'field' => 'Management IP ports', 'value' => $net->vports, 'element' => 'select', 'min' => 0, 'max' => 48, 'width' => 135, 'class' => 'port_select'))), array('title' => 'Ports', 'items' => array(array('special' => 'mactable', 'count' => $net->ports + $net->uplinks, 'element' => 'none', 'class' => 'win_iptable', 'trclass' => 'head', 'attr' => array('cellpadding' => 5, 'cellspacing' => 0), 'tr' => array(array('name' => 'Port', 'attr' => array('width' => '10%'), 'class' => ''), array('name' => 'MAC addresses', 'attr' => array('width' => '30%'), 'class' => ''), array('name' => 'Connected Device', 'attr' => array('width' => '60%'), 'class' => '')), 'struct' => array(array('el' => 'num', 'attr' => array('width' => '10%'), 'class' => ''), array('el' => 'input', 'attr' => array('width' => '30%'), 'class' => ''), array('el' => 'input', 'attr' => array('width' => '50%'), 'class' => ''))))), array('title' => 'IP Adrresses', 'items' => array(array('special' => 'iptable', 'count' => $net->nics, 'element' => 'none', 'class' => 'win_iptable win_table_small', 'conn' => $conn, 'trclass' => 'head', 'attr' => array('cellpadding' => 0, 'cellspacing' => 0), 'items' => $ipdata))), array('title' => 'Vlans', 'items' => array(array('special' => 'vlan', 'ports' => $net->ports + $net->uplinks, 'element' => 'none', 'class' => '', 'items' => $vlandata))), array('title' => 'Config data', 'items' => array(array('special' => 'config', 'field' => 'Config file of switch', 'element' => 'none', 'class' => 'text_notes', 'values' => $net->config_data))));
        break;
    case 3:
        // pach panel
        $ipdata = array();
        $macdata = array();
        $i = 1;
        foreach ($macs as $mac) {
            $cab1 = \Basic\Model_Cable::find()->where('port1', $mac->id)->get();
            $cab2 = \Basic\Model_Cable::find()->where('port2', $mac->id)->get();
            $dev11 = \Basic\Model_Device::find()->where('id', $cab1->dev1);
            $dev12 = \Basic\Model_Device::find()->where('id', $cab1->dev2);
            $dev21 = \Basic\Model_Device::find()->where('id', $cab2->dev1);
            $dev22 = \Basic\Model_Device::find()->where('id', $cab2->dev2);
            $d = array('n' => $i, 'id' => $mac->id, 'mac_addr' => $mac->mac_address, 'conn_dev' => $mac->conn_device, 'type' => $mac->type, 'vlan' => $mac->vlan, 'devname11' => $dev11->hostname, 'devname12' => $dev12->hostname, 'devname21' => $dev21->hostname, 'devname22' => $dev22->hostname);
            array_push($macdata, $d);
            $i++;
        }
        $out['data'] = $macdata;
        $data = array(array('title' => 'General', 'items' => array(array('act' => 'act6', 'field' => 'Number of ports', 'value' => $net->ports / 2, 'element' => 'select', 'min' => 0, 'max' => 48, 'width' => 135, 'class' => 'port_select'))), array('title' => 'Ports', 'items' => array(array('special' => 'paneltable', 'count' => $net->ports + $net->uplinks, 'element' => 'none', 'class' => 'win_iptable', 'trclass' => 'head', 'items' => $macdata, 'conn' => $conn, 'attr' => array('cellpadding' => 5, 'cellspacing' => 0), 'tr' => array(array('name' => 'Port', 'attr' => array('width' => '10%'), 'class' => ''), array('name' => 'Patch panel', 'attr' => array('width' => '35%'), 'class' => ''), array('name' => 'Network port', 'attr' => array('width' => '35%'), 'class' => ''), array('name' => 'Connector', 'attr' => array('width' => '20%'), 'class' => '')), 'struct' => array(array('el' => 'num', 'attr' => array('width' => '10%'), 'class' => ''), array('el' => 'input', 'attr' => array('width' => '35%'), 'class' => ''), array('el' => 'input', 'attr' => array('width' => '35%'), 'class' => ''), array('el' => 'select', 'attr' => array('width' => '20%'), 'class' => ''))))));
        break;
    default:
        break;
}
$out['items'] = $data;
$debug = array('debug' => 'Page rendered in {exec_time}s using {mem_usage}mb of memory.');
array_push($out, $debug);
echo json_encode($out);
/*
Пример #8
0
 private function add_server($data, $rack)
 {
     /*
      -[1] => Device
               -[2] => Domain
               -[3] => In Service
               -[4] => Status
               -[5] => Position
               -[6] => Rack
               -[7] => Room
               -[8] => Building
               -[9] => Role
               -[10] => Manufacturer
               - [11] => Hardware
               -[12] => Size (U)
               [13] => OS
               [14] => OS Version
               [15] => OS Licence Key
               [16] => Serial
               [17] => Asset
               [18] => Customer
               [19] => Service Level
               [20] => Notes
     */
     $host = $data[1];
     if ($data[1] == '') {
         return false;
     }
     $server = \Basic\Model_Device::find()->where('rack', $rack->id)->where('hostname', $host)->get_one();
     if (!$server) {
         $props = array('hostname' => $host, 'type' => 0, 'cat' => 1, 'rack' => $rack->id, 'rack_pos' => $data[5] == '' ? 0 : $data[5], 'rack_units' => $data[12], 'parent_device' => 0, 'meta_default_data' => 2, 'meta_update_time' => time(), 'meta_update_user' => 1);
         //print_r($props);
         $server = new \Basic\Model_Device($props);
         $server->save();
         $this->add_device_default_fields($server, $data);
         return '<span style="color:green;">device added (ID:' . $server->id . ')</span>';
     } else {
         return '<span style="color:silver;">already exist</span>';
     }
 }
Пример #9
0
 public function action_mac()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('did', 'node id', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             $out = array('sources' => array(), 'mac' => array(), 'custom' => array());
             $device = \Basic\Model_Device::find($val->validated('did'));
             $source = Model_Source::find()->where('typeID', 1)->get();
             $sources = array();
             foreach ($source as $s) {
                 array_push($sources, array('id' => $s->id, 'url' => $s->content));
             }
             $out['sources'] = $sources;
             foreach ($device->network as $network) {
                 foreach ($network->mac as $mac) {
                     $cacti = Model_Cacti::find()->where('macID', $mac->id)->get_one();
                     /* TODO: dodati extend u cacti modelu
                         'graph' => array(
                         'key_from' => 'id',
                         'model_to' => '\Graphing\Model_Cacti',
                         'key_to' => 'macID',
                         'cascade_save' => false,
                         'cascade_delete' => false,
                         )
                        */
                     if ($cacti) {
                         array_push($out['mac'], array('id' => $mac->id, 'type' => $mac->type, 'cacti' => array('id' => $cacti->id, 'name' => $cacti->name, 'graph' => $cacti->graphID, 's' => $cacti->sourceID)));
                     } else {
                         array_push($out['mac'], array('id' => $mac->id, 'type' => $mac->type, 'cacti' => array()));
                     }
                 }
             }
             $customs = Model_Cacti::find()->where('deviceID', $device->id)->where('macID', 0)->get();
             foreach ($customs as $cacti) {
                 array_push($out['custom'], array('id' => $cacti->id, 'name' => $cacti->name, 'graph' => $cacti->graphID, 's' => $cacti->sourceID));
             }
             echo json_encode($out);
         }
     }
 }