Beispiel #1
0
 public function action_index()
 {
     $msg = $this->request->param('msg');
     if ($this->request->param('sort')) {
         $sort = $this->request->param('sort');
     } else {
         $sort = 'room_name';
     }
     if ($this->request->param('order')) {
         $order = $this->request->param('order');
     } else {
         $order = 'DESC';
     }
     $filters = array('filter_room_name' => $this->request->param('filter_room_name'), 'filter_number' => $this->request->param('filter_number'), 'filter_location' => $this->request->param('filter_location'));
     $total = Model_Room::rooms_total($filters);
     $count = $total;
     $pagination = Pagination::factory(array('total_items' => $count, 'items_per_page' => 5));
     $filters = array_merge($filters, array('sort' => $sort, 'order' => $order, 'limit' => $pagination->items_per_page, 'offset' => $pagination->offset));
     $rooms = Model_Room::rooms($filters);
     $sorting = new Sort(array('Name' => 'room_name', 'Number' => 'room_number', 'Location' => 'name', 'Action' => ''));
     $url = 'room/index';
     if ($this->request->param('filter_room_name')) {
         $url .= '/filter_room_name/' . $this->request->param('filter_room_name');
         $filter = $this->request->param('filter_room_name');
         $filter_select = 'filter_room_name';
     }
     if ($this->request->param('filter_number')) {
         $url .= '/filter_number/' . $this->request->param('filter_number');
         $filter = $this->request->param('filter_number');
         $filter_select = 'filter_number';
     }
     if ($this->request->param('filter_location')) {
         $url .= '/filter_location/' . $this->request->param('filter_location');
         $filter = $this->request->param('filter_location');
         $filter_select = 'filter_location';
     }
     $sorting->set_link($url);
     $sorting->set_order($order);
     $sorting->set_sort($sort);
     $heading = $sorting->render();
     $links = array('add_room' => Html::anchor('/room/add/', 'Create a Room', array('class' => 'createButton l')), 'locations' => Html::anchor('/location', 'Locations', array('class' => 'pageAction l')), 'delete' => URL::site('/room/delete/'));
     $table = array('heading' => $heading, 'data' => $rooms);
     // Render the pagination links
     $pagination = $pagination->render();
     $filter_room_name = $this->request->param('filter_room_name');
     $filter_url = URL::site('room/index');
     $view = View::factory('room/list')->bind('links', $links)->bind('table', $table)->bind('count', $count)->bind('pagination', $pagination)->bind('filter', $filter)->bind('filter_select', $filter_select)->bind('filter_url', $filter_url)->bind('msg', $msg);
     Breadcrumbs::add(array('System', Url::site('system')));
     Breadcrumbs::add(array('Room', Url::site('room')));
     $this->content = $view;
 }
Beispiel #2
0
 public function action_get()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('did', 'Device id', 'required|min_length[1]|max_length[18]');
         if ($val->run()) {
             $device = Model_Device::find($val->validated('did'));
             $rack = Model_Rack::find($device->rack);
             $room = Model_Room::find($rack->room);
             $floor = Model_Floor::find($room->floor);
             $build = Model_Building::find($floor->building);
             $data = array('id' => $device->id, 'hostname' => $device->hostname, 'rack' => $device->rack, 'rack_pos' => $device->rack_pos, 'rack_units' => $device->rack_units, 'cat' => $device->cat, 'type' => $device->type, 'room' => $room->id, 'floor' => $floor->id, 'build' => $build->id);
             echo json_encode($data);
         }
     }
 }
