Author: viol Date: Wed Aug 10 15:26:18 2011 New Revision: 2717 Log: removes the ap-monitor tool from the mobac services. Adds commandline option to activate the daemon mode. Modified: apps/mobac-services/init/mobac-services apps/mobac-services/masd.config apps/mobac-services/masd.py apps/mobac-services/www/services.html Modified: apps/mobac-services/init/mobac-services ============================================================================== --- apps/mobac-services/init/mobac-services Wed Aug 10 14:48:35 2011 (r2716) +++ apps/mobac-services/init/mobac-services Wed Aug 10 15:26:18 2011 (r2717) @@ -20,7 +20,7 @@ DESC="Mobile ACcess Services" NAME=masd.py DAEMON=/opt/mobac-services/$NAME -DAEMON_ARGS="" +DAEMON_ARGS="-d" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/mobac-services Modified: apps/mobac-services/masd.config ============================================================================== --- apps/mobac-services/masd.config Wed Aug 10 14:48:35 2011 (r2716) +++ apps/mobac-services/masd.config Wed Aug 10 15:26:18 2011 (r2717) @@ -2,6 +2,7 @@ server.socket_port: 8080 server.socket_host: '0.0.0.0' tools.staticdir.root = "/opt/mobac-services" +tools.staticdir.index = "services.html" [/] tools.staticdir.on = True @@ -11,11 +12,3 @@ tools.staticdir.on = True tools.staticdir.dir = "www/lib" -#[/video] -#tools.staticdir.on = True -#tools.staticdir.dir = "www/stream-demo/video" - -#[/maps] -#tools.staticdir.on = True -#tools.staticdir.dir = "www/stream-demo/maps" - Modified: apps/mobac-services/masd.py ============================================================================== --- apps/mobac-services/masd.py Wed Aug 10 14:48:35 2011 (r2716) +++ apps/mobac-services/masd.py Wed Aug 10 15:26:18 2011 (r2717) @@ -1,22 +1,16 @@ #!/usr/bin/python import cherrypy, json, time, pickle, os, math, urllib2, subprocess, sys, socket from cherrypy.process import plugins +from optparse import OptionParser as op -cwd = os.getcwd() -cwd = "/opt/mobac-services" - -INDEX_PAGE = '/www/services.html' -### enable this plugin to daemonize this service -plugins.Daemonizer(cherrypy.engine).subscribe() - -### -#clientPositions = {'0.0.0.0':{'pos':0,'time':0.0}} PING_TIMEOUT = 2 -SOCKET_TIMEOUT = 2 +#SOCKET_TIMEOUT = 2 #socket.setdefaulttimeout(SOCKET_TIMEOUT) + # all available content, three different types (video, map, ap) +# TODO: In Datei auslagern content = {'DEFAULT':{'title':"Stadt Aachen", 'data':'/video/flv/UMIC-Day-7-mid.flv', 'type':'video'}, 'DEFAULT_MAP':{'title':"Stadt Aachen", 'data':'/maps/aachen-map-qm.jpg', 'type':'map'}, 'DEFAULT_AP':{'title':"unknown", 'data':None, 'type':'ap'}, @@ -94,37 +88,6 @@ (50.778206, 6.060939):('nyx_map','DEFAULT','131'), } -accessPoints_all={'116':'iris', - '117':'selene', - '126':'freya', - '118':'pan', - '119':'nike', - '120':'hebe', - '125':'gaia', - '127':'hyperion', - '129':'chaos', - '130':'chronos', - '131':'nyx', - '91':'ac-1', - '92':'ac-2', - '93':'ac-3', - '94':'ac-4', - '95':'ac-5', - '96':'ac-6', - '81':'lancom-1', - } - -accessPoints_select={'126':'freya', - '120':'hebe', - '127':'hyperion', - '125':'gaia', - } - -accessPoints = accessPoints_all - - -IP_PREFIX='192.168.5.' - nativeClients=['2001:19:7309:931d:47f:a23c:6fd2:e5c9', "2001:1a:f439:557c:965c:fc4e:4acd:9e82", @@ -157,79 +120,6 @@ pass return closestPos -def isApOnline(apId): - if apId in accessPoints.keys() : - ping = subprocess.Popen(['ping', '-c1', '-w2', '-n', IP_PREFIX + apId], stdout=subprocess.PIPE) - (pingOut,pingErr) = ping.communicate() - for s in pingOut.split(): - if ('time=' in s): - return s.split('=')[1] - pass - #ping = os.system('ping -c1 -w3 ' + IP_PREFIX + apId) ##attention: execution on user input - TODO parse/convert to int - #if (ping == 0): - #return 1 - return 0 - -def apInfoParser(iKey, iString): - if (iKey in ("client_ip","os_release","os_version","hostname","uptime")): - return {iKey:iString[iKey]} - elif (iKey == "assoclist"): - clients = [] - stations = iString[iKey].split("Station")[1:] - for s in stations: - if (len(s) == 0): continue - mac = s.split()[0] - stats = s.split(";")[1:] - clients.append({'mac':mac,'stats':stats}) - pass - return {iKey:clients} - pass - elif (iKey == "hipconf_ha"): - filterStats = ("Peer HIT","Peer IP","Peer NAT traversal UDP port","Local NAT traversal UDP port","Peer hostname") - assocs = [] - stations = iString[iKey].split("HA is ")[1:] - for s in stations: - if (len(s) == 0): continue - haState = s.split(';')[0] - stats = [st.strip() for st in s.split(";")[1:] if st.split(":")[0].strip() in filterStats] - assocs.append({'haState':haState,'stats':stats}) - pass - return {iKey:assocs} - pass - - elif (iKey in ("hip_version","hipd_version","hipfw_version","pisacd_version","pisasd_version")): - return {iKey:iString[iKey].split(';',1)[0]} - pass - elif (iKey == "route"): - return {iKey:iString[iKey]} - pass - elif (iKey == "coords"): - return {iKey:iString} - pass - elif (iKey == "iwconfig"): - return {iKey:iString[iKey].split(';',1)[0]} - pass - elif (iKey in ("wlan0","eth0","eth1","br-lan","hipconf_hi")): - return {iKey:[i for i in iString[iKey].split(';') if (len(i) > 1)]} - pass - elif (iKey == "ps"): - checkProcesses = ("hipd","hipfw","pisacd","pisasd") - return {iKey:[p for p in checkProcesses if p in iString[iKey]]} - pass -# elif (iKey == "dhcp_leases"): -# try: -# leases = {} -# leasesList = iString[iKey].split(";") -# for l in leasesList: -# if (len(l) > 0): -# x = l.split() -# leases.update({x[1]:{"ip":x[2], "id":x[3]}}) -# pass -# return {iKey:leases} -# except: -# return {iKey:""} -# pass - return " " def getClientHit(clientPisaIp): # returns the coresponding client hit of a client pisa IP macbookHit= '2001:19:7309:931d:047f:a23c:6fd2:e5c9' @@ -282,33 +172,9 @@ pass - - -### cherrypy plugin to sync content and client positions on start and stop to disk -class SyncPositions(plugins.SimplePlugin): - - def __init__(self, bus): - plugins.SimplePlugin.__init__(self, bus) - pass - - def start(self): - #print 'starting...' - #todo: read content and client positions from file - pass - def stop(self): - #print 'stopping...' - #todo: write client positions to file - pass - -getApInfoHist = {} #apId:{'time':0,'apInfo':{}] -counter = 0 ### class HipStream(object): - def index(self): #just return HIP_Stream.html - INDEX = open(cwd + INDEX_PAGE ,'r') - return INDEX.read(-1) - #def floorplan(self): # FLOORPLAN = open (cwd + '/war/floorplan/floorplan.html','r') # return FLOORPLAN.read(-1) @@ -335,17 +201,6 @@ else: return json.dumps(0) - ### get content for current location -# def getContent(self): -# ip = cherrypy.request.remote.ip - #print clientPositions - #time.sleep(4) - -# if (ip in clientPositions) and (clientPositions[ip]['pos'] in localContent): -# return json.dumps([content[con] for con in localContent[clientPositions[ip]['pos']]]) -# else: -# return json.dumps([content[con] for con in localContent[0]]) - def getContent(self, lat="0.0", lon="0.0"): #ip = cherrypy.request.remote.ip #print clientPositions @@ -369,73 +224,6 @@ def heartbeat(self): return("") - def getApInfo(self, apId, *infoTags): - global getApInfoHist - REQ_TIME_OFFSET = 4.0 - reqTime = time.time() - if (apId in getApInfoHist): - if (getApInfoHist[apId]['time'] >= (reqTime - REQ_TIME_OFFSET)): - if (getApInfoHist[apId]['requestDone']): - return json.dumps(getApInfoHist[apId]['apInfo']) - else: - return - else: - getApInfoHist[apId] = {} - #apInfo = {} - #if isApOnline(apId): - getApInfoHist[apId]['time'] = reqTime - getApInfoHist[apId]['requestDone'] = False - - apInfo = {"online": isApOnline(apId)} - if apInfo["online"]: - try: - page = json.load(urllib2.urlopen('http://192.168.5.' + apId + ':29868/request_ap_coordinates', timeout=SOCKET_TIMEOUT)) - if ((len(infoTags) == 0) or ("coords" in infoTags)): - apInfo.update(apInfoParser("coords",page)) - except: - print "error requesting AP coords" - pass - #try: - # page = json.load(urllib2.urlopen('http://192.168.5.' + apId + ':29868/request_ap_info?get_ps')) - # if ((len(infoTags) == 0) or ("ps" in infoTags)): - # apInfo.update(apInfoParser("ps",page)) - #except: - # #print "error" - # pass - try: - page = json.load(urllib2.urlopen('http://192.168.5.' + apId + ':29868/request_ap_info', timeout=SOCKET_TIMEOUT)) - if (len(infoTags) == 0): - for tagName in INFO_TAGS: - try: - apInfo.update(apInfoParser(tagName,page)) - pass - except: - pass - pass - else: - for tag in infoTags: - apInfo.update(apInfoParser(tag,page)) - pass - pass - pass - except: #urllib2.HTTPError, error: - print "error requesting AP info" - #no info service - #print error.read() - #raise - pass - pass - - getApInfoHist[apId] = {'time':time.time(),'apInfo':apInfo, 'requestDone':True} - return json.dumps(apInfo) - - def getAps(self): - aps = [] - for ap in accessPoints: - #aps.append({'id':ap,'name':accessPoints[ap],'online':isApOnline(ap)}) - aps.append({'id':ap,'name':accessPoints[ap]}) - return json.dumps(aps) - def getConnectionStats(self): clientStats = {'hit':'', 'ip':'', 'pip':'', 'type':''} apStats = {'hit':'', 'ip':'', 'pip':''} @@ -462,21 +250,23 @@ ### make pages accessable - index.exposed = True #setPos.exposed = True #doRefresh.exposed = True getContent.exposed = True getAll.exposed = True rpc.exposed = True heartbeat.exposed = True - getApInfo.exposed = True - getAps.exposed = True getConnectionStats.exposed = True -### start sync plugin -sync = SyncPositions(cherrypy.engine) -sync.subscribe() +if __name__ == '__main__': + parser = op() + parser.add_option("-d", "--daemon", action="store_true", dest="daemonize", default=False, + help="Start service as daemon") + (options, args) = parser.parse_args() + if options.daemonize: + ### enable this plugin to daemonize this service + plugins.Daemonizer(cherrypy.engine).subscribe() -### start HIP Stream Server -cherrypy.quickstart(HipStream(),config=cwd +'/masd.config') + ### start HIP Stream Server + cherrypy.quickstart(HipStream(),config=os.path.dirname(os.path.realpath(__file__)) +'/masd.config') Modified: apps/mobac-services/www/services.html ============================================================================== --- apps/mobac-services/www/services.html Wed Aug 10 14:48:35 2011 (r2716) +++ apps/mobac-services/www/services.html Wed Aug 10 15:26:18 2011 (r2717) @@ -9,7 +9,7 @@ <center> <table id="services"> <tr> - <th colspan="4"><center> Mobile ACcess Services </center></th> + <th colspan="4"><center> Mobile ACcess Demo-Services </center></th> </tr> <tr> <td class="left"> <a href="stream-demo/stream-demo.html"> Handover Service</a></td> @@ -24,8 +24,10 @@ <td class="left"><a href="floorplan/floorplan.html"><img width="300" class="service_img" src="service-pics/floorplan.png"></a></td> - <td class="right"> <a href="/ap-monitor/ap-monitor.html"><img width="300" class="service_img" src="service-pics/ap-monitor.png"></a></td> - <td class="right"> <a href="/ap-monitor/ap-monitor.html"> AP Monitoring </a> </td> + <td class="right"> + </td> + <td class="right"> + </td> </tr> -- This is the pisa developer mailing list. Please also subscribe to the main pisa list at: //www.freelists.org/list/pisa