[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Debian]:Re: Dynamischer DNS-Server. Wie eintragen ???



Die Datei "/etc/ppp/peers/provider" muss die Option "usepeerdns",
die ab ppp-2.3.7 unterstuetzt wird, enthalten.

Die Adressen der Nameserver stehen dann nach dem Verbindungsaufbau in
den Umgebungsvariablen "DNS1" und "DNS2" sowie in der Datei
"/etc/ppp/resolv.conf".

In der Manual-Page des "pppd" und in "/usr/doc/ppp/changelog.gz" gibt
es (zumindest unter "potato") weitere Informationen.

Ich habe ein kleines Python-Programm, dass die Umgebungsvariablen
auswertet und in "/etc/ppp/ip-up.d" installiert werden muss,
geschrieben.

#!/usr/bin/python
#
# This scripts modifies "/etc/resolv.conf" and "/etc/junkbuster/forwardfile"
# if a PPP link goes up or down.
#
# On Debian systems copy it to "/etc/ppp/ip-up.d/001resolver" and create a
# symbolic link from "/etc/ppp/ip-down.d/zzyresolver" to this file.
#
# Copyright (C) 1999-2000 Andreas Voegele <andreas.voegele@gmx.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

import sys
import os
import string
from stat import *

class Provider:
    def __init__(self, domain_name, remote_ips, nameservers, http_proxy):
        self.domain_name = domain_name
        self.remote_ips = remote_ips
        self.nameservers = nameservers
        self.http_proxy = http_proxy
        
def remove_section(filename, commentleader, ppp_iface):
    begin = "%s %s begin\n" % (commentleader, ppp_iface)
    end = "%s %s end\n" % (commentleader, ppp_iface)
    tmpfilename = filename + ".tmp"
    input = open(filename)
    output = open(tmpfilename, "w")
    state = 0
    while 1:
        line = input.readline()
        if line:
            if state == 0:
                if line == begin:
                    state = 1
                else:
                    output.write(line)
            else:
                if line == end:
                    state = 0
        else:
            break
    output.close()
    input.close()
    try:
        os.unlink(filename)
    except:
        os.unlink(tmpfilename)
    else:
        os.rename(tmpfilename, filename)
            
def add_nameservers(resolvconf, ppp_iface, provider):
    address = os.environ.get("DNS1")
    if address:
        addresses = [ address ]
        address = os.environ.get("DNS2")
        if address:
            addresses.append(address)
    else:
        addresses = provider.nameservers
    if os.path.exists(resolvconf):
        f = open(resolvconf, "a")
        f.write("# %s begin\n" % ppp_iface)
        for address in addresses:
            f.write("nameserver %s\n" % address)
        f.write("# %s end\n" % ppp_iface)
        f.close()
    else:
        f = open(resolvconf, "w")
        f.write("# %s begin\ndomain %s\n" % (ppp_iface, provider.domain_name))
        for address in addresses:
            f.write("nameserver %s\n" % address)
        f.write("# %s end\n" % ppp_iface)
        f.close()

def remove_nameservers(resolvconf, ppp_iface):
    if os.path.exists(resolvconf):
        remove_section(resolvconf, "#", ppp_iface)
        if os.stat(resolvconf)[ST_SIZE] == 0:
            os.unlink(resolvconf)

def add_forwarder(forwardfile, ppp_iface, provider):
    if provider.http_proxy and os.path.exists(forwardfile):
        f = open(forwardfile)
        data = f.readlines()
        f.close()
        # find the last line with an "*" at the beginning
        n = len(data)
        while n > 0:
            if string.lstrip(data[n - 1][0]) == "*":
                break
            n = n - 1
        f = open(forwardfile, "w")
        f.writelines(data[0:n])
        f.write("# %s begin\n* %s . .\n# %s end\n"
                % (ppp_iface, provider.http_proxy, ppp_iface))
        f.writelines(data[n:])
        f.close()

def remove_forwarder(forwardfile, ppp_iface):
    if os.path.exists(forwardfile):
        remove_section(forwardfile, "#", ppp_iface)

def get_path(basename, filename):
    path = os.path.join(basename, filename)
    if os.path.islink(path):
        path = os.path.normpath(os.path.join(basename, os.readlink(path)))
    return path

def main():
    resolvconf = get_path("/etc", "resolv.conf")
    forwardfile = get_path("/etc/junkbuster", "forwardfile")

    ppp_iface = os.environ["PPP_IFACE"]
    ppp_remote = os.environ["PPP_REMOTE"]

    providers = [
        Provider("nikoma.de",
                 [ "212.122." ],
                 [ "212.122.128.10", "212.122.129.10" ],
                 "proxy.nikoma.de:8080"),
        Provider("dusnet.de",
                 [ "213.61." ],
                 [ "213.61.158.65", "213.61.159.34" ],
                 "proxy.dusnet.de:3128"),
        Provider("01019freenet.de",
                 [ "62.104." ],
                 [ "62.104.220.82", "62.104.196.134" ],
                 None),
        ]

    for p in providers:
        for ip in p.remote_ips:
            if ppp_remote[:len(ip)] == ip:
                if string.find(sys.argv[0], "ip-up") != -1:
                    add_nameservers(resolvconf, ppp_iface, p)
                    add_forwarder(forwardfile, ppp_iface, p)
                else:
                    remove_forwarder(forwardfile, ppp_iface)
                    remove_nameservers(resolvconf, ppp_iface)
                return

if __name__ == '__main__':
    main()

Reply to: