Ejemplo n.º 1
0
    def addNewUsers(self, request):
        """
            Add "count" number of raw users. Created users has no attribute assigned to them.
            Later you should assign attribute by updateUserAttrs
            
            return a list of created user_id s
        """
        request.needAuthType(request.ADMIN)
        request.checkArgs("count", "credit", "owner_name", "group_name",
                          "credit_comment")
        requester = request.getAuthNameObj()
        requester.canDo("ADD NEW USER")
        if request["owner_name"] != requester.getUsername():
            requester.canDo("CHANGE USERS OWNER")
        try:
            _count = int(request["count"])
        except ValueError:
            raise GeneralException(
                errorText("USER_ACTIONS", "COUNT_NOT_INTEGER"))

        try:
            credit = float(request["credit"])
        except ValueError:
            raise GeneralException(
                errorText("USER_ACTIONS", "CREDIT_NOT_FLOAT"))

        return user_main.getActionManager().addNewUsers(
            _count, credit, request["owner_name"],
            requester.getUsername(), request["group_name"],
            request.getRemoteAddr(), request["credit_comment"])
Ejemplo n.º 2
0
    def __delPrefixCheckInput(self,tariff_name,prefix_codes):
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	if not len(prefix_codes):
	    raise GeneralException(errorText("VOIP_TARIFF","NO_PREFIX_TO_DELETE"))
	for code in prefix_codes:
	    if not tariff_obj.hasPrefixCode(code):
		raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_CODE")%(tariff_obj.getTariffName(),code))
Ejemplo n.º 3
0
 def __createCheckAddReturnDic(self, bad_usernames, exist_usernames):
     ret = {}
     if len(bad_usernames) != 0:
         ret[errorText("USER_ACTIONS", "BAD_NORMAL_USERNAME", False) % ""] = bad_usernames
     if len(exist_usernames) != 0:
         ret[errorText("USER_ACTIONS", "NORMAL_USERNAME_EXISTS", False) % ""] = exist_usernames
     return ret
Ejemplo n.º 4
0
    def __checkRasMsg(self, ras_msg):
        """
            check and update ras_msg
        """
        if defs.FASTDIAL_PREFIX:  #@UndefinedVariable
            if ras_msg.hasAttr(
                    "called_number") and ras_msg["called_number"].startswith(
                        defs.FASTDIAL_PREFIX):  #@UndefinedVariable
                try:
                    fast_dial_index = int(
                        ras_msg["called_number"]
                        [len(defs.FASTDIAL_PREFIX):])  #@UndefinedVariable
                except ValueError:
                    raise GeneralException(
                        errorText("USER_LOGIN", "INVALID_FAST_DIAL_INDEX") %
                        ras_msg["called_number"])

                try:
                    fast_dial_entry = self.fast_dials[fast_dial_index]
                except IndexError:
                    raise GeneralException(
                        errorText("USER_LOGIN", "INVALID_FAST_DIAL_INDEX") %
                        fast_dial_index)

                instance = self.user_obj.getInstanceFromRasMsg(ras_msg)
                instance_info = self.user_obj.getInstanceInfo(instance)
                instance_info["attrs"]["fast_dial_index"] = fast_dial_index

                #called number will be set later by charge plugin
                ras_msg["called_number"] = fast_dial_entry
                ras_msg.getRasObj().setRedirectNumber(ras_msg.getReplyPacket(),
                                                      fast_dial_entry)
Ejemplo n.º 5
0
    def __updateRasCheckInput(self, ras_id, ras_ip, ras_description, ras_type,
                              radius_secret, comment):
        ras_obj = ras_main.getLoader()[ras_id]
        if ras_obj.getRasIP() != ras_ip:
            if not iplib.checkIPAddrWithoutMask(ras_ip):
                raise GeneralException(
                    errorText("RAS", "INVALID_RAS_IP") % ras_ip)

            if ras_main.getLoader().rasIPExists(ras_ip):
                raise GeneralException(
                    errorText("RAS", "RAS_IP_ALREADY_EXISTS") % ras_ip)

            if self.__rasIPExistsInDB(ras_ip):
                raise GeneralException(
                    errorText("RAS", "RAS_IS_INACTIVE") % ras_ip)

        if ras_obj.getRasDesc() != ras_description and ras_main.getLoader(
        ).rasDescExists(ras_description):
            raise GeneralException(
                errorText("RAS", "RAS_DESCRIPTION_ALREADY_EXISTS") %
                ras_description)

        self.__checkValidRasDescription(ras_description)

        if not ras_main.getFactory().hasType(ras_type):
            raise GeneralException(
                errorText("RAS", "RAS_TYPE_NOT_REGISTERED") % ras_type)
