Esempio n. 1
0
File: gui.py Progetto: zeph/wicd
def setup_dbus(force=True):
    """ Initialize DBus. """
    global bus, daemon, wireless, wired, DBUS_AVAIL
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        if force:
            print("Can't connect to the daemon, ' + \
                'trying to start it automatically...")
            if not misc.PromptToStartDaemon():
                print("Failed to find a graphical sudo program, ' + \
                    'cannot continue.")
                return False
            try:
                dbusmanager.connect_to_dbus()
            except DBusException:
                error(
                    None,
                    _("Could not connect to wicd's D-Bus interface. "
                      "Check the wicd log for error messages."))
                return False
        else:
            return False
    prefs.setup_dbus()
    netentry.setup_dbus()
    bus = dbusmanager.get_bus()
    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    daemon = dbus_ifaces['daemon']
    wireless = dbus_ifaces['wireless']
    wired = dbus_ifaces['wired']
    DBUS_AVAIL = True

    return True
Esempio n. 2
0
def setup_dbus(force=True):
    """ Initialize DBus. """
    global bus, daemon, wireless, wired
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        print >> sys.stderr, \
          _("Can't connect to the daemon, trying to start it automatically...")

    try:
           bus = dbusmanager.get_bus()
           dbus_ifaces = dbusmanager.get_dbus_ifaces()
           daemon = dbus_ifaces['daemon']
           wireless = dbus_ifaces['wireless']
           wired = dbus_ifaces['wired']
    except DBusException:
        print >> sys.stderr, \
          _("Can't automatically start the daemon, this error is fatal...")

    if not daemon:
        print 'Error connecting to wicd via D-Bus. ' \
            'Please make sure the wicd service is running.'
        sys.exit(3)

    netentry_curses.dbus_init(dbus_ifaces)
    return True
Esempio n. 3
0
def setup_dbus(force=True):
    global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id
    print "Connecting to daemon..."
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        if force:
            print "Can't connect to the daemon, trying to start it automatically..."
            misc.PromptToStartDaemon()
            try:
                dbusmanager.connect_to_dbus()
            except DBusException:
                error(
                    None, "Could not connect to wicd's D-Bus interface.  " +
                    "Check the wicd log for error messages.")
                return False
        else:
            return False

    if lost_dbus_id:
        gobject.source_remove(lost_dbus_id)
        lost_dbus_id = None
    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    daemon = dbus_ifaces['daemon']
    wireless = dbus_ifaces['wireless']
    wired = dbus_ifaces['wired']
    DBUS_AVAIL = True
    print "Connected."
    return True
Esempio n. 4
0
def setup_dbus(force=True):
    """ Initialize DBus. """
    global bus, daemon, wireless, wired
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        print(_(
            "Can't connect to the daemon, trying to start it automatically..."
        ),
              file=sys.stderr)

    try:
        bus = dbusmanager.get_bus()
        dbus_ifaces = dbusmanager.get_dbus_ifaces()
        daemon = dbus_ifaces['daemon']
        wireless = dbus_ifaces['wireless']
        wired = dbus_ifaces['wired']
    except DBusException:
        print(
            _("Can't automatically start the daemon, this error is fatal..."),
            file=sys.stderr)

    if not daemon:
        print('Error connecting to wicd via D-Bus. ' \
            'Please make sure the wicd service is running.')
        sys.exit(3)

    netentry_curses.dbus_init(dbus_ifaces)
    return True
Esempio n. 5
0
def setup_dbus(force=True):
    global bus, daemon, wireless, wired, DBUS_AVAIL
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        if force:
            print "Can't connect to the daemon, trying to start it automatically..."
            if not misc.PromptToStartDaemon():
                print "Failed to find a graphical sudo program, cannot continue."
                return False
            try:
                dbusmanager.connect_to_dbus()
            except DBusException:
                error(None, "Could not connect to wicd's D-Bus interface.  " +
                      "Check the wicd log for error messages.")
                return False
        else:  
            return False
    prefs.setup_dbus()
    netentry.setup_dbus()
    bus = dbusmanager.get_bus()
    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    daemon = dbus_ifaces['daemon']
    wireless = dbus_ifaces['wireless']
    wired = dbus_ifaces['wired']
    DBUS_AVAIL = True
    
    return True
