]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/roundcube_db.rb
3 require 'common/plugin'
12 cfg
= Configuration
.new()
13 @db_host = cfg
.roundcube_dbhost
14 @db_port = cfg
.roundcube_dbport
15 @db_opts = cfg
.roundcube_dbopts
16 @db_tty = cfg
.roundcube_dbtty
17 @db_name = cfg
.roundcube_dbname
18 @db_user = cfg
.roundcube_dbuser
19 @db_pass = cfg
.roundcube_dbpass
23 def describe_domain(domain
)
24 # Roundcube doesn't have a concept of domains.
28 def describe_account(account
)
29 user_id
= self.get_user_id(account
)
32 return 'User not found'
34 return "User ID: #{user_id}"
38 def delete_domain(domain
)
39 # Roundcube doesn't have a concept of domains.
42 def delete_account(account
)
43 # Delete the given username and any records in other tables
45 user_id
= self.get_user_id(account
)
47 # The Roundcube developers were nice enough to include
48 # DBMS-specific install and upgrade scripts, so Postgres can take
49 # advantage of ON DELETE triggers. Here's an example:
52 # user_id integer NOT NULL
53 # REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE
55 # This query is of course necessary with any DBMS:
56 sql_queries
= ['DELETE FROM users WHERE user_id = $1::int;']
59 connection
= PGconn
.connect(@db_host,
67 sql_queries
.each
do |sql_query
|
68 connection
.query(sql_query
, [user_id
])
74 # Pretend like we're database-agnostic in case we ever are.
75 raise DatabaseError
.new(e
)
81 def get_leftover_domains(db_domains
)
82 # Roundcube doesn't have a concept of domains.
87 def get_leftover_accounts(db_accounts
)
88 # Get a list of all users who have logged in to Roundcube.
89 rc_accounts
= self.get_roundcube_usernames()
90 return rc_accounts
- db_accounts
96 def get_user_id(account
)
100 connection
= PGconn
.connect(@db_host,
108 sql_query
= "SELECT user_id FROM users WHERE username = $1;"
110 connection
.query(sql_query
, [account
]) do |result
|
111 if result
.num_tuples
> 0
112 user_id
= result
[0]['user_id']
119 # Pretend like we're database-agnostic in case we ever are.
120 raise DatabaseError
.new(e
)
128 def get_roundcube_usernames()
131 # Just assume PostgreSQL for now.
133 connection
= PGconn
.connect(@db_host,
141 sql_query
= "SELECT username FROM users;"
142 connection
.query(sql_query
) do |result
|
143 usernames
= result
.field_values('username')
148 # Pretend like we're database-agnostic in case we ever are.
149 raise DatabaseError
.new(e
)