Пример #1
0
    def banip(self,
              ipaddress,
              reason="The Ban Hammer has spoken!",
              source="Wrapper",
              expires=False):
        """
        Ban an IP address (IPV-4)
        :param ipaddress - ip address to ban
        :param reason - text reason for ban
        :param source - source (author/op) of ban.
        :param expires - expiration in seconds from epoch time.  Field exists
        but not used by the vanilla server.
        - implement it for tempbans in future?
        - Gets converted to string representation in the ban file.

        This probably only works on 1.7.10 servers or later
        """
        if not isipv4address(ipaddress):
            return "Invalid IPV4 address: %s" % ipaddress
        banlist = getjsonfile("banned-ips", self.srv_data.serverpath)
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                banlist = dict()  # ensure valid dict before operating on it
            if find_in_json(banlist, "ip", ipaddress):
                return "address already banned"  # error text
            else:
                if expires:
                    try:
                        expiration = epoch_to_timestr(expires)
                    except Exception as e:
                        print('Exception: %s' % e)
                        return "expiration date invalid"  # error text
                else:
                    expiration = "forever"
                banlist.append({
                    "ip": ipaddress,
                    "created": epoch_to_timestr(time.time()),
                    "source": source,
                    "expires": expiration,
                    "reason": reason
                })
                if putjsonfile(banlist, "banned-ips",
                               self.srv_data.serverpath):
                    banned = ""
                    for client in self.srv_data.clients:
                        if client.ip == str(ipaddress):

                            console_command = "kick %s Your IP is Banned!" % client.username
                            self.eventhandler.callevent(
                                "proxy.console", {"command": console_command})
                            """ eventdoc
                                                    <description> internalfunction <description>

                                                """
                            banned += "\n%s" % client.username
                    return "Banned ip address: %s\nPlayers kicked as " \
                           "a result:%s" % (ipaddress, banned)
                return "Could not write banlist to disk"
        else:
            return "Banlist not found on disk"
Пример #2
0
    def banuuidraw(self,
                   uuid,
                   username,
                   reason="The Ban Hammer has spoken!",
                   source="Wrapper",
                   expires=False):
        """
        Ban a raw uuid/name combination with no mojang error checks
        :param uuid - uuid to ban (MCUUID)
        :param username - Name of player to ban
        :param reason - text reason for ban
        :param source - source (author/op) of ban.
        :param expires - expiration in seconds from epoch time.  Field exists
         but not used by the vanilla server
        - implement it for tempbans in future?
          Gets converted to string representation in the ban file.

        This probably only works on 1.7.10 servers or later
        """
        banlist = getjsonfile("banned-players", self.srv_data.serverpath)
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                banlist = dict()  # ensure valid dict before operating on it
            if find_in_json(banlist, "uuid", str(uuid)):
                return "player already banned"  # error text
            else:
                if expires:
                    try:
                        expiration = epoch_to_timestr(expires)
                    except Exception as e:
                        print('Exception: %s' % e)
                        return "expiration date invalid"  # error text
                else:
                    expiration = "forever"
                banlist.append({
                    "uuid": uuid.string,
                    "name": username,
                    "created": epoch_to_timestr(time.time()),
                    "source": source,
                    "expires": expiration,
                    "reason": reason
                })
                if putjsonfile(banlist, "banned-players",
                               self.srv_data.serverpath):
                    self.log.info("kicking %s... %s", username, reason)

                    console_command = "kick %s Banned: %s" % (username, reason)
                    self.eventhandler.callevent("proxy.console",
                                                {"command": console_command},
                                                abortable=False)
                    """ eventdoc
                                            <description> internalfunction <description>

                                        """  # noqa
                    return "Banned %s: %s - %s" % (username, uuid, reason)
                return "Could not write banlist to disk"
        else:
            return "Banlist not found on disk"
Пример #3
0
 def getuuidbanreason(self, uuid):
     """
     :param uuid: uuid of player as string
     :return: string representing ban reason
     """
     banlist = getjsonfile("banned-players", self.srv_data.serverpath)
     if banlist:
         banrecord = find_in_json(banlist, "uuid", uuid)
         return "%s by %s" % (banrecord["reason"], banrecord["source"])
     return "Banned by server"