Esempio n. 6
0
def setup_dbus(force=True):
    """ Initialize DBus. """
    global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id
    print "Connecting to daemon..."
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        if force:
            print "Can't connect to the daemon, trying to start it " + \
                "automatically..."
            misc.PromptToStartDaemon()
            try:
                dbusmanager.connect_to_dbus()
            except DBusException:
                error(None,
                    _("Could not connect to wicd's D-Bus interface. Check "
                    "the wicd log for error messages.")
                )
                return False
        else:
            return False

    if lost_dbus_id:
        gobject.source_remove(lost_dbus_id)
        lost_dbus_id = None
    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    daemon = dbus_ifaces['daemon']
    wireless = dbus_ifaces['wireless']
    wired = dbus_ifaces['wired']
    DBUS_AVAIL = True
    print "Connected."
    return True
Esempio n. 7
0
    def setup_dbus(self):
        dbusmanager.connect_to_dbus()
        self.bus = dbusmanager.get_bus()

        dbus_ifaces = dbusmanager.get_dbus_ifaces()
        self.daemon = dbus_ifaces['daemon']
        self.wireless = dbus_ifaces['wireless']
        self.wired = dbus_ifaces['wired']
Esempio n. 8
0
 def __init__(self):
     try:
         dbusmanager.connect_to_dbus()
         dbusInterfaces = dbusmanager.get_dbus_ifaces()
         self.wireless = dbusInterfaces["wireless"]
         self.daemon = dbusInterfaces["daemon"]
     except:
         raise Error("Daemon is not running")
     self.versionString = self.daemon.Hello()
Esempio n. 9
0
	def __init__(self):
		try: 
			dbusmanager.connect_to_dbus()
			dbusInterfaces	= dbusmanager.get_dbus_ifaces()
			self.wireless		= dbusInterfaces["wireless"]
			self.daemon		= dbusInterfaces["daemon"]
		except: 
			raise Error("Daemon is not running")
		self.versionString = self.daemon.Hello()
Esempio n. 10
0
def setup_dbus(force=True):
    global bus, daemon, wireless, wired
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        print >> sys.stderr, language['cannot_connect_to_daemon']
    bus = dbusmanager.get_bus()
    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    daemon = dbus_ifaces['daemon']
    wireless = dbus_ifaces['wireless']
    wired = dbus_ifaces['wired']

    netentry_curses.dbus_init(dbus_ifaces)
    return True
Esempio n. 11
0
def setup_dbus(force=True):
    global bus, daemon, wireless, wired
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        print >> sys.stderr, language['cannot_connect_to_daemon']
    bus = dbusmanager.get_bus()
    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    daemon = dbus_ifaces['daemon']
    wireless = dbus_ifaces['wireless']
    wired = dbus_ifaces['wired']

    netentry_curses.dbus_init(dbus_ifaces)
    return True
Esempio n. 12
0
def setup_dbus(force=True):
    global bus, daemon, wireless, wired
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        wicd = False
    bus = dbusmanager.get_bus()
    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    daemon = dbus_ifaces['daemon']
    wireless = dbus_ifaces['wireless']
    wired = dbus_ifaces['wired']

    if not daemon:
        return Fals

    return True
Esempio n. 13
0
def run():
    try:
        dbusmanager.connect_to_dbus()
    except DBusException:
        print >> sys.stderr, 'snooty: wicd: Cannot connect to the daemon.'
        raise

    bus = dbusmanager.get_bus()

    dbus_ifaces = dbusmanager.get_dbus_ifaces()
    this.daemon = dbus_ifaces['daemon']
    this.wired = dbus_ifaces['wired']
    this.wireless = dbus_ifaces['wireless']

    this.prev_state = -1

    bus.add_signal_receiver(status_changed_cb,
                            dbus_interface='org.wicd.daemon',
                            signal_name='StatusChanged')
