DNS::addRecord PHP Method

addRecord() public method

public addRecord ( $type, $domain, $name, $address )
    function addRecord($type, $domain, $name, $address)
    {
        $domainid = $this->domainId($domain);
        if ($domainid) {
            $safename = $this->db->quote($name);
            $safeaddress = $this->db->quote($address);
            switch (strtolower($type)) {
                case 'a':
                    if (!$this->isIP($address)) {
                        $this->raiseError("Invalid IP");
                        return false;
                    }
                    $query = $this->db->Execute("SELECT recordid FROM records_a WHERE domainid = '{$domainid}' AND name = {$safename} LIMIT 1");
                    if ($query->numRows() > 0) {
                        $this->raiseError("Record Exists\n");
                        return false;
                    }
                    $query = $this->db->Execute("SELECT recordid FROM records_cname WHERE domainid = '{$domainid}' AND name = {$safename} LIMIT 1");
                    if ($query->numRows() > 0) {
                        $this->raiseError("Conflict Detected! CNAME already exists for {$safename}\n");
                        return false;
                    }
                    $this->db->Execute("INSERT INTO records_a (domainid, name, address) VALUES ('{$domainid}', {$safename}, {$safeaddress})");
                    break;
                case 'cname':
                    $query = $this->db->Execute("SELECT recordid FROM records_cname WHERE domainid = '{$domainid}' AND name = {$safename} LIMIT 1");
                    if ($query->numRows() > 0) {
                        $this->raiseError("Record Exists\n");
                        return false;
                    }
                    $query = $this->db->Execute("SELECT recordid FROM records_a WHERE domainid = '{$domainid}' AND name = {$safename} LIMIT 1");
                    if ($query->numRows() > 0) {
                        $this->raiseError("Conflict Detected! An A record already exists for {$safename}\n");
                        return false;
                    }
                    $this->db->Execute("INSERT INTO records_cname (domainid, name, address) VALUES ('{$domainid}', {$safename}, {$safeaddress})");
                    break;
                case 'mx':
                    if (!preg_match("/.*\\.\$/", $address)) {
                        $this->raiseError("MX records must end in a period\n");
                        return false;
                    }
                    $this->db->Execute("INSERT INTO records_mx (domainid, priority, address) VALUES ('{$domainid}', {$safename}, {$safeaddress})");
                    break;
                default:
                    $this->raiseError("Invalid Record Type\n");
                    return false;
                    break;
            }
            $q = $this->db->Execute("SELECT domainid FROM mod_queue WHERE domainid = '{$domainid}' AND completed = '0'");
            if ($q->numRows() > 0) {
                return true;
            } else {
                $this->db->Execute("INSERT INTO mod_queue (domainid) VALUES ('{$domainid}')");
                return true;
            }
        } else {
            $this->raiseError("Invalid Domain\n");
            return false;
        }
    }