コード例 #1
0
ファイル: device.php プロジェクト: quickpacket/noclayer
 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);
         }
     }
 }
コード例 #2
0
ファイル: building.php プロジェクト: quickpacket/noclayer
 /**
  * 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);
     }
 }
コード例 #3
0
ファイル: ajax.php プロジェクト: quickpacket/noclayer
 public function action_headnav()
 {
     //print_r($this->valid);
     $data['building'] = Model_Building::find()->where('meta_update_user', $this->user)->get();
     return \Response::forge(\View::forge('ajax/headnav', $data));
 }
コード例 #4
0
ファイル: search.php プロジェクト: quickpacket/noclayer
 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);
     }
 }