def main():
    onionshare.strings = onionshare.load_strings()

    # start the Qt app
    app = Application()

    # check for root in Tails
    if onionshare.get_platform() == 'Tails' and not onionshare.is_root():
        subprocess.call(['/usr/bin/gksudo']+sys.argv)
        return

    # create the onionshare icon
    global window_icon, onionshare_gui_dir
    window_icon = QIcon("{0}/onionshare-icon.png".format(onionshare_gui_dir))

    # try starting hidden service
    onionshare_port = onionshare.choose_port()
    try:
        onion_host = onionshare.start_hidden_service(onionshare_port)
    except onionshare.NoTor as e:
        alert(e.args[0], QMessageBox.Warning)
        return
    onionshare.tails_open_port(onionshare_port)

    # select file to share
    filename, basename = select_file(onionshare.strings)
    if not filename:
        return

    # initialize the web app
    webapp.onionshare = onionshare
    webapp.onionshare_port = onionshare_port
    webapp.filename = filename
    webapp.onion_host = onion_host
    webapp.qtapp = app
    webapp.clipboard = app.clipboard()

    # run the web app in a new thread
    webapp_port = onionshare.choose_port()
    onionshare.tails_open_port(webapp_port)
    webapp_thread = WebAppThread(webapp_port)
    webapp_thread.start()

    # clean up when app quits
    def shutdown():
        onionshare.tails_close_port(onionshare_port)
        onionshare.tails_close_port(webapp_port)
    app.connect(app, SIGNAL("aboutToQuit()"), shutdown)

    # launch the window
    web = Window(basename, webapp_port)
    web.show()

    # all done
    sys.exit(app.exec_())
def main():
    onionshare.strings = onionshare.load_strings()

    # check for root in Tails
    if onionshare.get_platform() == 'Tails' and not onionshare.is_root():
        subprocess.call(['/usr/bin/gksudo']+sys.argv)
        return

    # try starting hidden service
    onionshare_port = onionshare.choose_port()
    try:
        onion_host = onionshare.start_hidden_service(onionshare_port)
    except onionshare.NoTor as e:
        alert(e.args[0], gtk.MESSAGE_ERROR)
        return
    onionshare.tails_open_port(onionshare_port)

    # select file to share
    filename, basename = select_file(onionshare.strings)
    if not filename:
        return

    # start the gui web server
    webapp_port = onionshare.choose_port()
    t = threading.Thread(target=start_webapp, kwargs={
        'webapp_port': webapp_port,
        'onionshare_port': onionshare_port,
        'filename': filename,
        'onion_host': onion_host
    })
    t.daemon = True
    t.start()
    onionshare.tails_open_port(webapp_port)

    # launch the window
    launch_window(webapp_port, onionshare_port, basename)
Exemple #3
0
def main():
    onionshare.strings = onionshare.load_strings()

    # start the Qt app
    app = Application()

    # check for root in Tails
    if onionshare.get_platform() == 'Tails' and not onionshare.is_root():
        subprocess.call(['/usr/bin/gksudo']+sys.argv)
        return

    # parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('--local-only', action='store_true', dest='local_only', help='Do not attempt to use tor: for development only')
    parser.add_argument('--stay-open', action='store_true', dest='stay_open', help='Keep hidden service running after download has finished')
    parser.add_argument('--debug', action='store_true', dest='debug', help='Log errors to disk')
    parser.add_argument('filename', nargs='?', help='File to share')
    args = parser.parse_args()

    filename = args.filename
    local_only = args.local_only
    stay_open = bool(args.stay_open)
    debug = args.debug

    onionshare.set_stay_open(stay_open)

    # create the onionshare icon
    global window_icon, onionshare_gui_dir
    window_icon = QIcon("{0}/onionshare-icon.png".format(onionshare_gui_dir))

    # try starting hidden service
    onionshare_port = onionshare.choose_port()
    local_host = "127.0.0.1:{0}".format(onionshare_port)
    if not local_only:
        try:
            onion_host = onionshare.start_hidden_service(onionshare_port)
        except onionshare.NoTor as e:
            alert(e.args[0], QMessageBox.Warning)
            return
    onionshare.tails_open_port(onionshare_port)

    # select file to share
    filename, basename = select_file(onionshare.strings, filename)
    if not filename:
        return

    # initialize the web app
    webapp.onionshare = onionshare
    webapp.onionshare_port = onionshare_port
    webapp.filename = filename
    if not local_only:
        webapp.onion_host = onion_host
    else:
        webapp.onion_host = local_host
    webapp.qtapp = app
    webapp.clipboard = app.clipboard()
    webapp.stay_open = stay_open
    webapp.debug = debug

    # run the web app in a new thread
    webapp_port = onionshare.choose_port()
    onionshare.tails_open_port(webapp_port)
    webapp_thread = WebAppThread(webapp_port)
    webapp_thread.start()

    # clean up when app quits
    def shutdown():
        onionshare.tails_close_port(onionshare_port)
        onionshare.tails_close_port(webapp_port)
    app.connect(app, SIGNAL("aboutToQuit()"), shutdown)

    # launch the window
    web = Window(basename, webapp_port)
    web.show()

    # all done
    sys.exit(app.exec_())
Exemple #4
0
def main():
    global url
    strings = onionshare.load_strings()

    # try starting hidden service
    port = onionshare.choose_port()
    try:
        onion_host = onionshare.start_hidden_service(port)
    except onionshare.NoTor as e:
        alert(e.args[0], gtk.MESSAGE_ERROR)
        return
    onionshare.tails_open_port(port)

    # select file to share
    filename, basename = select_file(strings)
    if not filename:
        return

    # open the window, launching webkit browser
    webgui.start_gtk_thread()
    browser, web_recv, web_send = webgui.sync_gtk_msg(webgui.launch_window)(
        title="OnionShare | {0}".format(basename),
        quit_function=Global.set_quit,
        echo=False)

    # clipboard
    clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)

    def set_clipboard():
        global url
        clipboard.set_text(url)
        web_send("update('{0}')".format('Copied secret URL to clipboard.'))

    # the async nature of things requires startup to be split into multiple functions
    def startup_async():
        global url
        filehash, filesize = onionshare.file_crunching(filename)
        onionshare.set_file_info(filename, filehash, filesize)
        url = 'http://{0}/{1}'.format(onion_host, onionshare.slug)
        web_send("update('{0}')".format(strings['give_this_url'].replace(
            '\'', '\\\'')))
        web_send("update('<strong>{0}</strong>')".format(url))
        web_send("url_is_set()")

        # clipboard needs a bit of time before copying url
        gobject.timeout_add(500, set_clipboard)

    def startup_sync():
        web_send("init('{0}', {1});".format(basename, json.dumps(strings)))
        web_send("update('{0}')".format(strings['calculating_sha1']))

        # run other startup in the background
        thread_crunch = thread.start_new_thread(startup_async, ())

        # start the web server
        thread_web = thread.start_new_thread(onionshare.app.run, (),
                                             {"port": port})

    gobject.timeout_add(500, startup_sync)

    # main loop
    last_second = time.time()
    uptime_seconds = 1
    clicks = 0
    while not Global.quit:

        current_time = time.time()
        again = False
        msg = web_recv()
        if msg:
            again = True

        # check msg for messages from the browser
        if msg == 'copy_url':
            set_clipboard()

        if not again:
            time.sleep(0.1)

    # shutdown
    onionshare.tails_close_port(port)