Ejemplo n.º 6
0
    def __checkUsernames(self, users):
        if len(self.usernames) != len(users):
            raise GeneralException(
                errorText("USER_ACTIONS", "VOIP_USER_COUNT_NOT_MATCH") %
                (len(users), len(self.usernames)))

        cur_voip_usernames = []
        for loaded_user in users.itervalues():
            if loaded_user.userHasAttr("voip_username"):
                cur_voip_usernames.append(
                    loaded_user.getUserAttrs()["voip_username"])

        to_check_usernames = []  #check users for exitence
        for username in self.usernames:
            checkVoIPUsernameChars(username)

            if self.usernames.count(username) > 1:
                raise GeneralException(
                    errorText("USER_ACTIONS", "DUPLICATE_USERNAME") %
                    (username))

            if username not in cur_voip_usernames:
                to_check_usernames.append(username)

        exists = voipUsernameExists(to_check_usernames)
        if exists:
            raise GeneralException(
                errorText("USER_ACTIONS", "VOIP_USERNAME_EXISTS") %
                ",".join(exists))
Ejemplo n.º 7
0
    def __convertToInt(self,cpm,free_sec,min_duration,round_to,min_chargable_duration,errs,line):
        try:
            cpm=float(cpm)
        except ValueError:
            errs.append("%s:%s"%(line,errorText("CHARGES","CPM_NOT_NUMERIC")))
            cpm=0

        try:
            free_sec=int(free_sec)
        except ValueError:
            errs.append("%s:%s"%(line,errorText("VOIP_TARIFF","FREE_SECONDS_NOT_NUMERIC")))
            free_sec=0

        try:
            min_duration=int(min_duration)
        except ValueError:
            errs.append("%s:%s"%(line,errorText("VOIP_TARIFF","MIN_DURATION_NOT_NUMERIC")))
            min_duration=0

        try:
            round_to=int(round_to)
        except ValueError:
            errs.append("%s:%s"%(line,errorText("VOIP_TARIFF","ROUND_TO_NOT_NUMERIC")))
            round_to=0

        try:
            min_chargable_duration=int(min_chargable_duration)
        except ValueError:
            errs.append("%s:%s"%(line,errorText("VOIP_TARIFF","MIN_CHARGABLE_DURATION_NOT_NUMERIC")))
            round_to=0

        return (cpm,free_sec,min_duration,round_to,min_chargable_duration)
Ejemplo n.º 8
0
 def __delPrefixCheckInput(self,tariff_name,prefix_codes):
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     if not len(prefix_codes):
         raise GeneralException(errorText("VOIP_TARIFF","NO_PREFIX_TO_DELETE"))
     for code in prefix_codes:
         if not tariff_obj.hasPrefixCode(code):
             raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_CODE")%(tariff_obj.getTariffName(),code))
Ejemplo n.º 9
0
    def __convertToInt(self,cpm,free_sec,min_duration,round_to,errs,line):
	try:
	    cpm=float(cpm)
	except ValueError:
	    errs.append("%s:%s"%(line,errorText("CHARGES","CPM_NOT_NUMERIC")))
	    cpm=0

	try:
	    free_sec=int(free_sec)
	except ValueError:
	    errs.append("%s:%s"%(line,errorText("VOIP_TARIFF","FREE_SECONDS_NOT_NUMERIC")))
	    free_sec=0

	try:
	    min_duration=int(min_duration)
	except ValueError:
	    errs.append("%s:%s"%(line,errorText("VOIP_TARIFF","MIN_DURATION_NOT_NUMERIC")))
	    min_duration=0

	try:
	    round_to=int(round_to)
	except ValueError:
	    errs.append("%s:%s"%(line,errorText("VOIP_TARIFF","ROUND_TO_NOT_NUMERIC")))
	    round_to=0

	return (cpm,free_sec,min_duration,round_to)
Ejemplo n.º 10
0
    def __addNewUsersCheckInput(self, _count, credit, owner_name, creator_name,
                                group_name, remote_address,
                                credit_change_comment, user_ids):
        if not isInt(_count) or _count <= 0:
            raise GeneralException(
                errorText("USER_ACTIONS", "INVALID_USER_COUNT") % _count)

        if not isFloat(credit):
            raise GeneralException(
                errorText("USER_ACTIONS", "CREDIT_NOT_FLOAT"))

        if credit < 0:
            raise GeneralException(
                errorText("USER_ACTIONS", "CREDIT_MUST_BE_POSITIVE"))

        admin_main.getLoader().checkAdminName(owner_name)
        admin_main.getLoader().checkAdminName(creator_name)
        group_main.getLoader().checkGroupName(group_name)

        if user_ids:
            if len(user_ids) != _count:
                raise GeneralException(
                    errorText("USER_ACTIONS", "USER_IDS_COUNT_NOT_MATCH"))

            for user_id in user_ids:
                if not isInt(user_id):
                    raise GeneralException(
                        errorText("USER", "INVALID_USER_ID") % user_id)
