Example #1
0
def store_endpoint(i):
    sid = crypto.shash(i.id)
    loc = store.path(sid)
    if not os.path.exists(loc): raise web.notfound()

    received = False

    if i.action == 'upload':
        if i.msg:
            loc1 = store.path(sid, '%.2f_msg.gpg' % (uuid.uuid4().int, ))
            crypto.encrypt(config.JOURNALIST_KEY, i.msg, loc1)
            received = 2

        if not isinstance(i.fh, dict) and i.fh.done != -1 and i.fh.filename:
            # we put two zeroes here so that we don't save a file
            # with the same name as the message
            loc2 = store.path(sid, '%.2f_doc.zip.gpg' % (uuid.uuid4().int, ))

            s = cStringIO.StringIO()
            zip_file = zipfile.ZipFile(s, 'w')
            zip_file.writestr(i.fh.filename, i.fh.file.getvalue())
            zip_file.close()
            s.reset()

            crypto.encrypt(config.JOURNALIST_KEY, s, loc2)
            received = i.fh.filename or '[unnamed]'

        if not crypto.getkey(sid):
            background.execute(lambda: crypto.genkeypair(sid, i.id))

    elif i.action == 'delete':
        potential_files = os.listdir(loc)
        if i.mid not in potential_files: raise web.notfound()
        assert '/' not in i.mid
        crypto.secureunlink(store.path(sid, i.mid))

    msgs = []
    for fn in os.listdir(loc):
        if fn.startswith('reply-'):
            msgs.append(
                web.storage(id=fn,
                            date=str(
                                datetime.datetime.fromtimestamp(
                                    os.stat(store.path(sid, fn)).st_mtime)),
                            msg=crypto.decrypt(
                                sid, i.id,
                                file(store.path(sid, fn)).read())))

    web.header('Cache-Control', 'no-cache, no-store, must-revalidate')
    web.header('Pragma', 'no-cache')
    web.header('Expires', '-1')
    return render.lookup(i.id, msgs, received=received)
Example #2
0
    def POST(self):
        i = web.input('id', fh={}, msg=None, mid=None, action=None)
        sid = crypto.shash(i.id)
        loc = store.path(sid)
        if not os.path.exists(loc): raise web.notfound()

        received = False

        if i.action == 'upload':
            if i.msg:
                loc1 = store.path(sid, '%.2f_msg.gpg' % (uuid.uuid4().int, ))
                crypto.encrypt(config.JOURNALIST_KEY, i.msg, loc1)
                received = 2

            if i.fh.value:
                # we put two zeroes here so that we don't save a file
                # with the same name as the message
                loc2 = store.path(sid, '%.2f_doc.gpg' % (uuid.uuid4().int, ))
                crypto.encrypt(config.JOURNALIST_KEY,
                               i.fh.file,
                               loc2,
                               fn=i.fh.filename)
                received = i.fh.filename or '[unnamed]'

            if not crypto.getkey(sid):
                background.execute(lambda: crypto.genkeypair(sid, i.id))

        elif i.action == 'delete':
            potential_files = os.listdir(loc)
            if i.mid not in potential_files: raise web.notfound()
            assert '/' not in i.mid
            crypto.secureunlink(store.path(sid, i.mid))

        msgs = []
        for fn in os.listdir(loc):
            if fn.startswith('reply-'):
                msgs.append(
                    web.storage(id=fn,
                                date=str(
                                    datetime.datetime.fromtimestamp(
                                        os.stat(store.path(sid,
                                                           fn)).st_mtime)),
                                msg=crypto.decrypt(
                                    sid, i.id,
                                    file(store.path(sid, fn)).read())))

        web.header('Cache-Control', 'no-cache, no-store, must-revalidate')
        web.header('Pragma', 'no-cache')
        web.header('Expires', '-1')
        return render.lookup(i.id, msgs, received=received)
Example #3
0
def store_endpoint(i):
  sid = crypto.shash(i.id)
  loc = store.path(sid)
  if not os.path.exists(loc): raise web.notfound()
  
  received = False
  
  if i.action == 'upload':
    if i.msg:
      loc1 = store.path(sid, '%.2f_msg.gpg' % (uuid.uuid4().int, ))
      crypto.encrypt(config.JOURNALIST_KEY, i.msg, loc1)
      received = 2
      
    if not isinstance(i.fh, dict) and i.fh.done != -1 and i.fh.filename:
      # we put two zeroes here so that we don't save a file 
      # with the same name as the message
      loc2 = store.path(sid, '%.2f_doc.zip.gpg' % (uuid.uuid4().int, ))

      s = cStringIO.StringIO()
      zip_file = zipfile.ZipFile(s, 'w')
      zip_file.writestr(i.fh.filename, i.fh.file.getvalue())
      zip_file.close()
      s.reset()

      crypto.encrypt(config.JOURNALIST_KEY, s, loc2)
      received = i.fh.filename or '[unnamed]'

    if not crypto.getkey(sid):
      background.execute(lambda: crypto.genkeypair(sid, i.id))
  
  elif i.action == 'delete':
    potential_files = os.listdir(loc)
    if i.mid not in potential_files: raise web.notfound()
    assert '/' not in i.mid
    crypto.secureunlink(store.path(sid, i.mid))
  
  msgs = []
  for fn in os.listdir(loc):
    if fn.startswith('reply-'):
      msgs.append(web.storage(
        id=fn,
        date=str(datetime.datetime.fromtimestamp(os.stat(store.path(sid, fn)).st_mtime)),
        msg=crypto.decrypt(sid, i.id, file(store.path(sid, fn)).read())
      ))

  web.header('Cache-Control', 'no-cache, no-store, must-revalidate')
  web.header('Pragma', 'no-cache')
  web.header('Expires', '-1')
  return render.lookup(i.id, msgs, received=received)
