]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/postfixadmin_plugin.rb
b14f295031e4ff1178ec114ca483562604d394d4
1 require 'common/plugin'
4 module PostfixadminPlugin
5 # Code that all Postfixadmin plugins (Prune, Rm, Mv...) will
6 # share. That is, we implement the Plugin interface.
10 @db_host = cfg
.postfixadmin_dbhost
11 @db_port = cfg
.postfixadmin_dbport
12 @db_opts = cfg
.postfixadmin_dbopts
13 @db_tty = cfg
.postfixadmin_dbtty
14 @db_name = cfg
.postfixadmin_dbname
15 @db_user = cfg
.postfixadmin_dbuser
16 @db_pass = cfg
.postfixadmin_dbpass
20 def describe_user(user
)
21 # There's no other unique identifier in PostfixAdmin
26 def describe_domain(domain
)
27 # There's no other unique identifier in PostfixAdmin
35 # Just assume PostgreSQL for now.
37 connection
= PGconn
.connect(@db_host,
45 # 'ALL' is a magic domain, and we don't want it.
46 sql_query
= "SELECT domain FROM domain WHERE domain <> 'ALL';"
47 connection
.query(sql_query
) do |result
|
48 domains
= result
.field_values('domain')
52 # But pretend like we're database-agnostic in case we ever are.
53 raise DatabaseError
.new(e
)
63 # Just assume PostgreSQL for now.
65 connection
= PGconn
.connect(@db_host,
73 sql_query
= 'SELECT username FROM mailbox;'
74 connection
.query(sql_query
) do |result
|
75 users
= result
.field_values('username')
79 # But pretend like we're database-agnostic in case we ever are.
80 raise DatabaseError
.new(e
)
87 def list_domains_users(domains
)
90 # Just assume PostgreSQL for now.
92 connection
= PGconn
.connect(@db_host,
100 sql_query
= 'SELECT username FROM mailbox WHERE domain IN $1;'
102 connection
.query(sql_query
, [domains
]) do |result
|
103 usernames
= result
.field_values('username')
108 # Pretend like we're database-agnostic in case we ever are.
109 raise DatabaseError
.new(e
)
118 # Get a list of all aliases, useful for testing.
122 # Just assume PostgreSQL for now.
124 connection
= PGconn
.connect(@db_host,
132 sql_query
= 'SELECT address,goto FROM alias;'
133 results
= connection
.query(sql_query
)
134 results
.each
do |row
|
135 aliases
<< row
# row should be a hash
139 # But pretend like we're database-agnostic in case we ever are.
140 raise DatabaseError
.new(e
)