ãã®èšäºã¯ãEximãšDovecotãã©ã®ããã«æ§æãããåäœããããç¥ã£ãŠãã人ã察象ãšããŠããããããã®ãµãŒãã¹ã®åºæ¬çãªèšå®ã«ã€ããŠã¯è§ŠããŸããã
ããŒããèªãã åŸã誰ãã決å®ãå®è¡ããããã«å¿ èŠãªç¥èãã¢ã€ãã¢ãåãåãããšãæã¿ãŸãã
ã¿ã¹ã¯ã¯ããµãŒããŒäžã®ã¡ãŒã«ã¹ãã¬ãŒãžãšIMAPã¢ã¯ã»ã¹ã䜿çšããŠããã©ãŒã«ããã¬ã©ã³ããµãŒãã¹ãæ§ç¯ããããšã§ãã
ãã®ã¯ã©ã¹ã¿ãŒã¯ãçŽ60ã®æ¯åºãæã€äŒç€Ÿã«ãµãŒãã¹ãæäŸããåæ¯åºã«ã¯ç¬èªã®ç¬¬3ã¬ãã«ãã¡ã€ã³ããããŸãã
ãµãŒãã¹ã®äž»ãªã¿ã¹ã¯ã¯ãã¡ãŒã«ãžã®äžæã®ãªãã¢ã¯ã»ã¹ã§ãã ãããã£ãŠãã¹ãã¬ãŒãžã«å°ççã«åæ£ãã2ã€ã®ãµãŒããŒã䜿çšããã¡ãŒã«ãã£ã¬ã¯ããªãåæããŸãã
äž¡æ¹ã®ãµãŒããŒãã¢ã¯ãã£ãã«ãªããŸããã€ãŸããããŒãéã§è² è·ãåæ£ãããŸãã ãã¡ã€ã³ã®äžéšã¯1ã€ã®ããŒãã«ãã£ãŠæäŸããããã¡ã€ã³ã®äžéšã¯å¥ã®ããŒãã«ãã£ãŠæäŸãããŸãã ããããã®ããŒãã§é害ãçºçãããšãã¯ã©ã€ã¢ã³ãã¯å¥ã®ããŒãã«åãæ¿ãããŸãã
ã¯ã©ã€ã¢ã³ã
ã¹ããŒã ïŒ
ã¹ãã¬ãŒãž ïŒã¡ãŒã«ããã¯ã¹ã¹ãã¬ãŒãžã 2ã€ã®ããŒãã§æ§æãããŸãã
åããŒãã¯ãç°ãªããã¹ãã£ã³ã°ãµã€ãã«ãã2x4Tb HDDãåããå°çšãµãŒããŒã§ã
DNSïŒstorage-01.domain.ruããã³storage-02.domain.ru
OSïŒFreeBSDã
ãœãããŠã§ã¢ïŒDovecotãEximãPostgresqlãããã³Nginx
SMTP ïŒSMTPãã©ãã£ãã¯ãåŠçãããµãŒããŒã2ã€ã®ããŒãã
ç°ãªããã¹ãã£ã³ã°ãµã€ãã«ããä»®æ³ãµãŒããŒã
DNSïŒsmtp-01.domain.ruããã³smtp-02.domain.ru
OSïŒFreeBSDã
ãœãããŠã§ã¢ïŒEximãPostgresql
PROXY ïŒIMAPãPOP3ãSMTPãµãŒãã¹ãžã®ãŠãŒã¶ãŒã¢ã¯ã»ã¹çšã®ãããã·ãµãŒããŒã
ä»®æ³ãµãŒããŒã ã¯ã©ã¹ã¿ãŒå ã§å¯äžã®éè€ãããªã³ã¯ã¯ããã®åçŽãã®èŠ³ç¹ãããã¹ãããã·ã§ããããæ°å以å ã«äžæããŸãã
DNSïŒmail.domain.ru
OSïŒFreeBSDã
ãœãããŠã§ã¢ïŒNginx
ã¹ãã¬ãŒãžã
DovecotãMDAãšããŠéžæãããã®ã¯ãããã«ã¯ã©ã¹ã¿åã§ããããã§ãã ã¡ãŒã«ãä¿åããããã«ãMaildir圢åŒãéžæãããŸããã ããã«éè€æé€ãå¿ èŠã«ãªããŸããããããã«ã€ããŠã¯ä»¥äžã§è©³ãã説æããŸãã
Datastorsã¯ãsmtpãµãŒããŒãšPROXYããã®ã¡ãŒã«ã®ã¿ãåãå ¥ããŸãã 圌ãã¯ãSMTPãµãŒããŒããã€ãã¹ããŠãèªåèªèº«ã«ã¡ãŒã«ãéä¿¡ããŸãã ããããå®å šã«é衚瀺ã«ããSMTPããŒããä»ããŠéä¿¡ã¡ãŒã«ãéä¿¡ã§ããŸãã
ãã¡ã€ã«ã·ã¹ãã å ã®ã¡ãŒã«ããã¯ã¹ãžã®ãã¹/ usr / mail /ãã¡ã€ã³ã¬ãã«2 /ãã¡ã€ã³ã¬ãã«3 /ããã¯ã¹/
èªèšŒã§ã¯ãå®å šãªmail@ldomain.mdomain.ruã¡ãŒã«ããã¯ã¹ããã°ã€ã³ãšããŠäœ¿çšãããŸã
DBïŒ
ããŒãã«ã®èª¬æïŒ
ã¡ãŒã«ããã¯ã¹ãä¿åããããã®ã¡ãŒã«ããŒãã«
- id
- ã¡ãŒã«ããã¯ã¹ - ã¡ãŒã«ããã¯ã¹ã®åå
- ãã¹ã¯ãŒã -MD5ã®ãã¹ã¯ãŒã
- ldomain_id -ldomainããŒãã«ã®ç¬¬3ã¬ãã«ãã¡ã€ã³ã®ID
- mdomain_id -mdomainããŒãã«ã®ç¬¬2ã¬ãã«ãã¡ã€ã³ã®ID
- active-ã¡ãŒã«ããã¯ã¹ã®ã¹ããŒã¿ã¹ã ãªã³/ãªã
第3ã¬ãã«ãã¡ã€ã³ãèšè¿°ããããã®ldomainããŒãã«
- id
- ãã¡ã€ã³ - ãã¡ã€ã³å
- active-ãã¡ã€ã³ã¹ããŒã¿ã¹ã ãªã³/ãªã
mdomain第2ã¬ãã«ã®ãã¡ã€ã³ã®èª¬æã®è¡š
- id
- ãã¡ã€ã³ - ãã¡ã€ã³å
- active-ãã¡ã€ã³ã¹ããŒã¿ã¹ã ãªã³/ãªã
ãããã«ãŒãã£ã³ã°ããŒãã«
- id
- ldomain_id -ldomainããŒãã«ããã®ç¬¬3ã¬ãã«ãã¡ã€ã³ã®ID
- mdomain_id -mdomainããŒãã«ã®ç¬¬2ã¬ãã«ãã¡ã€ã³ã®ID
- storage1-ã¡ã€ã³ã¹ãã¢
- storage2-ããã¯ã¢ããã¹ãã¬ãŒãžïŒãŸã 䜿çšãããŠããŸããïŒ
äžã§æžããããã«ã2ã€ã®ã¹ãã¬ãŒãžã«è² è·ïŒã¡ãŒã«ãã¡ã€ã³ïŒãåæ£ãã ãããããŒãã«ã§ã3çªç®ã®ã¬ãã«ã®ãã¡ã€ã³ãã©ã®ã¹ãã¬ãŒãžã«ããããå€æããŸãã
mail=# select * from maps limit 3; id | ldomain_id | mdomain_id | storage1 | storage2 ----+------------+------------+--------------------+--------------- 56 | 56 | 2 | storage-01.domain.ru | storage-02.domain.ru 57 | 57 | 2 | storage-02.domain.ru | storage-01.domain.ru 58 | 58 | 2 | storage-01.domain.ru | storage-02.domain.ru (3 )
ãã®è¡šã«åºã¥ããŠãExm Storagesããã³smtpããŒããã¬ã¿ãŒã®éä¿¡å ã決å®ããŸãã NginxããŠãŒã¶ãŒãæ¥ç¶ããå庫ã
ããŒã¿ããŒã¹ãšããŒãã«ã®äœæïŒ
psql -Upgsql template1 ctreate database mail; \q
CREATE TABLE mail ( "id" BIGSERIAL PRIMARY KEY, "mailbox" CHARACTER VARYING(32) not null, "password" CHARACTER VARYING(128), "ldomain_id" int NOT NULL, "mdomain_id" int NOT NULL, active BOOLEAN DEFAULT TRUE NOT NULL, CONSTRAINT "mail_ldomain_id_check" CHECK (("ldomain_id" > 0)) ); CREATE TABLE "ldomain" ( "id" BIGSERIAL PRIMARY KEY, "domain" CHARACTER VARYING(32) NOT NULL, "active" BOOLEAN DEFAULT TRUE NOT NULL, CONSTRAINT ldomain_k UNIQUE (domain) ); CREATE TABLE "mdomain" ( "id" BIGSERIAL PRIMARY KEY, "domain" CHARACTER VARYING(32) NOT NULL, "active" BOOLEAN DEFAULT TRUE NOT NULL, CONSTRAINT mdomain_k UNIQUE (domain) ); CREATE TABLE "maps" ( "id" SERIAL PRIMARY KEY, "ldomain_id" int NOT NULL, "mdomain_id" int NOT NULL, "storage1" CHARACTER VARYING(32) NOT NULL, "storage2" CHARACTER VARYING(32) NOT NULL, CONSTRAINT maps_ldomain_k UNIQUE (ldomain_id) );
ãã³ãã
Dovecotã¯MDAãšããŠæ©èœããŸãã Dovecotã®åºæ¬èšå®ã¯ãã®èšäºã®ç¯å²å€ã§ãããDovecotãDBããã³MTAãšãªã³ã¯ããããã«éèŠãªãã€ã³ãã®ã¿ã«çŠç¹ãåœãŠãŸãã
/usr/local/etc/dovecot/dovecot.conf protocols = imap pop3 lmtp # Exim LMTP
/usr/local/etc/dovecot/dovecot-sql.conf.ext driver = pgsql connect = host=localhost dbname=mail user=mail password=password default_pass_scheme = MD5 iterate_query = \ SELECT mail.mailbox || '@' || ldomain.domain || '.' || mdomain.domain AS user \ FROM mail \ INNER JOIN mdomain ON ( mail.mdomain_id = mdomain.id ) \ INNER JOIN ldomain ON ( mail.ldomain_id = ldomain.id ) password_query = \ SELECT mail.mailbox || '@' || ldomain.domain || '.' || mdomain.domain AS mail, mail.password \ FROM mail \ INNER JOIN mdomain ON ( mail.mdomain_id = mdomain.id ) \ INNER JOIN ldomain ON ( mail.ldomain_id = ldomain.id ) \ WHERE mailbox = '%n' AND \ ldomain.domain || '.' || mdomain.domain = '%d' AND \ mail.active = true AND \ ldomain.active = 'true' user_query = \ SELECT '/usr/mail/' || ldomain.domain || '.' || mdomain.domain || '/' || mail.mailbox AS home \ FROM mail \ INNER JOIN ldomain ON ( mail.ldomain_id = ldomain.id ) \ INNER JOIN mdomain ON ( mail.mdomain_id = mdomain.id ) \ WHERE mail.mailbox = '%n' AND \ ldomain.domain || '.' || mdomain.domain = '%d'
/usr/local/etc/dovecot/conf.d/10-auth.conf auth_username_format = %Lu # mail@ldomain.mdomain.ru !include auth-sql.conf.ext
/usr/local/etc/dovecot/conf.d/10-mail.conf mail_location = maildir:/usr/mail/%d/%n/Maildir # /usr/mail/ 2- / 3- //
ã¹ãã¬ãŒãžåæ
æåã¯ãDovecotïŒdsyncïŒèªäœã䜿çšããŠåæãèšå®ããŸããããæäœäžã«éåžžã«äžå¿«ãªåé¡ãçºçããŸããã å€æããããã«ãåé¡ã¯Maildirã¹ãã¬ãŒãžã¿ã€ãã«é¢é£ããŠããã Dsyncãã¯ã©ãã·ã¥ãå§ãã空ããã£ã¹ã¯é åã䜿ãæãããŠæåã®ã³ããŒãäœæããŸããã ãã®é ã«ã¯ããã¹ãŠã®ã¡ãŒã«ããã¯ã¹ãdboxïŒDovecotç¬èªã®åœ¢åŒïŒã«è»¢éã§ããªããªã£ãŠãããããdsyncãä»ããŠåæãäžæ¢ããå¿ èŠããããŸããã å šäœãšããŠããã®ã¡ã«ããºã ã«å¯Ÿããä»ã®äž»åŒµã¯ãããŸããã§ããã
åçŽãªã¹ã¯ãªããã䜿çšããŠrsyncãå®è¡ããå¿ èŠããããŸãããrsyncã¯ãå®è¡ãããµãŒããŒããµãŒãã¹ãæäŸãããã¡ã€ã³ãããŒã¿ããŒã¹ããååŸãããã£ã¬ã¯ããªã2çªç®ã®ãµãŒããŒã«åæããŸãã ãããã£ãŠã2çªç®ã®ãµãŒããŒã§ã¯ãåãã¹ã¯ãªãããæåã®ãã£ã¬ã¯ããªãé§åããŸãã ãã¡ãããrsyncã¯ã¹ã±ãžã¥ãŒã«ã©ããã«å®è¡ãããããããã®ã¡ã«ããºã ã®ä¿¡é Œæ§ã¯äœããªããŸããéå§éã«ãŠã£ã³ããŠãããããµãŒããŒãã¯ã©ãã·ã¥ãããšã¬ã¿ãŒã倱ãããšã«ãªããŸãã
ã¹ã¯ãªããã¯2ã€ã®ãã©ã¡ãŒã¿ãŒ-local_server_name remote_server_nameã§èµ·åãããŸã
#mailrsync.pl storage-01.domain.ru storage-02.domain.ru
åæã¹ã¯ãªããïŒ
#!/usr/local/bin/perl use DBI; use threads; use Net::Nslookup; use Sys::Hostname; @host = split('\.',hostname); $dbn="mail"; $dbuser="mail"; $dbpass = "password" $curdata=`date +%Y-%m`; chop $curdata; $conn=DBI->connect("DBI:Pg:dbname=$dbn;host=localhost","$dbuser","$dbpass") or die "Cannot connect"; ($localhostname,$remotehost)=@ARGV; $mail_dir = "/usr/mail/"; sub domains { $q = "SELECT ldomain.domain,mdomain.domain,maps.storage1 FROM mail INNER JOIN ldomain on (mail.ldomain_id = ldomain.id) INNER JOIN mdomain on (mail.mdomain_id = mdomain.id) INNER JOIN maps on (maps.ldomain_id=ldomain.id) WHERE maps.storage1='".$localhostname."' AND mail.mailbox ='dir'"; $domain = $conn->prepare($q) or die "Can't prepare statement: $DBI::errstr"; $domain->execute(); while ( my @domain = $domain->fetchrow_array ) { @domains=(@domains,$domain[0].".".$domain[1]); } print "count of domains: ".($#domains + 1)."\n"; $dt = 2; # $count = ($#domains / $dt ); print "count: ".$count."\n"; $i1 = 0; for ($i2 = 0; $i2< $count; $i2++){ if ($dt > $#domains ){$dt = $#domains ;} print $dt."\n"; print "loop: ".$i2."\n"; foreach $item (@domains[$i1..$m]){ print "in \@domains: ".$mail_dir.$item."\n"; @stack = (@stack,$mail_dir.$item."/"); } push @threads,threads->create(\&sync,\@stack); $i1 = $dt+1; $dt = $dt + 2; @stack=(); } } sub sync { print "sync\n"; foreach $target (@stack){ system(`/usr/local/bin/rsync -H --delete-during -azz -e "/usr/bin/ssh -i /root/.ssh/dovecot_dsa" $target vmail\@$remotehost:$target`); print $target."\n"; } } domains(); foreach $thread (@threads) { $thread->join(); }
Dovecotã§ããã«ã€ããŠã¯ãããã ãã§ãã
Exim
Eximããã¡ã€ã³ããèªèãã§ããããã«ããããããŒãã«ã®ãšã³ããªã«åºã¥ããŠããŒã«ã«ãã¡ã€ã³ãå®çŸ©ããŸãã
domainlist LOCAL_DOMAINS = \ ${lookup pgsql{\ SELECT ldomain.domain || '.' || mdomain.domain AS domainname \ FROM ldomain, mdomain,maps \ WHERE ldomain.domain || '.' || mdomain.domain = LOWER('${quote_pgsql:$domain}') \ AND ldomain.active = 'true' \ AND maps.storage1 = 'storage-01.domain.ru' \ AND maps.ldomain_id = ldomain.id}}
hostlist relay_from_hostsã§smtpããŒããšãããã·ã®ã¢ãã¬ã¹ãæå®ãããããããã®ã¡ãŒã«ãèš±å¯ãªãã§åãå ¥ããŸãïŒã¯ã©ã€ã¢ã³ãã¯ãããã·ã«ãã°ã€ã³ããŸãïŒã
relay_from_hosts = localhost : smtp01.domain.ru : smtp02.domain.ru : mail.domain.ru
LMPT Dovecotçµç±ã§åä¿¡ã¡ãŒã«ãéä¿¡ããŸãã ããã§ãªããã°ããã¹ãŠãæšæºã§ãã ã¡ãŒã«ããã¯ã¹ãšãã¹ã¯ãŒããæ€çŽ¢ããããŒã¿ããŒã¹ã¯ãšãªã¯ãDovecot-aã®ãªã¹ããšåãã§ãã
SMTPããŒã
ããŒã¿ããŒã¹ã¯ã¹ãã¬ãŒãžãšåãã§ããããã¹ã¯ãŒããã£ãŒã«ããã¡ãŒã«ããŒãã«ã«ãªãç¹ãç°ãªããŸãã ãŠãŒã¶ãŒã¯ãããã®ãµãŒããŒã«æ¥ç¶ããŸããã smtpããŒãã¯ãäžçããã®ãã©ãã£ãã¯ã®ã¿ãåŠçããŸãã ããã¯ã¹ãååšãããã©ããã®ãã§ãã¯ã«åºã¥ããŠãæ¢åã®ããã¯ã¹ã®æåã®ã¿ãã¹ãããããŸãã
Exim
ã«ãŒãã決å®ããããã®ãªã¯ãšã¹ããé€ãæšæºæ§æ
ROUTE_LIST = "${lookup pgsql{\ SELECT COALESCE(storage1,'') || ' : ' || COALESCE(storage2,'') \ FROM (\ SELECT storage1,storage2 \ FROM maps \ INNER JOIN ldomain ON ( maps.ldomain_id = ldomain.id ) \ INNER JOIN mdomain ON ( maps.mdomain_id = mdomain.id ) \ WHERE ldomain.domain || '.' || mdomain.domain = '${quote_pgsql:$domain}' \ UNION ALL \ SELECT storage1,storage2 \ FROM co_maps \ INNER JOIN co_domain ON ( co_maps.domain_id = co_domain.id ) \ WHERE co_domain.domain = '${quote_pgsql:$domain}') AS foo}}"
SQLã¯ãšãªã¯åä¿¡è ã®ã¹ãã¢ã®ååãååŸããã«ãŒã¿ãŒã®route_listãã£ã¬ã¯ãã£ãã§ã¹ãã¢ã®ã¢ãã¬ã¹ã瀺ãããŸãã ãããã£ãŠãã¬ã¿ãŒã¯ããã®ã¡ãŒã«ããã¯ã¹ã®ã¢ã¯ãã£ããã¡ã€ã³ãååšããã¹ãã¬ãŒãžã«éä¿¡ãããŸãã
begin routers DATASTORE: driver = manualroute domains = DOMAINS transport = remote_smtp condition = MAILS route_list = * ROUTE_LIST no_more
ã¡ãŒã«ããã¯ã¹ãšãã¹ã¯ãŒããæ€çŽ¢ããããŒã¿ããŒã¹ã¯ãšãªã¯ãDovecotã®ãªã¹ããšåãã§ãã
ãããã·
åãDovecotããããã·ãšããŠæ©èœã§ããŸãããç§ã¯NginxãéžæããŸããããã®ç¹ã«é¢ããŠã¯ãããã·ã³ãã«ã§ç解ããããããã«èŠããŸããã ãŠãŒã¶ãŒãã©ãã«éä¿¡ããããnginxã«ç€ºã1ã€ã®ã¿ã¹ã¯ããããŸããã
PROXYã®nginx.conf
cat /usr/local/etc/nginx/nginx.conf worker_processes 1; worker_rlimit_nofile 8192; pid /var/run/nginx.pid; error_log /var/log/nginx-error.log debug; error_log /var/log/nginx-error.log notice; error_log /var/log/nginx-error.log info; events { worker_connections 8192; multi_accept on; use kqueue; } mail { ssl_certificate /usr/local/etc/ssl/proxy.crt; ssl_certificate_key /usr/local/etc/ssl/proxy.key; ssl_session_timeout 5m; xclient off; auth_http storage-01.domain.ru:8185/auth; pop3_capabilities "LAST" "TOP" "USER" "PIPELINING" "UIDL" "RESP-CODES" "EXPIRE" "IMPLEMENTATION"; imap_capabilities "IMAP4" "IMAP4rev1" "UIDPLUS" "IDLE" "LITERAL+" "QUOTA" "LIST-EXTENDED"; smtp_capabilities "SIZE 52428800" "8BITMIME" "PIPELINING" "STARTTLS" "HELP"; server { smtp_auth login plain; listen 25; protocol smtp; proxy on; starttls on; } server { smtp_auth login plain; listen 587; protocol smtp; proxy on; starttls on; } server { listen 110; protocol pop3; proxy on; starttls on; } server { listen 995; protocol pop3; proxy on; starttls on; } server { listen 143; protocol imap; proxy on; starttls on; } server { listen 993; protocol imap; proxy on; starttls on; } }
ãã£ã¬ã¯ãã£ã
auth_http storage-01.domain.ru:8185/auth;
泚æããŠ
auth_http storage-01.domain.ru:8185/auth;
Nginx ã¯ã¹ã¿ãã¯ã§ãåäœããŸã ïŒäž¡æ¹ã§ïŒïŒããWebãµãŒããŒã¢ãŒãã§ã¯ã1ã€ã®ç®çã®ããã«-èŠæ±storage-01.domain.ru:8185/authãåŠçããŸã
ãã®ãªã¯ãšã¹ãã¯ãã¯ã©ã€ã¢ã³ãã®èªèšŒãæåããå ŽåãèªèšŒã¹ããŒã¿ã¹ãã¬ãŒãåããµãŒãã¹ããŒããè¿ããŸã
"Auth-Status", "OK"; "Auth-Server", "storage-01.domain.ru"; "Auth-Port", "143";
ãã®åŸãPROXYã®nginxã¯ãå¿çã§è¿ãããã¹ãã¢ã«ã¯ã©ã€ã¢ã³ããéä¿¡ããŸãã
ãã¡ããã100åã®1ã§nginxãé€å€ããããšãã§ããŸããããã®ããã«ã¯ãPROXYã®ãŠãŒã¶ãŒãšã®ããŒã¹ãç¶æããå¿ èŠããããŸãã äžè¬çã«ããªãã·ã§ã³ããããŸãã
以äžã¯100ã®Nginxèšå®ã§ãäžèšãå®è£ ããããã®perlã¢ãžã¥ãŒã«ããããŸãã
worker_processes 4; worker_rlimit_nofile 8192; error_log /var/log/nginx-error.log info; events { worker_connections 8192; multi_accept on; } http { perl_modules perl/lib; perl_require mailauth.pm; perl_require Digest.pm; access_log off; server { listen 8185; ssl_certificate /usr/local/etc/ssl/storage-01.crt; ssl_certificate_key /usr/local/etc/ssl/storage-01.key; ssl_session_timeout 5m; location /auth { perl mailauth::handler; proxy_set_header X-Real-IP $remote_addr; } } }
ã¢ãžã¥ãŒã«mailauth.pm
package mailauth; use nginx; use DBI; use Net::Nslookup; use Digest::MD5 qw(md5_hex); $pg_user = "mail"; $pg_pass = "password"; $passhost = "localhost"; $mapshost = "localhost"; our $auth_ok; $protocol_ports->{'pop3'}=110; $protocol_ports->{'imap'}=143; $protocol_ports->{'smtp'}=25; $protocol_ports->{'smtpssl'}=465; sub handler { $r = shift; $Passdbh=DBI->connect("DBI:Pg:dbname=mail;host=$passhost","$pg_user","$pg_pass"); if (!$Passdbh) { $r->header_out("Auth-Status", "OK") ; $r->header_out("Auth-Server", '0.0.0.0'); $r->header_out("Auth-Port", $protocol_ports->{$r->header_in("Auth-Protocol")}); $r->send_http_header("text/html"); return OK; exit; }; $Mapsdbh=DBI->connect("DBI:Pg:dbname=mail;host=$mapshost","$pg_user","$pg_pass"); $auth_ok=0; $mailbox = $r->header_in("Auth-User"); our $get_pass_from_db=$Passdbh->prepare("SELECT password FROM mail INNER JOIN ldomain ON ( mail.ldomain_id = ldomain.id ) INNER JOIN mdomain ON ( mail.mdomain_id = mdomain.id ) WHERE mail.mailbox || '\@' || ldomain.domain || '.' || mdomain.domain = ? "); $get_pass_from_db->execute($mailbox); @row=$get_pass_from_db->fetchrow_array(); $passfromDB=@row[0]; $md5passFromConnect = md5_hex($r->header_in("Auth-Pass")); if ( $passfromDB eq $md5passFromConnect ){ $auth_ok=1; } if ($auth_ok==1){ @domain = split('\@',$mailbox); $get_server_from_maps = $Mapsdbh->prepare( "SELECT storage1 FROM maps INNER JOIN ldomain ON ( maps.ldomain_id = ldomain.id ) \ INNER JOIN mdomain ON ( maps.mdomain_id = mdomain.id ) \ WHERE ldomain.domain || '.' || mdomain.domain = ? " ); $get_server_from_maps->execute(@domain[1]); @row=$get_server_from_maps->fetchrow_array(); $server_from_maps = nslookup(host => $row[0], type => "A"); $r->header_out("Auth-Status", "OK") ; $r->header_out("Auth-Server", $server_from_maps); $r->header_out("Auth-Port", $protocol_ports->{$r->header_in("Auth-Protocol")}); } else { $r->header_out("mail:", $r->header_in("Auth-User")); $r->header_out("Auth-Status", "Invalid login or password") ; } $r->send_http_header("text/html"); return OK; } sub db_fail { $r->header_out("Auth-Status", "OK") ; $r->header_out("Auth-Server", '127.0.0.1'); $r->send_http_header("text/html"); } 1; __END__
ãã©ã³ã¹èª¿æŽãããã³ããã¯ã¢ããããŒããžã®åãæ¿ã
ããã§ãããã¯ã¢ããããŒããžã®åãæ¿ãã¯æåã¢ãŒãã«ãªããŸããã ããã¯ãmapsããŒãã«ã§storage1ãã£ãŒã«ãã®å€ãå€ããã ãã§ãã T.K. ãã¹ãŠã®ãµãŒããŒã¯ããããŸã§ã®ç£èŠã§ãã³ã°ã¢ããããååã§ããã
çµè«
ã¯ã©ã¹ã¿ãŒã¯3幎é皌åããŠããŸãã ãã®éã«ãããŒãã®1ã€ãäœåºŠãèœäžããŸããïŒãã®çµæããã®ããŒãã¯å¥ã®DCã«ç§»åããŸããïŒã
ãã®ãã¶ã€ã³ã¯ãè€éã§ãèªè»¢è»ãã®ããã«èŠãããããããŸããã ãããããã®ãœãªã¥ãŒã·ã§ã³ã®ã¢ãŒããã¯ãã£ã¯ãå®äŸ¡ã§ä¿¡é Œæ§ã®äœãããŒããŠã§ã¢ã䜿çšãããšãã決å®ããå§ãŸã£ãããšã匷調ããããšæããŸãã ãã®çµæãæå°éã®ãµãŒããŒã¬ã³ã¿ã«ã³ã¹ãã§ä¿¡é Œæ§ã®é«ããµãŒãã¹ãæäŸããŠããŸãã
ãããããã¡ã¢ã¯ååã«æ確ã§ã¯ãªããéèŠãªè©³çŽ°ã¯è¡šç€ºããŸããã§ããã ã³ã¡ã³ãã§ãããããã°ãç§ã¯ãããè£è¶³ããŸãã
PSã ãã®èšäºã¯é·ããã®ã§ããããšãå€æããã®ã§ãèå³ãããå Žåã¯ã次ã®èšäºã§ã¯ããã§åãäžããŠããªãéè€æé€ãšãã®ã¯ã©ã¹ã¿ãŒã®å¥ã®ç®¡çãµãŒãã¹ã«ã€ããŠèª¬æããŸãã
ãæž èŽããããšãããããŸããïŒ