| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * app/DataTables/General/IPv4DataTable.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Datatable for ipv4 search | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * it under the terms of the GNU General Public License as published by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * GNU General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * You should have received a copy of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @package    LibreNMS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @link       http://librenms.org | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @copyright  2016 Neil Lathwood | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author     Neil Lathwood <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | namespace App\DataTables\General; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use App\DataTables\BaseDataTable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use App\Models\General\IPv4; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | class IPv4DataTable extends BaseDataTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * Display ajax response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function ajax() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return $this->datatables | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ->eloquent($this->query()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ->editColumn('hostname', 'datatables.generic.hostname') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ->editColumn('ifName', function ($data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 $ifName = is_null($data->ifName) ? trans('devices.text.deleted') : $data->ifName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 return '<a href="'.url("devices/".$data->device_id."/ports/".$data->port_id).'">'.$ifName.'</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ->rawColumns(['hostname', 'ifName']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ->make(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * Get the query object to be processed by datatables. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function query() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $data = IPv4::join('ports', 'ports.port_id', '=', 'ipv4_addresses.port_id')->join('devices', 'devices.device_id', '=', 'ports.device_id')->select('ipv4_addresses.*', 'ports.*', 'devices.*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         //FIXME We should use this once laravel-datatables supports it upstream $data = IPv4::with('port.device')->select('ipv4_addresses.*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         return $this->applyScopes($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * Get columns. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 1 |  |     public function getColumns() | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             'hostname'  => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 1 |  |                 'name'      => 'device.hostname', | 
            
                                                                        
                            
            
                                    
            
            
                | 74 | 1 |  |                 'title'     => trans('devices.label.hostname'), | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |                 'orderable' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 76 | 1 |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |             'ifName'    => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 | 1 |  |                 'title' => trans('general.text.interface'), | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |             'ipv4_address' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 81 | 1 |  |                 'title'    => trans('general.text.address'), | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |             'ifDescr'   => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 84 | 1 |  |                 'title' => trans('general.text.port_descr'), | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * Get filename for export. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     protected function filename() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         return 'ipv4'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 98 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |  |