Esempio n. 14
0
def setup_dbus(force=True):
    global bus, daemon, wireless, wired
    try:
        dbusmanager.connect_to_dbus()
    except dbus.DBusException:
        print >> sys.stderr,\
            _("Can't connect to wicd daemon,trying to start it automatically...")
    else:
        bus = dbusmanager.get_bus()
        dbus_ifaces = dbusmanager.get_dbus_ifaces()
        daemon = dbus_ifaces[
            "daemon"]  ## @dbus.service.method('org.wicd.daemon')
        wireless = dbus_ifaces[
            "wireless"]  ## @dbus.service.method('org.wicd.daemon.wireless')
        wired = dbus_ifaces["wired"]  ## @

        if not daemon:
            print("Error connecting to wicd via D-Bus")

    return True
def setup_dbus(force=True):
    global bus, daemon, wireless, wired
    global manager, objects, adapter, devices

    try:
        dbusmanager.connect_to_dbus()
    except dbus.DBusException:
        print >> sys.stderr,\
            _("Can't connect to wicd daemon,trying to start it automatically...")
    else:
        bus = dbusmanager.get_bus()
        dbus_ifaces = dbusmanager.get_dbus_ifaces()
        daemon = dbus_ifaces[
            "daemon"]  ## @dbus.service.method('org.wicd.daemon')
        wireless = dbus_ifaces[
            "wireless"]  ## @dbus.service.method('org.wicd.daemon.wireless')
        wired = dbus_ifaces["wired"]  ## @

        ### BlueZ
        try:
            proxy_obj = bus.get_object("org.bluez", "/")
            manager = dbus.Interface(proxy_obj,
                                     "org.freedesktop.DBus.ObjectManager")
            objects = manager.GetManagedObjects()

            for path, interfaces in objects.iteritems():
                if "org.bluez.Device1" in interfaces:
                    devices[path] = interfaces[
                        "org.bluez.Device1"]  ## like /org/bluez/hci0/dev_xx_xx_xx_yy_yy_yy

            proxy_obj = bus.get_object("org.bluez", "/org/bluez/hci0")
            adapter = dbus.Interface(proxy_obj, "org.bluez.Adapter1")
        except Exception as e:
            print(str(e))

        if not daemon:
            print("Error connecting to wicd via D-Bus")

    return True
Esempio n. 16
0
 def setupDBus(self, force=True):
 """ Performs setup of DBus-related things """
     print "Connecting to daemon..."
     try:
         dbusmanager.connect_to_dbus()
     except DBusException:
         if force:
             print "Can't connect to the daemon, trying to start it automatically..."
             misc.PromptToStartDaemon()
             try:
                 dbusmanager.connect_to_dbus()
             except DBusException:
                 error(None, "Could not connect to wicd's D-Bus interface.  " +
                           "Check the wicd log for error messages.")
                 return False
         else:  
             return False
                 
     dbus_ifaces = dbusmanager.get_dbus_ifaces()
     self.daemon = dbus_ifaces['daemon']
     self.wireless = dbus_ifaces['wireless']
     self.wired = dbus_ifaces['wired']
     self.DBUS_AVAIL = True
     print "Connected."
Esempio n. 17
0
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import time

from gi.repository import GLib as gobject
from dbus import DBusException

from wicd import misc
from wicd import dbusmanager

misc.RenameProcess("wicd-monitor")
dbusmanager.connect_to_dbus()
dbus_dict = dbusmanager.get_dbus_ifaces()
daemon = dbus_dict["daemon"]
wired = dbus_dict["wired"]
wireless = dbus_dict["wireless"]

mainloop = None


def diewithdbus(func):
    """
    Decorator catching DBus exceptions, making wicd quit.
    """
    def wrapper(self, *__args, **__kargs):
        try:
            ret = func(self, *__args, **__kargs)
            self.__lost_dbus_count = 0
