]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mailshears/plugins/roundcube_db.rb
7d1a037623ecf75092162d7cdf77c30897b7c092
8 cfg
= Configuration
.new()
9 @db_host = cfg
.roundcube_dbhost
10 @db_port = cfg
.roundcube_dbport
11 @db_opts = cfg
.roundcube_dbopts
12 @db_tty = cfg
.roundcube_dbtty
13 @db_name = cfg
.roundcube_dbname
14 @db_user = cfg
.roundcube_dbuser
15 @db_pass = cfg
.roundcube_dbpass
19 def describe_domain(domain
)
20 # Roundcube doesn't have a concept of domains.
24 def describe_account(account
)
25 user_id
= self.get_user_id(account
)
28 return 'User not found'
30 return "User ID: #{user_id}"
34 def delete_domain(domain
)
35 # Roundcube doesn't have a concept of domains.
38 def delete_account(account
)
39 # Delete the given username and any records in other tables
41 user_id
= self.get_user_id(account
)
43 # The Roundcube developers were nice enough to include
44 # DBMS-specific install and upgrade scripts, so Postgres can take
45 # advantage of ON DELETE triggers. Here's an example:
48 # user_id integer NOT NULL
49 # REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE
51 # This query is of course necessary with any DBMS:
52 sql_queries
= ['DELETE FROM users WHERE user_id = $1::int;']
55 connection
= PGconn
.connect(@db_host,
63 sql_queries
.each
do |sql_query
|
64 connection
.query(sql_query
, [user_id
])
70 # Pretend like we're database-agnostic in case we ever are.
71 raise DatabaseError
.new(e
)
77 def get_leftover_domains(db_domains
)
78 # Roundcube doesn't have a concept of domains.
83 def get_leftover_accounts(db_accounts
)
84 # Get a list of all users who have logged in to Roundcube.
85 rc_accounts
= self.get_roundcube_usernames()
86 return rc_accounts
- db_accounts
92 def get_user_id(account
)
96 connection
= PGconn
.connect(@db_host,
104 sql_query
= "SELECT user_id FROM users WHERE username = $1;"
106 connection
.query(sql_query
, [account
]) do |result
|
107 if result
.num_tuples
> 0
108 user_id
= result
[0]['user_id']
115 # Pretend like we're database-agnostic in case we ever are.
116 raise DatabaseError
.new(e
)
124 def get_roundcube_usernames()
127 # Just assume PostgreSQL for now.
129 connection
= PGconn
.connect(@db_host,
137 sql_query
= "SELECT username FROM users;"
138 connection
.query(sql_query
) do |result
|
139 usernames
= result
.field_values('username')
144 # Pretend like we're database-agnostic in case we ever are.
145 raise DatabaseError
.new(e
)