def general_settings_view(request): context = { 'title': 'Einstellungen', 'errors': [], 'ip_form': forms.IpEditForm(), 'time_form': forms.TimeEditForm() } if request.method == 'POST': if 'type' in request.POST and request.POST['type'] == 'network': form = forms.IpEditForm(request.POST) if form.is_valid(): worker_com.set_interface(ip=form.cleaned_data['ip'], netmask=form.cleaned_data['subnet']) if 'type' in request.POST and request.POST['type'] == 'time': form = forms.TimeEditForm(request.POST) if form.is_valid(): worker_com.set_time(form.cleaned_data['time']) if 'type' in request.POST and request.POST[ 'type'] == 'deactivate_network': worker_com.deactivate_interface() return redirect('kasse:general_settings') if settings.ETHERNET_PORT is not None: interfaces = debinterface.Interfaces() adapter = interfaces.getAdapter(settings.ETHERNET_PORT) if adapter is not None: context['ip_address'] = adapter.get_attr('address') context['subnet'] = adapter.get_attr('netmask') else: context['eth_deactivated'] = True return render(request, 'settings/general_settings.html', context=context)
def activate_interface(ip, netmask): try: adapter_name = get_adapter_name() interfaces = debinterface.Interfaces() adapter = interfaces.getAdapter(adapter_name) if adapter is None: create_interface(adapter_name) interfaces = debinterface.Interfaces() adapter = interfaces.getAdapter(adapter_name) adapter.setAddressSource('static') adapter.setAddress(ip) adapter.setNetmask(netmask) adapter.setAuto(True) interfaces.writeInterfaces() restart_networking(adapter_name) except ValueError: return
def create_interface(name): options = { 'addrFam': 'inet', 'name': name, 'source': 'manual', } interfaces = debinterface.Interfaces() interfaces.addAdapter(options) interfaces.writeInterfaces() interfaces.updateAdapters()
def deactivate_interface(): try: adapter_name = get_adapter_name() interfaces = debinterface.Interfaces() adapter = interfaces.getAdapter(adapter_name) if adapter is not None: interfaces.removeAdapterByName(adapter_name) interfaces.writeInterfaces() restart_networking(adapter_name) except ValueError: return
def debint_setGateway(intf_name, gateway): itfs = debinterface.Interfaces() adapter = itfs.getAdapter(str(intf_name)) adapter.setGateway(str(gateway)) itfs.writeInterfaces()
def debint_del(intf_name): itfs = debinterface.Interfaces() itfs.removeAdapterByName(str(intf_name)) itfs.writeInterfaces()
def debint_create(opts_intf_name, \ opts_addrFam="inet", opts_source="manual", opts_auto=True, opts_hotplug=False, \ opts_up=None, opts_down=None, \ opts_broadcast=None, opts_network=None,\ opts_gateway=None, opts_netmask=None, opts_address=None): if opts_auto == opts_hotplug: print( "\t debint_create() failed, opts_auto and opts_hotplug MUST mutual exclusion: opts_auto:{}, opts_hotplug:{}" .format(opts_auto, opts_hotplug)) return -1 def_opts = { 'name': '', 'addrFam': '', 'source': '', 'auto': '', 'hotplug': '', 'up': [], 'down': [] } if opts_intf_name != None: def_opts["name"] = str(opts_intf_name) if opts_addrFam != None: def_opts["addrFam"] = str(opts_addrFam) if opts_source != None: def_opts["source"] = str(opts_source) if opts_auto != None: def_opts["auto"] = opts_auto if opts_hotplug != None: def_opts["hotplug"] = opts_hotplug ########################################### if opts_up != None: def_opts["up"] = opts_up if opts_down != None: def_opts["down"] = opts_down if opts_broadcast != None: def_opts["broadcast"] = str(opts_broadcast) if opts_network != None: def_opts["network"] = str(opts_network) if opts_gateway != None: def_opts["gateway"] = str(opts_gateway) if opts_netmask != None: def_opts["netmask"] = str(opts_netmask) if opts_address != None: def_opts["address"] = str(opts_address) #print("repr(def_opts):{}".format(repr(def_opts))) itfs = debinterface.Interfaces() itfs.addAdapter(def_opts) itfs.writeInterfaces()