Ejemplo n.º 11
0
        def checkPort(port_name):
            if not ras_obj.hasPort(port_name):
                raise GeneralException(
                    errorText("RAS", "RAS_DONT_HAVE_PORT") % port_name)

            if not len(port_name):
                raise GeneralException(
                    errorText("RAS", "INVALID_PORT_NAME") % port_name)
Ejemplo n.º 12
0
 def __updateTariffCheckInput(self,tariff_id,tariff_name,comment):
     tariff_obj=tariff_main.getLoader().getTariffByID(tariff_id)
     if tariff_obj.getTariffName()!=tariff_name:
         if not isValidName(tariff_name):
             raise GeneralException(errorText("VOIP_TARIFF","BAD_TARIFF_NAME")%tariff_name)
     
         if tariff_main.getLoader().tariffNameExists(tariff_name):
             raise GeneralException(errorText("VOIP_TARIFF","TARIFF_NAME_ALREADY_EXISTS")%tariff_name)
Ejemplo n.º 13
0
    def __leafCheckName(self, leaf_name):
        if bw_main.getLoader().leafNameExists(leaf_name):
            raise GeneralException(
                errorText("BANDWIDTH", "LEAF_NAME_ALREADY_EXISTS") % leaf_name)

        if not isValidName(leaf_name):
            raise GeneralException(
                errorText("BANDWIDTH", "INVALID_LEAF_NAME") % leaf_name)
Ejemplo n.º 14
0
    def checkAdminID(self, admin_id):
        if not isInt(admin_id):
            raise GeneralException(
                errorText("ADMIN", "ADMIN_ID_INVALID") % admin_id)

        if not self.admins_id.has_key(admin_id):
            raise GeneralException(
                errorText("ADMIN", "ADMIN_ID_INVALID") % admin_id)
Ejemplo n.º 15
0
    def __updateTariffCheckInput(self,tariff_id,tariff_name,comment):
	tariff_obj=tariff_main.getLoader().getTariffByID(tariff_id)
	if tariff_obj.getTariffName()!=tariff_name:
	    if not isValidName(tariff_name):
	        raise GeneralException(errorText("VOIP_TARIFF","BAD_TARIFF_NAME")%tariff_name)
	
	    if tariff_main.getLoader().tariffNameExists(tariff_name):
		raise GeneralException(errorText("VOIP_TARIFF","TARIFF_NAME_ALREADY_EXISTS")%tariff_name)
Ejemplo n.º 16
0
    def __addGroupCheckInput(self,group_name,comment,owner_id):
	if not isValidName(group_name):
	    raise GeneralException(errorText("GROUPS","GROUP_NAME_INVALID")%group_name)

	if group_main.getLoader().groupNameExists(group_name):
	    raise GeneralException(errorText("GROUPS","GROUP_NAME_TAKEN")%group_name)	
	
	admin_main.getLoader().checkAdminID(owner_id)
Ejemplo n.º 17
0
 def __createCheckAddReturnDic(self, bad_usernames, exist_usernames):
     ret = {}
     if len(bad_usernames) != 0:
         ret[errorText("USER_ACTIONS", "BAD_VOIP_USERNAME", False) %
             ""] = bad_usernames
     if len(exist_usernames) != 0:
         ret[errorText("USER_ACTIONS", "VOIP_USERNAME_EXISTS", False) %
             ""] = exist_usernames
     return ret
Ejemplo n.º 18
0
 def __checkDeleteValue(self, admin_obj, admin_perm_obj, perm_value):
     perm_obj = admin_perm_obj.getPermObj()
     if perm_obj.getValueType() != "MULTIVALUE":
         raise GeneralException(
             errorText("PERMISSION", "NO_VALUE_TO_DELETE"))
     if perm_value not in admin_perm_obj.getValue():
         raise GeneralException(
             errorText("PERMISSION", "PERMISSION_NOT_HAVE_THIS_VALUE") %
             perm_value)
Ejemplo n.º 19
0
    def __addNewPoolCheckInput(self, ippool_name, comment):
        if not isValidName(ippool_name):
            raise GeneralException(
                errorText("IPPOOL", "BAD_IP_POOL_NAME") % ippool_name)

        if ippool_main.getLoader().ippoolNameExists(ippool_name):
            raise GeneralException(
                errorText("IPPOOL", "IP_POOL_NAME_ALREADY_EXISTS") %
                ippool_name)
