/** * API to store a new subnet */ public function store(DhcpSharedNetwork $dhcp_shared_network, DhcpSubnetRequest $request) { $subnet = $dhcp_shared_network->subnets()->create($request->all()); logThis('Added subnet ' . $subnet->network_address . '/' . $subnet->cidr . ' to shared network ' . $dhcp_shared_network->name); event(new DhcpSubnetWasAdded($subnet, $request->start_ip, $request->end_ip)); $this->dispatch(new RewriteDhcpConfig()); return $subnet; }
/** * Delete a shared network */ public function destroy(DhcpSharedNetwork $dhcp_shared_network) { $dhcp_shared_network->delete(); flash()->info('Deleted', 'Shared Network ' . $dhcp_shared_network->name . ' was deleted.'); logThis('DHCP Shared Network ' . $dhcp_shared_network->name . ' was deleted.'); $this->dispatch(new RewriteDhcpConfig()); return redirect()->route('dhcp.index'); }
/** * 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)); }
/** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { $provisioning = Provisioning::all(); $customers = Customer::all(); $onts = Ont::all(); $accessSwitches = AccessSwitch::all(); $dhcpSharedNetworks = DhcpSharedNetwork::all(); $ipaddresses = Ipaddress::all(); $ports = AccessSwitchPort::all(); return view('home')->with('provisioning', $provisioning)->with('customers', $customers)->with('onts', $onts)->with('accessSwitches', $accessSwitches)->with('ports', $ports)->with('ipaddresses', $ipaddresses)->with('DhcpSharedNetworks', $dhcpSharedNetworks); }
/** * Access Switches Index */ public function index() { $dhcpConfiFile = 'dhcp/dhcpd.conf'; if (Storage::exists($dhcpConfiFile)) { $dhcp_config_file = Storage::get($dhcpConfiFile); } else { $dhcp_config_file = ''; } $shared_networks = DhcpSharedNetwork::all(); return view('dhcp.index')->with('sharedNetworks', $shared_networks)->with('dhcp_config_file', $dhcp_config_file); }
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'); }
public function rewriteDhcpConfig() { $date = date('Y-m-d-H-i-s'); $fileToStore = 'dhcp/dhcpd.conf'; $backupFile = 'dhcp/backups/dhcpd.conf-' . $date; Storage::copy($fileToStore, $backupFile); $globalOptions = DhcpOption::first(); $sharedNetworks = DhcpSharedNetwork::with('subnets')->get(); $template = view()->file(app_path('../resources/views/dhcp/templates/dhcpd-body.blade.php'))->with('dhcpOptions', $globalOptions)->with('sharedNetworks', $sharedNetworks); Storage::put($fileToStore, $template); logThis('dhcpd.conf rewritten, backup written to ' . $backupFile); }
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'); }
public function edit($id) { $subnet = DhcpSubnet::findOrFail($id); $networks = DhcpSharedNetwork::all(); return view('dhcp.subnet.edit', compact('subnet', 'networks')); }