예제 #1
0
    def test_save(self):
        driver = self.driver

        common.auth(driver)

        file = open(FILENAME, "r")

        i = 0
        for link in file.readlines():
            i += 1
            link = link.strip("\n")
            if link.find(
                    "Page "
            ) < 0 and i >= START_WITH and i < TRESHOLD + START_WITH:
                driver.get(link)
                print "Saving " + link
                time.sleep(random.randint(1, 2))
                driver.find_element_by_xpath("//button[2]").click()
                time.sleep(random.randint(1, 2))
                driver.find_element_by_link_text(".pdfAdobe Reader").click()
                time.sleep(random.randint(1, 2))
                driver.find_element_by_link_text(".docMicrosoft Word").click()
                time.sleep(random.randint(1, 2))
                driver.find_element_by_link_text(".rtfMicrosoft Word").click()
                time.sleep(random.randint(5, 10))
예제 #2
0
    def GET(self):
        auth()

        if web.ctx.query == "":
            render = web.template.frender("./view/templates/other_backup.html")
            return render()
        '''
        datatype=list|file|tar
        file=""
        path=log|etc|conf
        type=sys|usr|web
        '''
        arg_map = get_method_query_to_map(web.ctx.query[1:]);
        command = ""
        res = ""

        try:
            if "path" in arg_map.keys():
                if arg_map["type"] == "usr":
                    path = "/opt/program/" + arg_map["path"]
                else:
                    path = "/opt/system/" + arg_map["path"]

            if arg_map["datatype"] == "list":
                res, status = exec_sub("find " + path + " -type f -name '*'")
                res = res.strip('\n');
                if len(res) != 0:
                    res = res.split("\n");
                else:
                    res = [];
                res = json.dumps(res)
            elif arg_map["datatype"] == "file":
                web.header('Content-type', 'text/plain')
                if arg_map["file"].startswith("/opt/system") or arg_map["file"].startswith("/opt/program/etc") or arg_map["file"].startswith("/opt/program/log"):
                    if os.path.exists(arg_map["file"]):
                        f = open(arg_map["file"])
                        res = f.read()
                        f.close()
            elif arg_map["datatype"] == "tar":
                file = arg_map["path"] + "-" + datetime.datetime.now().strftime('%y-%m-%d-%H-%M-%S') + ".tar.gz"
                if arg_map["type"] == "usr":
                    file = "usr-" + file
                file_path = "/var/" + file

                exec_sub("cd " + path + "&& tar -zcf " + file_path + " ./*")
                web.header('Content-type', 'application/x-tar')
                web.header('Content-disposition', 'attachment;filename=' + file)
                if os.path.exists(file_path):
                    f = open(file_path)
                    res = f.read()
                    f.close()
                os.remove(file_path)

        except Exception as e:
            raise RestfulError("580 " + e.message)
        else:
            return res
예제 #3
0
    def PUT(self):
        auth()
        '''
        file=""
        data=log|etc
        action=clear|clearall|tar|save|del
        type=sys|usr|web
        '''
        client_json_data = web.data()
        json_data = json.loads(client_json_data)

        try:
            if json_data["type"] == "web":
                if json_data["data"] == "log" and json_data["action"] == "clear":
                    #exec_sub("echo ''>/opt/system/log/restful-server/restful.log")
                    f = open('/opt/system/log/restful-server/restful.log', 'w')
                    f.truncate(0);
                    f.close()

            if json_data["type"] == "usr":
                if json_data["data"] == "log":
                    if json_data["action"] == "clearall":
                        res, status = exec_sub("find /opt/program/log -type f -name '*'")
                        res = res.strip('\n').split("\n");
                        for file in res:
                            f = open(file, 'w')
                            f.truncate(0);
                            f.close()
                    if json_data["action"] == "del":
                        file_path = json_data["file"]
                        if os.path.exists(file_path):
                            os.remove(file_path)
                if json_data["data"] == "etc":
                    if json_data["action"] == "save":
                        file_path = json_data["file"]
                        if os.path.exists(file_path):
                            f = open(file, 'w')
                            f.truncate(0);
                            f.write(json_data["file_text"]);
                            f.close()


        except Exception as e:
            raise RestfulError("580 " + e.message)
        else:
            return ""
예제 #4
0
    def test_gather(self):
        driver = self.driver

        file = open(FILENAME, "a")

        common.auth(driver)

        i = START_WITH - 1
        file.write(MAIN_URL + "\n")
        while True:
            driver.get(MAIN_URL + str(i))
            file.write("Page " + str(i) + "\n")
            i += 1
            elems = False
            for elem in driver.find_elements_by_xpath("(//a[@itemprop='jobTitle'])"):
                elems = True
                file.write(elem.get_property('href') + "\n")
            if not elems:
                break
            file.flush()
            print "Page " + str(i) + " done!"
        print "Job ended!"
