diff options
author | Britney Fransen <brfransen@gmail.com> | 2022-12-30 21:06:31 (GMT) |
---|---|---|
committer | Britney Fransen <brfransen@gmail.com> | 2022-12-30 21:06:31 (GMT) |
commit | 1ecfae71fe7dc9c069089f8d6d75b7978fbb94e1 (patch) | |
tree | 41c6ae77ded023e0d94c4944c73b1c0dffeb4da0 /linhes/linhes-web/website/contents/mvp_select.py | |
parent | 6c530f338a1967bdbdda9e09e915d4a1e194d27f (diff) | |
download | linhes_pkgbuild-1ecfae71fe7dc9c069089f8d6d75b7978fbb94e1.zip linhes_pkgbuild-1ecfae71fe7dc9c069089f8d6d75b7978fbb94e1.tar.gz linhes_pkgbuild-1ecfae71fe7dc9c069089f8d6d75b7978fbb94e1.tar.bz2 |
linhes-web: initial inclusion
Diffstat (limited to 'linhes/linhes-web/website/contents/mvp_select.py')
-rw-r--r-- | linhes/linhes-web/website/contents/mvp_select.py | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/linhes/linhes-web/website/contents/mvp_select.py b/linhes/linhes-web/website/contents/mvp_select.py new file mode 100644 index 0000000..8283d68 --- /dev/null +++ b/linhes/linhes-web/website/contents/mvp_select.py @@ -0,0 +1,146 @@ +#!/usr/bin/python +# + +import urllib2 +import string +import sys +import time +import datetime +import socket + +def read_accepted(): + + global dhcp_accepted + dhcp_accepted = [] + try: + infile = open('/tmp/dhcp.leases', 'r') + except(IOError), e: + print "couldn't open accepted" + else: + filelist = infile.readlines() + infile.close() + for item in filelist: + item=item.strip() + macaddress=item.split(" ")[1] + if macaddress not in dhcp_accepted: + dhcp_accepted.append(macaddress) + #print macaddress + +def read_offered(): + global dhcp_offered + dhcp_offered = [] + try: + today = datetime.date.today() + + host = socket.gethostname() + filename='/var/log/' + filename+=str(today) + filename+='/' + filename+=host + filename+='/dnsmasq' + infile = open(filename, 'r') + except(IOError), e: + print "couldn't open offered" + else: + filelist = infile.readlines() + infile.close() + for item in filelist: + item=item.strip() + if item.find("DHCPOFFER") != -1 : + macaddress=item.rpartition(" ")[2] + if macaddress not in dhcp_offered: + dhcp_offered.append(macaddress) + #print macaddress + + + +def read_current(): + global dhcp_current + dhcp_current = [] + try: + infile = open('/etc/dnsmasq.mvpmc.conf', 'r') + except(IOError), e: + print "couldn't open current" + else: + filelist = infile.readlines() + infile.close() + for item in filelist: + item=item.strip() + if item.find("dhcp-host") != -1 : + macaddress=item.partition(",")[2] + + if macaddress not in dhcp_current : + dhcp_current.append(macaddress) + # print macaddress + + + + + + + +def make_html(): + global dhcp_accepted + global dhcp_offered + buttonform_top=''' + <div class="content" style="solid #aaa; width:500px; height:300px; overflow:auto; color:#FFF;text-align:left;"> + <form action="/mvp_process.py" method="get"> + ''' + + + buttonform_bottom=''' + Mac Address: + <input type="text" name="activemvp"> + + </br> + <input id="submitbutton" type="submit" /> + </form> + </div> + ''' + checkboxline = ''' + <input type="checkbox" name="activemvp" value="%s" %s /> %s <br /> + ''' + print '<br />' + da = set(dhcp_accepted) + dof = set(dhcp_offered) + dc = set(dhcp_current) + possible_mac= dof -dc + #possible_mac= dof -da - dc + + print buttonform_top + for mac in dhcp_current: + print checkboxline % (mac ,' checked="yes"' , mac) + for mac in possible_mac: + print checkboxline % (mac , " " ,mac) + print buttonform_bottom + + +#------------------- +global dhcp_accepted +global dhcp_offered +global dhcp_current + + + + +read_offered() +#print "--" +#print '</br>' +read_accepted() +#print "--" +#print '</br>' +read_current() +#print "--" +#print '</br>' + + + +#possible_mac= (dof - da) +#possible_mac = dof +#print "should be unchecked:" +#print possible_mac + + +make_html() + + |