summaryrefslogtreecommitdiffstats
path: root/abs/mv-core/local-website/contents/mvp_select.py
blob: 8283d68b56131933b2ac32e9d19f5b381a90de1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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()