Ejemplo n.º 1
0
def main(argv):
    rtlist = []

    for rtstr in argv[1:]:
        ret = rtstr.split("/")
        if (ret.__len__() != 2):
            print("Error, use CIDR notation (e.g. 1.1.1.1/24):", rtstr)
            return 255

        try:
            addr, mask = ret[0], int(ret[1])
        except:
            print("Error, use CIDR notation (e.g. 1.1.1.1/24):", rtstr)
            return 255

        rt = ip4route.IP4Route(addr, mask)
        if (rt.isValid() == False):
            print("Error, invalid route:", rtstr)
            return 255

        rtlist.append(rt)

    if (rtlist == []):
        print("One or more valid routes required.")
        return 255

    rtlist, summarized = acrs.summarize(rtlist)

    for rt in rtlist:
        assert(rt.isValid() == True)
        print(rt)

    if summarized == True:
        return 0
    elif summarized == False:
        return 1
    else:
        assert(False)
Ejemplo n.º 2
0
def main():
    rtlist = []

    print "Content-type: text/html\n\n"
    print "<h1>Results:</h1>"
    print "(Use your browser's back button to return to the previous page.)"
    print "</br></br>"

    # If an exception is thrown, cgitb will allow errors to be printed to
    # the web page, in addition to the python version and a timestamp.
    # This is useful for debugging purposes. If you don't want this to happen,
    # either comment out the next line, or see the python documentation
    # on how to make it write to a log file.
    cgitb.enable()
    form = cgi.FieldStorage()

    if (not "summary-input" in form):
        print "Error: One or more prefixes required."
        return 1

    args = form["summary-input"].value.split()

    if (args.__len__() > ARGS_LIMIT):
        print "The web version of this demo is artificially limited to", \
              ARGS_LIMIT, "prefixes so the web server doesn't get too bogged " \
              "down. Consider downloading a command line version from " \
              "acrs.googlecode.com (it's open source and no cost) " \
              "or bribing the server operator to increase ARGS_LIMIT in ", \
              "acrs-web-demo.py."
        return 1

    for rtstr in args:
        ret = rtstr.split("/")
        if (ret.__len__() != 2):
            print "Error, use CIDR notation (e.g. 1.1.1.0/24):", rtstr
            return 1

        try:
            addr, mask = ret[0], int(ret[1])
        except:
            print "Error, use CIDR notation (e.g. 1.1.1.0/24):", rtstr
            return 1

        rt = ip4route.IP4Route(addr, mask)
        if (rt.isValid() == False):
            print "Error, invalid route:", rtstr
            return 1

        rtlist.append(rt)

    if (rtlist == []):
        print "One or more valid routes required."
        return 1

    rtlist, summarized = acrs.summarize(rtlist)

    for rt in rtlist:
        assert (rt.isValid() == True)
        print rt, "</br>"

    return 0
Ejemplo n.º 3
0
def main():
    rtlist = []

    print "Content-type: text/html\n\n"
    print "<h1>Results:</h1>"
    print "(Use your browser's back button to return to the previous page.)"
    print "</br></br>"

    # If an exception is thrown, cgitb will allow errors to be printed to
    # the web page, in addition to the python version and a timestamp.
    # This is useful for debugging purposes. If you don't want this to happen,
    # either comment out the next line, or see the python documentation
    # on how to make it write to a log file.
    cgitb.enable()
    form = cgi.FieldStorage()

    if (not "summary-input" in form):
        print "Error: One or more prefixes required."
        return 1

    args = form["summary-input"].value.split()

    if (args.__len__() > ARGS_LIMIT):
        print "The web version of this demo is artificially limited to", \
              ARGS_LIMIT, "prefixes so the web server doesn't get too bogged " \
              "down. Consider downloading a command line version from " \
              "acrs.googlecode.com (it's open source and no cost) " \
              "or bribing the server operator to increase ARGS_LIMIT in ", \
              "acrs-web-demo.py."
        return 1

    for rtstr in args:
        ret = rtstr.split("/")
        if (ret.__len__() != 2):
            print "Error, use CIDR notation (e.g. 1.1.1.0/24):", rtstr
            return 1

        try:
            addr, mask = ret[0], int(ret[1])
        except:
            print "Error, use CIDR notation (e.g. 1.1.1.0/24):", rtstr
            return 1

        rt = ip4route.IP4Route(addr, mask)
        if (rt.isValid() == False):
            print "Error, invalid route:", rtstr
            return 1

        rtlist.append(rt)

    if (rtlist == []):
        print "One or more valid routes required."
        return 1

    rtlist, summarized = acrs.summarize(rtlist)

    for rt in rtlist:
        assert(rt.isValid() == True)
        print rt, "</br>"

    return 0