Exemplo n.º 1
0
 public function update(Request $request, $subnetId)
 {
     if (!$request->has('ids')) {
         return redirect()->action('DhcpRangeController@edit', $subnetId)->with('success_message', 'Awww');
     }
     $subnet = DhcpSubnet::findOrFail($subnetId);
     foreach ($request->ids as $index => $id) {
         $range = DhcpRange::findOrNew($id);
         $range->start = $request->starts[$index];
         $range->end = $request->ends[$index];
         $range->subnet_id = $subnetId;
         if (!$range->start and !$range->end) {
             $range->delete();
         } else {
             $range->save();
         }
     }
     // $ranges = $subnet->ranges;
     // foreach ($ranges as $range) {
     //     $parts = preg_split('\.', $range->start);
     //     $ip1 = $parts[3];
     //     $parts = preg_split('\.', $range->end);
     //     $ip2 = $parts[3];
     //     $valueRange = range($ip1, $ip1);
     // }
     return redirect()->action('DhcpRangeController@edit', $subnetId)->with('success_message', 'Updated!');
 }
Exemplo n.º 2
0
 public function edit($subnetId = null)
 {
     $options = DhcpOption::forSubnet($subnetId);
     $subnetName = '';
     if ($subnetId) {
         $subnet = DhcpSubnet::findOrFail($subnetId);
         $subnetName = $subnet->name;
     }
     return view('dhcp.option.edit', compact('options', 'subnetId', 'subnetName'));
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $shared_network = new DhcpSharedNetwork();
     $shared_network->name = 'Management';
     $shared_network->is_management = true;
     $shared_network->save();
     $newSubnet = new DhcpSubnet();
     $newSubnet->network_address = '192.168.127.0';
     $newSubnet->subnet_mask = '255.255.255.0';
     $newSubnet->cidr = '24';
     $newSubnet->start_ip = '192.168.127.1';
     $newSubnet->end_ip = '192.168.127.253';
     $newSubnet->routers = '192.168.127.254';
     $newSubnet->broadcast_address = '192.168.127.255';
     $newSubnet->dns_servers = '8.8.8.8';
     $subnet = $shared_network->subnets()->create($newSubnet->toArray());
     // \Event::fire(new DhcpSubnetWasAdded($subnet, $subnet->start_ip, $subnet->end_ip));
     event(new DhcpSubnetWasAdded($subnet, $subnet->start_ip, $subnet->end_ip));
 }
Exemplo n.º 4
0
 public function update(Request $request, $id)
 {
     $network = DhcpSharedNetwork::findOrFail($id);
     $network->fill($request->all());
     $network->save();
     $network->subnets()->update(['network_id' => null]);
     if ($request->has('subnets')) {
         $subnets = DhcpSubnet::whereIn('id', $request->subnets)->get();
         $network->subnets()->saveMany($subnets);
     }
     return redirect()->action('DhcpNetworkController@index');
 }
Exemplo n.º 5
0
 public function getDhcpFile()
 {
     if (Cache::has('dhcpfile')) {
         return (new Response(Cache::get('dhcpfile'), 200))->header('Content-Type', 'text/plain');
     }
     $globals = DhcpOption::globals()->get();
     $networks = DhcpSharedNetwork::all();
     $subnets = DhcpSubnet::notInSharedNetwork()->get();
     $entries = DhcpEntry::all();
     $dhcpFile = new DhcpFile($globals, $networks, $subnets, $entries);
     $contents = Cache::rememberForever('dhcpfile', function () use($dhcpFile) {
         return $dhcpFile->asText();
     });
     return (new Response($contents, 200))->header('Content-Type', 'text/plain');
 }
Exemplo n.º 6
0
 /**
  * API to delete a subnet
  */
 public function destroy(DhcpSubnet $dhcp_subnet)
 {
     $dhcp_subnet->delete();
     $this->dispatch(new RewriteDhcpConfig());
     logThis('Removed subnet ' . $dhcp_subnet->network_address . '/' . $dhcp_subnet->cidr . ' from shared network ' . $dhcp_subnet->shared_network->name);
 }
Exemplo n.º 7
0
 public function indexSubnets()
 {
     $subnets = DhcpSubnet::all();
     return view('dhcp.index_subnets', compact('subnets'));
 }
Exemplo n.º 8
0
 public function destroy($id)
 {
     $subnet = DhcpSubnet::findOrFail($id);
     $subnet->delete();
     return redirect()->action('DhcpSubnetController@index');
 }