Ejemplo n.º 1
0
 def decrypt(self, key):
     #pass
     #print(self.payload)
     #print(key)
     if self.payload != None and self.payload != b'' and key != None:
         print("Len:", len(self.payload))
         self.payload = aes.decrypt(self.payload, key)
Ejemplo n.º 2
0
 def set_all_variable(self):
     self.set_variable('ansible_host', self.name)
     self.set_variable('ansible_port', self.port)
     self.set_variable('ansible_user', self.host.normal_user)
     # self.set_variable('ansible_ssh_pass', self.host.sshpasswd) #密码登陆
     self.set_variable("ansible_become", True)
     self.set_variable("ansible_become_method", 'sudo')
     self.set_variable("ansible_become_user", 'root')
     self.set_variable("ansible_become_pass", decrypt(self.host.sshpasswd))
Ejemplo n.º 3
0
def edit_templates(template_id):
    result = get_template_by_id(template_id)
    location = decrypt(app.secret_key, result["location"])
    print(location)
    with open(location, "rb") as docx_file:
        result = mammoth.convert_to_html(docx_file)
        html = result.value  # The generated HTML
        #print(html)
        return html
Ejemplo n.º 4
0
    async def __request_validate(self, outside_self, **kwargs):

        #校验凭证并获取用户数据
        if self.isTicket:
            token = outside_self.request.headers.get_list("Authorization")
            if len(token) <= 0:
                raise InnerErrorCustom(code="20001", msg="拒绝访问!")
            else:
                token = token[0]
            c = outside_self.redisC(key=token)
            result = await c.get_dict()
            if not result:
                raise InnerErrorCustom(code="20002", msg="拒绝访问")

            if result.get("status") == '1':
                raise PubErrorCustom("账户已到期!")
            elif result.get("status") == '2':
                raise PubErrorCustom("账户已冻结!")
            outside_self.user = result
            outside_self.token = token

        outside_self.data = None

        if self.isParams:
            if outside_self.request.method in ['POST', 'PUT']:
                outside_self.data = outside_self.get_body_argument(
                    "data", None)
                if not outside_self.data:
                    outside_self.data = json.dumps(json.loads(outside_self.request.body.decode('utf-8')).get("data",None)) if outside_self.request.body \
                        else '{}'
                if not outside_self.data:
                    outside_self.data = '{}'
            elif outside_self.request.method == 'GET':
                outside_self.data = outside_self.get_argument("data", None)
            elif outside_self.request.method == 'DELETE':
                outside_self.data = '{}'
            else:
                raise PubErrorCustom("拒绝访问!")

            if not outside_self.data:
                raise PubErrorCustom("拒绝访问!")

            if self.isPasswd:
                if outside_self.data != '{}':
                    outside_self.data = json.loads(decrypt(outside_self.data))
                else:
                    outside_self.data = json.loads(outside_self.data)
            else:
                outside_self.data = json.loads(outside_self.data)

        logger.info("请求的参数: {}".format(outside_self.data))
Ejemplo n.º 5
0
def bulk_fill(secret_key, templates, clients):
    for template_id in templates:
        template = get_template_by_id(template_id)
        template_location = decrypt(secret_key, template['location']).decode()

        for client_id in clients:
            client_data = get_client_by_id(client_id)
            mapping_id = client_data["mapping_id"]
            mapping_dict = fetch_mapping_by_id(mapping_id)
            mapped_client_data = map_client_data_to_template(
                client_data, template_id, mapping_dict)

            try:
                temp_client_data_file = open('../scripts/temp.json',
                                             'w',
                                             encoding='utf-8')
            except Exception as e:
                print(e)
                return Response(status=409)
            else:
                with temp_client_data_file as f:
                    json.dump(mapped_client_data, f, ensure_ascii=False)
                print(type(template_location))
                template_location = template_location.replace('\\', '/')
                print(template_location)
                result = subprocess.run([
                    'python3', '../scripts/docgen.py', template_location,
                    '../scripts/temp.json'
                ],
                                        encoding='utf-8',
                                        stdout=subprocess.PIPE)
                print("result")
                result = result.stdout.split("\n")
                print(result)
                document_name = result[-2].split(":")[1].strip()
                print(document_name)
                add_document_generated(document_name, client_id)
Ejemplo n.º 6
0
def save_templates(template_id):
    json_data = request.get_json(force=True)
    #print(json_data)
    html = json_data["html"]
    buf = html2docx(html, title="Edited Template")
    result = get_template_by_id(template_id)
    location = decrypt(app.secret_key, result["location"])
    #print(location)
    with open(location, "wb") as fp:
        fp.write(buf.getvalue())
        add_template_to_db(result["filename"], location)
        template_filename = result["filename"]
        # Now add the jinja-fields in the template to the template document in MongoDB
        template_location = os.path.join(app.config['UPLOAD_FOLDER'],
                                         template_filename)
        modified_count = set_jinja_fields(template_location, template_id)

        if (modified_count):
            print("Added jinja-fields for", str(modified_count), "template")
            return Response(status=200)
        else:
            print("Failed to add jinja fields to mongo.db.template")
            return Response(status=409)
    return Response(status=200)