Example #4
0
def store_endpoint(i):
    sid = crypto.shash(i.id)
    loc = store.path(sid)
    if not os.path.exists(loc):
        raise web.notfound()

    received = False

    if i.action == "upload":
        if i.msg:
            loc1 = store.path(sid, "%.2f_msg.gpg" % (uuid.uuid4().int,))
            crypto.encrypt(config.JOURNALIST_KEY, i.msg, loc1)
            received = 2

        if not isinstance(i.fh, dict) and i.fh.done != -1 and i.fh.filename:
            # we put two zeroes here so that we don't save a file
            # with the same name as the message
            loc2 = store.path(sid, "%.2f_doc.gpg" % (uuid.uuid4().int,))
            crypto.encrypt(config.JOURNALIST_KEY, i.fh.file, loc2, fn=i.fh.filename)
            received = i.fh.filename or "[unnamed]"

        if not crypto.getkey(sid):
            background.execute(lambda: crypto.genkeypair(sid, i.id))

    elif i.action == "delete":
        potential_files = os.listdir(loc)
        if i.mid not in potential_files:
            raise web.notfound()
        assert "/" not in i.mid
        crypto.secureunlink(store.path(sid, i.mid))

    msgs = []
    for fn in os.listdir(loc):
        if fn.startswith("reply-"):
            msgs.append(
                web.storage(
                    id=fn,
                    date=str(datetime.datetime.fromtimestamp(os.stat(store.path(sid, fn)).st_mtime)),
                    msg=crypto.decrypt(sid, i.id, file(store.path(sid, fn)).read()),
                )
            )

    web.header("Cache-Control", "no-cache, no-store, must-revalidate")
    web.header("Pragma", "no-cache")
    web.header("Expires", "-1")
    return render.lookup(i.id, msgs, received=received)
Example #5
0
    def POST(self):
        i = web.input('id', fh={}, msg=None, mid=None, action=None)
        sid = crypto.shash(i.id)
        loc = store.path(sid)
        if not os.path.exists(loc): raise web.notfound()
        
        received = False
        
        if i.action == 'upload':
            if i.msg:
                loc1 = store.path(sid, '%s_msg.gpg' % time.time())
                crypto.encrypt(config.JOURNALIST_KEY, i.msg, loc1)
                received = 2
                
            if i.fh.value:
                # we put two zeroes here so that we don't save a file 
                # with the same name as the message
                loc2 = store.path(sid, '%s_doc.gpg' % time.time())
                crypto.encrypt(config.JOURNALIST_KEY, i.fh.file, loc2, fn=i.fh.filename)
                received = i.fh.filename or '[unnamed]'

            if not crypto.getkey(sid):
                background.execute(lambda: crypto.genkeypair(sid, i.id))
        
        elif i.action == 'delete':
            potential_files = os.listdir(loc)
            if i.mid not in potential_files: raise web.notfound()
            assert '/' not in i.mid
            crypto.secureunlink(store.path(sid, i.mid))
        
        msgs = []
        for fn in os.listdir(loc):
            if fn.startswith('reply-'):
                msgs.append(web.storage(
                  id=fn,
                  date=datetime.datetime.fromtimestamp(float(store.cleanname(fn))),
                  msg=crypto.decrypt(sid, i.id, file(store.path(sid, fn)).read())
                ))

        web.header('Cache-Control', 'no-cache, no-store, must-revalidate')
        web.header('Pragma', 'no-cache')
        web.header('Expires', '-1')
        return render.lookup(i.id, msgs, received=received)
Example #6
0
 def async_genkey(sid, codename):
     with app.app_context():
         background.execute(lambda: crypto_util.genkeypair(sid, codename))
Example #7
0
 def async_genkey(sid, codename):
     with app.app_context():
         background.execute(lambda: crypto_util.genkeypair(sid, codename))
Example #8
0
import os

from model import *
from background import execute

if not os.path.exists('data.db'):
    db.connect()
    db.create_tables(
        [Video, Quality, VideoQuality, WaitingQueue, ProcessedVideo])
    db.close()

if not os.path.exists('encoded'):
    os.mkdir('encoded')

if not os.path.exists('upload'):
    os.mkdir('upload')

if not execute("ffmpeg -h"):
    print("FFMPEG not installed! Please install ffmpeg and add it to PATH")
else:
    print("All good! Now run app.py")