]>
gitweb.michael.orlitzky.com - mailshears.git/blob - postfixadmin_plugin.rb
97d59f267214060a7b9824d47338727e29b58b24
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
)
60 def domain_exists(domain
)
61 # Does the given domain exist in Postfixadmin? We use a naive
62 # implementation here based on list_domains(). This isn't in our
63 # superclass because not all plugins have a concept of domains.
64 domains
= list_domains()
65 return domains
.include?(domain
)
72 # Just assume PostgreSQL for now.
74 connection
= PGconn
.connect(@db_host,
82 sql_query
= 'SELECT username FROM mailbox;'
83 connection
.query(sql_query
) do |result
|
84 users
= result
.field_values('username')
88 # But pretend like we're database-agnostic in case we ever are.
89 raise DatabaseError
.new(e
)
96 def list_domains_users(domains
)
99 # Just assume PostgreSQL for now.
101 connection
= PGconn
.connect(@db_host,
109 sql_query
= 'SELECT username FROM mailbox WHERE domain IN $1;'
111 connection
.query(sql_query
, [domains
]) do |result
|
112 usernames
= result
.field_values('username')
117 # Pretend like we're database-agnostic in case we ever are.
118 raise DatabaseError
.new(e
)
127 # Get a list of all aliases, useful for testing.
131 # Just assume PostgreSQL for now.
133 connection
= PGconn
.connect(@db_host,
141 sql_query
= 'SELECT address,goto FROM alias;'
142 results
= connection
.query(sql_query
)
143 results
.each
do |row
|
144 aliases
<< row
# row should be a hash
148 # But pretend like we're database-agnostic in case we ever are.
149 raise DatabaseError
.new(e
)