public function action_query($domain) { $domain = strtolower($domain); Log::write('check', 'dns: ' . $domain); //validate format and chars if (!preg_match('/^(?:[-A-Za-z0-9]+\\.)+[A-Za-z]{2,6}$/', $domain)) { return View::make('dns.index')->with('title', 'DNS Check')->with('type', 'dns')->with('valid', 0); } $dns = new Dns($domain); $dns_all = $dns->all(); $dns_soa = $dns->soa(); $dns_ns = $dns->ns(); return View::make('dns.info', array('title' => $domain . '\'s dns info', 'all' => $dns_all, 'soa' => $dns_soa, 'ns' => $dns_ns, 'domain' => $domain, 'type' => 'dns')); }
/** * validate the email * * @since 2.2.0 * * @param string $email target email address * @param boolean $dns optional validate dns * * @return integer */ public function validate($email = null, $dns = true) { $output = Validator::FAILED; /* validate email */ if (filter_var($email, FILTER_VALIDATE_EMAIL) !== false) { $output = Validator::PASSED; $emailArray = explode('@', $email); /* validate dns */ if ($dns === true) { $dnsValidator = new Dns(); $output = $dnsValidator->validate($emailArray[1], 'MX'); } } return $output; }
/** * Discover host and port for specified prefix and ports * * @param $email * @param $prefix * @param $ports * @return array * @throws \Exception */ private function analyse($email, $prefix, $ports) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new \Exception('Not a valid email'); } $host = null; $domain = explode('@', $email); if ($mxServer = Dns::getTopMx($domain[1])) { // save MX-server information $mxServerDomains = explode('.', $mxServer); $mxServerRoot = implode('.', array_slice($mxServerDomains, -2, 2)); $this->mxServer = $mxServer; $this->mxServerRoot = $mxServerRoot; } if ($port = Socket::pingPort($prefix . $domain[1], $ports)) { $host = $prefix . $domain[1]; } elseif ($mxServer) { if ($port = Socket::pingPort($mxServer, $ports)) { $host = $mxServer; } else { $revMxServer = gethostbyaddr(gethostbyname($mxServer)); $revMxServerDomains = explode('.', $revMxServer); $revMxServerRoot = @implode('.', array_slice($revMxServerDomains, -2, 2)); if ($port = Socket::pingPort($prefix . $revMxServerRoot, $ports)) { $host = $prefix . $revMxServerRoot; } else { if ($port = Socket::pingPort($prefix . $mxServerRoot, $ports)) { $host = $prefix . $mxServerRoot; } } } } return [$host, $port]; }
/** * validate the url * * @since 2.2.0 * * @param string $url target url address * @param boolean $dns optional validate dns * * @return integer */ public function validate($url = null, $dns = true) { $output = ValidatorInterface::FAILED; /* validate url */ if (filter_var($url, FILTER_VALIDATE_URL) !== false) { $output = ValidatorInterface::PASSED; /* validate dns */ if ($dns === true) { $parsedUrl = parse_url($url); if (isset($parsedUrl['host'])) { $dnsValidator = new Dns(); $output = $dnsValidator->validate($parsedUrl['host']); } } } return $output; }
/** * Static function that detects wether we're running windows or not and then either uses the native version of * getmxrr or the alternative one. See getmxrr_windows below for more information. * * @param hostname The host for which we want to get the mx records. * @param mxhosts The array we are going to fill with the mx records. * @return Returns either true or false. * @static */ function getmxrr($hostname, &$mxhosts) { if (OsDetect::isWindows()) { // call the alternative version return Dns::getmxrr_windows($hostname, $mxhosts); } else { // use the native version return getmxrr($hostname, $mxhosts); } }
/** * Checks the given email address */ function validate($value) { if (empty($value)) { $this->_setError(false); return true; } list($userName, $domain) = explode("@", $value); $connectAddress = $domain; if (!Dns::checkdnsrr($domain, "A")) { $this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_UNREACHABLE); return false; } if (Dns::checkdnsrr($domain, "MX") && Dns::getmxrr($domain, $mxHosts)) { $connectAddress = $mxHosts[0]; } if ($connect = fsockopen($connectAddress, 25)) { $out = fgets($connect, 1024); if (ereg("^220", $out)) { $server =& HttpVars::getServer(); fputs($connect, "HELO " . $server["HTTP_HOST"] . "\r\n"); $out = fgets($connect, 1024); fputs($connect, "MAIL FROM: <" . $value . ">\r\n"); $from = fgets($connect, 1024); fputs($connect, "RCPT TO: <" . $value . ">\r\n"); $to = fgets($connect, 1024); fputs($connect, "QUIT\r\n"); fclose($connect); if (!ereg("^250", $from) || !ereg("^250", $to)) { $this->_setError(ERROR_RULE_EMAIL_DNS_NOT_PERMITTED); return false; } } } else { $this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_UNREACHABLE); return false; } return true; }
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_USERAGENT, 'LocalDomains_PHP/1.0.0(roy@leadnt.com)'); $result = curl_exec($ch); curl_close($ch); return $result; } public function exec() { $ip = $this->getMyIp(); $domainInfo = $this->api_call('domain.info', array('domain' => $this->domain)); $domainId = $domainInfo['domain']['id']; $record = $this->api_call('record.list', array('domain_id' => $domainId, 'offset' => '0', 'length' => '1', 'sub_domain' => $this->sub_domain)); if ($record['info']['record_total'] == 0) { $this->api_call('record.create', array('domain_id' => $domainId, 'sub_domain' => $this->sub_domain, 'record_type' => 'A', 'record_line' => '默认', 'value' => $ip, 'ttl' => '3600')); } else { if ($record['records'][0]['value'] != $ip) { $this->api_call('record.modify', array('domain_id' => $domainId, 'record_id' => $record['records'][0]['id'], 'sub_domain' => $this->sub_domain, 'record_type' => 'A', 'record_line' => '默认', 'value' => $ip)); } else { echo '指向正常'; } } } } $dns = new Dns(); $dns->exec();
function add_domain($domain_name, $parent_name) { global $gbl, $login, $ghtml; $user = str_replace(".", "", $domain_name); $domain = new Domain(null, null, $domain_name); $domain->initThisDef(); $domain->password = crypt('admin'); $domain->cpstatus = 'on'; $domain->parent_clname = "client-{$parent_name}"; $domain->username = $user; $domain->dbpserverlist = array('localhost'); $web = new Web(null, null, $domain_name); $web->initThisDef(); $web->syncserver = 'localhost'; $web->username = $user; $web->ttype = 'virtual'; $web->write(); $mmail = new Mmail(null, null, $domain_name); $mmail->initThisDef(); $mmail->syncserver = 'localhost'; $mmail->write(); $mailaccount = new Mailaccount(null, null, "test@{$domain_name}"); $mailaccount->initThisDef(); $mailaccount->syncserver = 'localhost'; $mailaccount->password = crypt('admin'); $mailaccount->parent_clname = "domain-{$domain_name}"; $mailaccount->cpstatus = 'on'; $mailaccount->write(); $ftpuser = new ftpuser(null, null, "test@{$domain_name}"); $ftpuser->initThisDef(); $ftpuser->password = crypt('admin'); $ftpuser->parent_clname = "domain-{$domain_name}"; $ftpuser->cpstatus = 'on'; $ftpuser->write(); $dns = new Dns(null, null, $domain_name); $dns->initThisDef(); $dns->syncserver = 'localhost'; $dns->createDefaultTemplate('192.168.1.1', 'dns22.lxcenter.net'); $dns->write(); $unname = $user; $uuser = new Uuser(null, null, $unname); $uuser->initThisDef(); $uuser->username = $user; $uuser->password = crypt('admin'); $uuser->parent_clname = "domain-{$domain_name}"; $uuser->cpstatus = 'on'; $uuser->syncserver = localhost; $uuser->write(); $uuser->dbaction = 'clean'; //$web->addObject('uuser', $uuser); $domain->write(); print "Added domain\n"; }