Alternc  latest
Alternc logiel libre pour l'hébergement
alternc_fix_opendkim.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3  // create the missing opendkim keys and update dns zones accordingly when necessary.
4 
5 $f=@fopen("/etc/alternc/my.cnf","rb");
6 if (!$f) {
7  echo "Can't open /etc/alternc/my.cnf !\n";
8  exit(1);
9 }
10 $mdb=""; $mhost=""; $muser=""; $mpass="";
11 
12 while ($s=fgets($f,1024)) {
13  if (preg_match('#database="([^"]*)#',$s,$mat)) {
14  $mdb=$mat[1];
15  }
16  if (preg_match('#host="([^"]*)#',$s,$mat)) {
17  $mhost=$mat[1];
18  }
19  if (preg_match('#user="([^"]*)#',$s,$mat)) {
20  $muser=$mat[1];
21  }
22  if (preg_match('#password="([^"]*)#',$s,$mat)) {
23  $mpass=$mat[1];
24  }
25 }
26 fclose($f);
27 if (!$mdb || !$mhost || !$muser || !$mpass) {
28  echo "Can't find data in /etc/alternc/my.cnf\n";
29  exit(1);
30 }
31 
32 $ALTERNC_ROOT="/var/alternc/html";
33 
34 $f=@fopen("/etc/alternc/local.sh","rb");
35 if (!$f) {
36  echo "Can't open /etc/alternc/local.sh !\n";
37  exit(1);
38 }
39 while ($s=fgets($f,1024)) {
40  if (preg_match('#ALTERNC_HTML="([^"]*)#',$s,$mat)) {
41  $ALTERNC_ROOT=$mat[1];
42  }
43 }
44 fclose($f);
45 $ALTERNC_ROOT=rtrim($ALTERNC_ROOT,"/");
46 
47 
48 if (!file_exists("/usr/bin/opendkim-genkey")
49  && !file_exists("/usr/sbin/opendkim-genkey")) {
50  echo "opendkim-tools not installed, please launch:\n";
51  echo "apt-get install opendkim-tools\n";
52  exit(1);
53 }
54 
55 
56 require_once("/usr/share/alternc/panel/class/db_mysql.php");
58 if (!$db) {
59  echo "Can't connect to MySQL !\n";
60  exit(1);
61 }
62 
64 $r=$db->query("SELECT domaine FROM domaines where gesmx=1 AND gesdns=1;");
65 while ($db->next_record()) {
66  $c=$db->Record;
67  if (!file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.private") ||
68  !file_exists("/etc/opendkim/keys/".$c["domaine"]."/alternc.txt")) {
69  echo "Creating Opendkim key for domain ".$c["domaine"]."\n";
70  if (!is_dir("/etc/opendkim/keys/".$c["domaine"]."")) {
71  if (!mkdir("/etc/opendkim/keys/".$c["domaine"]."")) {
72  echo "Error creating the directory /etc/opendkim/keys/".$c["domaine"]." !\n";
73  } else {
74  echo "Created the directory /etc/opendkim/keys/".$c["domaine"]."\n";
75  }
76  }
77  chdir("/etc/opendkim/keys/".$c["domaine"]."");
78  passthru("opendkim-genkey -r -d ".$c["domaine"]." -s alternc 2>&1");
79  passthru("chown opendkim:opendkim alternc.private 2>&1");
80  $db->query("UPDATE domaines SET dns_action='UPDATE' WHERE domaine='".$c["domaine"]."';");
81  $hasdoneone=true;
82  }
83 }
84 
85 if ($hasdoneone) {
86  echo "I created some keys, launching update_domaines...\n";
87  passthru("/usr/lib/alternc/update_domains.sh 2>&1");
88 } else {
89  echo "I did nothing, opendkim seems fine...\n";
90 }
91 
exit
Definition: adm_doadd.php:70
if(! $mdb||! $mhost||! $muser||! $mpass) $ALTERNC_ROOT
if(! $f) $mdb
if(! $db) $hasdoneone
$c
Definition: bootstrap.php:47
Mysql Database class.
Definition: db_mysql.php:27