예제 #5
0
def gen_auth_url_qrcode(environ, start_response):
    """
    函数计算入口
    接口参数(get):
        scenario_type: marketer / merchant / alipay
        state: 微信重定向参数
        timestamp: 时间戳
        signature: 时间戳计算的加密值
        redirect_url: 微信重定向url
    """
    context = environ['fc.context']
    request_uri = environ['fc.request_uri']

    for k, v in environ.items():
        if k.startswith("HTTP_"):
            # process custom request headers
            pass

    # do something here
    env = environ['env']
    params_str = request_uri.split('?')[-1]
    params_dict = parse_query_string(params_str)

    timestamp = int(params_dict.get('timestamp', 0))
    signature = params_dict.get('signature')
    scenario_type = params_dict.get('scenario_type', '')
    state = params_dict.get('state', '')
    redirect_url = params_dict.get('redirect_url', '')
    version = params_dict.get('version', '')

    if auth(timestamp, signature):
        bytes_data = generate_auth_url_qrcode(scenario_type=scenario_type,
                                              state=state,
                                              env=env,
                                              version=version,
                                              redirect_url=redirect_url)
    else:
        bytes_data = b''

    # response status
    status = '200 OK'
    if not bytes_data:
        status = '403 FORBIDDEN'
    response_headers = [('Content-type', 'image/png'),
                        ('Content-Disposition',
                         "attachment; filename={}".format("qrcode.png"))]
    start_response(status, response_headers)

    return [bytes_data]
def application(environ, start_response):
    standard_request = Request(environ)
    userName = standard_request.headers.get('X-Auth-User', '')
    userKey = standard_request.headers.get('X-Auth-Key', '')
    response_body = auth(userName, userKey)
    if response_body == "OK":
        status = '200 OK'

    else:
        status = '401 ERROR'
    response_headers = [('Content-Type', "text/plain"),
                        ('Content-Length', str(len(response_body)))]
    start_response(status, response_headers)

    return response_body
예제 #7
0
def gen_qrcode(environ, start_response):
    """
    函数计算入口
    接口参数:
        uuids: uuid 数组
        url: 二维码背景
    """
    context = environ['fc.context']
    request_uri = environ['fc.request_uri']
    for k, v in environ.items():
        if k.startswith("HTTP_"):
            # process custom request headers
            pass
    # do something here

    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0
    request_body_bytes = environ['wsgi.input'].read(request_body_size)
    request_body = parse.unquote(request_body_bytes.decode('utf8'))

    env = environ['env']
    body_dic = json.loads(request_body)
    uuids = body_dic['uuids']
    url = body_dic['url']
    timestamp = int(body_dic['timestamp'])
    signature = body_dic['signature']

    if auth(timestamp, signature):
        bytes_data = generate_qrcode(uuids=uuids, env=env, url=url)
    else:
        bytes_data = b''

    # response status
    status = '200 OK'
    if not bytes_data:
        status = '403 FORBIDDEN'
    response_headers = [('Content-type', 'application/octet-stream'),
                        ('Content-Disposition',
                         "attachment; filename={}".format("qrcode.zip")),
                        ('Content-Length', len(bytes_data))]
    start_response(status, response_headers)

    return [bytes_data]
예제 #8
0
import common
import sys
import time

sock = common.create_connection("10.1.212.136" , 7017)
if sock is False:
    print "Connect to server failed"
    sys.exit(1)

last_pluse = common.pluse(sock)
print "[Pluse]" + str(last_pluse)

code,msg = common.auth(sock)
print "[Auth]" + str(code) + ":" + msg

tid,code,msg = common.Execute(sock , "ls -al")
print "[Execute]" + str(code) + ":" + msg

time.sleep(2)
res,output = common.GetResult(sock , str(tid) )
print "----" + output + "----"

예제 #9
0
import common
import sys
import time

sock = common.create_connection("10.1.212.136", 7017)
if sock is False:
    print "Connect to server failed"
    sys.exit(1)

last_pluse = common.pluse(sock)
print "[Pluse]" + str(last_pluse)

code, msg = common.auth(sock)
print "[Auth]" + str(code) + ":" + msg

tid, code, msg = common.Execute(sock, "ls -al")
print "[Execute]" + str(code) + ":" + msg

time.sleep(2)
res, output = common.GetResult(sock, str(tid))
print "----" + output + "----"