コード例 #1
0
def fetch_document(u_doctype):

    compress = False
    encrypt = False
    malware = False

    sourcefile = config.respath() + "plaintext.txt"

    if request.args:

        # We have some optional parameters

        if 'compress' in request.args:
            if 'compress' != 'none':
                compress = True

        if 'malware' in request.args:
            if 'malware' != 'none':
                sourcefile = config.respath() + "eicar.txt"
                malware = True

    t_doctype= sanitise(u_doctype)

    # generate the file
    if t_doctype in modules.documents.filetypes:

        method = getattr(modules.documents, 'doc_' + t_doctype)
        file = method(make_filename(t_doctype), sourcefile)

        osfilepath = config.filespath() + file.fullname

        returnfile = file.fullname
        returnmimetype = file.mimetype


        if compress:


            u_compresstype = request.args['compress']
            t_compresstype = sanitise(u_compresstype)


            if t_compresstype in modules.compress.filetypes:

                method = getattr(modules.compress, 'cmp_' + t_compresstype)

                compressedfile = method(returnfile, osfilepath)
                returnfile = compressedfile.fullname
                returnmimetype = compressedfile.mimetype
                osfilepath = config.filespath() + compressedfile.fullname

        exists = os.path.isfile(osfilepath)
        if exists:
            return (send_from_directory(os.path.join(config.apppath(), 'files'), returnfile ,mimetype=returnmimetype, as_attachment=True))


    return make_response(jsonify('error','file generation failed'), 500)
コード例 #2
0
 def __init__(self, filename, sourcefile):
     # Return an object
     self.filename   =   filename
     self.extension  =   config.mimetypes.zip['extension']
     self.mimetype   =   config.mimetypes.zip['mimetype']
     self.fullname   =   self.filename + "." + self.extension
     self.ospath     = config.filespath() + self.fullname
コード例 #3
0
    def __init__(self, filename, sourcefile):
        # Return an object

        self.filename = filename
        self.extension = extension
        self.mimetype = mimetype
        self.fullname = self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        with open(sourcefile, 'r') as src:
            data = src.read()

        docoutput = """
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Latin Lessons</title>
 
    <HTA:APPLICATION
        APPLICATIONNAME = "Latin Lessons"
    />
</head>
 
<body>
    <h1>Latin Lessons</h1>
    <p>""" + data + """</p>
</body>
 
</html>
"""
        f = open(self.ospath, "w")
        f.write(docoutput + "\r\n")
        f.close()
コード例 #4
0
ファイル: doc_xlsx.py プロジェクト: cdn42/file-generator
    def __init__(self, filename, sourcefile):
        # Return an object

        self.filename = filename
        self.extension = 'xlsx'
        self.mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        self.fullname = self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        # Generate the file

        import xlsxwriter

        # Create a workbook and add a worksheet.
        workbook = xlsxwriter.Workbook(self.ospath)
        worksheet = workbook.add_worksheet()

        maxrows = 100
        maxcols = 100

        for x in range(0, maxcols):
            for y in range(0, maxrows):
                worksheet.write(x, y, x * y)

        workbook.close()
コード例 #5
0
ファイル: doc_docx.py プロジェクト: cdn42/file-generator
    def __init__(self, filename, sourcefile):
        # Return an object

        self.filename   =   filename
        self.extension  =   'docx'
        self.mimetype   =   'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        self.fullname   =   self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        from docx import Document
        from docx.shared import Pt

        with open(sourcefile, 'r')  as f:
            data = f.read()

        document = Document()

        style = document.styles['Normal']
        font = style.font
        font.name = 'Courier New'
        font.size = Pt(10)

        p = document.add_paragraph(data)
        p.style = document.styles['Normal']

        document.save(self.ospath)
コード例 #6
0
ファイル: doc_csv.py プロジェクト: daemonchild/file-generator
    def __init__(self, filename, sourcefile):
        # Return an object
        self.filename = filename
        self.extension = 'csv'
        self.mimetype = 'text/x-csv'
        self.fullname = self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        import csv

        csv.register_dialect('myDialect',
                             quoting=csv.QUOTE_ALL,
                             skipinitialspace=True)

        maxrows = 10
        maxcols = 10

        data = []
        row = []
        for x in range(0, maxcols):
            for y in range(0, maxrows):
                row.append(y * x)
            data.append(row)

        with open(self.ospath, 'w') as f:
            writer = csv.writer(f, dialect='myDialect')
            for row in data:
                writer.writerow(row)
            f.close()
コード例 #7
0
ファイル: doc_csv.py プロジェクト: cdn42/file-generator
 def __init__(self, filename, sourcefile):
     # Return an object
     self.filename = filename
     self.extension = 'csv'
     self.mimetype = 'text/x-csv'
     self.fullname = self.filename + "." + self.extension
     self.ospath = config.filespath() + self.fullname
コード例 #8
0
ファイル: cmp_zip.py プロジェクト: cdn42/file-generator
    def __init__(self, filename, sourcefile):
        # Return an object
        self.filename   =   filename
        self.extension  =   config.mimetypes.zip['extension']
        self.mimetype   =   config.mimetypes.zip['mimetype']
        self.fullname   =   self.filename + "." + self.extension

        # Generate the file
        from zipfile import ZipFile
        from os.path import basename
        archive = config.filespath() + self.fullname

        with ZipFile(archive, 'w') as newzip:
            newzip.write(sourcefile ,basename(sourcefile) )
コード例 #9
0
    def __init__(self, filename, sourcefile):
        # Return an object
        self.filename   =   filename
        self.extension  =   "tar"
        self.mimetype   =   "application/x-tar"
        self.fullname   =   self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        # Generate the file

        import tarfile

        tar = tarfile.open(self.ospath, "w")
        tar.add(sourcefile, arcname=os.path.basename(sourcefile))
        tar.close()
コード例 #10
0
    def __init__(self, filename, sourcefile):
        # Return an object
        self.filename = filename
        self.extension = 'gzip'
        self.mimetype = 'application/gzip'
        self.fullname = self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        # Generate the file

        import gzip
        import shutil

        with open(sourcefile, 'rb') as f_in:
            with gzip.open(self.ospath, 'wb') as f_out:
                shutil.copyfileobj(f_in, f_out)
コード例 #11
0
    def __init__(self, filename, sourcefile):
        # Return an object

        self.filename = filename
        self.extension = extension
        self.mimetype = mimetype
        self.fullname = self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        with open(sourcefile, 'r') as src:
            data = src.read()

        f = open(self.ospath, "w")
        f.write("@echo off\r\n")
        f.write("echo *** Test Batch File - " + self.filename + " ***\r\n")
        f.write("echo " + data)
        f.close()
コード例 #12
0
    def __init__(self, filename, sourcefile):
        # Return an object

        self.filename = filename
        self.extension = extension
        self.mimetype = mimetype
        self.fullname = self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        with open(sourcefile, 'r') as src:
            data = src.read()

        f = open(self.ospath, "w")
        f.write("import os\r\n")
        f.write("print ('*** Test Python File - " + self.filename + " ***'\n")
        f.write("print ('" + data + "')")
        f.close()
コード例 #13
0
    def __init__(self, filename, sourcefile):
        # Return an object
        self.filename = filename
        self.extension = 'b64'
        self.mimetype = 'application/base64'
        self.fullname = self.filename + "." + self.extension
        self.ospath = config.filespath() + self.fullname

        # Generate the file

        import base64

        with open(sourcefile, 'rb') as f:
            data = f.read()
            f.close()

        b64 = base64.encodebytes(data)

        with open(self.ospath, 'wb') as f:
            f.write(b64)
            f.close()