bug 1318: Fix a check for if there were any servers
[cacert-devel.git] / includes / general.php
index 26a369e..065daaa 100644 (file)
                //echo "Points due to name matches: $points<br/>";
 
                $shellpwd = escapeshellarg($pwd);
-               $do = `grep -F -- $shellpwd /usr/share/dict/american-english`;
+               $do = shell_exec("grep -F -- $shellpwd /usr/share/dict/american-english");
                if($do)
                        $points--;
 
                $fp = fopen($tmpfname, "w");
                fputs($fp, $message);
                fclose($fp);
-               $do = `/usr/bin/gpg --homedir /home/gpg --clearsign "$tmpfname"|/usr/sbin/sendmail "$to"`;
+               $to_esc = escapeshellarg($to);
+               $do = shell_exec("/usr/bin/gpg --homedir /home/gpg --clearsign \"$tmpfname\"|/usr/sbin/sendmail ".$to_esc);
                @unlink($tmpfname);
        }
 
                if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\+\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email))
                {
                        list($username,$domain)=explode('@',$email,2);
-                       $dom = escapeshellarg($domain);
-                       $line = trim(`dig +short MX $dom 2>&1`);
-#echo $email."-$dom-$line-\n";
-#echo `dig +short mx heise.de 2>&1`."-<br>\n";
-
-                       $list = explode("\n", $line);
-                       foreach($list as $row) {
-                               if(!strstr($row, " ")) {
-                                       continue;
+                       $mxhosts = array();
+                       $mxweight = array();
+                       if( !getmxrr($domain, $mxhosts, $mxweight) ) {
+                               $mxhostrr = array($domain);
+                               $mxweight = array(0);
+                       } else if ( empty($mxhosts) ) {
+                               $mxhostrr = array($domain);
+                               $mxweight = array(0);
+                       }
+
+                       $mxhostprio = array();
+                       for($i = 0; $i < count($mxhostrr); $i++) {
+                               $mx_host = trim($mxhostrr[$i], '.');
+                               $mx_prio = $mxweight[$i];
+                               if(empty($mxhostprio[$mx_prio])) {
+                                       $mxhostprio[$mx_prio] = arraY();
+                               }
+                               $mxhostprio[$mx_prio][] = $mx_host;
+                       }
+
+                       array_walk($mxhostprio, function(&$mx) { shuffle($mx); } );
+
+                       $mxhosts = array();
+                       foreach($mxhostprio as $mx_prio => $mxhostnames) {
+                               foreach($mxhostnames as $mx_host) {
+                                       $mxhosts[] = $mx_host;
                                }
-                               list($pri, $mxhosts[]) = explode(" ", trim($row), 2);
                        }
-                       $mxhosts[] = $domain;
-                       array_walk($mxhosts, function(&$mx) { $mx = trim($mx, '.'); } );
 
                        foreach($mxhosts as $key => $domain)
                        {