Ejemplo n.º 20
0
def checkFromTo(_from,to):
	if not isInt(_from) or _from<0:
	    raise GeneralException(errorText("GENERAL","FROM_VALUE_INVALID")%_from)

	if not isInt(to) or to<0 or to>1024*1024*50:
	    raise GeneralException(errorText("GENERAL","TO_VALUE_INVALID")%to)
	
	if _from>to or to-_from>3000:
	    raise GeneralException(errorText("GENERAL","TO_VALUE_INVALID")%to)
Ejemplo n.º 21
0
    def __addDestinationToFastDialCheckInput(self, voip_username, destination,
                                             _index):
        if not destination.isdigit():
            raise GeneralException(
                errorText("USER_ACTIONS", "INVALID_DESTINATION") % destination)

        if not isInt(_index) or _index < 0 or _index > 9:
            raise GeneralException(
                errorText("USER_ACTIONS", "INVALID_FAST_DIAL_INDEX") % _index)
Ejemplo n.º 22
0
 def __delUserCheckInput(self, user_ids, comment, del_connections,
                         del_audit_logs, admin_name, remote_address):
     admin_main.getLoader().checkAdminName(admin_name)
     if not iplib.checkIPAddr(remote_address):
         raise GeneralException(
             errorText("GENERAL", "INVALID_IP_ADDRESS") % remote_address)
     if len(user_ids) == 0:
         raise GeneralException(
             errorText("USER_ACTIONS", "INVALID_USER_COUNT") % 0)
Ejemplo n.º 23
0
    def __changeDepositCheckInput(self,changer_admin_name,admin_name,deposit_change,comment,remote_addr):
	self.__getAdminLoader().checkAdminName(changer_admin_name)
	self.__getAdminLoader().checkAdminName(admin_name)
	
	if not isFloat(deposit_change):
	    raise GeneralException(errorText("ADMIN","DEPOSIT_SHOULD_BE_FLOAT"))
	
	if not iplib.checkIPAddr(remote_addr):
	    raise GeneralException(errorText("GENERAL","INVALID_IP_ADDRESS")%remote_addr)
Ejemplo n.º 24
0
 def __addInterfaceCheckInput(self, interface_name, comment):
     if bw_main.getLoader().interfaceNameExists(interface_name):
         raise GeneralException(
             errorText("BANDWIDTH", "INTERFACE_NAME_ALREADY_EXISTS") %
             interface_name)
     if not isValidName(interface_name):
         raise GeneralException(
             errorText("BANDWIDTH", "INVALID_INTERFACE_NAME") %
             interface_name)
Ejemplo n.º 25
0
def checkFromTo(_from, to):
    if not isInt(_from) or _from < 0:
        raise GeneralException(
            errorText("GENERAL", "FROM_VALUE_INVALID") % _from)

    if not isInt(to) or to < 0 or to > 1024 * 1024 * 50:
        raise GeneralException(errorText("GENERAL", "TO_VALUE_INVALID") % to)

    if _from > to or to - _from > 3000:
        raise GeneralException(errorText("GENERAL", "TO_VALUE_INVALID") % to)
Ejemplo n.º 26
0
    def __updateGroupCheckInput(self,group_id,group_name,comment,owner_name):
	group_obj=group_main.getLoader().getGroupByID(group_id)
	if group_obj.getGroupName()!=group_name:
	    if group_main.getLoader().groupNameExists(group_name):
		raise GeneralException(errorText("GROUPS","GROUP_NAME_TAKEN")%group_name)	

	    if not isValidName(group_name):
	        raise GeneralException(errorText("GROUPS","GROUP_NAME_INVALID")%group_name)

	admin_main.getLoader().checkAdminName(owner_name)
Ejemplo n.º 27
0
    def __checkStartEnd(self,start,end):
	"""
	    check start and end varibales
	"""
	
	if end<=start:
	    raise GeneralException(errorText("GENERAL","RANGE_END_LESS_THAN_START")%self.raw_range)
    
	if start-end>1024*1024:
	    raise GeneralException(errorText("GENERAL","RANGE_IS_TOO_LARGE")%self.raw_range)	
Ejemplo n.º 28
0
    def changeInit(self,multi_login):
	try:
	    self.multi_login=int(multi_login)
	except:
	    raise GeneralException(errorText("USER_ACTIONS","INVALID_MULTI_LOGIN"))

	if self.multi_login < 0 or self.multi_login > 255:
	    raise GeneralException(errorText("USER_ACTIONS","INVALID_MULTI_LOGIN"))

	self.useGenerateQuery({"multi_login":self.multi_login})
