美文网首页aardio
aardio后台进程

aardio后台进程

作者: LCSan | 来源:发表于2023-09-02 14:25 被阅读0次
    import win;
    import web.json;
    import myplu.fiddler;
    import wsock.tcp.asynHttpServer;
    import console;
    
    function getIp(){
        import inet.adapter;
        import sys.networkCards;
        for networkCard in ..sys.networkCards.each("PCI"){  
            for adptInfo in ..inet.adapter.each() {
                if(tostring(networkCard.adapterName) == tostring(adptInfo.adapterName)){
                    return adptInfo.ipAddressList.ipAddress ; 
                }
            }
        }
    }
    
    var fetch_cache = {}; 
    var filter_urls = {}; 
    
    myplu.fiddler.fiddlerApplication.BeforeResponse = function (s) {
        var url = s.fullUrl; 
        
        var ft = table.find(filter_urls,function(v,index){
            return string.find(url,"@@"+v);     
        });
        
        if(ft){
            table.push(fetch_cache,{url=url;
            method=s.RequestMethod;
            responseCode=s.responseCode;
            requestHeaders=myplu.fiddler.getHeaders(s.RequestHeaders);
            responseHeaders=myplu.fiddler.getHeaders(s.ResponseHeaders);
            requestBody=s.GetRequestBodyAsString();
            responseBody=s.GetResponseBodyAsString();});
        }   
    }
    
    var httpServer = wsock.tcp.asynHttpServer();
    
    // http服务器处理,接收前端消息
    httpServer.run(function(response,request,session){
        response.headers["Access-Control-Allow-Origin"] = "*";
        response.headers["Access-Control-Allow-Headers"] = "*";
        response.contentType = "application/json; charset=utf-8";       
        select(request.path) {
            case "/filterUrl" {
                var data = request.query("rule");
                if(!data){
                    data = request.postData();
                }
                filter_urls = web.json.parse(data);
                response.write({state="ok";msg="filter updated";data=filter_urls});
            }
            case "/startFetch" {
                if(!myplu.fiddler.fiddlerApplication.IsStarted()){
                    myplu.fiddler.startup(0);
                    response.write({state="ok";msg="service started";poxy=getIp() +":"+ tostring(myplu.fiddler.fiddlerApplication.oProxy.ListenPort)});
                }else{          
                    response.write({state="ok";msg="start success"});
                }
            }
            case "/stopFetch" {
                myplu.fiddler.stop();
                response.write({state="ok";msg="stop success"});
            }
            case "/fetch" {
                var data = request.postData();
                table.push(fetch_cache,data);
                response.write({state="ok";msg="fetch success"});
            }
            case "/getMsg" {
                try{
                    if(#fetch_cache){
                        var data = table.pop(fetch_cache);                  
                        response.write(data);
                    }else{
                        response.write({});
                    }
                }
                catch(e){
                    response.write({});
                }           
            }
            case "/clearMsg" {
                fetch_cache = {};
                response.write({state="ok";msg="clear success"});
            }
            case "/quit" {
                win.quitMessage();
                response.write({state="ok";msg="Exited"});
            }
            else {
                var data = `%s<br/>
    Url:%s<br/>
    Method:%s<br/>
    <br/>
    `           
                var res = string.format(data, "更新嗅探规则,需要抓取的url列表", httpServer.getUrl("filterUrl")+`?rule=["https://www.xxx.com/xxx"]`, "GET")
                res += string.format(data, "启动嗅探服务", httpServer.getUrl("startFetch"), "GET")
                res += string.format(data, "停止嗅探服务", httpServer.getUrl("stopFetch"), "GET")
                res += string.format(data, "获取一条嗅探消息", httpServer.getUrl("getMsg"), "GET")
                res += string.format(data, "清理嗅探结果队列", httpServer.getUrl("clearMsg"), "GET")
                res += string.format(data, "停止服务,结束进程", httpServer.getUrl("quit"), "GET")
                
                response.contentType = "text/html; charset=utf-8";
                response.write(res);
            }
        }
    });
    
    httpServer.start("0.0.0.0",8888);
    
    win.loopMessage();
    myplu.fiddler.stop();
    httpServer.stop();
    

    相关文章

      网友评论

        本文标题:aardio后台进程

        本文链接:https://www.haomeiwen.com/subject/gbmxvdtx.html