def genrespdata(useragent): respstr = '<html><head><title>Responsive Server</title></head><body bgcolor="#eeeeee"><h1>Details of your device</h1><table border="1">' os = sdk.getOS(useragent) touch = sdk.isTouch(useragent) resolution = sdk.getDisplayResolution(useragent) g3 = sdk.is3G(useragent) wifi = sdk.isWifi(useragent) ram = sdk.getRAM(useragent) width = sdk.getDisplayWidth(useragent) height = sdk.getDisplayHeight(useragent) qwerty = sdk.isQwerty(useragent) camres = sdk.getPrimCamRes(useragent) respstr += '<tr><td>OS</td><td>'+str(os)+'</td></tr>' respstr += '<tr><td>Touch</td><td>'+str(touch)+'</td></tr>' respstr += '<tr><td>3G</td><td>'+str(g3)+'</td></tr>' respstr += '<tr><td>WIFI</td><td>'+str(wifi)+'</td></tr>' respstr += '<tr><td>RAM</td><td>'+str(ram)+'</td></tr>' respstr += '<tr><td>WIDTH</td><td>'+str(width)+'</td></tr>' respstr += '<tr><td>HEIGHT</td><td>'+str(height)+'</td></tr>' respstr += '<tr><td>QWERTY</td><td>'+str(qwerty)+'</td></tr>' respstr += '<tr><td>CAMERA RESOLUTION</td><td>'+str(camres)+'</td></tr>' respstr += '</table></body></html>' print respstr return respstr
def get(self): val=self.request.headers['User-Agent'] jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__))) ret=sdk.isTouch(val) self.response.headers['Content-Type'] = 'text/html' #ret=None if(ret==True): template_values = { } template = jinja_environment.get_template("index.html") self.response.out.write(template.render(template_values)) else: template_values = { } template = jinja_environment.get_template("simp.html") self.response.out.write(template.render(template_values))
def get(self): useragent = self.request.headers['user-agent'] if (str(sdk.getOS(str(useragent))) == 'None'): form = ''' <html> <head> <style> label.nhelp2 {display:none} label.dhelp2 {display:none} label.bhelp2 {display:none} label.shelp2 {display:none} </style> <script> function init() { nh=document.getElementById("nh"); dh=document.getElementById("dh"); bh=document.getElementById("bh"); sh=document.getElementById("sh"); sub=document.getElementById("submit"); nh.innerHTML=""; dh.innerHTML=""; bh.innerHTML=""; sh.innerHTML=""; } function display(id) { que=document.getElementById(id+"2"); if(que.style.display=="none") { que.style.display="block"; que.style.color="green"; } else que.style.display="none"; } function budget(id) { bud=document.getElementById("bu") if(id==3||id==4) { bud.style.display="block"; } else { bud.style.display="none"; } bud=document.getElementById("name") if(id==0) { bud.style.display="block"; } else { bud.style.display="none"; } bud=document.getElementById("bu1") if(id==3) { bud.style.display="block"; } else { bud.style.display="none"; } } function validate() { i=0; type=document.getElementById("type"); name=document.getElementById("Name"); dist=document.getElementById("dist"); budg=document.getElementById("budg"); state=document.getElementById("state"); sub=document.getElementById("submit"); nh=document.getElementById("nh"); dh=document.getElementById("dh"); bh=document.getElementById("bh"); sh=document.getElementById("sh"); if(type.value=="none") { sub.disabled=true; i=1;} else if(name.value=="none" && dist.value=="none" && state.value=="none") {sub.disabled=true; i=1;} else if((type.value=="Hotel" || type.value=="Beach Resort") && budg.value=="none") { sub.disabled=true; i=1;} //Name if(name.value!="none"){ if(name.value.match(/\D/)) { //alert("name is a string"); if(i==0)sub.disabled=false; nh.innerHTML=""; } else { nh.innerHTML="name is not a string"; nh.style.color="red"; //alert("name is not a string"); sub.disabled=true; i=1; } } //Distance if(dist.value!="none"){ if(dist.value.match(/\d/)) { //alert("dist is a number"); if(i==0)sub.disabled=false; dh.innerHTML=""; } else { dh.innerHTML="dist is a string"; dh.style.color="red"; //alert("dist is a string"); sub.disabled=true; i=1; } } //Budget if(type.value=="Hotel" || type.value=="Beach Resort") { if(budg.value!="none"){ if(budg.value.match(/less than [0-9]+/gi)||budg.value.match(/greater than [0-9]+/gi)||budg.value.match(/\d/)) { //alert("budget is a number"); if(i==0)sub.disabled=false; bh.innerHTML=""; } else { bh.innerHTML="budget is a string"; bh.style.color="red"; //alert("budget is a string"); sub.disabled=true; i=1; } } } //State if(state.value!="none"){ if(state.value.match(/\D/)) { //alert("state is a string"); sh.innerHTML=""; if(i==0)sub.disabled=false; } else { sh.innerHTML="state is not a string"; sh.style.color="red"; //alert("state is not a string"); sub.disabled=true; i=1; }} if(i==1) sub.disabled=true; } </script> </head> <body> <h1>Query</h1> <hr><hr> <h3>Type of Tourist Place:</h3> <form action="" method=post> <select size=1 name="Type" id="type" onchange="validate()"> <option id=-1 value="none" onclick=budget(id)>Select the type of place</option> <option id=0 value="Tourist" onclick=budget(id)>Tourist</option> <option id=3 value="Hotel" onclick=budget(id) >Hotel</option> </select> <div id=name style="display:none"><h3>Enter Name:</h3> <input type=text name="Name" id="Name" value="none" onblur="validate()" /><label id=nh></label> <label class=nhelp id=nhelp onmouseover=display(id)>?</label><label class=nhelp2 id=nhelp2>Enter Name</label> </div> <br /> <div id=bu style="display:none"><h3>Enter City:</h3> <input type=text name="city" id="budg" value="none" /><label id=bh></label> <label class=bhelp id=bhelp onmouseover=display(id)>?</label><label class=bhelp2 id=bhelp2>Enter city</label> </div> <br /> <div id=bu1 style="display:none"><h3>Enter Rate:</h3> <input type=text name="rate" id="name1" value="none" /><label id=bh></label> <label class=bhelp id=bhelp onmouseover=display(id)>?</label><label class=bhelp2 id=bhelp2>Enter city</label> </div> <br /> <input type=submit id="submit" value=Search /><input type=reset onclick=init() /> </form> </body></html> ''' self.response.write((form)) else: f = ''' <html> <head> <title>cgi input</title> </head> <body> <h2>The OS OF MOBILE IS=</h2> %s <h2>HAS QUERTY?=</h2> %s <h2>HAS TOUCH ENABLED?=</h2> %s <h2>HAS CAMERA?=</h2> %s <h2>HAS FM?=</h2> %s </body> </html> ''' self.response.write( f % (sdk.getOS(str(useragent)), sdk.isTouch(str(useragent)), sdk.isQwerty(str(useragent)), sdk.isPrimCam( str(useragent)), sdk.isFM(str(useragent))))
def get_response(user_agent): sdk.isTouch(user_agent)
def do_GET(self): self.send_response(200) # self.headers used nto extract the headers m = re.search("User-Agent:\s([a-z A-Z 0-9 / \. ' ' \- ; \, ( ) :]*[0-9 \.]*)", str(self.headers)) print "The following is the user agent\n" print m.group(1), "\n \n" usragent = m.group(1) self.send_header("Content-type", "text/html") self.end_headers() # checks for touch support if sdk.isTouch(usragent) == None: self.wfile.write("touch support not known") else: st = "supported" if sdk.isTouch(usragent) else "not supported" st1 = "Touch: " + st self.wfile.write(st1) self.wfile.write("\n") # Gives RAM ram = sdk.getRAM(usragent) if ram == None: ram = "not known" self.wfile.write("RAM in GB: " + str(ram)) self.wfile.write("\n") # Gives display width disp = sdk.getDisplayWidth(usragent) if disp == None: disp = "not known" self.wfile.write("Display width in pixels: " + str(disp)) self.wfile.write("\n") # Gives OS os = sdk.getOS(usragent) if os == None: os = "not known" self.wfile.write("OS of device: " + os) self.wfile.write("\n") # Gives height of device ht = sdk.getHeight(usragent, st="mm") if ht == None: ht = "not known" self.wfile.write("height of device in mm: " + str(ht)) self.wfile.write("\n") # Checks for bluetooth if sdk.isBluetooth(usragent) == None: self.wfile.write("Bluetooth support not known") else: st = "supported" if sdk.isBluetooth(usragent) else "not supported" st1 = "Bluetooth: " + st self.wfile.write(st1) self.wfile.write("\n") # Gives internal memory mem = sdk.getInternalMemory(usragent) if mem == None: mem = "not known" self.wfile.write("Internal Memory in GB: " + str(mem)) self.wfile.write("\n") # Gives no of sims in device st3 = sdk.getSimNum(usragent) if st3 == None: st3 = "not known" self.wfile.write("Number of sims: " + str(st3)) self.wfile.write("\n")
def do_GET(self): useragent=self.headers['user-agent'] f = open('log.txt','a') f.write(str(self.command)+' command from (ip,port)='+str(self.client_address)+'\n') f.close() self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() if (str(sdk.getOS(str(useragent)))=='None'): form=''' <html> <head> <script> function budget(id) { bud=document.getElementById("bu") if(id==3||id==4) { bud.style.display="block"; } else { bud.style.display="none"; } } </script> </head> <body> <h1>Query</h1> <hr><hr> <h3>Type of Tourist Place:</h3> <form action="" method=post> <select size=1 name="Type"> <option value="none">Select the type of place</option> <option id=0 value="Heritage Site" onclick=budget(id)>Heritage Site</option> <option id=1 value="Beach" onclick=budget(id)>Beach</option> <option id=2 value="Hill Station" onclick=budget(id)>Hill Station</option> <option id=3 value="Hotel" onclick=budget(id)>Hotel</option> <option id=4 value="Beach Resort" onclick=budget(id)>Beach Resort</option> </select> <h3>Enter Name:</h3> <input type=text name="Name" value="none"/><br /> <h3>Enter Distance:</h3> <input type=text name="Distance" value="none"/><br /> <div id=bu style="display:none"><h3>Enter your Budget:</h3> <input type=text name="Budget" value="none"/></div> <h3>Enter State:</h3> <input type=text name="State" value="none"/><br /><br /> <input type=submit value=Search /><input type=reset /> </form> </body></html>''' self.wfile.write((form)) else: f=''' <html> <head> <title>cgi input</title> </head> <body> <h2>The OS OF MOBILE IS=</h2> %s <h2>HAS QUERTY?=</h2> %s <h2>HAS TOUCH ENABLED?=</h2> %s <h2>HAS CAMERA?=</h2> %s <h2>HAS FM?=</h2> %s </body> </html> ''' self.wfile.write(f%(sdk.getOS(str(useragent)),sdk.isTouch(str(useragent)),sdk.isQwerty(str(useragent)),sdk.isPrimCam(str(useragent)),sdk.isFM(str(useragent))))
def get(self): useragent=self.request.headers['user-agent'] if (str(sdk.getOS(str(useragent)))=='None'): form=''' <html> <head> <style> label.nhelp2 {display:none} label.dhelp2 {display:none} label.bhelp2 {display:none} label.shelp2 {display:none} </style> <script> function init() { nh=document.getElementById("nh"); dh=document.getElementById("dh"); bh=document.getElementById("bh"); sh=document.getElementById("sh"); sub=document.getElementById("submit"); nh.innerHTML=""; dh.innerHTML=""; bh.innerHTML=""; sh.innerHTML=""; } function display(id) { que=document.getElementById(id+"2"); if(que.style.display=="none") { que.style.display="block"; que.style.color="green"; } else que.style.display="none"; } function budget(id) { bud=document.getElementById("bu") if(id==3||id==4) { bud.style.display="block"; } else { bud.style.display="none"; } bud=document.getElementById("name") if(id==0) { bud.style.display="block"; } else { bud.style.display="none"; } bud=document.getElementById("bu1") if(id==3) { bud.style.display="block"; } else { bud.style.display="none"; } } function validate() { i=0; type=document.getElementById("type"); name=document.getElementById("Name"); dist=document.getElementById("dist"); budg=document.getElementById("budg"); state=document.getElementById("state"); sub=document.getElementById("submit"); nh=document.getElementById("nh"); dh=document.getElementById("dh"); bh=document.getElementById("bh"); sh=document.getElementById("sh"); if(type.value=="none") { sub.disabled=true; i=1;} else if(name.value=="none" && dist.value=="none" && state.value=="none") {sub.disabled=true; i=1;} else if((type.value=="Hotel" || type.value=="Beach Resort") && budg.value=="none") { sub.disabled=true; i=1;} //Name if(name.value!="none"){ if(name.value.match(/\D/)) { //alert("name is a string"); if(i==0)sub.disabled=false; nh.innerHTML=""; } else { nh.innerHTML="name is not a string"; nh.style.color="red"; //alert("name is not a string"); sub.disabled=true; i=1; } } //Distance if(dist.value!="none"){ if(dist.value.match(/\d/)) { //alert("dist is a number"); if(i==0)sub.disabled=false; dh.innerHTML=""; } else { dh.innerHTML="dist is a string"; dh.style.color="red"; //alert("dist is a string"); sub.disabled=true; i=1; } } //Budget if(type.value=="Hotel" || type.value=="Beach Resort") { if(budg.value!="none"){ if(budg.value.match(/less than [0-9]+/gi)||budg.value.match(/greater than [0-9]+/gi)||budg.value.match(/\d/)) { //alert("budget is a number"); if(i==0)sub.disabled=false; bh.innerHTML=""; } else { bh.innerHTML="budget is a string"; bh.style.color="red"; //alert("budget is a string"); sub.disabled=true; i=1; } } } //State if(state.value!="none"){ if(state.value.match(/\D/)) { //alert("state is a string"); sh.innerHTML=""; if(i==0)sub.disabled=false; } else { sh.innerHTML="state is not a string"; sh.style.color="red"; //alert("state is not a string"); sub.disabled=true; i=1; }} if(i==1) sub.disabled=true; } </script> </head> <body> <h1>Query</h1> <hr><hr> <h3>Type of Tourist Place:</h3> <form action="" method=post> <select size=1 name="Type" id="type" onchange="validate()"> <option id=-1 value="none" onclick=budget(id)>Select the type of place</option> <option id=0 value="Tourist" onclick=budget(id)>Tourist</option> <option id=3 value="Hotel" onclick=budget(id) >Hotel</option> </select> <div id=name style="display:none"><h3>Enter Name:</h3> <input type=text name="Name" id="Name" value="none" onblur="validate()" /><label id=nh></label> <label class=nhelp id=nhelp onmouseover=display(id)>?</label><label class=nhelp2 id=nhelp2>Enter Name</label> </div> <br /> <div id=bu style="display:none"><h3>Enter City:</h3> <input type=text name="city" id="budg" value="none" /><label id=bh></label> <label class=bhelp id=bhelp onmouseover=display(id)>?</label><label class=bhelp2 id=bhelp2>Enter city</label> </div> <br /> <div id=bu1 style="display:none"><h3>Enter Rate:</h3> <input type=text name="rate" id="name1" value="none" /><label id=bh></label> <label class=bhelp id=bhelp onmouseover=display(id)>?</label><label class=bhelp2 id=bhelp2>Enter city</label> </div> <br /> <input type=submit id="submit" value=Search /><input type=reset onclick=init() /> </form> </body></html> ''' self.response.write((form)) else: f=''' <html> <head> <title>cgi input</title> </head> <body> <h2>The OS OF MOBILE IS=</h2> %s <h2>HAS QUERTY?=</h2> %s <h2>HAS TOUCH ENABLED?=</h2> %s <h2>HAS CAMERA?=</h2> %s <h2>HAS FM?=</h2> %s </body> </html> ''' self.response.write(f%(sdk.getOS(str(useragent)),sdk.isTouch(str(useragent)),sdk.isQwerty(str(useragent)),sdk.isPrimCam(str(useragent)),sdk.isFM(str(useragent))))