Пример #4
0
 def getuuidbanreason(self, uuid):
     """
     :param uuid: uuid of player as string
     :return: string representing ban reason
     """
     banlist = getjsonfile("banned-players", self.serverpath)
     if banlist:
         banrecord = find_in_json(banlist, "uuid", uuid)
         return "%s by %s" % (banrecord["reason"], banrecord["source"])
     return "Banned by server"
Пример #5
0
    def banip(self, ipaddress, reason="The Ban Hammer has spoken!",
              source="Wrapper", expires=False):
        """
        Ban an IP address (IPV-4)
        :param ipaddress - ip address to ban
        :param reason - text reason for ban
        :param source - source (author/op) of ban.
        :param expires - expiration in seconds from epoch time.  Field exists
        but not used by the vanilla server.
        - implement it for tempbans in future?
        - Gets converted to string representation in the ban file.

        This probably only works on 1.7.10 servers or later
        """
        if not isipv4address(ipaddress):
            return "Invalid IPV4 address: %s" % ipaddress
        banlist = getjsonfile("banned-ips", self.srv_data.serverpath)
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                banlist = dict()  # ensure valid dict before operating on it
            if find_in_json(banlist, "ip", ipaddress):
                return "address already banned"  # error text
            else:
                if expires:
                    try:
                        expiration = epoch_to_timestr(expires)
                    except Exception as e:
                        print('Exception: %s' % e)
                        return "expiration date invalid"  # error text
                else:
                    expiration = "forever"
                banlist.append({"ip": ipaddress,
                                "created": epoch_to_timestr(time.time()),
                                "source": source,
                                "expires": expiration,
                                "reason": reason})
                if putjsonfile(banlist, "banned-ips", self.srv_data.serverpath):
                    banned = ""
                    for client in self.srv_data.clients:
                        if client.ip == str(ipaddress):

                            console_command = "kick %s Your IP is Banned!" % client.username
                            self.eventhandler.callevent("proxy.console",
                                                        {"command": console_command})
                            """ eventdoc
                                                    <description> internalfunction <description>

                                                """
                            banned += "\n%s" % client.username
                    return "Banned ip address: %s\nPlayers kicked as " \
                           "a result:%s" % (ipaddress, banned)
                return "Could not write banlist to disk"
        else:
            return "Banlist not found on disk"
Пример #6
0
    def banuuid(self,
                uuid,
                reason="The Ban Hammer has spoken!",
                source="Wrapper",
                expires=False):
        """
        Ban someone by UUID  This is the 1.7.6 way to ban..
        :param uuid - uuid to ban (MCUUID)
        :param reason - text reason for ban
        :param source - source (author/op) of ban.
        :param expires - expiration in seconds from epoch time.  Field exists
         but not used by the vanilla server
        - implement it for tempbans in future?
          Gets converted to string representation in the ban file.

        This probably only works on 1.7.10 servers or later
        """
        banlist = getjsonfile("banned-players", self.srv_data.serverpath)
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                banlist = dict()  # ensure valid dict before operating on it
            if find_in_json(banlist, "uuid", str(uuid)):
                return "player already banned"  # error text
            else:
                if expires:
                    try:
                        expiration = epoch_to_timestr(expires)
                    except Exception as e:
                        print('Exception: %s' % e)
                        return "expiration date invalid"  # error text
                else:
                    expiration = "forever"
                name = self.uuids.getusernamebyuuid(uuid.string)
                banlist.append({
                    "uuid": uuid.string,
                    "name": name,
                    "created": epoch_to_timestr(time.time()),
                    "source": source,
                    "expires": expiration,
                    "reason": reason
                })
                if putjsonfile(banlist, "banned-players",
                               self.srv_data.serverpath):
                    # this actually is not needed. Commands now handle the kick.
                    console_command = "kick %s %s" % (name, reason)
                    self.run_command(console_command)

                    return "Banned %s: %s" % (name, reason)
                return "Could not write banlist to disk"
        else:
            return "Banlist not found on disk"