Ejemplo n.º 29
0
    def check(self, admin_obj, admin_perm_obj, group_name):
        if admin_perm_obj.getValue(
        ) == "All" and not admin_obj.canUseGroup(group_name):
            raise GeneralException(
                errorText("GROUPS", "GROUP_CHANGE_DENIED") % group_name)

        elif group_main.getLoader().getGroupByName(
                group_name).getOwnerID() != admin_obj.getAdminID():
            raise GeneralException(
                errorText("GROUPS", "GROUP_CHANGE_DENIED") % group_name)
Ejemplo n.º 30
0
 def s_login(self, ras_msg):
     if ras_msg.hasAttr("caller_id"):
         for pattern in self.caller_id_patterns:
             if pattern.search(ras_msg["caller_id"]):
                 return
         raise LoginException(
             errorText("USER_LOGIN", "LOGIN_FROM_THIS_CALLER_ID_DENIED"))
     elif not self.allow_no_caller_id:
         raise LoginException(
             errorText("USER_LOGIN", "LOGIN_FROM_THIS_CALLER_ID_DENIED"))
Ejemplo n.º 31
0
    def __updatePoolCheckInput(self,ippool_id,ippool_name,comment):
	ippool_main.getLoader().checkIPpoolID(ippool_id)

	ippool_obj=ippool_main.getLoader().getIPpoolByID(ippool_id)
	if ippool_obj.getIPpoolName()!=ippool_name:
	    if not isValidName(ippool_name):
		raise GeneralException(errorText("IPPOOL","BAD_IP_POOL_NAME")%ippool_name)
	
	    if ippool_main.getLoader().ippoolNameExists(ippool_name):
		raise GeneralException(errorText("IPPOOL","IP_POOL_NAME_ALREADY_EXISTS")%ippool_name)
Ejemplo n.º 32
0
    def __addGroupCheckInput(self, group_name, comment, owner_id):
        if not isValidName(group_name):
            raise GeneralException(
                errorText("GROUPS", "GROUP_NAME_INVALID") % group_name)

        if group_main.getLoader().groupNameExists(group_name):
            raise GeneralException(
                errorText("GROUPS", "GROUP_NAME_TAKEN") % group_name)

        admin_main.getLoader().checkAdminID(owner_id)
Ejemplo n.º 33
0
    def login(self,ras_msg):
	if self.user_obj.instances>self.multi_login:
	    raise LoginException(errorText("USER_LOGIN","MAX_CONCURRENT"))

	if ras_msg.hasAttr("multi_login"):
	    self.multilogin_allowed.append(ras_msg["multi_login"])
	else:
	    self.multilogin_allowed.append(True)
	
	if False in self.multilogin_allowed and self.user_obj.instances>1:
	    raise LoginException(errorText("USER_LOGIN","RAS_DOESNT_ALLOW_MULTILOGIN"))
Ejemplo n.º 34
0
    def __changePermValue(self,admin_obj,perm_name,perm_value):
	perm_obj=perm_loader.getLoader()[perm_name]
	if perm_obj.getValueType()=="MULTIVALUE":
	    admin_perm_obj=admin_obj.getPerms()[perm_name]
	    if admin_perm_obj.multi_value.hasValue(perm_value):
		raise GeneralException(errorText("PERMISSION","PERMISSION_ALREADY_HAS_VALUE")%(perm_name,perm_value)) 
	    perm_value=admin_perm_obj.multi_value.addNewValue(perm_value)
	elif perm_obj.getValueType()=="NOVALUE":
	    raise GeneralException(errorText("PERMISSION","ALREADY_HAS_PERMISSION")%perm_name) #this is really there's no value to change
	    
	self.__changePermValueDB(admin_obj,perm_name,perm_value)
Ejemplo n.º 35
0
    def __chargeRuleCheckInput(self,charge_name,charge_type,ras_id,ports):
	"""
	    check ChargeRule inputs and raise an exception on bad input
	"""
	charge_obj=charge_main.getLoader().getChargeByName(charge_name)
	if charge_obj.getType()!=charge_type:
	    raise GeneralException(errorText("CHARGES","ANOTHER_CHARGE_TYPE_REQUIRED")%charge_type)
	if ras_id!=charge_rule.ChargeRule.ALL:
	    ras_main.getLoader().checkRasID(ras_id)
	    if len(ports)==0:
		raise GeneralException(errorText("CHARGES","NO_PORT_SELECTED"))
Ejemplo n.º 36
0
    def __addNewAdminCheckInput(self,username,password,name,comment,creator_id):
	if not self.__getAdminLoader().adminNameAvailable(username):
	    raise GeneralException(errorText("ADMIN","ADMIN_USERNAME_TAKEN")%username)
	    
	if self.__checkAdminUserChars(username) != 1:
	    raise GeneralException(errorText("ADMIN","BAD_USERNAME")%username)

	if password.checkPasswordChars() != 1:
	    raise GeneralException(errorText("ADMIN","BAD_PASSWORD"))
	
	self.__getAdminLoader().checkAdminID(creator_id)