Esempio n. 18
0
import gobject
import time

from dbus import DBusException

from wicd import wpath
from wicd import misc
from wicd import dbusmanager

misc.RenameProcess("wicd-monitor")

if __name__ == '__main__':
    wpath.chdir(__file__)

dbusmanager.connect_to_dbus()
dbus_dict = dbusmanager.get_dbus_ifaces()
daemon = dbus_dict["daemon"]
wired = dbus_dict["wired"]
wireless = dbus_dict["wireless"]

mainloop = None

def diewithdbus(func):
    def wrapper(self, *__args, **__kargs):
        try:
            ret = func(self, *__args, **__kargs)
            self.__lost_dbus_count = 0
            return ret
        except DBusException, e:
            print  "Caught exception %s" % str(e)
            if not hasattr(self, "__lost_dbus_count"):
Esempio n. 19
0
    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2]))
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile(),
                            self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(self.frame, (0, 1), ui,
                                            dbusmanager.get_dbus_ifaces())
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols,
                                                  self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(data[0], data[2], data[1],
                                                "WEP", data[5], data[4], False)
            if 'X' in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _('Are you sure you want to discard settings for '
                             'the selected networks?')
                    text += '\n\n' + '\n'.join(data['essid'])
                    confirm, trash = TextDialog(
                        text,
                        20,
                        50,
                        buttons=[(_('OK'), 1), (_('Cancel'), -1)],
                    ).run(ui, self.frame)
                    if confirm == 1:
                        for x in data['bssid']:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(self.size,
                                       event,
                                       button,
                                       col,
                                       row,
                                       focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                # F10 has been changed to S to avoid using function keys,
                # which are often caught by the terminal emulator.
                # But F10 still works, because it doesn't hurt and some users might be used to it.
                if k == 'f10' or k == 'S' or k == 's':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue
Esempio n. 20
0
import getopt
import time
import os
import wicd
from wicd import dbusmanager
from dbus import DBusException

# connection to DBUS interface
try:
    dbusmanager.connect_to_dbus()
except DBusException:
        print "Cannot connect to WICD daemon, please be sure daemon is started before using wconfig. You can start daemon with /etc/init.d/wicd start, or /etc/rc.d/wicd start, or wicd from root account."
        sys.exit()

bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon']
wireless = dbus_ifaces['wireless']
[state, info] = daemon.GetConnectionStatus()

# CONFIG
output_as = "Text" # default, also XML avaible
autoconnect = False # try to connect if found a unsecured network
extra_debugging = False
network_timeout = 30

def main():
	try:
		opts, args = getopt.getopt(sys.argv[1:], "i:m:e:hdaxsg", ["help", "auto-connect", "xml", "scan", "debug", "--connect-by-id", "--connect-by-mac", "--connect-by-name"]) # output=

	except getopt.GetoptError, err:
Esempio n. 21
0
    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2])
                    )
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile(),
                            self.frame
                        )
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(
                        self.frame,
                        (0, 1),
                        ui,
                        dbusmanager.get_dbus_ifaces()
                    )
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols, self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(
                        data[0],
                        data[2],
                        data[1],
                        "WEP",
                        data[5],
                        data[4],
                        False
                    )
            if 'X' in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _('Are you sure you want to discard settings for '
                        'the selected networks?')
                    text += '\n\n' + '\n'.join(data['essid'])
                    confirm, trash = TextDialog(text, 20, 50,
                        buttons=[(_('OK'), 1), (_('Cancel'), -1)],
                        ).run(ui, self.frame)
                    if confirm == 1:
                        for x in data['bssid']:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(
                    self.size, event, button, col, row, focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if  k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                if k == 'f10':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue
Esempio n. 22
0
except:
    exit(1)

# Get status and active interface
try:
    # Initially return_dict['cstat_intf_active']['name'] None because this field is
    # appended with interface type and to avoid appending interface type when no interface is found
    return_dict['cstat_intf_active']['name'] = None 
    return_dict['cstat_intf_active']['type'] = '-'
    return_dict['cstat_intf_active']['ip'] = '-'
    return_dict['cstat_intf_active']['mask'] = '-'

    bus = dbus.SystemBus()
    daemon = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon'), 'org.wicd.daemon')
    wicd_dbusmanager.connect_to_dbus()
    status = wicd_dbusmanager.get_dbus_ifaces()['daemon'].GetConnectionStatus()

    if status[0] == wicd_misc.NOT_CONNECTED:
        return_dict['cstat_status'] = 'Not connected'
        
    elif status[0] == wicd_misc.CONNECTING:
        return_dict['cstat_status'] = 'Connecting ({0})...'.format(status[1][0][0].upper() + status[1][0][1:])

    elif status[0] == wicd_misc.WIRELESS:
        try:
            iwconfig = wicd_dbusmanager.get_dbus_ifaces()['wireless'].GetIwconfig()
            ap = unicode(wicd_dbusmanager.get_dbus_ifaces()['wireless'].GetCurrentNetwork(iwconfig))
        except:
            return_dict['cstat_status'] = '-'
        else:
            if ap != 'None':
Esempio n. 23
0
    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or "Q" in keys or "q" in keys:
                loop.quit()
                # return False
            if "f5" in keys or "R" in keys:
                self.lock_screen()
                self.doScan()
            if "k" in keys or "K" in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if "right" in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(urwid.Pile([self.confCols, self.footer2]))
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(self.wiredCB.get_body().get_selected_profile(), self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = "conf"
            if "enter" in keys or "C" in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(self.frame, (0, 1), ui, dbusmanager.get_dbus_ifaces())
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols, self.footer2]))
                self.diag = self.pref
                self.diag_type = "pref"
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or "h" in keys or "?" in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = "wired"
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = "wireless"
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                # data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(data[0], data[2], data[1], "WEP", data[5], data[4], False)
            if "X" in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _("Are you sure you want to discard settings for " "the selected networks?")
                    text += "\n\n" + "\n".join(data["essid"])
                    confirm, trash = TextDialog(text, 20, 50, buttons=[(_("OK"), 1), (_("Cancel"), -1)]).run(
                        ui, self.frame
                    )
                    if confirm == 1:
                        for x in data["bssid"]:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(self.size, event, button, col, row, focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if k == "esc" or k == "q" or k == "Q":
                    self.restore_primary()
                    break
                # F10 has been changed to S to avoid using function keys,
                # which are often caught by the terminal emulator.
                # But F10 still works, because it doesn't hurt and some users might be used to it.
                if k == "f10" or k == "S" or k == "s":
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue
Esempio n. 24
0
import getopt
import time
import os
import wicd
from wicd import dbusmanager
from dbus import DBusException

# connection to DBUS interface
try:
    dbusmanager.connect_to_dbus()
except DBusException:
    print "Cannot connect to WICD daemon, please be sure daemon is started before using wconfig. You can start daemon with /etc/init.d/wicd start, or /etc/rc.d/wicd start, or wicd from root account."
    sys.exit()

bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon']
wireless = dbus_ifaces['wireless']
[state, info] = daemon.GetConnectionStatus()

# CONFIG
output_as = "Text"  # default, also XML avaible
autoconnect = False  # try to connect if found a unsecured network
extra_debugging = False
network_timeout = 30


def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "i:m:e:hdaxsg", [
            "help", "auto-connect", "xml", "scan", "debug", "--connect-by-id",
Esempio n. 25
0
    def handle_keys(self, keys):
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2]))
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile())
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        wid, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(self.frame, (0, 1), ui,
                                            dbusmanager.get_dbus_ifaces())
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols,
                                                  self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(data[0], data[2], data[1],
                                                "WEP", data[5], data[4], False)

        for k in keys:
            if urwid.util.is_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(self.size,
                                       event,
                                       button,
                                       col,
                                       row,
                                       focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                if k == 'f10':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue