Exemple #1
0
 def handleState_dhcp(_type, _desc, _state):
     if _state in ["on", "started"]:
         ch = CallHandler("dhcp", "System.Service", "stop",
                          "tr.org.pardus.comar.system.service.set",
                          self.winId(), comlink.busSys, comlink.busSes)
         ch.registerError(self.comarError)
         ch.registerAuthError(self.comarError)
         ch.registerDBusError(self.busError)
         ch.call()
Exemple #2
0
 def callHandler(self, script, model, method, action):
     ch = CallHandler(script, model, method, action, 0, self.busSys, self.busSes)
     ch.registerError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.registerAuthError(self.busError)
     ch.registerCancel(self.cancelError)
     return ch
Exemple #3
0
 def handleState_dhcp(_type, _desc, _state):
     if _state in ["on", "started"]:
         ch = CallHandler("dhcp", "System.Service", "stop", "tr.org.pardus.comar.system.service.set", self.winId(), comlink.busSys, comlink.busSes)
         ch.registerError(self.comarError)
         ch.registerAuthError(self.comarError)
         ch.registerDBusError(self.busError)
         ch.call()
Exemple #4
0
 def callMethod(self, method, action, model="Net.Filter"):
     ch = CallHandler("iptables", model, method,
                      action,
                      self.winId(),
                      self.busSys, self.busSes)
     ch.registerError(self.comarError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.registerCancel(self.cancelError)
     return ch
Exemple #5
0
 def callMethod(self, method, action, model="Net.Filter"):
     ch = CallHandler("iptables", model, method, action, self.winId(),
                      comlink.busSys, comlink.busSes)
     ch.registerError(self.comarError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     return ch
Exemple #6
0
 def callMethod(self, method, action):
     ch = CallHandler("grub", "Boot.Loader", method,
                      action,
                      self.winId(),
                      self.busSys, self.busSes)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.registerCancel(self.cancelError)
     return ch
Exemple #7
0
        self.user = useredit.UserStack(self)
        self.useredit = useredit.UserStack(self, edit=True)
        self.group = groupedit.GroupStack(self)

    def setupBusses(self):
        try:
            self.busSys = dbus.SystemBus()
            self.busSes = dbus.SessionBus()
        except dbus.DBusException:
            KMessageBox.error(self, i18n("Unable to connect to DBus."), i18n("DBus Error"))
            return False
        return True

    def callMethod(self, method, action, async = True, handleCancel = True):
        ch = CallHandler("baselayout", "User.Manager", method,
                         action,
                         self.winId(), async, self.busSys, self.busSes)
        ch.registerError(self.comarError)
        ch.registerAuthError(self.comarError)
        ch.registerDBusError(self.busError)
        if handleCancel:
            ch.registerCancel(self.cancelError)
        return ch

    def cancelError(self):
        message = i18n("You are not authorized for this operation.")
        KMessageBox.sorry(self, message, i18n("Error"))

    def busError(self, exception):
        KMessageBox.error(self, str(exception), i18n("DBus Error"))
        self.setupBusses()
Exemple #8
0
 def startDHCP():
     ch = CallHandler("dhcp", "System.Service", "start",
                      "tr.org.pardus.comar.system.service.set",
                      self.winId(), comlink.busSys, comlink.busSes)
     ch.registerDone(startIptables)
     ch.registerError(self.dhcpError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.call()
Exemple #9
0
    def callMethod(self, method, action, handler, handleErrors, *args):
        ch = CallHandler("System.Manager", method, action, self.sysBus, self.sesBus)

        if handleErrors:
            ch.registerError(self.comarError)
            ch.registerAuthError(self.comarAuthError)
            ch.registerDBusError(self.busError)
            ch.registerCancel(self.cancelError)
        if handler:
            ch.registerDone(handler)

        ch.call(*args)
Exemple #10
0
 def setDHCP():
     ch = CallHandler("dhcp", "Net.Share", "checkShare", "tr.org.pardus.comar.net.share.set", self.winId(), comlink.busSys, comlink.busSes)
     ch.registerDone(updown)
     ch.registerError(self.dhcpError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.call(shr.net_addr, shr.net_mode, shr.net_mask, shr.dns_server)
Exemple #11
0
    def slotCheckBox(self):
        def handleState_dhcp(_type, _desc, _state):
            if _state in ["on", "started"]:
                ch = CallHandler("dhcp", "System.Service", "stop", "tr.org.pardus.comar.system.service.set", self.winId(), comlink.busSys, comlink.busSes)
                ch.registerError(self.comarError)
                ch.registerAuthError(self.comarError)
                ch.registerDBusError(self.busError)
                ch.call()
        def stopIptables():
            ch = self.callMethod("stop", "tr.org.pardus.comar.system.service.set", "System.Service")
            ch.call()

        def removeNatRules():
            ch = self.callMethod("setRule", "tr.org.pardus.comar.net.filter.set")
            ch.registerDone(stopIptables)
            ch.call("-t nat -F")

        def handleState_iptables(_type, _desc, _state):
            if _state in ["on", "started"]:
                removeNatRules()

        if not self.sharecheckBox.isOn():
            # FIXME gui freezes if checkbox is clicked 2 times without any other action

            ch = CallHandler("dhcp", "System.Service", "info", "tr.org.pardus.comar.system.service.set", self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(handleState_dhcp)
            ch.registerError(self.comarError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call()

            ch = self.callMethod("info", "tr.org.pardus.comar.system.service.set", "System.Service")
            ch.registerDone(handleState_iptables)
            ch.call()

            self.groupBox1.setEnabled(False)
            self.applyBut.setEnabled(False)

        else:
            self.groupBox1.setEnabled(True)
            self.applyBut.setEnabled(True)
Exemple #12
0
 def upShr():
     ch = CallHandler(shr.script, "Net.Link", "setState", "tr.org.pardus.comar.net.link", self.winId(), comlink.busSys, comlink.busSes)
     ch.registerDone(upInt)
     ch.registerError(self.updownError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.call(shr.name, "up")
Exemple #13
0
 def updown():
     if shr.state == "up":
         ch = CallHandler(shr.script, "Net.Link", "setState", "tr.org.pardus.comar.net.link", self.winId(), comlink.busSys, comlink.busSes)
         ch.registerDone(downInt)
         ch.registerError(self.updownError)
         ch.registerAuthError(self.comarError)
         ch.registerDBusError(self.busError)
         ch.call(shr.name, "down")
     else:
         downInt()
Exemple #14
0
    def shareConnection(self):
        int_if = (self.profiles[self.intcombo.currentItem()].devname.split("(")[-1])[:-1]
        shr_if = (self.profiles[self.sharecombo.currentItem()].devname.split("(")[-1])[:-1]

        if int_if == shr_if:
            KMessageBox.information(self, i18n("The interfaces that you have selected must be different to share internet connection"), i18n("Check Selected Interfaces"))
            return

        #Set share settings(dhcp...)
        int = self.profiles[self.intcombo.currentItem()]
        shr = self.profiles[self.sharecombo.currentItem()]

        #İptables
        self.rule_add = str("-t nat -A POSTROUTING -o %s -j MASQUERADE" % (int_if))
        def notifyOK():
            KMessageBox.information(self, i18n("The sharing of your connection has been successfully done."), i18n("Sharing is OK"))
            self.close()

        def setRule():
            ch = self.callMethod("setRule", "tr.org.pardus.comar.net.filter.set")
            ch.registerDone(notifyOK)
            ch.call(self.rule_add)

        def setProfile():
            ch = self.callMethod("setProfile", "tr.org.pardus.comar.net.filter.set")
            ch.registerDone(setRule)
            ch.call("default","*","*","*","*")

        def startIptables():
            ch = self.callMethod("start", "tr.org.pardus.comar.system.service.set", "System.Service")
            ch.registerDone(setProfile)
            ch.call()

        #DHCP Server
        def startDHCP():
            ch = CallHandler("dhcp", "System.Service", "start", "tr.org.pardus.comar.system.service.set", self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(startIptables)
            ch.registerError(self.dhcpError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call()

        #Down and up the interfaces to avoid lack of routing queries
        #down the interfaces
        #up the interfaces
        def upInt():
            ch = CallHandler(int.script, "Net.Link", "setState", "tr.org.pardus.comar.net.link", self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(startDHCP)
            ch.registerError(self.updownError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(int.name, "up")

        def upShr():
            ch = CallHandler(shr.script, "Net.Link", "setState", "tr.org.pardus.comar.net.link", self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(upInt)
            ch.registerError(self.updownError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(shr.name, "up")

        def downInt():
            if int.state == "up":
                ch = CallHandler(int.script, "Net.Link", "setState", "tr.org.pardus.comar.net.link", self.winId(), comlink.busSys, comlink.busSes)
                ch.registerDone(upShr)
                ch.registerError(self.updownError)
                ch.registerAuthError(self.comarError)
                ch.registerDBusError(self.busError)
                ch.call(int.name, "down")

        def updown():
            if shr.state == "up":
                ch = CallHandler(shr.script, "Net.Link", "setState", "tr.org.pardus.comar.net.link", self.winId(), comlink.busSys, comlink.busSes)
                ch.registerDone(downInt)
                ch.registerError(self.updownError)
                ch.registerAuthError(self.comarError)
                ch.registerDBusError(self.busError)
                ch.call(shr.name, "down")
            else:
                downInt()
        def setDHCP():
            ch = CallHandler("dhcp", "Net.Share", "checkShare", "tr.org.pardus.comar.net.share.set", self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(updown)
            ch.registerError(self.dhcpError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(shr.net_addr, shr.net_mode, shr.net_mask, shr.dns_server)

        if shr.name == None:
            shr.name = ""
        if shr.state == None:
            shr.state = "down"
        if shr.net_addr == None:
            shr.net_addr = ""
        if shr.net_mode == None:
            shr.net_mode = "auto"
        if shr.net_mask == None:
            shr.net_mask = ""
        if shr.dns_server == None:
            shr.dns_server = ""
        if shr.net_mode == "manual":
            setDHCP()
        if shr.net_mode == "auto":
            shr.net_addr = "10.10.10.1"
            shr.net_mask = "255.255.255.0"
            shr.net_mode = "manual"
            if int.net_mode == "manual":
                shr.net_gate = str(int.net_addr)
            else:
                exist = 0
                ifcfg = commands.getstatusoutput("/sbin/ifconfig %s" % int.devname.split("(")[-1][:-1])
                for addr in str(ifcfg[1]).split(" "):
                    if addr.startswith("addr:"):
                        shr.net_gate = addr[5:]
                        exist = 1
                if exist == 0:
                    KMessageBox.information(self, i18n("You do not have an ip address for the interface that goes to internet"), i18n("IP address not found"))
                    return

            ch = CallHandler(shr.script, "Net.Link", "setAddress", "tr.org.pardus.comar.net.link.set", self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(setDHCP)
            ch.registerError(self.comarError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(shr.name, shr.net_mode, shr.net_addr, shr.net_mask, shr.net_gate)
Exemple #15
0
 def startDHCP():
     ch = CallHandler("dhcp", "System.Service", "start", "tr.org.pardus.comar.system.service.set", self.winId(), comlink.busSys, comlink.busSes)
     ch.registerDone(startIptables)
     ch.registerError(self.dhcpError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.call()
Exemple #16
0
    def shareConnection(self):
        int_if = (self.profiles[self.intcombo.currentItem()].devname.split("(")
                  [-1])[:-1]
        shr_if = (self.profiles[self.sharecombo.currentItem()].devname.split(
            "(")[-1])[:-1]

        if int_if == shr_if:
            KMessageBox.information(
                self,
                i18n(
                    "The interfaces that you have selected must be different to share internet connection"
                ), i18n("Check Selected Interfaces"))
            return

        #Set share settings(dhcp...)
        int = self.profiles[self.intcombo.currentItem()]
        shr = self.profiles[self.sharecombo.currentItem()]

        #İptables
        self.rule_add = str("-t nat -A POSTROUTING -o %s -j MASQUERADE" %
                            (int_if))

        def notifyOK():
            KMessageBox.information(
                self,
                i18n(
                    "The sharing of your connection has been successfully done."
                ), i18n("Sharing is OK"))
            self.close()

        def setRule():
            ch = self.callMethod("setRule",
                                 "tr.org.pardus.comar.net.filter.set")
            ch.registerDone(notifyOK)
            ch.call(self.rule_add)

        def setProfile():
            ch = self.callMethod("setProfile",
                                 "tr.org.pardus.comar.net.filter.set")
            ch.registerDone(setRule)
            ch.call("default", "*", "*", "*", "*")

        def startIptables():
            ch = self.callMethod("start",
                                 "tr.org.pardus.comar.system.service.set",
                                 "System.Service")
            ch.registerDone(setProfile)
            ch.call()

        #DHCP Server
        def startDHCP():
            ch = CallHandler("dhcp", "System.Service", "start",
                             "tr.org.pardus.comar.system.service.set",
                             self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(startIptables)
            ch.registerError(self.dhcpError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call()

        #Down and up the interfaces to avoid lack of routing queries
        #down the interfaces
        #up the interfaces
        def upInt():
            ch = CallHandler(int.script, "Net.Link",
                             "setState", "tr.org.pardus.comar.net.link",
                             self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(startDHCP)
            ch.registerError(self.updownError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(int.name, "up")

        def upShr():
            ch = CallHandler(shr.script, "Net.Link",
                             "setState", "tr.org.pardus.comar.net.link",
                             self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(upInt)
            ch.registerError(self.updownError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(shr.name, "up")

        def downInt():
            if int.state == "up":
                ch = CallHandler(int.script, "Net.Link",
                                 "setState", "tr.org.pardus.comar.net.link",
                                 self.winId(), comlink.busSys, comlink.busSes)
                ch.registerDone(upShr)
                ch.registerError(self.updownError)
                ch.registerAuthError(self.comarError)
                ch.registerDBusError(self.busError)
                ch.call(int.name, "down")

        def updown():
            if shr.state == "up":
                ch = CallHandler(shr.script, "Net.Link",
                                 "setState", "tr.org.pardus.comar.net.link",
                                 self.winId(), comlink.busSys, comlink.busSes)
                ch.registerDone(downInt)
                ch.registerError(self.updownError)
                ch.registerAuthError(self.comarError)
                ch.registerDBusError(self.busError)
                ch.call(shr.name, "down")
            else:
                downInt()

        def setDHCP():
            ch = CallHandler("share", "Net.Share",
                             "checkShare", "tr.org.pardus.comar.net.share.set",
                             self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(updown)
            ch.registerError(self.dhcpError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(shr.net_addr, shr.net_mode, shr.net_mask, shr.dns_server)

        if shr.name == None:
            shr.name = ""
        if shr.state == None:
            shr.state = "down"
        if shr.net_addr == None:
            shr.net_addr = ""
        if shr.net_mode == None:
            shr.net_mode = "auto"
        if shr.net_mask == None:
            shr.net_mask = ""
        if shr.dns_server == None:
            shr.dns_server = ""
        if shr.net_mode == "manual":
            setDHCP()
        if shr.net_mode == "auto":
            shr.net_addr = "10.10.10.1"
            shr.net_mask = "255.255.255.0"
            shr.net_mode = "manual"
            if int.net_mode == "manual":
                shr.net_gate = str(int.net_addr)
            else:
                exist = 0
                ifcfg = commands.getstatusoutput(
                    "/sbin/ifconfig %s" % int.devname.split("(")[-1][:-1])
                for addr in str(ifcfg[1]).split(" "):
                    if addr.startswith("addr:"):
                        shr.net_gate = addr[5:]
                        exist = 1
                if exist == 0:
                    KMessageBox.information(
                        self,
                        i18n(
                            "You do not have an ip address for the interface that goes to internet"
                        ), i18n("IP address not found"))
                    return

            ch = CallHandler(shr.script, "Net.Link",
                             "setAddress", "tr.org.pardus.comar.net.link.set",
                             self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(setDHCP)
            ch.registerError(self.comarError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call(shr.name, shr.net_mode, shr.net_addr, shr.net_mask,
                    shr.net_gate)
Exemple #17
0
 def upShr():
     ch = CallHandler(shr.script, "Net.Link",
                      "setState", "tr.org.pardus.comar.net.link",
                      self.winId(), comlink.busSys, comlink.busSes)
     ch.registerDone(upInt)
     ch.registerError(self.updownError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.call(shr.name, "up")
Exemple #18
0
 def updown():
     if shr.state == "up":
         ch = CallHandler(shr.script, "Net.Link",
                          "setState", "tr.org.pardus.comar.net.link",
                          self.winId(), comlink.busSys, comlink.busSes)
         ch.registerDone(downInt)
         ch.registerError(self.updownError)
         ch.registerAuthError(self.comarError)
         ch.registerDBusError(self.busError)
         ch.call(shr.name, "down")
     else:
         downInt()
Exemple #19
0
 def setDHCP():
     ch = CallHandler("share", "Net.Share",
                      "checkShare", "tr.org.pardus.comar.net.share.set",
                      self.winId(), comlink.busSys, comlink.busSes)
     ch.registerDone(updown)
     ch.registerError(self.dhcpError)
     ch.registerAuthError(self.comarError)
     ch.registerDBusError(self.busError)
     ch.call(shr.net_addr, shr.net_mode, shr.net_mask, shr.dns_server)
Exemple #20
0
    def slotCheckBox(self):
        def handleState_dhcp(_type, _desc, _state):
            if _state in ["on", "started"]:
                ch = CallHandler("dhcp", "System.Service", "stop",
                                 "tr.org.pardus.comar.system.service.set",
                                 self.winId(), comlink.busSys, comlink.busSes)
                ch.registerError(self.comarError)
                ch.registerAuthError(self.comarError)
                ch.registerDBusError(self.busError)
                ch.call()

        def stopIptables():
            ch = self.callMethod("stop",
                                 "tr.org.pardus.comar.system.service.set",
                                 "System.Service")
            ch.call()

        def removeNatRules():
            ch = self.callMethod("setRule",
                                 "tr.org.pardus.comar.net.filter.set")
            ch.registerDone(stopIptables)
            ch.call("-t nat -F")

        def handleState_iptables(_type, _desc, _state):
            if _state in ["on", "started"]:
                removeNatRules()

        if not self.sharecheckBox.isOn():
            self.groupBox1.setEnabled(False)
            self.buttonGroup2.setEnabled(False)

            ch = CallHandler("dhcp", "System.Service", "info",
                             "tr.org.pardus.comar.system.service.set",
                             self.winId(), comlink.busSys, comlink.busSes)
            ch.registerDone(handleState_dhcp)
            ch.registerError(self.comarError)
            ch.registerAuthError(self.comarError)
            ch.registerDBusError(self.busError)
            ch.call()

            ch = self.callMethod("info",
                                 "tr.org.pardus.comar.system.service.set",
                                 "System.Service")
            ch.registerDone(handleState_iptables)
            ch.call()

        else:
            self.groupBox1.setEnabled(True)
            self.buttonGroup2.setEnabled(True)