Ejemplo n.º 37
0
    def __checkFastDialString(self, fast_dial_numbers):

        if len(fast_dial_numbers) != 10:
            raise GeneralException(
                errorText("USER_ACTIONS", "INVALID_FAST_DIAL"))

        for number in fast_dial_numbers:
            if number != "" and not number.isdigit():
                raise GeneralException(
                    errorText("USER_ACTIONS", "INVALID_FAST_DIAL_ENTRY") %
                    number)
Ejemplo n.º 38
0
    def __getDateInSeconds(self, date, date_unit):
        try:
            date = float(date)
        except ValueError:
            raise GeneralException(errorText("GENERAL", "INVALID_DATE") % date)

        try:
            return self.unit_table[date_unit] * date
        except KeyError:
            raise GeneralException(
                errorText("GENERAL", "INVALID_DATE_UNIT") % date_unit)
Ejemplo n.º 39
0
    def __changeDepositCheckInput(self, changer_admin_name, admin_name,
                                  deposit_change, comment, remote_addr):
        self.__getAdminLoader().checkAdminName(changer_admin_name)
        self.__getAdminLoader().checkAdminName(admin_name)

        if not isFloat(deposit_change):
            raise GeneralException(
                errorText("ADMIN", "DEPOSIT_SHOULD_BE_FLOAT"))

        if not iplib.checkIPAddr(remote_addr):
            raise GeneralException(
                errorText("GENERAL", "INVALID_IP_ADDRESS") % remote_addr)
Ejemplo n.º 40
0
    def __getDateInSeconds(self,date,date_unit):
	unit_table={"minutes":60,"hours":3600,"days":24*3600,"months":24*3600*30,"years":24*3600*30*365}

	try:
	    date=float(date)
	except ValueError:	
    	    raise GeneralException(errorText("GENERAL","INVALID_DATE")%date)

	try:
	    return unit_table[date_unit]*date
	except KeyError:
	    raise GeneralException(errorText("GENERAL","INVALID_DATE_UNIT")%date_unit)
Ejemplo n.º 41
0
    def login(self, ras_msg):
        if self.user_obj.instances > self.multi_login:
            raise LoginException(errorText("USER_LOGIN", "MAX_CONCURRENT"))

        if ras_msg.hasAttr("multi_login"):
            self.multilogin_allowed.append(ras_msg["multi_login"])
        else:
            self.multilogin_allowed.append(True)

        if False in self.multilogin_allowed and self.user_obj.instances > 1:
            raise LoginException(
                errorText("USER_LOGIN", "RAS_DOESNT_ALLOW_MULTILOGIN"))
Ejemplo n.º 42
0
    def changeInit(self, multi_login):
        try:
            self.multi_login = int(multi_login)
        except ValueError:
            raise GeneralException(
                errorText("USER_ACTIONS", "INVALID_MULTI_LOGIN"))

        if self.multi_login < 0 or self.multi_login > 255:
            raise GeneralException(
                errorText("USER_ACTIONS", "INVALID_MULTI_LOGIN"))

        self.useGenerateQuery({"multi_login": self.multi_login})
Ejemplo n.º 43
0
    def __delIPfromPoolCheckInput(self, ippool_name, ips):
        ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name)

        for ip in ips:
            self.__checkIPAddr(ip)

            if not ippool_obj.hasIP(ip):
                raise GeneralException(
                    errorText("IPPOOL", "IP_NOT_IN_POOL") % ip)

            if ippool_obj.isIPUsed(ip):
                raise GeneralException(errorText("IPPOOL", "IP_IS_USED") % ip)
Ejemplo n.º 44
0
    def __updateChargeCheckInput(self,charge_id,name,comment,visible_to_all):
	"""
	    check inputs of changeChargeInfo
    	    raise an exception on bad input
	"""
	charge_obj=charge_main.getLoader().getChargeByID(charge_id)
	checkDBBool(visible_to_all,"Visible To All")
	if charge_obj.getChargeName() != name and charge_main.getLoader().chargeNameExists(name):
		raise GeneralException(errorText("CHARGES","CHARGE_NAME_EXISTS") % name)

	if not isValidName(name):
	    raise GeneralException(errorText("CHARGES","INVALID_CHARGE_NAME") % name)