Пример #7
0
    def banuuidraw(self, uuid, username, reason="The Ban Hammer has spoken!",
                   source="Wrapper", expires=False):
        """
        Ban a raw uuid/name combination with no mojang error checks
        :param uuid - uuid to ban (MCUUID)
        :param username - Name of player to ban
        :param reason - text reason for ban
        :param source - source (author/op) of ban.
        :param expires - expiration in seconds from epoch time.  Field exists
         but not used by the vanilla server
        - implement it for tempbans in future?
          Gets converted to string representation in the ban file.

        This probably only works on 1.7.10 servers or later
        """
        banlist = getjsonfile("banned-players", self.srv_data.serverpath)
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                banlist = dict()  # ensure valid dict before operating on it
            if find_in_json(banlist, "uuid", str(uuid)):
                return "player already banned"  # error text
            else:
                if expires:
                    try:
                        expiration = epoch_to_timestr(expires)
                    except Exception as e:
                        print('Exception: %s' % e)
                        return "expiration date invalid"  # error text
                else:
                    expiration = "forever"
                banlist.append({"uuid": uuid.string,
                                "name": username,
                                "created": epoch_to_timestr(time.time()),
                                "source": source,
                                "expires": expiration,
                                "reason": reason})
                if putjsonfile(banlist, "banned-players", self.srv_data.serverpath):
                    self.log.info("kicking %s... %s", username, reason)

                    console_command = "kick %s Banned: %s" % (username, reason)
                    self.eventhandler.callevent("proxy.console",
                                                {"command": console_command})
                    """ eventdoc
                                            <description> internalfunction <description>

                                        """
                    return "Banned %s: %s - %s" % (username, uuid, reason)
                return "Could not write banlist to disk"
        else:
            return "Banlist not found on disk"
Пример #8
0
    def banuuid(self, uuid, reason="The Ban Hammer has spoken!",
                source="Wrapper", expires=False):
        """
        Ban someone by UUID  This is the 1.7.6 way to ban..
        :param uuid - uuid to ban (MCUUID)
        :param reason - text reason for ban
        :param source - source (author/op) of ban.
        :param expires - expiration in seconds from epoch time.  Field exists
         but not used by the vanilla server
        - implement it for tempbans in future?
          Gets converted to string representation in the ban file.

        This probably only works on 1.7.10 servers or later
        """
        banlist = getjsonfile(
            "banned-players", self.javaserver.serverpath
        )
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                banlist = dict()  # ensure valid dict before operating on it
            if find_in_json(banlist, "uuid", str(uuid)):
                return "player already banned"  # error text
            else:
                if expires:
                    try:
                        expiration = epoch_to_timestr(expires)
                    except Exception as e:
                        print('Exception: %s' % e)
                        return "expiration date invalid"  # error text
                else:
                    expiration = "forever"
                name = self.uuids.getusernamebyuuid(uuid.string)
                banlist.append({"uuid": uuid.string,
                                "name": name,
                                "created": epoch_to_timestr(time.time()),
                                "source": source,
                                "expires": expiration,
                                "reason": reason})
                if putjsonfile(banlist,
                               "banned-players",
                               self.javaserver.serverpath):
                    # this actually is not needed. Commands now handle the kick.
                    console_command = "kick %s %s" % (name, reason)
                    self.run_command(console_command)

                    return "Banned %s: %s" % (name, reason)
                return "Could not write banlist to disk"
        else:
            return "Banlist not found on disk"
Пример #9
0
 def pardonname(self, username):
     banlist = getjsonfile("banned-players", self.srv_data.serverpath)
     if banlist is not False:  # file and directory exist.
         if banlist is None:  # file was empty or not valid
             return "No bans have ever been recorded..?"
         banrecord = find_in_json(banlist, "name", str(username))
         if banrecord:
             for x in banlist:
                 if x == banrecord:
                     banlist.remove(x)
             if putjsonfile(banlist, "banned-players", self.srv_data.serverpath):
                 return "pardoned %s" % username
             return "Could not write banlist to disk"
         else:
             return "That person was never banned"  # error text
     else:
         return "Banlist not found on disk"  # error text
