def changeQuery(self, ibs_query, src, action, **args): admin_obj = args["admin_obj"] users = args["users"] self.__changeCheckInput(users, admin_obj) i = 0 for user_id in users: loaded_user = users[user_id] if loaded_user.hasAttr("persistent_lan_mac"): ras_id = ras_main.getLoader().getRasByIP(self.ras_ip[i]).getRasID() ibs_query += self.__updatePlanUserAttrsQuery(user_id, self.mac[i], self.ip[i], ras_id) self.updated_users.append( ( (ras_id, user_id, self.mac[i], self.ip[i]), ( user_id, loaded_user.getUserAttrs()["persistent_lan_mac"], loaded_user.getUserAttrs()["persistent_lan_ras_id"], ), ) ) else: ras_id = ras_main.getLoader().getRasByIP(self.ras_ip[i]).getRasID() ibs_query += self.__insertPlanUserAttrsQuery(user_id, self.mac[i], self.ip[i], ras_id) self.inserted_users.append((ras_id, user_id, self.mac[i], self.ip[i])) i += 1 return ibs_query
def reActiveRas(self, ras_ip): """ ReActive ras, by setting it's active flag to true """ ras_info = self.__reActiveRasCheckInput(ras_ip) self.__reActiveRasDB(ras_info) ras_main.getLoader().loadRas(ras_info["ras_id"])
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)
def reActiveRas(self,ras_ip): """ ReActive ras, by setting it's active flag to true """ ras_info=self.__reActiveRasCheckInput(ras_ip) self.__reActiveRasDB(ras_info) ras_main.getLoader().loadRas(ras_info["ras_id"])
def __deletePoolCheckInput(self,ippool_name): ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) def checkIPpoolInRas(ras_obj): if ras_obj.hasIPpool(ippool_obj.getIPpoolID()): raise GeneralException(errorText("IPPOOL","IPPOOL_USED_IN_RAS")%ras_obj.getRasIP()) ras_main.getLoader().runOnAllRases(checkIPpoolInRas) self.__checkPoolUsageInUsers(ippool_obj) self.__checkPoolUsageInGroups(ippool_obj)
def addNewRas(self,ras_ip,ras_type,radius_secret): """ ras_ip(string): ip of ras ras_type(string): type of ras, this should perviously registered radius_secret(string): """ self.__addNewRasCheckInput(ras_ip,ras_type,radius_secret) ras_id=self.__getNewRasID() self.__addNewRasDB(ras_id,ras_ip,ras_type,radius_secret) ras_main.getLoader().loadRas(ras_id) return ras_id
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"))
def deActiveRas(self,ras_ip): """ DeActive ras, by setting it's active flag to false Inactive rases, won't load into memory, they are just keep there because other table reference to em """ self.__deActiveRasCheckInput(ras_ip) ras_obj=ras_main.getLoader().getRasByIP(ras_ip) self.__checkRasInCharges(ras_obj) self.__deActiveRasDB(ras_obj) ras_obj.deActivated() ras_main.getLoader().unloadRas(ras_obj.getRasID())
def _HandleAcctPacket(self, fd, pkt): server.Server._HandleAcctPacket(self, fd, pkt) if defs.LOG_RADIUS_REQUESTS: self.__logRequest(pkt,"Accounting") reply=self.CreateReplyPacket(pkt) try: ras_main.getLoader().getRasByIP(pkt.source[0])._handleRadAcctPacket(pkt,reply) except: logException(LOG_ERROR,"HandleAcctPacket exception\n") self.SendReplyPacket(fd, reply)
def __deletePoolCheckInput(self, ippool_name): ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) def checkIPpoolInRas(ras_obj): if ras_obj.hasIPpool(ippool_obj.getIPpoolID()): raise GeneralException( errorText("IPPOOL", "IPPOOL_USED_IN_RAS") % ras_obj.getRasIP()) ras_main.getLoader().runOnAllRases(checkIPpoolInRas) self.__checkPoolUsageInUsers(ippool_obj) self.__checkPoolUsageInGroups(ippool_obj)
def deActiveRas(self, ras_ip): """ DeActive ras, by setting it's active flag to false Inactive rases, won't load into memory, they are just keep there because other table reference to em """ self.__deActiveRasCheckInput(ras_ip) ras_obj = ras_main.getLoader().getRasByIP(ras_ip) self.__checkRasInCharges(ras_obj) self.__checkRasOnlines(ras_obj) self.__deActiveRasDB(ras_obj) ras_obj.deActivated() ras_main.getLoader().unloadRas(ras_obj.getRasID())
def deleteRas(self, ras_ip): """ UNUSED FOR NOW! it's supposed to delete a ras, but we don't need it because we should active/deactive it this is only useful if we check other tables, and if they don't have any reference, we let it delete """ self.__deleteRasCheckInput(ras_ip) ras_obj = ras_main.getLoader().getRasByIP(ras_ip) self.__checkRasInCharges(ras_obj) self.__deleteRasLogicallyDB(ras_obj) ras_main.getLoader().unloadRas(ras_obj.getRasID())
def deleteRas(self,ras_ip): """ UNUSED FOR NOW! it's supposed to delete a ras, but we don't need it because we should active/deactive it this is only useful if we check other tables, and if they don't have any reference, we let it delete """ self.__deleteRasCheckInput(ras_ip) ras_obj=ras_main.getLoader().getRasByIP(ras_ip) self.__checkRasInCharges(ras_obj) self.__deleteRasLogicallyDB(ras_obj) ras_main.getLoader().unloadRas(ras_obj.getRasID())
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"))
def __updateRasCheckInput(self,ras_id,ras_ip,ras_type,radius_secret): 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 not ras_main.getFactory().hasType(ras_type): raise GeneralException(errorText("RAS","RAS_TYPE_NOT_REGISTERED")%ras_type)
def addNewRas(self, ras_ip, ras_description, ras_type, radius_secret, comment): """ ras_ip(string): ip of ras ras_description(string): unique string reperesentation of ras ras_type(string): type of ras, this should perviously registered radius_secret(string): """ self.__addNewRasCheckInput(ras_ip, ras_description, ras_type, radius_secret, comment) ras_id = self.__getNewRasID() self.__addNewRasDB(ras_id, ras_ip, ras_description, ras_type, radius_secret, comment) ras_main.getLoader().loadRas(ras_id) return ras_id
def updateRas(self,ras_id,ras_ip,ras_type,radius_secret): """ update ras info, notice that ras_ip is changable ras_id(integer): ras_id that we want to change properties ras_ip(string): ras_ip ras_type(string): type of ras radius_secret(string): """ self.__updateRasCheckInput(ras_id,ras_ip,ras_type,radius_secret) self.__updateRasDB(ras_id,ras_ip,ras_type,radius_secret) ras_obj=ras_main.getLoader()[ras_id] if ras_obj.getType()==ras_type: self.__reloadRas(ras_main.getLoader()[ras_id],True) else: self.__reloadRas(ras_main.getLoader()[ras_id],True,True)
def getActiveRasIPs(self, request): request.needAuthType(request.ADMIN) creator_obj = request.getAuthNameObj() creator_obj.canDo("LIST RAS") sorted = SortedList(ras_main.getLoader().getAllRasIPs()) sorted.sort(False) return sorted.getList()
def getRasAttributes(self, request): request.needAuthType(request.ADMIN) request.checkArgs("ras_ip") creator_obj = request.getAuthNameObj() creator_obj.canDo("GET RAS INFORMATION") return ras_main.getLoader().getRasByIP( request["ras_ip"]).getAllAttributes()
def __reloadRas(self, ras_obj, unload=False, force_reload=False): """ reload ras_obj if ras_obj.handle_reload is True and force_reload is False, reloading in done by calling _reload method of ras_obj else it will be done by unloading/reloading ras_obj if force_reload is True, it'll unload/reload ras always """ if ras_obj.handle_reload and not force_reload: ras_obj._reload() else: if unload: ras_main.getLoader().unloadRas(ras_obj.getRasID()) ras_main.getLoader().loadRas(ras_obj.getRasID())
def __fixRasIPs(self, db_usages): ras_usages = [] for row in db_usages: ras_ip = ras_main.getLoader().getRasByID(row["ras_id"]).getRasIP() ras_usages.append((ras_ip, row["duration"])) return ras_usages
def getRasInfo(self,request): request.needAuthType(request.ADMIN) creator_obj=request.getAuthNameObj() creator_obj.canDo("GET RAS INFORMATION") request.checkArgs("ras_ip") ras_obj=ras_main.getLoader().getRasByIP(request["ras_ip"]) return ras_obj.getInfo()
def __delPortCheckInput(self,ras_ip,port_names): ras_obj=ras_main.getLoader().getRasByIP(ras_ip) def checkPort(port_name): if not ras_obj.hasPort(port_name): raise GeneralException(errorText("RAS","RAS_DONT_HAVE_PORT")%port_name) map(checkPort,port_names)
def __checkDuplicateOnline(self, ras_msg): """ check if there's any other user online, with this global unique id """ global_unique_id = (ras_msg.getRasID(), ras_msg.getUniqueIDValue()) if self.ras_onlines.has_key(global_unique_id): current_online_user_obj = apply(self.getUserObjByUniqueID, global_unique_id) current_online_user_id = current_online_user_obj.getUserID() getLogConsole().log(current_online_user_obj.getUserRepr(), "Duplicate Login", [("New User", ras_msg.getUserRepr()), ("Ras", ras_main.getLoader().getRasByID( global_unique_id[0]).getRasIP()), ("ID", global_unique_id[1])]) toLog( "User %s logged on %s, while user %s was on it, force logouting %s" % (ras_msg.getUserRepr(), global_unique_id, current_online_user_id, current_online_user_id), LOG_ERROR) self.clearUser(current_online_user_id, global_unique_id[0], global_unique_id[1], \ "Another user logged on this global unique id", False)
def clearUser(self, user_id, ras_id, unique_id, kill_reason, no_commit=True): """ clear instance of user from online if no_commit is true no credit is deducted from user """ user_obj = None self.loading_user.loadingStart(user_id) try: user_obj, instance = self.__getUserAndInstance( user_id, ras_id, unique_id) self.__forceLogoutUser(user_obj, instance, kill_reason, no_commit) finally: self.loading_user.loadingEnd(user_id) if user_obj != None: getLogConsole().log( user_obj.getUserRepr(), "Clear User", [("Ras", ras_main.getLoader().getRasByID(ras_id).getRasIP()), ("ID", unique_id), ("Kill Reason", kill_reason)])
def getActiveRasIPs(self,request): request.needAuthType(request.ADMIN) creator_obj=request.getAuthNameObj() creator_obj.canDo("LIST RAS") sorted=SortedList(ras_main.getLoader().getAllRasIPs()) sorted.sort(False) return sorted.getList()
def __checkStaleOnlines(self, user_obj): instance = user_obj.instances while instance > 0: instance_info = user_obj.getInstanceInfo(instance) user_msg = user_obj.createUserMsg(instance, "IS_ONLINE") if user_msg.send(): instance_info["check_online_fails"] = 0 else: instance_info["check_online_fails"] += 1 if instance_info[ "check_online_fails"] == defs.CHECK_ONLINE_MAX_FAILS: toLog( "Maximum Check Online Fails Reached for user %s" % user_obj.getUserID(), LOG_DEBUG) getLogConsole().log( user_obj.getUserRepr(), "Check Online Fail", [("Ras", ras_main.getLoader().getRasByID( instance_info["ras_id"]).getRasIP()), ("ID", "(%s,%s)" % (instance_info["unique_id"], instance_info["unique_id_val"]))]) self.__forceLogoutUser( user_obj, instance, errorText("USER_LOGIN", "MAX_CHECK_ONLINE_FAILS_REACHED", False)) instance -= 1
def __reloadRas(self,ras_obj,unload=False,force_reload=False): """ reload ras_obj if ras_obj.handle_reload is True and force_reload is False, reloading in done by calling _reload method of ras_obj else it will be done by unloading/reloading ras_obj if force_reload is True, it'll unload/reload ras always """ if ras_obj.handle_reload and not force_reload: ras_obj._reload() else: if unload: ras_main.getLoader().unloadRas(ras_obj.getRasID()) ras_main.getLoader().loadRas(ras_obj.getRasID())
def applyConditions(self): """ Apply conditions on tables, should check conditions here """ print self.search_helper.getConds() con_table=self.search_helper.getTable("connection_log") con_details_table=self.search_helper.getTable("connection_log_details") self.__addUserIDCondition(con_table) con_table.ltgtSearch(self.search_helper,"credit_used","credit_used_op","credit_used") self.search_helper.setCondValue("login_time_from_op",">=") con_table.dateSearch(self.search_helper,"login_time_from","login_time_from_unit","login_time_from_op","login_time") self.search_helper.setCondValue("login_time_to_op","<") con_table.dateSearch(self.search_helper,"login_time_to","login_time_to_unit","<","login_time") self.search_helper.setCondValue("logout_time_from_op",">=") con_table.dateSearch(self.search_helper,"logout_time_from","login_time_from_unit",">=","logout_time") self.search_helper.setCondValue("logout_time_to_op","<") con_table.dateSearch(self.search_helper,"logout_time_to","login_time_to_unit","<","logout_time") con_table.exactSearch(self.search_helper,"successful","successful",lambda yesno:{"yes":"t","no":"f"}[yesno.lower()]) con_table.exactSearch(self.search_helper,"service","service",lambda _type:user_main.getConnectionLogManager().getTypeValue(_type)) con_table.exactSearch(self.search_helper,"ras_ip","ras_id",lambda ras_ip:ras_main.getLoader().getRasByIP(ras_ip).getRasID())
def getFormattedOnlineUsers(date_type): """ return a list of online user dics. return value is a list to be sortable """ onlines_dic=user_main.getOnline().getOnlineUsersByRas() onlines=[] for (ras_id,unique_id) in onlines_dic: user_obj=onlines_dic[(ras_id,unique_id)] try: instance=user_obj.getInstanceFromUniqueID(ras_id,unique_id) if instance==None: continue instance_info=user_obj.getInstanceInfo(instance) report_dic={"user_id":user_obj.getUserID(), "service":user_obj.getType(), "ras_ip":ras_main.getLoader().getRasByID(instance_info["ras_id"]).getRasIP(), "unique_id":instance_info["unique_id"], "unique_id_val":instance_info["unique_id_val"], "login_time":AbsDateFromEpoch(user_obj.getTypeObj().getLoginTime(instance)).getDate(date_type), "login_time_epoch":user_obj.getTypeObj().getLoginTime(instance), "duration_secs":time.time()-user_obj.getTypeObj().getLoginTime(instance), "attrs":instance_info["attrs"], "owner_id":user_obj.getLoadedUser().getBasicUser().getOwnerObj().getAdminID(), "owner_name":user_obj.getLoadedUser().getBasicUser().getOwnerObj().getUsername(), "current_credit":user_obj.calcCurrentCredit() } report_dic.update(user_obj.getTypeObj().getOnlineReportDic(instance)) onlines.append(report_dic) except: logException(LOG_DEBUG) pass return onlines
def getRasPorts(self,request): request.needAuthType(request.ADMIN) request.checkArgs("ras_ip") creator_obj=request.getAuthNameObj() creator_obj.canDo("GET RAS INFORMATION") sorted=SortedList(ras_main.getLoader().getRasByIP(request["ras_ip"]).getPorts().values()) sorted.sortByPostText("[\"port_name\"]",0) return sorted.getList()
def getFormattedOnlineUsers(date_type, onlines_filter): """ return a list of online user dics. format is (normal_list, voip_list) return value is a tuple of lists to be sortable """ onlines_dic=user_main.getOnline().getOnlineUsersByRas() normal_onlines=[] voip_onlines=[] for (ras_id,unique_id) in onlines_dic: user_obj=onlines_dic[(ras_id,unique_id)] try: instance = user_obj.getInstanceFromUniqueID(ras_id,unique_id) if instance == None: #eh? continue #continue if we are not intreseted in this instance if not onlines_filter.filter(user_obj, instance): continue instance_info=user_obj.getInstanceInfo(instance) report_dic={"user_id":user_obj.getUserID(), "service":user_obj.getType(), "ras_ip":ras_main.getLoader().getRasByID(instance_info["ras_id"]).getRasIP(), "ras_description":ras_main.getLoader().getRasByID(instance_info["ras_id"]).getRasDesc(), "unique_id":instance_info["unique_id"], "unique_id_val":instance_info["unique_id_val"], "login_time":AbsDateFromEpoch(user_obj.getTypeObj().getLoginTime(instance)).getDate(date_type), "login_time_epoch":user_obj.getTypeObj().getLoginTime(instance), "duration_secs":time.time()-user_obj.getTypeObj().getLoginTime(instance), "attrs":instance_info["attrs"], "owner_id":user_obj.getLoadedUser().getBasicUser().getOwnerObj().getAdminID(), "owner_name":user_obj.getLoadedUser().getBasicUser().getOwnerObj().getUsername(), "current_credit":user_obj.calcCurrentCredit(), "group_name":user_obj.getLoadedUser().getBasicUser().getGroupObj().getGroupName() } report_dic.update(user_obj.getTypeObj().getOnlineReportDic(instance)) if user_obj.getType() == "VoIP": voip_onlines.append(report_dic) else: normal_onlines.append(report_dic) except: logException(LOG_DEBUG) pass return (normal_onlines, voip_onlines)
def __updateAttributeCheckInput(self,ras_ip,attrs): ras_obj=ras_main.getLoader().getRasByIP(ras_ip) for attr_name in attrs: if ras_obj.getAttribute(attr_name)==None: raise GeneralException(errorText("RAS","RAS_DONT_HAVE_ATTR")%attr_name) if type(ras_obj.getAttribute(attr_name)) == types.IntType: attrs[attr_name]=to_int(attrs[attr_name],"%s Attribute Value"%attr_name)
def _reload(self): """ reload ras_obj only if self.handle_reload==True if it has been set to False, reloading is done by unloading/reloading the object """ (ras_info, ras_attrs, ports, ippools) = ras_main.getLoader().getRasInfo(self.getRasID()) if self.getRasIP() != ras_info["ras_ip"] or self.getRasDesc( ) != ras_info["ras_description"]: ras_main.getLoader().unKeepObj(self) ras_loader_changed = True else: ras_loader_changed = False self.ras_ip = ras_info["ras_ip"] self.ras_description = ras_info["ras_description"] self.ras_id = ras_info["ras_id"] self.ras_type = ras_info["ras_type"] self.comment = ras_info["comment"] self.ports = ports self.ippools = ippools self.attributes = ras_attrs self.radius_secret = ras_info["radius_secret"] ras_main.getLoader().updateRadiusRemoteHost(self.ras_ip, self.radius_secret) if ras_loader_changed: ras_main.getLoader().keepObj(self)
def getRasPorts(self, request): request.needAuthType(request.ADMIN) request.checkArgs("ras_ip") creator_obj = request.getAuthNameObj() creator_obj.canDo("GET RAS INFORMATION") sorted = SortedList(ras_main.getLoader().getRasByIP( request["ras_ip"]).getPorts().values()) sorted.sortByPostText("[\"port_name\"]", 0) return sorted.getList()
def addIPpoolToRas(self,ras_ip,ippool_name): """ add an ippool to ras """ self.__addIPpoolToRasCheckInput(ras_ip,ippool_name) ras_obj=ras_main.getLoader().getRasByIP(ras_ip) ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) self.__addIPpoolToRasDB(ras_obj.getRasID(),ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def __getRasIDsDic(self): """ return a dic in format {ras_id:0} all loaded ras_ids will be added in dic """ _dic = {} for ras_id in ras_main.getLoader().getAllRasIDs(): _dic[ras_id] = 0 return _dic
def delIPpoolFromRas(self,ras_ip,ippool_name): """ delete ippool with name "ippool_name" from ras with ip "ras_ip" """ self.__delIPpoolFromRasCheckInput(ras_ip,ippool_name) ras_obj=ras_main.getLoader().getRasByIP(ras_ip) ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) self.__delIPpoolFromRasDB(ras_obj.getRasID(),ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def delAttributes(self, ras_ip): """ delete all attributes of ras with ip "ras_ip" this is reset to default, as it means ras doesn't have any specific attribute """ self.__delAttributesCheckInput(ras_ip) ras_obj = ras_main.getLoader().getRasByIP(ras_ip) self.__delAttributesDB(ras_obj) self.__reloadRas(ras_obj)
def addIPpoolToRas(self, ras_ip, ippool_name): """ add an ippool to ras """ self.__addIPpoolToRasCheckInput(ras_ip, ippool_name) ras_obj = ras_main.getLoader().getRasByIP(ras_ip) ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) self.__addIPpoolToRasDB(ras_obj.getRasID(), ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def delIPpoolFromRas(self, ras_ip, ippool_name): """ delete ippool with name "ippool_name" from ras with ip "ras_ip" """ self.__delIPpoolFromRasCheckInput(ras_ip, ippool_name) ras_obj = ras_main.getLoader().getRasByIP(ras_ip) ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) self.__delIPpoolFromRasDB(ras_obj.getRasID(), ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def __delPortCheckInput(self, ras_ip, port_names): ras_obj = ras_main.getLoader().getRasByIP(ras_ip) def checkPort(port_name): if not ras_obj.hasPort(port_name): raise GeneralException( errorText("RAS", "RAS_DONT_HAVE_PORT") % port_name) map(checkPort, port_names)
def updateRas(self, ras_id, ras_ip, ras_description, ras_type, radius_secret, comment): """ update ras info, notice that ras_ip is changable ras_id(integer): ras_id that we want to change properties ras_ip(string): ras_ip ras_type(string): type of ras radius_secret(string): """ self.__updateRasCheckInput(ras_id, ras_ip, ras_description, ras_type, radius_secret, comment) self.__updateRasDB(ras_id, ras_ip, ras_description, ras_type, radius_secret, comment) ras_obj = ras_main.getLoader()[ras_id] if ras_obj.getType() == ras_type: self.__reloadRas(ras_main.getLoader()[ras_id], True) else: self.__reloadRas(ras_main.getLoader()[ras_id], True, True)
def delAttributes(self,ras_ip): """ delete all attributes of ras with ip "ras_ip" this is reset to default, as it means ras doesn't have any specific attribute """ self.__delAttributesCheckInput(ras_ip) ras_obj=ras_main.getLoader().getRasByIP(ras_ip) self.__delAttributesDB(ras_obj) self.__reloadRas(ras_obj)
def appliesOnCond(self, conds): if conds.has_key("ras_ips"): conds["ras_ids"] = [] for ras_ip in conds["ras_ips"]: conds["ras_ids"].append(ras_main.getLoader().getRasByIP(ras_ip).getRasID()) return True return False
def __updateAttributeCheckInput(self, ras_ip, attrs): ras_obj = ras_main.getLoader().getRasByIP(ras_ip) for attr_name in attrs: if ras_obj.getAttribute(attr_name) == None: raise GeneralException( errorText("RAS", "RAS_DONT_HAVE_ATTR") % attr_name) if type(ras_obj.getAttribute(attr_name)) == types.IntType: attrs[attr_name] = to_int(attrs[attr_name], "%s Attribute Value" % attr_name)
def getRasDescriptions(self, request): """ return list of tuples in format [(ras_description,ras_ip)] """ request.needAuthType(request.ADMIN) creator_obj = request.getAuthNameObj() creator_obj.canDo("LIST RAS") sorted = SortedDic(ras_main.getLoader().getRasDescToIPMap()) sorted.sortByKey(False) return sorted.getList()
def getRasPortInfo(self,ras_ip,port_names): """ ras_ip(string): ip of ras port_names(Multistr instance): port names, we'll return a dic of port info {"port_name":port_name,"phone":phone_no,"type":type,"comment":comment} """ ras_obj=ras_main.getLoader().getRasByIP(ras_ip) if not ras_obj.hasPort(port_names[0]): raise GeneralException(errorText("RAS","RAS_DONT_HAVE_PORT")%port_names[0]) return ras_obj.getPorts()[port_names[0]]
def run(self): plan_table = self.getSearchHelper().getTable("persistent_lan_users") plan_table.exactSearch(self.getSearchHelper(), "persistent_lan_mac", "persistent_lan_mac", MultiStr) plan_table.exactSearch(self.getSearchHelper(), "persistent_lan_ip", "persistent_lan_ip", MultiStr) plan_table.exactSearch( self.getSearchHelper(), "persistent_lan_ras_ip", "persistent_lan_ras_id", lambda ras_ip: ras_main.getLoader().getRasByIP(ras_ip).getRasID(), )
def getRasIPpools(self,request): """ return a sorted list of ip pool names """ request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("GET RAS INFORMATION") request.checkArgs("ras_ip") ippool_ids=ras_main.getLoader().getRasByIP(request["ras_ip"]).getIPpools() ippool_names=map(lambda ippool_id:ippool_main.getLoader().getIPpoolByID(ippool_id).getIPpoolName(),ippool_ids) sorted=SortedList(ippool_names) sorted.sort(0) return sorted.getList()
def __checkRasAndPortWildcards(self, request): if request["ports"] == "_ALL_": ports = [charge_rule.ChargeRule.ALL] else: ports = requestDicToList(request["ports"]) if request["ras"] == "_ALL_": ras = charge_rule.ChargeRule.ALL else: ras = ras_main.getLoader().getRasByIP(request["ras"]).getRasID() return (ras, ports)
def __checkRasAndPortWildcards(self,request): if request["ports"]=="_ALL_": ports=[charge_rule.ChargeRule.ALL] else: ports=requestDicToList(request["ports"]) if request["ras"]=="_ALL_": ras=charge_rule.ChargeRule.ALL else: ras=ras_main.getLoader().getRasByIP(request["ras"]).getRasID() return (ras,ports)
def init(): global radius_server_started if defs.RADIUS_SERVER_ENABLED==0: return toLog("Initializing IBS Radius Server",LOG_DEBUG) global ibs_dic ibs_dic=dictionary.Dictionary("%s/radius_server/dictionary"%defs.IBS_ROOT) srv=IBSRadiusServer(dict=ibs_dic,addresses=defs.RADIUS_SERVER_BIND_IP,authport=defs.RADIUS_SERVER_AUTH_PORT,acctport=defs.RADIUS_SERVER_ACCT_PORT) srv.hosts=ras_main.getLoader().getRadiusRemoteHosts() thread_main.runThread(srv.Run,[],"radius") radius_server_started=True
def getRasPortInfo(self, ras_ip, port_names): """ ras_ip(string): ip of ras port_names(Multistr instance): port names, we'll return a dic of port info {"port_name":port_name,"phone":phone_no,"type":type,"comment":comment} """ ras_obj = ras_main.getLoader().getRasByIP(ras_ip) if not ras_obj.hasPort(port_names[0]): raise GeneralException( errorText("RAS", "RAS_DONT_HAVE_PORT") % port_names[0]) return ras_obj.getPorts()[port_names[0]]
def getBWSnapShotForUser(self, request): """ real time version """ request.needAuthType(request.ADMIN) request.checkArgs("user_id", "ras_ip", "unique_id_val") requester = request.getAuthNameObj() requester.canDo("SEE REALTIME SNAPSHOTS") return self.__getUserBWValues( to_int(request["user_id"], "user id"), ras_main.getLoader().getRasByIP(request["ras_ip"]).getRasID(), request["unique_id_val"])
def getRasIPpools(self, request): """ return a sorted list of ip pool names """ request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("GET RAS INFORMATION") request.checkArgs("ras_ip") ippool_ids = ras_main.getLoader().getRasByIP( request["ras_ip"]).getIPpools() ippool_names = map( lambda ippool_id: ippool_main.getLoader().getIPpoolByID(ippool_id). getIPpoolName(), ippool_ids) return ippool_names
def __updatePortCheckInput(self,ras_ip,port_names,phones,_type,comments): ras_obj=ras_main.getLoader().getRasByIP(ras_ip) 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) map(checkPort,port_names) if _type not in ras.PORT_TYPES: raise GeneralException(errorText("RAS","INVALID_PORT_TYPE")%_type)
def _reload(self): """ reload ras_obj only if self.handle_reload==True if it has been set to False, reloading is done by unloading/reloading the object """ (ras_info,ras_attrs,ports,ippools)=ras_main.getLoader().getRasInfo(self.getRasID()) if self.ras_ip!=ras_info["ras_ip"]: ras_main.getLoader().unKeepObj(self) ras_ip_changed=True else: ras_ip_changed=False self.ras_ip=ras_info["ras_ip"] self.ras_id=ras_info["ras_id"] self.ras_type=ras_info["ras_type"] self.radius_secret=ras_info["radius_secret"] self.ports=ports self.ippools=ippools self.attributes=ras_attrs if ras_ip_changed: ras_main.getLoader().keepObj(self)
def __repairConnectionsDic(self,connections,details_dic,date_type): for connection in connections: connection["login_time_formatted"]=AbsDate(connection["login_time"],"gregorian").getDate(date_type) connection["logout_time_formatted"]=AbsDate(connection["logout_time"],"gregorian").getDate(date_type) try: connection["ras_ip"]=ras_main.getLoader().getRasByID(connection["ras_id"]).getRasIP() except GeneralException: connection["ras_ip"]="id:%s"%connection["ras_id"] connection["service_type"]=user_main.getConnectionLogManager().getIDType(connection["service"]) try: connection["details"]=details_dic[connection["connection_log_id"]] except KeyError: connection["details"]={} return connections
def getInfo(self): """ return a dictionary of charge rule infos """ if self.ras_id!=self.ALL: ras=ras_main.getLoader().getRasByID(self.ras_id).getRasIP() else: ras=self.ras_id return {"rule_id":self.rule_id, "charge_name":self.charge_obj.getChargeName(), "day_of_weeks":self.day_of_weeks.getDayNames(), "ras":ras, "ports":self.ports, "start_time":self.start_time, "end_time":self.end_time }