Ejemplo n.º 45
0
    def __leafCheckRates(self,default_rate_kbits,default_ceil_kbits,total_rate_kbits,total_ceil_kbits):
	self.__checkLimitKbits(default_rate_kbits)
	self.__checkLimitKbits(default_ceil_kbits)

	if not isInt(total_rate_kbits):
	    raise GeneralException(errorText("BANDWIDTH","INVALID_TOTAL_LIMIT_KBITS")%total_rate_kbits)

	if not isInt(total_ceil_kbits):
	    raise GeneralException(errorText("BANDWIDTH","INVALID_TOTAL_LIMIT_KBITS")%total_ceil_kbits)
	
	if total_rate_kbits*total_ceil_kbits<0:
	    raise GeneralException(errorText("BANDWIDTH","INVALID_TOTAL_LIMIT_KBITS")%"%s,%s"%(total_rate_kbits,total_ceil_kbits))
Ejemplo n.º 46
0
    def changeInit(self, mail_quota):
        try:
            mail_quota = int(mail_quota)
        except ValueError:
            raise GeneralException(
                errorText("USER_ACTIONS", "MAIL_QUOTA_NOT_INTEGER"))

        if mail_quota <= 0:
            raise GeneralException(
                errorText("USER_ACTIONS", "MAIL_QUOTA_NOT_INTEGER"))

        self.useGenerateQuery({"mail_quota": mail_quota})
Ejemplo n.º 47
0
    def __addChargeCheckInput(self,name,comment,charge_type,admin_id,visible_to_all):
	"""
	    check addCharge inputs validity
	    raise exception on bad input
	"""
	admin_main.getLoader().checkAdminID(admin_id)
	checkDBBool(visible_to_all,"Visible to all")
	self.__checkChargeType(charge_type)
	if charge_main.getLoader().chargeNameExists(name):
	    raise GeneralException(errorText("CHARGES","CHARGE_NAME_EXISTS") % name)
	
	if not isValidName(name):
	    raise GeneralException(errorText("CHARGES","INVALID_CHARGE_NAME") % name)
Ejemplo n.º 48
0
    def __addNewUsersCheckInput(self,_count,credit,owner_name,creator_name,group_name,remote_address,credit_change_comment):
	if not isInt(_count) or _count<=0:
	    raise GeneralException(errorText("USER_ACTIONS","INVALID_USER_COUNT")%_count)
	
	if not isFloat(credit):
	    raise GeneralException(errorText("USER_ACTIONS","CREDIT_NOT_FLOAT"))

	if credit<0:
	    raise GeneralException(errorText("USER_ACTIONS","CREDIT_MUST_BE_POSITIVE"))
	
	admin_main.getLoader().checkAdminName(owner_name)
	admin_main.getLoader().checkAdminName(creator_name)
	group_main.getLoader().checkGroupName(group_name)
Ejemplo n.º 49
0
    def __updatePrefixCheckInput(self,tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to,min_chargable_duration):
        tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
        
        if not tariff_obj.hasPrefixID(prefix_id):
            raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_ID")%(tariff_obj.getTariffName(),prefix_id))

        if tariff_obj.getPrefixByID(prefix_id).getPrefixCode()!=prefix_code and tariff_obj.hasPrefixCode(prefix_code):
            raise GeneralException(errorText("VOIP_TARIFF","PREFIX_CODE_ALREADY_EXIST")%(prefix_code,tariff_obj.getTariffName()))
                
        errs=[]
        self.__checkPrefix(prefix_code,prefix_name,cpm,free_second,min_duration,round_to,min_chargable_duration,errs,1)
        if errs:
            raise GeneralException("\n".join(errs))
Ejemplo n.º 50
0
    def __updatePrefixCheckInput(self,tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to):
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	
	if not tariff_obj.hasPrefixID(prefix_id):
	    raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_ID")%(tariff_obj.getTariffName(),prefix_id))

	if tariff_obj.getPrefixByID(prefix_id).getPrefixCode()!=prefix_code and tariff_obj.hasPrefixCode(prefix_code):
	    raise GeneralException(errorText("VOIP_TARIFF","PREFIX_CODE_ALREADY_EXIST")%(prefix_code,tariff_obj.getTariffName()))
		
	errs=[]
	self.__checkPrefix(prefix_code,prefix_name,cpm,free_second,min_duration,round_to,errs,1)
	if errs:
	    raise GeneralException("\n".join(errs))
Ejemplo n.º 51
0
    def __checkStartEnd(self, start, end):
        """
            check start and end varibales
        """

        if end <= start:
            raise GeneralException(
                errorText("GENERAL", "RANGE_END_LESS_THAN_START") %
                self.raw_range)

        if start - end > 1024 * 1024:
            raise GeneralException(
                errorText("GENERAL", "RANGE_IS_TOO_LARGE") % self.raw_range)
