Пример #1
0
 function output_onpost_form_ipaddr_rev()
 {
     global $construct, $main, $db;
     $form_ipaddr_rev = $this->form_ipaddr_rev();
     $ipaddr_rev = get('ipaddr_rev');
     $ret = TRUE;
     $_POST['ip_addresses__ip'] = ip2long($_POST['ip_addresses__ip']);
     $_POST['ip_addresses__hostname'] = validate_hostname($_POST['ip_addresses__hostname']);
     $ret = $form_ipaddr_rev->db_set(array('node_id' => intval(get('node'))), "ip_addresses", "id", $ipaddr_rev);
     if ($ret) {
         $main->message->set_fromlang('info', 'insert_success', make_ref('/node_editor', array("node" => get('node'))));
     } else {
         $main->message->set_fromlang('error', 'generic');
     }
 }
Пример #2
0
 /**
  * Edits PTR
  *
  * @access public
  * @param mixed $address
  * @param mixed $print_error
  * @return void
  */
 public function ptr_edit($address, $print_error)
 {
     // validate hostname
     if (validate_hostname($address->dns_name) === false) {
         return false;
     }
     // new record
     if ($this->ptr_exists($address->PTR) === false) {
         // fake lastid
         $this->lastId = $address->id;
         // new ptr record
         $this->ptr_add($address, true);
     } else {
         // fetch domain
         $domain = $this->pdns_fetch_domain($address->subnetId);
         // fetch old
         $old_record = $this->PowerDNS->fetch_record($address->PTR);
         // create insert array
         $update = $this->PowerDNS->formulate_update_record($this->PowerDNS->get_ip_ptr_name($this->transform_address($address->ip_addr, "dotted")), null, $address->dns_name, null, null, null, $old_record->change_date);
         $update['id'] = $address->PTR;
         // update
         $this->PowerDNS->update_domain_record($domain->id, $update);
         // ok
         $this->Result->show("success", "PTR record updated", false);
     }
 }
Пример #3
0
    # Correct some types
    foreach ($result as &$row) {
        $row['password'] = $row['password'] ? true : false;
        $row['port'] = (int) $row['port'];
        $row['users'] = (int) $row['users'];
    }
    return $result;
}, 'POST' => function ($path) {
    $data = get_json_body();
    # Validate
    $params = array('host' => get_optional($data, 'host', '', 'string'), 'port' => get_optional($data, 'port', 27750, 'int'), 'session_id' => get_required($data, 'id', 'string'), 'protocol' => get_required($data, 'protocol', 'string'), 'title' => get_required($data, 'title', 'string'), 'users' => get_optional($data, 'users', 0, 'int'), 'owner' => get_required($data, 'owner', 'string'), 'password' => get_optional($data, 'password', 0, 'int'), 'update_key' => random_string(), 'client_ip' => $_SERVER['REMOTE_ADDR']);
    if ($params['host'] == '') {
        # TODO check X-Forwarded-For too
        $params['host'] = $_SERVER['REMOTE_ADDR'];
    }
    validate_hostname($params['host']);
    if (!preg_match("/\\A[a-zA-Z0-9:-]{1,64}\\z/", $params['session_id'])) {
        throw new ApiException(422, 'BADDATA', 'Invalid session ID');
    }
    if ($params['port'] <= 0 || $params['port'] >= 65536) {
        throw new ApiException(422, 'BADDATA', 'Invalid port number');
    }
    # Rate limiting
    $db = init_db();
    $q = $db->prepare('SELECT COUNT(id) FROM drawpile_sessions
WHERE client_ip=:ip AND last_active >= TIMESTAMPADD(MINUTE, -' . SESSION_TIMEOUT_MINUTES . ', CURRENT_TIMESTAMP)');
    $q->execute(array("ip" => $params['client_ip']));
    $session_count = $q->fetch(PDO::FETCH_NUM)[0];
    if ($session_count >= RATE_LIMIT) {
        throw new ApiException(429, "RATELIMIT", "You have announced too many sessions (' . {$session_count} . ') too quickly!");
    }
Пример #4
0
function validate_name_ns($name, $node)
{
    global $db;
    // Validate as per hostname
    $ret = validate_hostname($name);
    // Check if string already is used and add extension if used.
    $i = 2;
    $extension = '';
    do {
        $cnt = $db->cnt('', 'nodes', "name_ns = '" . $ret . $extension . "' AND id != '" . $node . "'");
        if ($cnt > 0) {
            $extension = "-" . $i;
            $i++;
        }
    } while ($cnt > 0);
    return $extension != '' ? $ret . $extension : $ret;
}
Пример #5
0
 /**
  * Validates record name
  *
  *	- if not null validate hostname
  *
  * @access private
  * @param mixed $name
  * @return void
  */
 private function validate_record_name($name)
 {
     // null is ok, otherwise URI is required
     if (strlen($name) > 0 && !validate_hostname($name)) {
         $this->Result->show("danger", _("Invalid record name"), true);
     }
     // ok
     return $name;
 }
Пример #6
0
 ***************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database);
$Result = new Result();
$PowerDNS = new PowerDNS($Database);
# verify that user is logged in
$User->check_user_session();
# checks / validation
if ($_POST['action'] != "delete") {
    // fqdn
    if ($_POST['action'] == "add") {
        if (validate_hostname($_POST['name']) === false) {
            $Result->show("danger", "Invalid domain name", true);
        }
    }
    // master
    if (strlen($_POST['master']) > 0) {
        if (!filter_var($_POST['master'], FILTER_VALIDATE_IP)) {
            $Result->show("danger", "Master must be an IP address", true);
        }
    }
    // type
    if (!in_array($_POST['type'], (array) $PowerDNS->domain_types)) {
        $Result->show("danger", "Invalid domain type", true);
    }
    # new domain
    if ($_POST['action'] == "add" && !isset($_POST['manual'])) {
    $PowerDNS->domain_edit("add", array("name" => $zone, "type" => "NATIVE"));
    // create default records
    $PowerDNS->create_default_records($values);
}
// remove existing records and links
$PowerDNS->remove_all_ptr_records($domain->id);
$Addresses->ptr_unlink_subnet_addresses($subnet->id);
// fetch all hosts
$hosts = $Addresses->fetch_subnet_addresses($subnet->id, "ip_addr", "asc");
// create PTR records
if (sizeof($hosts) > 0) {
    foreach ($hosts as $h) {
        // ignore PTR
        if ($h->PTRignore == "1") {
            $ignored[] = $h;
        } elseif (validate_hostname($h->dns_name) !== false) {
            // formulate new record
            $record = $PowerDNS->formulate_new_record($domain->id, $PowerDNS->get_ip_ptr_name($h->ip), "PTR", $h->dns_name, $values['ttl']);
            // insert record
            $PowerDNS->add_domain_record($record, false);
            // link
            $Addresses->ptr_link($h->id, $PowerDNS->lastId);
            // ok
            $success[] = $h;
        } else {
            $failures[] = $h;
        }
    }
} else {
    $empty = true;
}