Exemplo n.º 1
0
def main_entry():
    """Main function."""
    global ui, dlogger
    # We are not python.
    misc.RenameProcess('wicd-curses')

    ui = urwid.raw_display.Screen()

    # if options.debug:
    #     dlogger = logging.getLogger("Debug")
    #     dlogger.setLevel(logging.DEBUG)
    #     dlogger.debug("wicd-curses debug logging started")

    # Default Color scheme.
    # Other potential color schemes can be found at:
    # http://excess.org/urwid/wiki/RecommendedPalette

    # Thanks to nanotube on #wicd for helping with this
    ui.register_palette([
        ('body', 'default', 'default'),
        ('focus', 'black', 'light gray'),
        ('header', 'light blue', 'default'),
        ('important', 'light red', 'default'),
        ('connected', 'dark green', 'default'),
        ('connected focus', 'black', 'dark green'),
        ('editcp', 'default', 'default', 'standout'),
        ('editbx', 'light gray', 'dark blue'),
        ('editfc', 'white', 'dark blue', 'bold'),
        ('editnfc', 'brown', 'default', 'bold'),
        ('tab active', 'dark green', 'light gray'),
        ('infobar', 'light gray', 'dark blue'),
        ('listbar', 'light blue', 'default'),
        # Simple colors around text
        ('green', 'dark green', 'default'),
        ('blue', 'light blue', 'default'),
        ('red', 'dark red', 'default'),
        ('bold', 'white', 'black', 'bold')
    ])
    # Handle SIGQUIT correctly (otherwise urwid leaves the terminal in a bad
    # state)
    signal.signal(signal.SIGQUIT, handle_sigquit)
    # This is a wrapper around a function that calls another a function that
    # is a wrapper around a infinite loop.  Fun.
    urwid.set_encoding('utf8')
    ui.run_wrapper(run)
Exemplo n.º 2
0
from wicd.translations import _

ICON_AVAIL = True
USE_EGG = False
# Import egg.trayicon if we're using an older gtk version
if not hasattr(gtk, "StatusIcon"):
    try:
        import egg.trayicon
        USE_EGG = True
    except ImportError:
        print(('Unable to load tray icon: Missing both egg.trayicon and ' + \
            'gtk.StatusIcon modules.'))
        ICON_AVAIL = False

misc.RenameProcess("wicd-client")

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

daemon = wireless = wired = lost_dbus_id = None
DBUS_AVAIL = False

theme = gtk.icon_theme_get_default()
theme.append_search_path(wpath.images)


def catchdbus(func):
    """ Decorator to catch DBus exceptions. """
    def wrapper(*args, **kwargs):
        try:
Exemplo n.º 3
0
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   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:
Exemplo n.º 4
0
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import optparse
import dbus
import dbus.service
import sys
from wicd import misc
from wicd.translations import _

misc.RenameProcess('wicd-cli')

exit_status = 0

if getattr(dbus, 'version', (0, 0, 0)) < (0, 80, 0):
    import dbus.glib
else:
    from dbus.mainloop.glib import DBusGMainLoop
    DBusGMainLoop(set_as_default=True)