Ejemplo n.º 52
0
    def __addNewRasCheckInput(self,ras_ip,ras_type,radius_secret):
	if not iplib.checkIPAddrWithoutMask(ras_ip):
	    raise GeneralException(errorText("RAS","INVALID_RAS_IP")%ras_ip)

	if ras_main.getLoader().rasIPExists(ras_ip):
	    raise GeneralException(errorText("RAS","RAS_IP_ALREADY_EXISTS")%ras_ip)

	if self.__rasIPExistsInDB(ras_ip):
	    raise GeneralException(errorText("RAS","RAS_IS_INACTIVE")%ras_ip)


	if not ras_main.getFactory().hasType(ras_type):
	    raise GeneralException(errorText("RAS","RAS_TYPE_NOT_REGISTERED")%ras_type)
Ejemplo n.º 53
0
    def __checkFilter(self,_filter,filter_type,filter_value,protocol):
	if filter_type in ["sport","dport"] and protocol in ["tcp","udp"]:
	    for port in filter_value.split(","):
		try:
		    port=int(port)
		    if port>65536 or port<0:
		        raise GeneralException(errorText("BANDWIDTH","INVALID_FILTER")%_filter)
		except ValueError:
		    raise GeneralException(errorText("BANDWIDTH","INVALID_FILTER")%_filter)
		
	elif sp[0] == "icmp-type" and protocol == "icmp":
	    pass
	else:
	    raise GeneralException(errorText("BANDWIDTH","INVALID_FILTER")%_filter)
Ejemplo n.º 54
0
    def __changeCreditCheckInput(self,user_ids,credit,changer_admin_name,remote_address,credit_change_comment,loaded_users):
	if not isFloat(credit):
	    raise GeneralException(errorText("USER_ACTIONS","CREDIT_NOT_FLOAT"))

	admin_main.getLoader().checkAdminName(changer_admin_name)

	if not iplib.checkIPAddr(remote_address):
	    raise GeneralException(errorText("GENERAL","INVALID_IP_ADDRESS")%remote_address)

	if len(user_ids)==0:
	    raise GeneralException(errorText("USER_ACTIONS","INVALID_USER_COUNT")%0)

	for loaded_user in loaded_users:
	    if credit<0 and loaded_user.getBasicUser().getCredit()+credit<0:
		raise GeneralException(errorText("USER_ACTIONS","CAN_NOT_NEGATE_CREDIT")%(loaded_user.getUserID(),loaded_user.getBasicUser().getCredit()))
Ejemplo n.º 55
0
    def checkIPpoolName(self,ippool_name):
	"""
	    check if pool with name "ippool_name" exists
	    raise a GeneralException if not
	"""
	if not self.pool_names.has_key(ippool_name):
	    raise GeneralException(errorText("IPPOOL","INVALID_IP_POOL_NAME")%ippool_id)
Ejemplo n.º 56
0
    def __checkChargeRuleInCharge(self,charge_rule_id,charge_name):
	"""
	    check if charge rule with id "charge_rule_id" is in charge with name "charge_name"
	    raise a GeneralException if it isn't
	"""
	if charge_rule_id not in charge_main.getLoader().getChargeByName(charge_name).getRules():
	    raise GeneralException(errorText("CHARGES","CHARGE_RULE_NOT_IN_CHARGE")%(charge_rule_id,charge_name))
Ejemplo n.º 57
0
    def __checkDateValues(self,year,month,day,hour,minute,second):
	"""
	    check date values and ranges
	"""
	if year<1200 or year > 2500 or month<1 or month>12 or day<1 or day>31 or hour <0 or hour >= 24 or \
	   minute<0 or minute>=60 or second<0 or second>=60:
	    raise GeneralException(errorText("GENERAL","INVALID_DATE")%self.date)
Ejemplo n.º 58
0
    def __createNodeObj(self,node_id):
	try:
    	    node_info=self.__getNodeInfoDB(node_id)
	except IndexError:
	    raise GeneralException(errorText("BANDWIDTH","NODE_ID_NOT_FOUND")%node_id)

	return Node(node_info["node_id"],node_info["parent_id"],node_info["interface_id"],node_info["rate_kbits"],node_info["ceil_kbits"])
Ejemplo n.º 59
0
    def __savePermsOfAdminToTemplateCheckInput(self,admin_username,template_name):
	admin_main.getLoader().checkAdminName(admin_username)

	if not len(template_name) or not template_name.isalnum():
	    raise GeneralException(errorText("PERMISSION","INVALID_PERM_TEMPLATE_NAME")%template_name)

	self.__checkDuplicateTemplateName(template_name)
Ejemplo n.º 60
0
    def s_canStayOnline(self):
	result=self.createCanStayOnlineResult()
	if self.__isAbsExpired():
	    result.setKillForAllInstances(errorText("USER_LOGIN","ABS_EXP_DATE_REACHED",False),self.user_obj.instances)
	else:
	    result.newRemainingTime(self.abs_exp_date-time.time())
	return result