示例#1
0
    def config_read(self):
        global myself

        uid = None

        linkpath = '%s/myself' % proximatedir
        try:
            linkvalue = os.readlink(linkpath)
        except OSError:
            linkvalue = None

        if self.options.identity != None:
            # Look for an uid
            ident = self.options.identity
            myself = get_user(ident)
            if myself == None:
                myself = create_user(ident)
        else:
            if linkvalue != None:
                # first see if the old 'myself' symlink is good
                uid = parse_user_dentry(linkvalue)
            if uid != None:
                myself = get_user(uid)

        if myself == None:
            create_myself()

        userdir = 'u_%s' % myself.get('uid')
        if userdir != linkvalue:
            xremove(linkpath)
            try:
                os.symlink(userdir, linkpath)
            except OSError, (errno, strerror):
                die('Can not create a symlink: %s -> %s (%s)\n' % (userdir, linkpath, strerror))
示例#2
0
def set_traffic_mode(mode):
    """ Set mode == TRAFFIC_NORMAL for normal traffic.
        Set mode == TRAFFIC_MINIMAL for minimal traffic. """
    global trafficmode
    if mode < 0 or mode > TRAFFIC_UPPER_BOUND:
        die('Invalid traffic mode %d\n' % mode)
    trafficmode = mode
示例#3
0
    def __init__(self, options):
        global images_path, proximatedir, broadcastports

        self.options = options

        self.register_plugin(PLUGIN_TYPE_STATE)

        self.pluginstorage = {}

        home = os.getenv('HOME')
        if home == None:
            die('HOME not defined\n')

        images_path = '%s/MyDocs/.images' %(home)

        if options.proximatedir != None:
            proximatedir = options.proximatedir
        else:
            proximatedir = '%s/.proximate' %(home)
        if not xmkdir(proximatedir):
            die('Can not create a proximate directory: %s\n' %(proximatedir))

        set_log_file('%s/log' %(proximatedir))

        read_communities()
        self.config_read()

        if options.broadcastports != None:
            broadcastports = options.broadcastports

        if options.traffic_mode != None:
            set_traffic_mode(options.traffic_mode)

        info('I am %s aka %s\n' %(myself.get('nick'), myself.get('uid')))
示例#4
0
def load_external_plugins(options=None, ui=None):
    # Load external plugins, if any
    pdir = get_external_plugin_dir()
    try:
        fnames = os.listdir(pdir)
    except OSError:
        return
    if len(fnames) > 0:
        sys.path.insert(0, pdir)
    imported = {}
    for fname in fnames:
        if not (fname.endswith('.py') or fname.endswith('.pyc')):
            continue
        modulename = fname.rpartition('.')[0]    # Strip file extension
        if modulename in imported:
            continue
        module = __import__(modulename)
        fullpath = os.path.join(pdir, fname)
        try:
            if ui != None:
                module.init_ui(ui)
            else:
                module.init(options)
            imported[modulename] = None
        except TypeError:
            die('external plugin %s failed\n' % fullpath)
        except AttributeError:
            pass
示例#5
0
def run_gui():
    """ Start Graphical User Interface """

    main_gui = Proximate_GUI()

    for modulename in [
        "community_gui",
        "messaging_gui",
        "notification_gui",
        "filesharing_gui",
        "messageboard_gui",
        "filetransfergui",
        "radar",
        "keymanagement_gui",
        "settings_gui",
    ]:
        module = __import__(modulename)
        try:
            module.init_ui(main_gui)
        except TypeError:
            die("GUI module %s init() called with invalid arguments\n" % (modulename))

    proximatestate.load_external_plugins(ui=main_gui)

    main_gui.run()
示例#6
0
    def register_handler(self, rtype, handler, handlername):
        """ Register a slave handler that replies to the master.
            Handler will be called with the ip address and the payload
            of the message from master when a message with the
            corresponding rtype is received.
            Handlername is used for debugging purposes. """

        if self.handlers.has_key(rtype):
            die('Fetch handler for rtype %s already registered\n' %(rtype))
        self.handlers[rtype] = handler
        self.handlername[rtype] = handlername
示例#7
0
    def append_input(self, data):
        """ This function can be used to insert arbitrary data to the
        input queue. It is useful when the socket has already been read before
        creating TCP_Queue object. The data that was read can be partially
        or fully passed for TCP_Queue to be processed. This can be used
        to skip protocol headers before processing the connection as
        TCP_Queue messages. """

        if self.status == TCPQ_OK:
            die('TCP_Queue: you may not insert data with append_input() after it has been initialized!\n')

        self.inb += data
示例#8
0
def run_ui():
    """ Start Curses User Interface """

    main_ui = Curses_UI()

    for modulename in ["community_curses", "messaging_curses"]:
        module = __import__(modulename)
        try:
            module.init_ui(main_ui)
        except TypeError:
            die("Curses module %s init() called with invalid arguments\n" % (modulename))

    main_ui.run()
