Hi All,

Being the crap programmer that I am I recently enlisted the help of
StevenK to write a radius web frontend in python, and although I am much
appreciative to Steven for his efforts I am still having a problem and
dont particularly want to bother Steven with my inferior programming and
troubleshooting abilities...this is where you come in.

Would someone mind having a quick look at this program and send me any
suggestions/fixes for the problem to which I am about to explain.

The backend is the cistron userlist file (/etc/raddb/userlist) which
looks like this:

user1   Password = "pass1"
        Session-Timeout = 10800,
        Idle-Timeout = 10800,
        Fall-Through = 1

user2   Password = "pass2"
        Session-Timeout = 7200,
        Idle-Timeout = 7200,
        Fall-Through = 1

user3    Password = "pass3"
        Session-Timeout = 10800,
        Idle-Timeout = 10800,
        Fall-Through = 1

now the python script reads the file and spews a list of configured
users to the screen with a radio button next to each config. Down the
bottom it allows you to add a new user with defined session and idle
timeouts. The problem is that the script dies in the arse *unless* you
have 2 empty lines at the bottom of the file, but this causes an 'empty'
config in the webpages list. If you then add a new user, it creates a
*new* 'empty' config, creating two empty configs and three empty lines
in the file...This ends in a huge mess of empty lines and radio buttons
on the web page.


Any ideas?

Cheers,

Adam.


-- 
Adam Hewitt - CCNA, LCP
Senior Network Engineer
GLOBAL DIAL PTY LTD

PO BOX 829 Claremont, Western Australia 6910
Suite 1/278 Stirling Highway, Claremont WA 6010
        Telephone: +61 8 9383 1800    Facsimile: +61 8 9383 2818
        Email: [EMAIL PROTECTED] Website: www.globaldial.com
________________________________________________________
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential and/or
privileged material.  Any review, retransmission, dissemination or
other use of, or taking of any action in reliance upon, this
information by persons or entities other than the intended
recipient is prohibited.  If you have received this email in error,
please immediately notify us via email at [EMAIL PROTECTED]
-------------------------------------------------------
#!/usr/bin/python

import sys

file = "/etc/raddb/userlist"

f = open(file)
parsed_file = [[]]
counter = 0
for x in f.xreadlines():
    if x == '\n':
        parsed_file.append([])
        counter+=1
        continue
    number = -1
    if x.endswith('\n\n'): number = -2
    parsed_file[counter].append(x[:number])

data_hash = {}
for x in sys.stdin.read().split('&'):
    tmp_line = x.split('=')
    if len(tmp_line) == 2:
        data_hash[tmp_line[0]] = tmp_line[1]
if not data_hash.has_key('button'):
    data_hash['button'] = ''

if data_hash['button'] == 'Add':
    tmp_array = ["%s\tPassword=\"%s\"" % (data_hash['user'], data_hash['pass'])]
    tmp_array.append("\tSession-Timeout = %s," % data_hash['sess'])
    tmp_array.append("\tIdle-Timeout = %s," % data_hash['idle'])
    tmp_array.append("\tFall-Through = 1")
    parsed_file.append(tmp_array)
elif data_hash['button'] == 'Delete':
    tmp_delete = data_hash['count'].split('\0')
    tmp_delete.reverse()
    for i in tmp_delete:
        del parsed_file[int(i)]

print "Content-type: text/html\n\n"
print "<html><head><title>Radius</title></head>"
print "<body>"

print "<form method=\"post\">"
print "<table>"
counter = 0
for x in parsed_file:
    print "<tr>"
    print "<td><input type=\"checkbox\" name=\"count\" value=\"%s\"></td>" % counter
    print "<td>"
    for y in x:
        print "%s<br>" % y
    print "</td></tr>"
    counter += 1
    print "<tr><td></td>"
print "<td>Username: <input name=\"user\"><br>Password: <input name=\"pass\"><br>Session-Timeout: <input name=\"sess\"><br>Idle-Timeout: <input name=\"idle\"></td></tr>"
print "<tr><td><input type=\"submit\" name=\"button\" value=\"Add\"></td><td><input type=\"submit\" name=\"button\" value=\"Delete\"></td></tr>"
print "</table>"
print "</form>"

f = open(file, "w")
for x in parsed_file:
    for y in x:
        f.write('%s\n' % y)
    f.write('\n')

#commands.getstatusoutput("killall -HUP radiusd")

print "</body></html>"
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to