ZoomQuiet avatar ZoomQuiet committed 06fe88f

updated for KNOSS-vol51...

Comments (0)

Files changed (2)

+.*\.wsgic
 .*\.pyc
 .*\.egg
 .*\.so
 import base64
 import time
 from hashlib import md5
+from base64 import urlsafe_b64encode
 
 class Borg():
     '''base http://blog.youxu.info/2010/04/29/borg
 
 @app.route('/')
 def hello():
-    return "Hello, world! - Bottle @ SAE 4 urisaok!{v12.04.23} from YY talking.."
+    return '''Hollo, there! 
+    - Bottle @ SAE 4 urisaok!
+    - {v12.04.23} from YY talking..
+    usage:
+    $ curl -d 'uri=hrrp://sina.com' http://urisaok.sinaapp.com/qchk
+    or
+    $ curl -d 'uri=hrrp://sina.com' http://urisaok.sinaapp.com/chk
+                    +-- want check url
+    '''
 
 @app.route('/chk/', method="POST")
+@app.route('/chk', method="POST")
 def chk():
     uri = request.forms.get('uri')
-    print uri
+    #print uri
     result = _askCloud(cfg.APITYPE, uri)
-    return "/chk %s"% result
+    return "/chk:: %s"% cfg.PHISHTYPE[str(result)]
+
+@app.route('/qchk/', method="POST")
+@app.route('/qchk', method="POST")
+def qchk():
+    url = request.forms.get('uri').split("/")
+    if 1 == len(url):
+        uri = url[0]
+    else:
+        uri = url[2]
+    k = urlsafe_b64encode(uri)
+    print k
+    import sae.kvdb
+    kv = sae.kvdb.KVClient()
+    print "kv.get_info() %s"% kv.get_info()
+    v = kv.get(k)
+    print "kv.get(uri)~ type=%s var=%s"%(type(v),v)
+    if None == v:
+        result = _askCloud(cfg.APITYPE, uri)
+        kv.add(k, result)
+        return "/qchk(KSC)::\t %s" % cfg.PHISHTYPE[str(result)]
+    else:
+        return "/qchk(KVDB)::\t %s" % cfg.PHISHTYPE[str(v)]
+    #result = _askCloud(cfg.APITYPE, uri)
+    #return "/qchk"
 
 def _askCloud(api_path, url):
     args = __genQueryArgs(api_path, url)
     key_values = [("%s=%s" % (k, v)) for k, v in args.iteritems()]
     api_url = "http://%s/%s/"% (cfg.OPEN_HOST, api_path) + "?" + "&".join(key_values)
-    print api_url
+    #print api_url
     result = eval(urilib.urlopen(api_url).read())
-    print type(result)
-    print result
+    #print type(result)
+    #print result
     if result['success'] == 1:
-        doc = result['phish']
-        return "%s:: %s"% (doc, cfg.PHISHTYPE[str(doc)])
+        return result['phish']
+        #doc = result['phish']
+        #return "%s:: %s"% (doc, cfg.PHISHTYPE[str(doc)])
     else:
         return result
 
     args["timestamp"] = "%.3f" % (time.time())
     sign_base_string = __genSignString(api_path, args)
     args["sign"] = md5(sign_base_string + cfg.SECRET).hexdigest()
-    print args, sign_base_string
+    #print args, sign_base_string
     return args
 
     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.