ZoomQuiet avatar ZoomQuiet committed 766dcd8

revert as v1 old style..

Comments (0)

Files changed (5)

-120421 ZQ 使用全新 saecloud 重构金山云安全的 SAE 应用,v2
 110323 ZQ 快速建立了基于GAE 的人工查询服务代码
 .hg
 +-- default     默认分支包含主要的文档
 +-- GAE         可部署在GAE上的版本
-+-- SAE         可部署在SAE上的版本
-+-- bottle      本地运行的版本
-`-- tools       相关实验性支持脚本
 
 
 依赖
 -------------------------------------------------------------------------------
-Bottle
+Bottle+GAE
 
 部署
 -------------------------------------------------------------------------------
 
+
+记要
+-------------------------------------------------------------------------------
+110323  Zoom.Quiet 创建
+
 ---
 name: urisaok
-version: 2
+version: 1
 ...
 # -*- coding: utf-8 -*-
 VERSION = "urisaok v11.12.28"
 '''网址云RESTful API 包装服务:
+    - 111226 clone into SAE
+    - 110324 clone into GAE
+    - 110323 init.
 依赖:
     + bottle
-    + SAE
 '''
+
+from bottle import Bottle, request
+
 import sae
 import urllib2 as urilib
-from bottle import Bottle, request
 
 import base64
 import time
 from hashlib import md5
-from base64 import urlsafe_b64encode
 
 class Borg():
     '''base http://blog.youxu.info/2010/04/29/borg
         ,'1':'钓鱼'
         ,'2':'网站高风险,有钓鱼嫌疑'
         }
+
 # init all var
 cfg = Borg()
 
 
 @app.route('/')
 def hello():
-    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
-    '''
+    return "Hello, world! - Bottle @ SAE 4 urisaok!{v12.01.12} from YY talking.."
 
 @app.route('/chk/', method="POST")
-@app.route('/chk', method="POST")
 def chk():
     uri = request.forms.get('uri')
-    #print uri
+    print uri
+    #result = "try chk"
     result = _askCloud(cfg.APITYPE, uri)
-    return "/chk:: %s"% cfg.PHISHTYPE[str(result)]
+    return "/chk %s"% 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"
+@app.route('/ask/:uri')
+def ask(uri):
+    print uri
+    result = _askCloud(cfg.APITYPE, uri)
+    return "/ask %s"% result
 
 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 result
     if result['success'] == 1:
-        return result['phish']
-        #doc = result['phish']
-        #return "%s:: %s"% (doc, cfg.PHISHTYPE[str(doc)])
+        doc = result['phish']
+        return "%s:: %s"% (doc, cfg.PHISHTYPE[str(doc)])
     else:
         return result
 
     args["sign"] = md5(sign_base_string + cfg.SECRET).hexdigest()
     #print args, sign_base_string
     return args
-
     
 def __genSignString(api_path, args):
     keys = args.keys()
     return base_string
 
 
-from sae.ext.shell import ShellMiddleware
-application = sae.create_wsgi_app(ShellMiddleware(app, '1q2w3e4r5t')) 
-#application = sae.create_wsgi_app(app)
+application = sae.create_wsgi_app(app)

shell.py

-import sae
-from sae.ext.shell import ShellMiddleware
-
-def urisaok(environ, start_response):
-    status = '200 OK'
-    response_headers = [('Content-type', 'text/plain')]
-    start_response(status, response_headers)
-    return ["Hello, world!"]
-
-application = sae.create_wsgi_app(ShellMiddleware(urisaok, '1q2w3e4r'))
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.