class PbxContext(Base): __tablename__ = 'pbx_contexts' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) customer_id = Column( Integer, ForeignKey('customers.id', onupdate="CASCADE", ondelete="CASCADE")) domain = Column(Unicode(64), unique=True) profile = Column(Unicode(64)) context = Column(Unicode(128)) caller_id_name = Column(Unicode(64)) caller_id_number = Column(Unicode(15)) gateway = Column(Unicode(64), default=u'default') def __init__(self, customer_id=None, domain=None, context=None, gateway=None, profile=None, caller_id_name=None, caller_id_number=None): self.customer_id = customer_id self.domain = domain self.context = context self.gateway = gateway self.profile = profile self.caller_id_name = caller_id_name self.caller_id_number = caller_id_number def by_domain(self, domain=None): return Session.query(PbxContext).filter_by(domain=domain).first()
class VoipPbxServiceProfile(Base): __tablename__ = 'pbx_voip_service_profiles' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) voip_service_id = Column( Integer, ForeignKey('voip_services.id', onupdate='CASCADE', ondelete='CASCADE')) voip_service_policy_id = Column(Integer, default=0) name = Column(Unicode(64)) description = Column(UnicodeText) amount = Column(Numeric) max_extensions_enforced = Column(Boolean, default=False) max_extensions = Column(Integer, default=0) included_extension_minutes_enforced = Column(Boolean, default=False) included_extension_minutes = Column(Integer, default=0) included_pbx_minutes = Column(Integer, default=0) included_pbx_minutes_enforced = Column(Boolean, default=False) can_create_extensions = Column(Boolean, default=True) can_delete_metered_extensions = Column(Boolean, default=True) overage_fee = Column(Numeric) billable_seconds_increment = Column(Integer, default=0) max_virtual_extensions = Column(Integer, default=0) enforce_max_virtual_extensions = Column(Boolean, default=False)
class Ticket(Base): __tablename__ = 'tickets' query = db.query_property() id = Column(Integer, autoincrement=True, primary_key=True) customer_id = Column( Integer, ForeignKey('customers.id', onupdate="CASCADE", ondelete="CASCADE")) opened_by = Column( Integer, ForeignKey('users.id', onupdate="CASCADE", ondelete="CASCADE")) ticket_status_id = Column( Integer, ForeignKey('ticket_statuses.id', onupdate="CASCADE", ondelete="CASCADE")) ticket_priority_id = Column( Integer, ForeignKey('ticket_priorities.id', onupdate="CASCADE", ondelete="CASCADE")) ticket_type_id = Column( Integer, ForeignKey('ticket_types.id', onupdate="CASCADE", ondelete="CASCADE")) created = Column(DateTime, default=datetime.now()) expected_resolve_date = Column(DateTime, default=datetime.now()) subject = Column(Unicode(255), nullable=True) description = Column(UnicodeText, nullable=False) ticket_note = relationship('TicketNote', backref='ticket_notes') ticket_type = relationship('TicketType', backref='ticket_types') ticket_priority = relationship('TicketPriority', backref='ticket_priorities') ticket_status = relationship('TicketStatus', backref='ticket_statuses')
class PbxCallingRule(Base): __tablename__ = 'pbx_calling_rules' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(64))
class PbxCdr(Base): __tablename__ = 'cdr' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) caller_id_name = Column(Unicode(64)) caller_id_number = Column(Unicode(64)) destination_number = Column(Unicode(64)) context = Column(Unicode(64)) start_stamp = Column(DateTime, default=datetime.now()) answer_stamp = Column(DateTime, default=datetime.now()) end_stamp = Column(DateTime, default=datetime.now()) duration = Column(Integer, default=0) billsec = Column(Integer, default=0) hangup_cause = Column(Unicode(128)) uuid = Column(Unicode(64)) bleg_uuid = Column(Unicode(64)) accountcode = Column(Unicode(16)) local_ip_v4 = Column(Unicode(15)) read_codec = Column(Unicode(128)) write_codec = Column(Unicode(128)) call_direction = Column(Unicode(16)) user_id = Column(Unicode(16)) customer_id = Column(Unicode(16)) extension = Column(Unicode(16)) def __repr__(self): return "PbxCdr(%(id)s)" % self.__dict__
class e911StreetType(Base): __tablename__ = 'e911_street_types' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(32))
class PbxGateway(Base): __tablename__ = 'pbx_gateways' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(64), nullable=True) pbx_profile_id = Column( Integer, ForeignKey('pbx_profiles.id', onupdate="CASCADE", ondelete="CASCADE")) username = Column(Unicode(64), nullable=True) password = Column(Unicode(64), nullable=True) proxy = Column(Unicode(64), nullable=True) mask = Column(Unicode(15), default=u'32') register = Column(Boolean, default=False) register_proxy = Column(Unicode(128), nullable=True) register_transport = Column(Unicode(64), default=u"udp") extension = Column(Unicode(64), nullable=True) realm = Column(Unicode(64), nullable=True) from_domain = Column(Unicode(64), nullable=True) from_user = Column(Unicode(32), nullable=True) expire_seconds = Column(Integer, nullable=False, default=600) retry_seconds = Column(Integer, nullable=False, default=30) ping = Column(Unicode(4), default=u"60") context = Column(Unicode(32), default=u"default") caller_id_in_from = Column(Boolean, default=False) contact_params = Column(Unicode(32), nullable=True) rfc5626 = Column(Boolean, default=True) reg_id = Column(Integer, nullable=True, default=1) def __str__(self): return self.name
class CallCenterTier(Base): __tablename__ = 'call_center_tiers' query = Session.query_property() def __init__(self, queue=None, agent=None, state='Waiting', level=None, position=None): self.queue = queue self.agent = agent self.state = state self.level = level self.position = position id = Column(Integer, autoincrement=True, primary_key=True) queue_id = Column( Integer, ForeignKey('call_center_queues.id', onupdate="CASCADE", ondelete="CASCADE")) agent_id = Column( Integer, ForeignKey('call_center_agents.id', onupdate="CASCADE", ondelete="CASCADE")) extension = Column(Unicode(15), nullable=True) queue = Column(Unicode(255)) agent = Column(Unicode(255)) state = Column(Unicode(255)) level = Column(Integer) position = Column(Integer, nullable=False, default=0)
class PbxRegistration(Base): __tablename__ = 'sip_registrations' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) call_id = Column(Unicode(255)) sip_user = Column(Unicode(255)) sip_host = Column(Unicode(255)) presence_hosts = Column(Unicode(255)) contact = Column(Unicode(1024)) status = Column(Unicode(255)) rpid = Column(Unicode(255)) expires = Column(Integer) user_agent = Column(Unicode(255)) server_user = Column(Unicode(255)) server_host = Column(Unicode(255)) profile_name = Column(Unicode(255)) hostname = Column(Unicode(255)) network_ip = Column(Unicode(255)) network_port = Column(Unicode(255)) sip_username = Column(Unicode(255)) sip_realm = Column(Unicode(255)) mwi_user = Column(Unicode(255)) mwi_host = Column(Unicode(255)) orig_server_host = Column(Unicode(255)) orig_hostname = Column(Unicode(255)) sub_host = Column(Unicode(255))
class CallCenterQueue(Base): __tablename__ = 'call_center_queues' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) domain = Column(Unicode(64), default=u"sip.vwna.com") context = Column(Unicode(128), default=u"sip.vwna.com") name = Column(Unicode(64)) audio_type = Column(Integer) audio_name = Column(Unicode(255)) strategy = Column(Unicode(64), default=u'longest-idle-agent') moh_sound = Column(Unicode(255), default=u'local_stream://moh') time_base_score = Column(Unicode(32), default=u'system') max_wait_time = Column(Integer, default=300) max_wait_time_with_no_agent = Column(Integer, default=300) max_wait_time_with_no_agent_reached = Column(Integer, default=90) tier_rules_apply = Column(Boolean, default=False) tier_rule_wait_second = Column(Integer, default=300) tier_rule_wait_multiply_level = Column(Boolean, default=True) tier_rule_agent_no_wait = Column(Boolean, default=True) discard_abandoned_after = Column(Integer, default=300) abandoned_resume_allowed = Column(Boolean, default=False) failed_route_id = Column( Integer, ForeignKey('pbx_routes.id', onupdate="CASCADE", ondelete="CASCADE")) record_calls = Column(Boolean, default=False) announce_position = Column(Boolean, default=False) announce_sound = Column(Unicode(1024)) announce_frequency = Column(Integer, default=60) approx_hold_time = Column(Integer, default=300) def __str__(self): return self.id
class PbxDialog(Base): __tablename__ = 'sip_dialogs' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) call_id = Column(Unicode(255)) uuid = Column(Unicode(255)) sip_to_user = Column(Unicode(255)) sip_to_host = Column(Unicode(255)) sip_from_user = Column(Unicode(255)) sip_from_host = Column(Unicode(255)) contact_user = Column(Unicode(255)) contact_host = Column(Unicode(255)) state = Column(Unicode(255)) direction = Column(Unicode(255)) user_agent = Column(Unicode(255)) profile_name = Column(Unicode(255)) hostname = Column(Unicode(255)) contact = Column(Unicode(255)) presence_id = Column(Unicode(255)) presence_data = Column(Unicode(255)) call_info = Column(Unicode(255)) call_info_state = Column(Unicode(255)) expires = Column(Integer, default=0) status = Column(Unicode(255)) rpid = Column(Unicode(255)) sip_to_tag = Column(Unicode(255)) sip_from_tag = Column(Unicode(255)) rcd = Column(Integer, default=0)
class AdminGroup(Base): __tablename__ = 'admin_groups' query = db.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(64), unique=True, nullable=False) description = Column(UnicodeText) created_date = Column(DateTime, default=datetime.now) admin_users = relationship("AdminUser", secondary=admin_user_groups, backref='admin_groups') @property def permissions(self): perms = [] for perm in self.admin_permissions: perms.append(perm.name) return perms def __init__(self, name, description): self.name = name self.description = description self.created_date = datetime.now() def __repr__(self): return '<AdminGroup: name=%s>' % self.name def __unicode__(self): return self.name
def init_model(engine): """Call me before using any of the tables or classes in the model""" Session.configure(bind=engine) """Call me before using any of the tables or classes in the model""" Session.configure(bind=engine, expire_on_commit=False ) Base.query = Session.query_property() metadata = Base.metadata
class TicketStatus(Base): __tablename__ = 'ticket_statuses' query = db.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(32), default=u'Unknown') description = Column(Unicode(255), default=u'Unknown')
class PbxDeviceManufacturer(Base): __tablename__ = 'pbx_device_manufacturers' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(64)) description = Column(Unicode(128)) supported = Column(Boolean, default=False)
class PbxFax(Base): __tablename__ = 'pbx_faxes' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) context = Column(Unicode(64), default=u'sip.freepybx.org') domain = Column(Unicode(128), default=u'sip.freepybx.org') extension = Column(Unicode(128), nullable=False)
class CrmLeadType(Base): __tablename__ = 'crm_lead_types' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) context = Column(Unicode(64)) name = Column(Unicode(64)) description = Column(Unicode(128))
class CrmLog(Base): __tablename__ = 'crm_logs' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) text = Column(UnicodeText, nullable=False) created = Column(DateTime, default=datetime.date(datetime.now())) user_id = Column(Integer)
class PbxDNC(Base): __tablename__ = 'pbx_dnc' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) context = Column(Unicode(64), nullable=False) domain = Column(Unicode(128), nullable=False) created = Column(DateTime, default=datetime.date(datetime.now())) did = Column(Unicode(20), nullable=False)
class PbxRouteType(Base): __tablename__ = 'pbx_route_types' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(64)) description = Column(Unicode(255)) def __str__(self): return self.id
class CrmGroupMember(Base): __tablename__ = 'crm_group_members' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) context = Column(Unicode(64)) crm_group_id = Column( Integer, ForeignKey('crm_groups.id', onupdate="CASCADE", ondelete="CASCADE")) extension = Column(Unicode(15))
class CrmNote(Base): __tablename__ = 'crm_notes' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) created = Column(DateTime, default=datetime.date(datetime.now())) note = Column(UnicodeText, nullable=False) crm_account_id = Column( Integer, ForeignKey('crm_accounts.id', onupdate="CASCADE", ondelete="CASCADE"))
class AuthorizeNetAccount(Base): __tablename__ = 'authorize_net_accounts' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) customer_id = Column( Integer, ForeignKey('customers.id', onupdate='CASCADE', ondelete='CASCADE')) api_username = Column(Unicode(128)) transaction_id = Column(Unicode(128))
class PbxProfile(Base): __tablename__ = 'pbx_profiles' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(64), nullable=True) odbc_credentials = Column(Unicode(64), nullable=True) manage_presence = Column(Boolean, default=True) presence_db_name = Column(Unicode(64), default=u'share_presence') presence_hosts = Column(UnicodeText, default=u'sip.mydomain.com') send_presence_on_register = Column(Boolean, default=True) delete_subs_on_register = Column(Boolean, default=True) caller_id_type = Column(Unicode(16), default=u'rpid') auto_jitterbuffer_msec = Column(Integer, default=120) apply_inbound_acl = Column(Unicode(64), default=u'gateways') dialplan = Column(Unicode(64), default=u'XML,enum') ext_rtp_ip = Column(Unicode(64), default=u"auto") ext_sip_ip = Column(Unicode(64), default=u"auto") rtp_ip = Column(Unicode(64), default=u"auto") sip_ip = Column(Unicode(64), default=u"auto") sip_port = Column(Integer, nullable=False, default=5060) sql_in_transactions = Column(Boolean, default=False) nonce_ttl = Column(Integer, default=60) use_rtp_timer = Column(Boolean, default=True) rtp_timer_name = Column(Unicode(64), default=u"soft") codec_prefs = Column(Unicode(255), default=u'PCMU,PCMA,G722,G726,H264,H263') inbound_codec_negotiation = Column(Unicode(64), default=u"generous") rtp_timeout_sec = Column(Integer, default=300) rtp_hold_timeout_sec = Column(Integer, default=1800) rfc2833_pt = Column(Integer, default=101) dtmf_duration = Column(Integer, default=100) dtmf_type = Column(Unicode(64), default=u'rfc2833') session_timeout = Column(Integer, default=1800) multiple_registrations = Column(Unicode(64), default=u'contact') vm_from_email = Column(Unicode(64), default=u'*****@*****.**') accept_blind_reg = Column(Boolean, default=False) auth_calls = Column(Boolean, default=True) auth_all_packets = Column(Boolean, default=False) log_auth_failures = Column(Boolean, default=True) disable_register = Column(Boolean, default=False) codec_ms = Column(Integer, default=20) minimum_session_expires = Column(Integer, default=120) email_domain = Column(Unicode(64), default=u'freeswitch.org') def get_gateways(self): return Session.query(PbxGateway).filter_by(pbx_profile_id=self.id) def __str__(self): return "sip profile: %s:%s" % (self.ext_rtp_ip, self.sip_port) def __repr__(self): return u'%r' % self.__dict__
class CustomerNote(Base): __tablename__ = 'customer_notes' query = db.query_property() id = Column(Integer, autoincrement=True, primary_key=True) customer_id = Column( Integer, ForeignKey('customers.id', onupdate="CASCADE", ondelete="CASCADE")) created = Column(DateTime, default=datetime.now()) subject = Column(Unicode(128), nullable=True) note = Column(UnicodeText, nullable=False)
class AdminUser(Base): __tablename__ = 'admin_users' query = db.query_property() id = Column(Integer, autoincrement=True, primary_key=True) username = Column(Unicode(128), unique=True, nullable=False) password = Column(Unicode(32), nullable=False) first_name = Column(Unicode(64), nullable=True) last_name = Column(Unicode(64), nullable=True) last_login = Column(DateTime, default=datetime.now()) remote_addr = Column(Unicode(15), nullable=True) session_id = Column(Unicode(128), nullable=True) active = Column(Boolean, default=True) def __unicode__(self): return self.name or self.username @property def name(self): return self.first_name + ' ' + self.last_name @property def permissions(self): for g in self.admin_groups: perms = g.permissions return perms def __init__(self, username, password, first_name, last_name): self.username = username self.password = password self.first_name = first_name self.last_name = last_name @classmethod def register_login(class_, username, session, request): user = db.query(AdminUser).filter( AdminUser.username == username).first() if user: now = datetime.now() user.last_login = now user.session_id = session.id user.remote_addr = request.environ["HTTP_REMOTE_EU"] db.commit() db.flush() db.remove() def __repr__(self): return "<AdminUser({0},{1},{2},{3},{4},{5},{6},{7},{8})>".format( self.id, self.username, self.password, self.first_name, self.last_name, self.last_login, self.remote_addr, self.session_id, self.active)
class PbxBlacklistedNumber(Base): __tablename__ = 'pbx_blacklisted_numbers' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) domain = Column(Unicode(64), default=u"sip.freepybx.org") context = Column(Unicode(128), default=u"sip.freepybx.org") cid_number = Column(Unicode(15), nullable=False) def __str__(self): return self.id
class PbxAclBlacklist(Base): __tablename__ = 'pbx_acl_blacklist' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(64), nullable=True) ip = Column(Unicode(15), nullable=False) mask = Column(Unicode(15), default=u'24') def __str__(self): return self.name
class CallCenterAgentLog(Base): __tablename__ = 'call_center_agent_logs' query = Session.query_property() id = Column(Integer, autoincrement=True, primary_key=True) agent = Column(Unicode(128), nullable=False) queue = Column(Unicode(128), nullable=False) log_epoch = Column(Integer, default=0) log_type = Column(Integer, default=0) data = Column(Unicode(1024), nullable=False) uuid = Column(Unicode(255))
class Provider(Base): __tablename__ = 'providers' query = db.query_property() def __init__(self, name=None, email=None): self.name = name self.email = email def __composite_values__(self): return [self.name, self.username] def __eq__(self, other): if isinstance(other, Provider): return self.name == other.name and self.username == other.username return False def __ne__(self, other): return not self.__eq__(other) def __repr__(self): return "<Provider({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}>".format( self.id, self.name, self.email, self.address, self.address_2, self.city, self.state, self.zip, self.url, self.tel, self.mobile, self.username, self.password, self.active) id = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(100), nullable=False) email = Column(Unicode(100)) address = Column(Unicode(100)) address_2 = Column(Unicode(100)) city = Column(Unicode(100)) state = Column(Unicode(100)) zip = Column(Unicode(15)) url = Column(Unicode(100)) tel = Column(Unicode(100)) mobile = Column(Unicode(100)) username = Column(Unicode(128), unique=True, nullable=False) password = Column(Unicode(32), nullable=False) active = Column(Boolean, default=True) # Allowed IP... ip = Column(Unicode(15)) def _get_ip(self): return getattr(self, '_ip', None) def _set_ip(self, value): try: self._ip = unpack_ip(value) except: self._ip = value ip = property(_get_ip, _set_ip)
def init_model(engine): """Call me before using any of the tables or classes in the model""" Session.configure(bind=engine) Base.query = Session.query_property() metadata = Base.metadata