PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/pdns_to_postfix_backup_mx.php

http://freshdns.googlecode.com/
PHP | 54 lines | 29 code | 13 blank | 12 comment | 0 complexity | cf4288112e80548274b3e4506f7f8237 MD5 | raw file
 1#!/usr/bin/php -q
 2<?php
 3ob_start();
 4
 5$mysql_host 	= "localhost"; 	/* ENTER YOUR HOSTNAME */
 6$mysql_db 		= "pdns";		/* ENTER THE DATABASE NAME */
 7$mysql_user 	= "pdns";		/* ENTER THE MYSQL USERNAME */
 8$mysql_pass 	= "";			/* ENTER THE MYSQL PASSWORD */
 9
10mysql_connect("localhost", $mysql_user, $mysql_pass) or die (mysql_error());
11mysql_select_db($mysql_db) or die (mysql_error());
12
13/* LET'S DEFINE SOME ARRAY'S */
14$domains = array();
15$recipient = array();
16$transport = array();
17
18/* LET'S GET ALL DOMAINS */
19$query = "SELECT name FROM domains WHERE name <> '' GROUP BY name ORDER BY name";
20$query = mysql_query($query) or die (mysql_error());
21while($record = mysql_fetch_assoc($query))
22{
23	$domains[] = $record['name']." OK";
24	$recipient[] = "@".$record['name']." OK";
25	$transport[] = $record['name']." smtp:[mail.".$record['name']."]";
26}
27
28/* LET'S SAVE THE OUTPUT */
29$output = '';
30
31/* SAVE THE RELAY DOMAINS */
32file_put_contents("/etc/postfix/relay_domains", implode("\n", $domains));
33
34/* LET'S MAKE POSTFIX UNDERSTAND THIS FILE */
35exec("postmap /etc/postfix/relay_domains", $output);
36
37/* SAVE THE RELAY RECIPIENTS */
38file_put_contents("/etc/postfix/relay_recipient", implode("\n", $recipient));
39
40/* LET'S MAKE POSTFIX UNDERSTAND THIS FILE */
41exec("postmap /etc/postfix/relay_recipient", $output);
42
43/* SAVE THE TRANSPORT */
44file_put_contents("/etc/postfix/transport", implode("\n", $transport));
45
46/* LET'S MAKE POSTFIX UNDERSTAND THIS FILE */
47exec("postmap /etc/postfix/transport", $output);
48
49/* LET'S RELOAD POSTFIX */
50exec("/etc/init.d/postfix reload", $output);
51
52/* COLLECT THE OUTPUT */
53$content = ob_get_clean();
54?>