Пример #10
0
 def pardonname(self, username):
     banlist = getjsonfile("banned-players", self.serverpath)
     if banlist is not False:  # file and directory exist.
         if banlist is None:  # file was empty or not valid
             return "No bans have ever been recorded..?"
         banrecord = find_in_json(banlist, "name", str(username))
         if banrecord:
             for x in banlist:
                 if x == banrecord:
                     banlist.remove(x)
             if putjsonfile(banlist, "banned-players", self.serverpath):
                 return "pardoned %s" % username
             return "Could not write banlist to disk"
         else:
             return "That person was never banned"  # error text
     else:
         return "Banlist not found on disk"  # error text
Пример #11
0
 def isuuidbanned(self, uuid):  # Check if the UUID of the user is banned
     banlist = getjsonfile("banned-players", self.srv_data.serverpath)
     if banlist:  # make sure banlist exists
         banrecord = find_in_json(banlist, "uuid", str(uuid))
         if banrecord:
             # if ban has expired
             if read_timestr(banrecord["expires"]) < int(time.time()):
                 pardoning = self.pardonuuid(str(uuid))
                 if pardoning[:8] == "pardoned":
                     self.log.info("UUID: %s was pardoned "
                                   "(expired ban)", str(uuid))
                     return False  # player is "NOT" banned (anymore)
                 else:
                     self.log.warning("isuuidbanned attempted a pardon of"
                                      " uuid: %s (expired ban), "
                                      "but it failed:\n %s",
                                      uuid, pardoning)
             return True  # player is still banned
     return False  # banlist empty or record not found
Пример #12
0
 def isuuidbanned(self, uuid):  # Check if the UUID of the user is banned
     banlist = getjsonfile("banned-players", self.serverpath)
     if banlist:  # make sure banlist exists
         banrecord = find_in_json(banlist, "uuid", str(uuid))
         if banrecord:
             # if ban has expired
             if read_timestr(banrecord["expires"]) < int(time.time()):
                 pardoning = self.pardonuuid(str(uuid))
                 if pardoning[:8] == "pardoned":
                     self.log.info("UUID: %s was pardoned "
                                   "(expired ban)", str(uuid))
                     return False  # player is "NOT" banned (anymore)
                 else:
                     self.log.warning(
                         "isuuidbanned attempted a pardon of"
                         " uuid: %s (expired ban), "
                         "but it failed:\n %s", uuid, pardoning)
             return True  # player is still banned
     return False  # banlist empty or record not found
Пример #13
0
    def pardonip(self, ipaddress):
        if not isipv4address(ipaddress):
            return "Invalid IPV4 address: %s" % ipaddress
        banlist = getjsonfile("banned-ips", self.srv_data.serverpath)
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                return "No IP bans have ever been recorded."
            banrecord = find_in_json(banlist, "ip", ipaddress)
            if banrecord:
                for x in banlist:
                    if x == banrecord:
                        banlist.remove(x)
                if putjsonfile(banlist, "banned-ips", self.srv_data.serverpath):
                    return "pardoned %s" % ipaddress
                return "Could not write banlist to disk"
            else:
                return "That address was never banned"  # error text

        else:
            return "Banlist not found on disk"  # error text
Пример #14
0
    def pardonip(self, ipaddress):
        if not isipv4address(ipaddress):
            return "Invalid IPV4 address: %s" % ipaddress
        banlist = getjsonfile("banned-ips", self.serverpath)
        if banlist is not False:  # file and directory exist.
            if banlist is None:  # file was empty or not valid
                return "No IP bans have ever been recorded."
            banrecord = find_in_json(banlist, "ip", ipaddress)
            if banrecord:
                for x in banlist:
                    if x == banrecord:
                        banlist.remove(x)
                if putjsonfile(banlist, "banned-ips", self.serverpath):
                    return "pardoned %s" % ipaddress
                return "Could not write banlist to disk"
            else:
                return "That address was never banned"  # error text

        else:
            return "Banlist not found on disk"  # error text