示例#9
0
def main(options, args):
    if options.debug:
        support.set_debug_mode(options.verbose)

    # Initialize seed for crypto and other plugins
    random.seed()

    # Init order for plugins: proximatestate, wlancontrol, community, ... (others)
    # State plugin must be the second plugin that is initialized
    proximatestate.init(options)

    # 'wlancontrol' and 'community' must be initialized first in this order
    for modulename in ['wlancontrol', 'community', 'udpfetcher',
                       'sendfile', 'tcpfetcher', 'fetcher',
                       'filesharing', 'settings',
                       'keymanagement', 'notify',
                       'messaging', 'scheduler', 'messageboard',
                       'userpresence', 'vibra']:
        module = __import__(modulename)
        try:
            module.init(options)
        except TypeError:
            raise
            die('module %s init() called with invalid arguments\n' %(modulename))

    proximatestate.load_external_plugins(options=options)

    plugins_ready()

    listener.init()

    rval = 1
    try:
        if options.usegui:
            from guihandler import run_gui
            run_gui()
        else:
            from cursesui import run_ui
            run_ui()
        rval = 0
    except Exception, err:
        import traceback
        print_exc()
        warning("proximate exception: %s\n" % err)
示例#10
0
def get_options():
    parser = OptionParser()
    parser.add_option(
        "-b",
        "--broadcast-port",
        action="append",
        type="int",
        dest="broadcastports",
        metavar="port",
        help="Set UDP discovery ports. This option can be used multiple times to set multiple ports. You should always broadcast to the default port (%d) at least."
        % (DEFAULT_PROXIMATE_PORT),
    )
    parser.add_option(
        "--chat-no-context",
        default=True,
        action="store_false",
        dest="chatcontext",
        help="Disable conversation context recovery and sending in chat. This option makes messaging unreliable.",
    )
    parser.add_option("-d", "--debug", default=False, action="store_true", dest="debug", help="Debug mode")
    parser.add_option(
        "--enable-key-exchange",
        default=False,
        action="store_true",
        dest="key_exchange",
        help="Enable key exchange. This is an experimental feature still in development. Default: disabled",
    )
    parser.add_option(
        "--enable-personal",
        default=False,
        action="store_true",
        dest="personal_communities",
        help="Enable personal communities. This is an experimental feature still in development. Default: disabled",
    )
    parser.add_option(
        "--enable-presence",
        default=False,
        action="store_true",
        dest="presence",
        help="Enable presence notification. This is an experimental feature still in development. Default: disabled",
    )
    parser.add_option(
        "-i", "--identity", default=None, dest="identity", metavar="uid", help="Assume identity x, where x is an uid"
    )
    parser.add_option(
        "-I", "--interface", default=None, dest="interface", help="Set the network interface used by Proximate"
    )
    parser.add_option("-n", "--no-gui", default=True, action="store_false", dest="usegui", help="No GUI")
    parser.add_option(
        "-p",
        "--port",
        type="int",
        dest="activeport",
        metavar="x",
        help="Set UDP and TCP port to x. Default UDP port is %d. TCP port is randomized by default."
        % (DEFAULT_PROXIMATE_PORT),
    )
    parser.add_option(
        "-t",
        "--proximate-dir",
        default=None,
        dest="proximatedir",
        metavar="dir",
        help="Set Proximate directory. Default: $HOME/.proximate",
    )
    parser.add_option("--test", default=None, dest="test", metavar="plugin", help="Run self-test for plugin")
    parser.add_option(
        "--traffic-mode",
        default=None,
        dest="traffic_mode",
        metavar="x",
        type="int",
        help="Set traffic mode: 0 for normal traffic. 1 for minimal traffic. Normal traffic is the default.",
    )
    parser.add_option(
        "--udp-fetcher", default=False, action="store_true", dest="udp_fetcher", help="Use UDP for communication"
    )
    parser.add_option(
        "-u",
        "--udp-mode",
        default=3,
        type="int",
        dest="udpmode",
        metavar="mask",
        help="Set UDP mode to mask. 0 means no UDP traffic. 1 means listen but do not send broadcasts. 2 means send but do not listen to broadcasts. 3 (default) means both listen and send.",
    )
    parser.add_option(
        "-v", "--verbose", default=False, action="store_true", dest="verbose", help="Verbose debug output"
    )
    parser.add_option("--version", default=False, action="store_true", help="Print version number")
    (options, args) = parser.parse_args()

    if options.version:
        sys.stdout.write("Proximate %s\n" % get_version())
        sys.exit(0)

    display = os.getenv("DISPLAY")
    if display == None or len(display) == 0:
        options.usegui = False

    portlist = []
    if options.activeport != None:
        portlist.append(options.activeport)
    if options.broadcastports != None:
        portlist += options.broadcastports
    for port in portlist:
        if not valid_port(port):
            die("Invalid port given: %d\n" % (port))

    return (options, args)