コード例 #1
0
ファイル: views.py プロジェクト: amirrahbaran/linux-web-admin
def shutdown(TheInterface):
    TheInterfaceMainName = TheInterface.name
    ethernet_filename = "ifcfg-" + TheInterfaceMainName
    ethernet_file_object = File(ethernet_filename, NETWORK_CONF_PATH)
    if not ethernet_file_object.Existed():
        return False
    for line in ethernet_file_object.Read().split("\n"):
        match = re.search('^iface\s+(\S+)\s+inet', line)
        if match:
            TheInterfaceName = match.group(1)
            ethernet_object = NetworkInterface(TheInterfaceName)
            ethernet_object.ifDown()
            ethernet_object.Down()
    return True
コード例 #2
0
ファイル: views.py プロジェクト: amirrahbaran/linux-web-admin
def setNetworkConfigurationOf(TheInterface):
    if not TheInterface.status:
        return False
    TheInterfaceMainName = TheInterface.name
    IPv4AddressList = TheInterface.ipv4address.split(",")
    IPv4AddressCounter = 0
    ConfigurationsText = ""
    for eachIpv4Address in IPv4AddressList:
        isVirtual = False
        if IPv4AddressCounter > 0:
            TheInterfaceName = TheInterfaceMainName + (
                ":" + (str(IPv4AddressCounter - 1)))
            isVirtual = True
        else:
            TheInterfaceName = TheInterfaceMainName
        ipv4address_with_cidr = eachIpv4Address.split("/")

        if TheInterface.status:
            ConfigurationsText += "auto " + TheInterfaceName + "\n"

        ConfigurationsText += "iface " + TheInterfaceName + " inet "

        if TheInterface.dhcp:
            ConfigurationsText += "dhcp\n"
        else:
            ConfigurationsText += "static\n"
            ConfigurationsText += "\taddress " + ipv4address_with_cidr[0] + "\n"
            if len(ipv4address_with_cidr) > 1:
                ConfigurationsText += "\tnetmask " + ipv4address_with_cidr[
                    1] + "\n"
            else:
                ConfigurationsText += "\tnetmask 24\n"
            if not isVirtual:
                if TheInterface.gateway != "":
                    ConfigurationsText += "\tgateway " + TheInterface.gateway + "\n"

        if not isVirtual:
            if TheInterface.mtu != "1500":
                ConfigurationsText += "\tmtu " + TheInterface.mtu + "\n"

            if TheInterface.manual_dns:
                nameservers = TheInterface.dnsserver.replace(",", " ")
                ConfigurationsText += "\tdns-nameservers " + nameservers
                ConfigurationsText += "\n"
        ConfigurationsText += "\n"
        IPv4AddressCounter += 1
    ethernet_filename = "ifcfg-" + TheInterfaceMainName
    ethernet_file_object = File(ethernet_filename, NETWORK_CONF_PATH)
    return ethernet_file_object.Write(ConfigurationsText)
コード例 #3
0
ファイル: views.py プロジェクト: amirrahbaran/linux-web-admin
def setPermanentRouteTable(TheRoutes):
    route_conf_main = File(ROUTE_CONF_FILE, ROUTE_CONF_PATH)
    route_conf_main.Remove()

    if len(TheRoutes) < 1:
        return False
    ConfigurationsText = "#!/bin/sh\n"
    for eachRoute in TheRoutes:
        if eachRoute.status:
            Ipv4List = eachRoute.ipv4address.split(",")
            for eachIpv4Address in Ipv4List:
                ConfigurationsText += "route add "
                ConfigurationsText += " -net " + eachIpv4Address
                ConfigurationsText += " gw " + eachRoute.gateway
                if eachRoute.interface != "":
                    ConfigurationsText += " dev " + eachRoute.interface
                if eachRoute.metric != 0:
                    ConfigurationsText += " metric " + str(eachRoute.metric)
                ConfigurationsText += " || true \n"

    route_conf_main.Write(ConfigurationsText)
    route_conf_main.MakeExec()
コード例 #4
0
ファイル: views.py プロジェクト: amirrahbaran/linux-web-admin
def reconstructIpsecConfurations():
    ipsec_conf_main = File(IPSEC_ETC_CONF, IPSEC_PREFIX)
    ipsec_secrets_main = File(IPSEC_SECRETS, IPSEC_PREFIX)
    IPSEC_MainConfigurationsText = """config setup
    uniqueids="no"
    strictcrlpolicy="no"

conn %default
    mobike="no"
    keyingtries="%forever"
    leftsendcert="always"
    #forceencaps="yes"\n\n
    """
    IPSEC_MainSecretsText = ""
    tunnels = Tunnel.objects.all()
    for eachTunnel in tunnels:
        requested_profile = Profile.objects.get(name=eachTunnel.profile)
        IPSEC_MainConfigurationsText += setVpnTunnelConfigurationOf(
            eachTunnel, requested_profile)
        IPSEC_MainSecretsText += setVpnTunnelSecretOf(eachTunnel)
    ipsec_conf_main.Write(IPSEC_MainConfigurationsText)
    ipsec_secrets_main.Write(IPSEC_MainSecretsText)
コード例 #5
0
ファイル: views.py プロジェクト: amirrahbaran/linux-web-admin
def removeNetworkConfigurationOf(TheInterface):
    TheInterfaceMainName = TheInterface.name
    ethernet_filename = "ifcfg-" + TheInterfaceMainName
    ethernet_file_object = File(ethernet_filename, NETWORK_CONF_PATH)
    ethernet_file_object.Remove()
コード例 #6
0
ROUTE_CONF_PATH = '/etc/network/if-up.d/'
route_conf_object = Directory(ROUTE_CONF_PATH)
if not route_conf_object.Existed():
    route_conf_object.Make()

# IPSec VPN
IPSEC_KEYDB = "/etc/ipsec.d/"
ipsec_keydb_object = Directory(IPSEC_KEYDB)
if not ipsec_keydb_object.Existed():
    ipsec_keydb_object.Make()

# FILES
NETWORK_CONF_MAIN = '/etc/network/'
NETWORK_CONF_IFACE = 'interfaces'
ethernet_conf_main = File(NETWORK_CONF_IFACE, NETWORK_CONF_MAIN)
MainConfigurationsText = """# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

source /etc/network/interfaces.d/ifcfg-*
"""
ethernet_conf_main.Write(MainConfigurationsText)

ROUTE_CONF_FILE = 'routes'
route_conf_main = File(ROUTE_CONF_FILE, ROUTE_CONF_PATH)
if route_conf_main.Existed():
    route_conf_main.MakeExec()

# python begins the file section
python = '/usr/bin/python'