def apply_changes(request): messages = [] status = models.get_status() network_interfaces = "" ntp_conf = "" dhcpd_conf = "log-facility local7;\n\n" smb_conf = "" _deletefile(settings.R66_ETC_DIR + "/ppp/peers/r66") _deletefile(settings.R66_ETC_DIR + "/ppp/r66.chat") _deletefile(settings.R66_ETC_DIR + "/hostapd/*.conf") _deletefile(settings.R66_ETC_DIR + "/wpa_supplicant/*.conf") time.sleep(3) ppp = models.NetPPP.objects.all() for p in ppp: if p.enabled: strings = p.to_peer() _writefile(strings, settings.R66_ETC_DIR + "/ppp/peers/r66") strings = p.to_chat() _writefile(strings, settings.R66_ETC_DIR + "/ppp/r66.chat") netifaces = models.NetIface.objects.all() for n in netifaces: try: # TODO: Clean previous files for each device # print "> " + str(n) p = n.get_enabled_profile() # can be none if n.enabled and p: network_interfaces += p.to_network_interfaces() type_ = p.netiface_type if type_ == "bridge": # wifi can be only master mode if n.wifi_device: strings = p.to_hostapd_conf() _writefile(strings, settings.R66_ETC_DIR + "/hostapd/" + n.name + ".conf") if type_ == "internal": # cannot be p.dhcp == True _tmp = p.to_ntp_conf() if _tmp != "": ntp_conf = _tmp # wifi can be only master mode if n.wifi_device: strings = p.to_hostapd_conf() _writefile(strings, settings.R66_ETC_DIR + "/hostapd/" + n.name + ".conf") if p.dhcpd_settings \ and p.dhcpd_settings.enabled: dhcpd_conf += p.to_dhcpd_conf() if type_ == "external": if not p.net_settings.dhcp: _tmp = p.to_ntp_conf() if _tmp != "": ntp_conf = _tmp # wifi can be only client mode if n.wifi_device: strings = p.to_wpa_supplicant_conf() _writefile(strings, settings.R66_ETC_DIR + "/wpa_supplicant/" + n.name + ".conf") if type_ == "unused": pass # nothing to do except Exception, e: messages.append(str(e))
def configuration_changed(request): status = models.get_status() res = status.to_dict() return simplejson.dumps(res)