Exemplo n.º 1
0
#!/usr/bin/env python
"""
CGI-Tools Python Package
Copyright (C) 2016 Assaf Gordon ([email protected])
License: BSD (See LICENSE file)
"""

from cgi_tools import force_C_locale, set_resource_limits, set_app_code, \
                      http_server_error


def cgi_main():
    http_server_error("test script, failing on purpose")


if __name__ == "__main__":
    set_app_code(2001)
    set_resource_limits(walltime=3)
    force_C_locale()
    cgi_main()
Exemplo n.º 2
0
"""
CGI-Tools Python Package
Copyright (C) 2016 Assaf Gordon ([email protected])
License: BSD (See LICENSE file)

Limit runtime to 1 second of %100 CPU time,
then waste CPU cycles for a long time.

SIGXCPU exception is expeccted, which is caught and the script terminated
while printing HTTP error message.
"""

import math,sys
from cgi_tools import set_resource_limits

set_resource_limits(walltime=10,cputime=1)

for i in xrange(0,sys.maxint):
    a = math.sqrt(i)
Exemplo n.º 3
0
    (local, remote) = save_cgi_file_param(form, "datafile",
                                          ".cgi-file-checksum")
    return (local, remote)


def run_checksum(filename):
    cmd = ["sha1sum", filename]
    (out, err) = check_run_cmd_list(cmd)
    # return the first whitespace-delimited field (the checksum value)
    return out.split()[0]


def cgi_main():
    """
    Main script: get CGI parameters, return HTML content.
    """

    (local, remote) = get_cgi_params()
    cksum = run_checksum(local)
    os.unlink(local)

    print("Content-Type: text/plain")
    print("")
    print("sha1 checksum of: %s = %s" % (str(remote), str(cksum)))


if __name__ == "__main__":
    set_resource_limits(walltime=2, filesize=1024 * 1024)
    force_C_locale()
    cgi_main()
Exemplo n.º 4
0
    # Cleanup
    shutil.rmtree(d)

    # Send plain text output
    if plain_output:
        print ("Content-Type: text/html")
        print ("")
        print (file_list.encode('ascii','ignore'))
        return


    # Send pretty HTML output
    print ("Content-Type: text/html")
    print ("")

    tmpl = Template(html_tmpl)
    html = tmpl.render(language=language,
                       script=script, stdin=stdin,
                       results=html_file_list)
    print (html.encode('ascii','ignore'))


if __name__ == "__main__":
    set_app_code(459)
    # note:max file size must be the same (or larger)
    # to the 'ulimit -f' set in port-a-script.sh
    # (otherwise the script will fail with 'ulimit -f: permission denied')
    set_resource_limits(walltime=4,filesize=100*1024)
    force_C_locale()
    cgi_main()
Exemplo n.º 5
0
 def test_resource_limit(self):
     ## For now, just test that it doesn't crash
     set_resource_limits(cputime=1000, walltime=1000)