Beispiel #3
0
 /**
  * 
  * frontend CRUD connector for rack managment ...
  * @author hrvoje
  * @param unknown_type $id
  */
 public function action_rack($id = null)
 {
     if ($id) {
         if ($id != 'new') {
             $rack = Model_Rack::find($id);
             if ($rack) {
                 $update = $this->isPost('up');
                 if ($update) {
                     $set = false;
                     //name of rack
                     $name = $this->isPost('name');
                     if ($name) {
                         $rack->name = $name;
                         $set = true;
                     }
                     //rack size
                     $size = $this->isPost('size');
                     if ($size) {
                         $rack->size = $size;
                         $set = true;
                     }
                     //save data to rack
                     if ($set) {
                         $rack->meta_update_time = time();
                         $rack->meta_update_user = $this->user;
                         $rack->save();
                         echo json_encode(array('success' => 'ok'));
                     }
                 }
             }
         }
         //new rack
         if ($id == 'new') {
             $val = \Validation::forge();
             $val->add_field('room', 'room id', 'required|min_length[1]|max_length[20]');
             if ($val->run()) {
                 $ord = 0;
                 $rc = Model_Rack::find()->where('room', $val->validated('room'))->get();
                 foreach ($rc as $rack) {
                     if ($rack->room_pos > $ord) {
                         $ord = $rack->room_pos;
                     }
                 }
                 //check if room exist
                 $roomdata = Model_Room::find($_POST['room']);
                 if ($roomdata) {
                     $props = array('name' => 'new rack', 'room' => $_POST['room'], 'room_pos' => $ord + 1, 'hidden_rack' => 0, 'size' => 42, 'position' => 0, 'notes' => null, 'meta_default_data' => 0, 'meta_update_time' => time(), 'meta_update_user' => $this->user);
                     //print_r($props);
                     $new = new Model_Rack($props);
                     $new->save();
                     $rack = array("name" => $new['name'], "units" => $new['size'], "id" => $new['id'], "equs" => array());
                     // delete gaps
                     $racks = Model_Rack::find()->where('room', $val->validated('room'))->order_by('room_pos', 'asc')->get();
                     $i = 1;
                     foreach ($racks as $r) {
                         $r->room_pos = $i;
                         $r->save();
                         $i++;
                     }
                     echo json_encode($rack);
                 }
             }
         }
         if ($id == 'move') {
             $val = \Validation::forge();
             $val->add_field('id', 'rack id', 'required|min_length[1]|max_length[20]');
             $val->add_field('room', 'room id', 'required|min_length[1]|max_length[20]');
             $val->add_field('ord', 'order', 'required|min_length[1]|max_length[20]');
             $val->add_field('to', 'to another room', 'required|min_length[1]|max_length[1]');
             if ($val->run()) {
                 $rack = Model_Rack::find()->where('id', $val->validated('id'))->get_one();
                 if ($rack) {
                     $nr = $val->validated('room');
                     $no = $val->validated('ord');
                     $new_room_r = Model_Rack::find()->where('room', $nr)->where('room_pos', '>=', $no)->order_by('room_pos', 'asc')->get();
                     $old_room_r = Model_Rack::find()->where('room', $rack->room)->where('room_pos', '>=', $rack->room_pos)->order_by('room_pos', 'asc')->get();
                     // update room set room_pos
                     $n = $no + 1;
                     //2
                     foreach ($new_room_r as $new_rack) {
                         $new_rack->room_pos = $n;
                         $new_rack->save();
                         $n++;
                     }
                     $n = $rack->room_pos - 1;
                     //2
                     foreach ($old_room_r as $old_rack) {
                         if ($n == $no - 1) {
                             $n++;
                             if (!$val->validated('to')) {
                                 $no--;
                             }
                         }
                         $old_rack->room_pos = $n;
                         $old_rack->save();
                         $n++;
                     }
                     \Log::debug("no" . $no);
                     $rack->room = $nr;
                     $rack->room_pos = $no;
                     $rack->save();
                     // delete gaps
                     $new_room_r = Model_Rack::find()->where('room', $nr)->order_by('room_pos', 'asc')->get();
                     $old_room_r = Model_Rack::find()->where('room', $rack->room)->order_by('room_pos', 'asc')->get();
                     $i = 1;
                     foreach ($old_room_r as $old_rack) {
                         $old_rack->room_pos = $i;
                         $old_rack->save();
                         $i++;
                     }
                     $i = 1;
                     foreach ($new_room_r as $new_rack) {
                         $new_rack->room_pos = $i;
                         $new_rack->save();
                         $i++;
                     }
                     echo json_encode(array('status' => 'ok'));
                 }
             }
         }
         if ($id == 'pos') {
             $val = \Validation::forge();
             $val->add_field('id', 'rack id', 'required|min_length[1]|max_length[20]');
             $val->add_field('pos', 'position id', 'required|min_length[1]|max_length[20]');
             if ($val->run()) {
                 $rack = Model_Rack::find()->where('id', $val->validated('id'))->get_one();
                 if ($rack) {
                     $rack->position = $val->validated('pos');
                     $rack->save();
                 }
                 echo json_encode(array('status' => 'ok'));
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Frontend delete controller
  */
 public function action_remove()
 {
     $val = \Validation::forge();
     $val->add_field('id', 'node id', 'required|min_length[1]|max_length[20]');
     $val->add_field('type', 'node type', 'required|min_length[1]|max_length[20]');
     if ($val->run()) {
         //remove building
         if ($val->validated('type') == 'building') {
             $ren = Model_Building::find($val->validated('id'));
         }
         //remove floor
         if ($val->validated('type') == 'floor') {
             $ren = Model_Floor::find($val->validated('id'));
         }
         //remove room
         if ($val->validated('type') == 'room') {
             $ren = Model_Room::find($val->validated('id'));
         }
         $stat = $ren->delete();
         $a = array("status" => $stat);
         echo json_encode($a);
     }
 }
Beispiel #5
0
 protected function newuserdata($user)
 {
     //add new building
     $props = array('name' => 'Building DEMO', 'meta_update_time' => time(), 'meta_update_user' => $user);
     $building = new Model_Building($props);
     $building->save();
     //add defualt floor
     $props = array('name' => 'Floor 1', 'building' => $building->id, 'meta_update_time' => time(), 'meta_update_user' => $user);
     $floor = new Model_Floor($props);
     $floor->save();
     //add default room
     $props = array('name' => 'Room A', 'floor' => $floor->id, 'meta_update_time' => time(), 'meta_update_user' => $user);
     $room = new Model_Room($props);
     $room->save();
     //add default room
     $props = array('name' => 'Default rack', 'room' => $room->id, 'room_pos' => 0, 'hidden_rack' => 0, 'size' => 48, 'numbering_direction' => 0, 'meta_default_data' => 0, 'meta_update_time' => time(), 'meta_update_user' => $user);
     $rack = new Model_Rack($props);
     $rack->save();
     //$switch=$this->add_switch($rack,$user,2,'c1-switch-windows');
     $switch = $this->add_switch($rack, $user, 48, 'c1-switch-linux');
     $pdu = $this->add_pdu($rack, $user);
     for ($i = 10; $i <= 47; $i++) {
         $this->add_server($i, $rack, $user, $switch['id'], $switch['macs'], $pdu);
     }
     //monitoring
     $qmonitor = array('iconw' => 1, 'iconc' => 1, 'iconu' => 1, 'osdw' => 1, 'osdu' => 1, 'osdc' => 1, 'soundw' => 1, 'soundu' => 1, 'soundc' => 1, 'meta_update_user' => $user);
     $monitor = new Model_Monitoring_Data($qmonitor);
     $monitor->save();
     $q = array('typeID' => 1, 'user' => 'guest', 'pass' => 'guest', 'content' => 'https://nagios.demo.netways.de/nagios/cgi-bin/status.cgi', 'meta_update_time' => time(), 'meta_update_user' => $user);
     $source = new Model_Monitoring_Source($q);
     $source->save();
     /*
      //server
     
     //cables
     DB::query("INSERT INTO `cables` (`id`, `dev1`, `port1`, `name1`, `dev2`, `port2`, `name2`, `type`, `meta_update_time`, `meta_update_user`) VALUES
     		('', 1, 1, 1, 2, 1, 1, 1, 1337743207, 2),
     		('', 1, 2, 2, 2, 2, 2, 1, 1337743221, 2);")->execute();
     
     //device_fieldset
     DB::query("INSERT INTO `device_fieldset` (`id`, `name`, `type`, `deviceID`, `tab`, `value`, `static`) VALUES
     		('', 'Manufacturer', 'input', 1, 1, NULL, 1),
     		('', 'Model', 'input', 1, 1, NULL, 1),
     		('', 'Admin url', 'input', 1, 2, NULL, 1),
     		('', 'Ports', 'network', 1, 2, NULL, 1),
     		('', 'Images', 'img', 1, 3, NULL, 0),
     		('', 'Export to pdf', 'print', 1, 3, NULL, 0),
     		('', 'Manufacturer', 'input', 2, 1, NULL, 1),
     		('', 'Model', 'input', 2, 1, NULL, 1),
     		('', 'Admin url', 'input', 2, 2, NULL, 1),
     		('', 'Ports', 'network', 2, 2, NULL, 1),
     		('', 'Images', 'img', 2, 3, NULL, 0),
     		('', 'Export to pdf', 'print', 2, 3, NULL, 0);")->execute();
     
     //device network
     DB::query("INSERT INTO `device_network` (`id`, `fieldsetID`, `deviceID`, `nics`, `vports`, `ports`, `uplinks`, `config_data`, `type`) VALUES
     		('', 4, 1, 2, 0, 0, 0, '', 1),
     		('', 10, 2, 0, 0, 24, 0, '', 2);")->execute();
     
     DB::query("INSERT INTO `network_ip_ports` (`id`, `networkID`, `nic_name`, `ipv4`, `ipv6`, `conn_type`, `conn_speed`, `type`) VALUES
     		('', 1, '', '', '', 1, 1, 1),
     		('', 1, '', '', '', 1, 3, 1);")->execute();
     
     DB::query("INSERT INTO `network_mac_ports` (`id`, `networkID`, `mac_address`, `conn_device`, `vlan`, `type`) VALUES
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1),
     		('', 2, '', 0, 0, 1);")->execute();
     */
 }
Beispiel #6
0
 public function action_index()
 {
     $out = array();
     if (count($_GET) > 0) {
         /*
                       'buildings'=>Array(),
                       'rooms'=>Array(),
                       'floors'=>Array(),
                       'buildings'=>Array(),
                       'fields'=>Array() */
         $key = false;
         if (isset($_GET['key'])) {
             $key = $_GET['key'];
         }
         if ($key) {
             $key_right = $key . '%';
             $key = '%' . $key . '%';
             //device hostname
             $device = Model_Device::find()->where('hostname', 'like', $key)->limit(5)->where('meta_update_user', $this->user)->get();
             $m = array('type' => 'Device', 'tn' => 1, 'items' => array());
             foreach ($device as $dev) {
                 $rack = $dev->racks;
                 $room = $rack->rooms;
                 array_push($m['items'], array('id' => $dev->id, 'name' => $dev->hostname, 'room' => $room->id, 'rack' => $rack->id, 'floor' => $room->floors->id, 'building' => $room->floors->buildings->id));
             }
             array_push($out, $m);
             //buildings
             $buildings = Model_Building::find()->where('name', 'like', $key)->where('meta_update_user', $this->user)->limit(5)->get();
             $m = array('type' => 'Building', 'tn' => 2, 'items' => array());
             foreach ($buildings as $bui) {
                 array_push($m['items'], array('id' => $bui->id, 'name' => $bui->name));
             }
             array_push($out, $m);
             //floors
             $floors = Model_Floor::find()->where('name', 'like', $key)->where('meta_update_user', $this->user)->limit(5)->get();
             $m = array('type' => 'Floor', 'tn' => 3, 'items' => array());
             foreach ($floors as $fl) {
                 array_push($m['items'], array('id' => $fl->id, 'name' => $fl->name, 'building' => $fl->buildings->id));
             }
             array_push($out, $m);
             //rooms
             $rooms = Model_Room::find()->where('name', 'like', $key)->where('meta_update_user', $this->user)->limit(5)->get();
             $m = array('type' => 'Room', 'tn' => 4, 'items' => array());
             foreach ($rooms as $rm) {
                 array_push($m['items'], array('id' => $rm->id, 'name' => $rm->name, 'floor' => $rm->floors->id, 'building' => $rm->floors->buildings->id));
             }
             array_push($out, $m);
             //racks
             $rack = Model_Rack::find()->where('name', 'like', $key)->where('meta_update_user', $this->user)->limit(5)->get();
             $m = array('type' => 'Rack', 'tn' => 5, 'items' => array());
             foreach ($rack as $rm) {
                 array_push($m['items'], array('id' => $rm->id, 'name' => $rm->name, 'floor' => $rm->rooms->floors->id, 'room' => $rm->rooms->id, 'building' => $rm->rooms->floors->buildings->id));
             }
             array_push($out, $m);
             //ip address
             $query = \DB::query('select distinct * from network_ip_ports where ipv4 like "' . $key_right . '" group by networkID limit 0,5');
             $ips = $query->as_object()->execute();
             foreach ($ips as $ip) {
                 $tab = $ip->type == 3 ? 6 : 2;
                 $network = Model_Device_Network::find()->where('id', $ip->networkID)->get_one();
                 $device = $network->device;
                 $m = array('type' => 'IPv4', 'tn' => 6, 'items' => array());
                 $room = $device->racks->rooms;
                 array_push($m['items'], array('id' => $ip->id, 'name' => $ip->ipv4, 'room' => $device->racks->rooms->id, 'rack' => $device->racks->id, 'building' => $room->floors->buildings->id, 'floor' => $room->floors->id, 'tab' => $tab, 'dev' => $device->id));
                 array_push($out, $m);
             }
             //raid
             $query = \DB::query('select df.id, df.name, df.tab, df.deviceID, d.hostname, df.value, hrd.model, hrd.serial_number, hrd.id as "rid" from device as d join device_fieldset as df on df.deviceID = d.id join hardware_raid AS hr on hr.fieldsetID = df.id join hardware_raid_data as hrd on hrd.hardware_raid = hr.id where hrd.model like "' . $key . '" or hrd.serial_number like "' . $key . '" group by hrd.serial_number, hrd.model');
             $raid = $query->as_object()->execute();
             foreach ($raid as $fd) {
                 $device = Model_Device::find($fd->deviceID);
                 $m = array('type' => $fd->name, 'tn' => 6, 'items' => array());
                 $room = $device->racks->rooms;
                 array_push($m['items'], array('id' => $fd->id, 'name' => $fd->value, 'room' => $device->racks->rooms->id, 'rack' => $device->racks->id, 'building' => $room->floors->buildings->id, 'floor' => $room->floors->id, 'tab' => $fd->tab, 'dev' => $fd->deviceID, 'hostname' => $fd->hostname, 'model' => $fd->model, 'serial' => $fd->serial_number, 'rid' => $fd->rid));
                 array_push($out, $m);
             }
             $notes = Model_Notes::find()->where('txt', 'like', $key)->where('meta_update_user', $this->user)->limit(5)->get();
             $m = array('type' => 'Device Notes', 'tn' => 7, 'items' => array());
             foreach ($notes as $note) {
                 $device = $note->device;
                 $room = $device->racks->rooms;
                 array_push($m['items'], array('id' => $note->id, 'name' => substr($note->txt, -100), 'room' => $device->racks->rooms->id, 'rack' => $device->racks->id, 'building' => $room->floors->buildings->id, 'floor' => $room->floors->id, 'tab' => 4, 'dev' => $device->id));
             }
             array_push($out, $m);
             //ram
             $query = \DB::query('select df.id, df.name, df.tab, df.deviceID, d.hostname, df.value, hrd.model, hrd.serial_number, hrd.id as "rid" from device as d join device_fieldset as df on df.deviceID = d.id join hardware_ram AS hr on hr.fieldsetID = df.id join hardware_ram_data as hrd on hrd.hardware_ram = hr.id where hrd.model like "' . $key . '" or hrd.serial_number like "' . $key . '" group by hrd.serial_number, hrd.model');
             $ram = $query->as_object()->execute();
             foreach ($ram as $fd) {
                 $device = Model_Device::find($fd->deviceID);
                 $m = array('type' => $fd->name, 'tn' => 8, 'items' => array());
                 $room = $device->racks->rooms;
                 array_push($m['items'], array('id' => $fd->id, 'name' => $fd->value, 'room' => $device->racks->rooms->id, 'rack' => $device->racks->id, 'building' => $room->floors->buildings->id, 'floor' => $room->floors->id, 'tab' => $fd->tab, 'dev' => $fd->deviceID, 'hostname' => $fd->hostname, 'model' => $fd->model, 'serial' => $fd->serial_number, 'rid' => $fd->rid));
                 array_push($out, $m);
             }
         }
         echo json_encode($out);
     }
 }