diff options
-rw-r--r-- | app/controllers/call_routes_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/sip_accounts_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 2 | ||||
-rw-r--r-- | app/views/users/_index_core.html.haml | 2 | ||||
-rw-r--r-- | misc/mon_ami/mon_ami_main.py | 9 | ||||
-rw-r--r-- | misc/mon_ami/mysqlr.py | 135 |
6 files changed, 146 insertions, 6 deletions
diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index e5cf56a..528081a 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -92,6 +92,8 @@ class CallRoutesController < ApplicationController account = SipAccount.where(:id => params[:sip_account_id]).first elsif !params[:hunt_group_id].blank? account = HuntGroup.where(:id => params[:hunt_group_id]).first + elsif !params[:fax_account_id].blank? + account = FaxAccount.where(:id => params[:fax_account_id]).first end if account diff --git a/app/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb index 8e88405..32d1210 100644 --- a/app/controllers/sip_accounts_controller.rb +++ b/app/controllers/sip_accounts_controller.rb @@ -10,7 +10,7 @@ class SipAccountsController < ApplicationController def index @sip_accounts = @parent.sip_accounts.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( - :page => @pagination_page_number, + :page => params[:page], :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') ) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 971ce4b..b4ef180 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -10,7 +10,7 @@ class UsersController < ApplicationController def index @users = @parent.users.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( - :page => @pagination_page_number, + :page => params[:page], :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') ) end diff --git a/app/views/users/_index_core.html.haml b/app/views/users/_index_core.html.haml index 78510a2..7038457 100644 --- a/app/views/users/_index_core.html.haml +++ b/app/views/users/_index_core.html.haml @@ -1,4 +1,4 @@ -- cache(['user_table_row_inner_td', I18n.locale, current_user, users.reorder(:updated_at).last, users.count, GsParameter.get('NUMBER_OF_SHOWN_ITEMS')]) do +- cache(['user_table_row_inner_td', I18n.locale, current_user, users.reorder(:updated_at).last, users.first, users.last, GsParameter.get('NUMBER_OF_SHOWN_ITEMS')]) do - if defined?(users.total_pages) = will_paginate users, :renderer => BootstrapPagination::Rails, :previous_label => raw('<i class = "icon-chevron-left"></i>'), :next_label => raw('<i class = "icon-chevron-right"></i>') diff --git a/misc/mon_ami/mon_ami_main.py b/misc/mon_ami/mon_ami_main.py index 72220e5..fe43618 100644 --- a/misc/mon_ami/mon_ami_main.py +++ b/misc/mon_ami/mon_ami_main.py @@ -9,7 +9,7 @@ from signal import signal, SIGHUP, SIGTERM, SIGINT from optparse import OptionParser from freeswitch import FreeswitchEventSocket from mon_ami_server import MonAMIServer -from sqliter import SQLiteR +from mysqlr import MySQLR def signal_handler(signal_number, frame): global event_socket @@ -40,7 +40,7 @@ def user_password_authentication(user_name, password): return True return False - db = SQLiteR(configuration_options.user_db_name) + db = MySQLR(configuration_options.user_db_name, configuration_options.user_db_user, configuration_options.user_db_password) if not db.connect(): lerror('cound not connect to user database "%s"' % configuration_options.user_db_name) return False @@ -53,6 +53,7 @@ def user_password_authentication(user_name, password): return True linfo('user-password authentication failed - user: %s, password: %s' % (user_name, '*' * len(str(password)))) + return False def main(): @@ -76,7 +77,9 @@ def main(): option_parser.add_option("-p", "--port", "--ami-port", action="store", type="int", dest="ami_port", default=5038) # User database - option_parser.add_option("--user-db-name", action="store", type="string", dest="user_db_name", default='/opt/GS5/db/development.sqlite3') + option_parser.add_option("--user-db-name", action="store", type="string", dest="user_db_name", default='gemeinschaft') + option_parser.add_option("--user-db-user", action="store", type="string", dest="user_db_user", default='gemeinschaft') + option_parser.add_option("--user-db-password", action="store", type="string", dest="user_db_password", default='gemeinschaft') option_parser.add_option("--user-db-table", action="store", type="string", dest="user_db_table", default='sip_accounts') option_parser.add_option("--user-db-name-row", action="store", type="string", dest="user_db_name_row", default='auth_name') option_parser.add_option("--user-db-password-row", action="store", type="string", dest="user_db_password_row", default='password') diff --git a/misc/mon_ami/mysqlr.py b/misc/mon_ami/mysqlr.py new file mode 100644 index 0000000..7ddf27a --- /dev/null +++ b/misc/mon_ami/mysqlr.py @@ -0,0 +1,135 @@ +# -*- coding: utf-8 -*- +# MySQL library + +import MySQLdb + +class MySQLR(): + + def __init__(self, database=None, user=None, password='', address='127.0.0.1', port=3306): + self.db_name = database + if (self.db_name == None): + self.db_name = ':memory:' + self.db_conn = None + self.db_cursor = None + self.db_port = int(port) + self.db_address = address + self.db_user = user + self.db_password = password + + def record_factory(self, cursor, row): + record = dict() + for index, column in enumerate(cursor.description): + record[column[0]] = row[index] + return record + + def connect(self, isolation_level = None): + try: + self.db_conn = MySQLdb.connect(host=self.db_address, port=self.db_port, user=self.db_user, passwd=self.db_password, db=self.db_name) + self.db_cursor = self.db_conn.cursor() + except: + return False + + return True + + def disconnect(self): + try: + self.db_nonn.close() + except: + return False + return True + + def execute(self, query, parameters = []): + try: + return self.db_cursor.execute(query, parameters) + except: + return False + + def fetch_row(self): + return self.db_cursor.fetchone() + + def fetch_rows(self): + return self.db_cursor.fetchall() + + def execute_get_rows(self, query, parameters = []): + if (self.execute(query, parameters)): + return self.fetch_rows() + else: + return False + + def execute_get_row(self, query, parameters = []): + query = "%s LIMIT 1" % query + if (self.execute(query, parameters)): + return self.fetch_row() + else: + return False + + def execute_get_value(self, query, parameters = []): + row = self.execute_get_row(query, parameters) + if (row): + return row[0] + else: + return row + + def create_table(self, table, structure, primary_key = None): + columns = list() + for row in structure: + key, value = row.items()[0] + sql_type = "VARCHAR(255)" + sql_key = '' + if (key == primary_key): + sql_key = 'PRIMARY KEY' + type_r = value.split(':', 1) + type_n = type_r[0] + if (type_n == 'integer'): + sql_type = 'INTEGER' + elif (type_n == 'string'): + try: + sql_type = "VARCHAR(%s)" % type_r[1] + except IndexError, e: + sql_type = "VARCHAR(255)" + + columns.append('"%s" %s %s' % (key, sql_type, sql_key)) + + query = 'CREATE TABLE "%s" (%s)' % (table, ', '.join(columns)) + return self.execute(query) + + def save(self, table, row): + keys = row.keys() + query = 'INSERT OR REPLACE INTO "%s" (%s) VALUES (:%s)' % (table, ', '.join(keys), ', :'.join(keys)) + + return self.execute(query, row) + + def find_sql(self, table, rows = None): + values = list() + if (rows): + if (type(rows) == type(list())): + rows_list = rows + else: + rows_list = list() + rows_list.append(rows) + + query_parts = list() + + for row in rows_list: + statements = list() + for key, value in row.items(): + if (value == None): + statements.append("`%s` IS %s" % (key, '%s')) + else: + statements.append("`%s` = %s" % (key, '%s')) + values.append(value) + query_parts.append('(%s)' % ' AND '.join(statements)) + + query = 'SELECT * FROM `%s` WHERE %s' % (table, ' OR '.join(query_parts)) + else: + query = 'SELECT * FROM `%s`' % table + return query, values + + def find(self, table, row = None): + query, value = self.find_sql(table, row) + + return self.execute_get_row(query, value) + + def findall(self, table, row = None): + query, values = self.find_sql(table, row) + return self.execute_get_rows(query, values) |