bus = dbus.SystemBus()
try:
    daemon = dbus.Interface(
        bus.get_object('org.wicd.daemon', '/org/wicd/daemon'),
        'org.wicd.daemon')
    wireless = dbus.Interface(
Exemplo n.º 5
0
def main():
    misc.RenameProcess('wicd-cli')

    exit_status = 0

    bus = dbus.SystemBus()
    try:
        daemon = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon'),
            'org.wicd.daemon')
        wireless = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wireless'),
            'org.wicd.daemon.wireless')
        wired = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wired'),
            'org.wicd.daemon.wired')
        config = dbus.Interface(
            bus.get_object('org.wicd.daemon', '/org/wicd/daemon/config'),
            'org.wicd.daemon.config')
    except dbus.DBusException:
        print('Error: Could not connect to the daemon. '
              'Please make sure it is running.')
        sys.exit(3)

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

    options = parse_args()
    op_performed = False

    if not (options.wireless or options.wired) and not options.status:
        print("Please use --wireless or --wired to specify "
              "the type of connection to operate on.")

    if options.status:
        status, info = daemon.GetConnectionStatus()
        if status in (misc.WIRED, misc.WIRELESS):
            connected = True
            status_msg = _('Connected')
            if status == misc.WIRED:
                conn_type = _('Wired')
            else:
                conn_type = _('Wireless')
        else:
            connected = False
            status_msg = misc._const_status_dict[status]

        print(_('Connection status') + ': ' + status_msg)
        if connected:
            print(_('Connection type') + ': ' + conn_type)
            if status == misc.WIRELESS:
                strength = daemon.FormatSignalForPrinting(info[2])
                print(
                    _('Connected to $A at $B (IP: $C)').replace(
                        '$A',
                        info[1]).replace('$B',
                                         strength).replace('$C', info[0]))
                print(_('Network ID: $A').replace('$A', info[3]))
            else:
                print(
                    _('Connected to wired network (IP: $A)').replace(
                        '$A', info[0]))
        else:
            if status == misc.CONNECTING:
                if info[0] == 'wired':
                    print(_('Connecting to wired network.'))
                elif info[0] == 'wireless':
                    print(
                        _('Connecting to wireless network "$A".').replace(
                            '$A', info[1]))
        op_performed = True

    if options.scan and options.wireless:
        # synchronized scan
        wireless.Scan(True)
        op_performed = True

    if options.load_profile and options.wired:
        is_valid_wired_network_profile(wired, options.name)
        wired.ReadWiredNetworkProfile(options.name)
        op_performed = True

    if options.list_networks:
        if options.wireless:
            print('#\tBSSID\t\t\tChannel\tESSID')
            for network_id in range(0, wireless.GetNumberOfNetworks()):
                print('%s\t%s\t%s\t%s' %
                      (network_id,
                       wireless.GetWirelessProperty(network_id, 'bssid'),
                       wireless.GetWirelessProperty(network_id, 'channel'),
                       wireless.GetWirelessProperty(network_id, 'essid')))
        elif options.wired:
            print('#\tProfile name')
            i = 0
            for profile in wired.GetWiredProfileList():
                print('%s\t%s' % (i, profile))
                i += 1
        op_performed = True

    if options.network_details:
        if options.wireless:
            if options.network >= 0:
                is_valid_wireless_network_id(wireless, options.network)
                network_id = options.network
            else:
                network_id = wireless.GetCurrentNetworkID(0)
                is_valid_wireless_network_id(wireless, network_id)
                # we're connected to a network, print IP
                print("IP: %s" % wireless.GetWirelessIP(0))

            print("Essid: %s" %
                  wireless.GetWirelessProperty(network_id, "essid"))
            print("Bssid: %s" %
                  wireless.GetWirelessProperty(network_id, "bssid"))
            if wireless.GetWirelessProperty(network_id, "encryption"):
                print("Encryption: On")
                print("Encryption Method: %s" % wireless.GetWirelessProperty(
                    network_id, "encryption_method"))
            else:
                print("Encryption: Off")
            print("Quality: %s" %
                  wireless.GetWirelessProperty(network_id, "quality"))
            print("Mode: %s" %
                  wireless.GetWirelessProperty(network_id, "mode"))
            print("Channel: %s" %
                  wireless.GetWirelessProperty(network_id, "channel"))
            print("Bit Rates: %s" %
                  wireless.GetWirelessProperty(network_id, "bitrates"))
        op_performed = True

    # network properties

    if options.network_property:
        options.network_property = options.network_property.lower()
        if options.wireless:
            if options.network >= 0:
                is_valid_wireless_network_id(wireless, options.network)
                network_id = options.network
            else:
                network_id = wireless.GetCurrentNetworkID(0)
                is_valid_wireless_network_id(wireless, network_id)
            if not options.set_to:
                print(
                    wireless.GetWirelessProperty(network_id,
                                                 options.network_property))
            else:
                wireless.SetWirelessProperty(network_id,
                                             options.network_property,
                                             options.set_to)
        elif options.wired:
            if not options.set_to:
                print(wired.GetWiredProperty(options.network_property))
            else:
                wired.SetWiredProperty(options.network_property,
                                       options.set_to)
        op_performed = True

    if options.disconnect:
        daemon.Disconnect()
        if options.wireless:
            if wireless.GetCurrentNetworkID(0) > -1:
                print("Disconnecting from %s on %s" %
                      (wireless.GetCurrentNetwork(0),
                       wireless.DetectWirelessInterface()))
        elif options.wired:
            if wired.CheckPluggedIn():
                print("Disconnecting from wired connection on %s" %
                      wired.DetectWiredInterface())
        op_performed = True

    if options.connect:
        check = None
        if options.wireless and options.network > -1:
            is_valid_wireless_network_id(wireless, options.network)
            name = wireless.GetWirelessProperty(options.network, 'essid')
            encryption = wireless.GetWirelessProperty(options.network,
                                                      'enctype')
            print("Connecting to %s with %s on %s" %
                  (name, encryption, wireless.DetectWirelessInterface()))
            wireless.ConnectWireless(options.network)

            check = wireless.CheckIfWirelessConnecting
            status = wireless.CheckWirelessConnectingStatus
            message = wireless.CheckWirelessConnectingMessage
        elif options.wired:
            print("Connecting to wired connection on %s" %
                  wired.DetectWiredInterface())
            wired.ConnectWired()

            check = wired.CheckIfWiredConnecting
            status = wired.CheckWiredConnectingStatus
            message = wired.CheckWiredConnectingMessage
        else:
            check = lambda: False
            status = lambda: False
            message = lambda: False

        # update user on what the daemon is doing
        last = None
        if check:
            while check():
                next_ = status()
                if next_ != last:
                    # avoid a race condition where status is updated
                    # to "done" after the loop check
                    if next_ == "done":
                        break
                    print(message())
                    last = next_
            print("done!")
            if status() != 'done':
                exit_status = 6
            op_performed = True

    if options.wireless and options.list_encryption_types:
        encryption_types = misc.LoadEncryptionMethods()
        # print 'Installed encryption templates:'
        print('%s\t%-20s\t%s' % ('#', 'Name', 'Description'))
        i = 0
        for encryption_type in encryption_types:
            print('%s\t%-20s\t%s' %
                  (i, encryption_type['type'], encryption_type['name']))
            print('  Req: %s' %
                  str_properties(encryption_type, encryption_type['required']))
            print('---')
            # don't print optionals (yet)
            # print '  Opt: %s' % str_properties(encryption_type,
            #                                    encryption_type['optional'])
            i += 1
        op_performed = True

    if options.save and options.network > -1:
        if options.wireless:
            is_valid_wireless_network_id(wireless, options.network)
            config.SaveWirelessNetworkProfile(options.network)
        elif options.wired:
            config.SaveWiredNetworkProfile(options.name)
        op_performed = True

    if not op_performed:
        print("No operations performed.")

    sys.exit(exit_status)