Example #1
0
 function find_reverse_domain($ip_address)
 {
     log_debug("domain_records", "Executing find_reverse_record({$ip_address})");
     /*
     	With IPv4 we are dealing with /24s... for IPv6, we need to
     	convert the record to ARPA and see which domain it belongs to
     */
     switch (ip_type_detect($ip_address)) {
         case "4":
             $ip_arpa = ipv4_convert_arpa($ip_address);
             $tmp = explode(".", $ip_address);
             $ip_ptr_name = $tmp[3];
             break;
         case "6":
             $ip_arpa = ipv6_convert_arpa($ip_address);
             $ip_ptr = $ip_arpa;
             // We fetch a list of all the IPv6 reverse domains
             // Note: this is cached in memory after first lookup for duration of this page session
             $reverse_ipv6_domains = array();
             $this->sql_obj->string = "SELECT domain_name FROM `dns_domains` WHERE domain_name LIKE '%ip6.arpa'";
             $this->sql_obj->execute();
             if ($this->sql_obj->num_rows()) {
                 $this->sql_obj->fetch_array();
                 foreach ($this->sql_obj->data as $data_row) {
                     $reverse_ipv6_domains[] = $data_row["domain_name"];
                 }
             }
             if (!$reverse_ipv6_domains) {
                 return 0;
             }
             // chomp the arpa address till we find the longest match
             while ($ip_arpa) {
                 foreach ($reverse_ipv6_domains as $domain) {
                     if ($ip_arpa == $domain) {
                         break 2;
                     }
                 }
                 $ip_arpa = substr($ip_arpa, 1);
                 if ($ip_arpa == "") {
                     // no matching domain
                     return 0;
                 }
             }
             // get domain name for final domain
             $ip_arpa = $domain;
             $ip_ptr_name = $ip_ptr;
             break;
         default:
             return 0;
             break;
     }
     // Fetch domain ID based on the arpa name of the domain
     $this->sql_obj->string = "SELECT id FROM `dns_domains` WHERE domain_name='" . $ip_arpa . "' LIMIT 1";
     $this->sql_obj->execute();
     if ($this->sql_obj->num_rows()) {
         // fetch domain ID
         $this->sql_obj->fetch_array();
         $this->id = $this->sql_obj->data[0]["id"];
         log_write("debug", "domain_records", "Found matching domain " . $ip_arpa . " with ID of " . $this->id . "");
         // now fetch the ID for the record that belongs to this domain
         $this->sql_obj->string = "SELECT id FROM `dns_records` WHERE id_domain='" . $this->id . "' AND name='" . $ip_ptr_name . "' LIMIT 1";
         $this->sql_obj->execute();
         if ($this->sql_obj->num_rows()) {
             $this->sql_obj->fetch_array();
             $this->id_record = $this->sql_obj->data[0]["id"];
             log_write("debug", "domain_records", "Found matching record with ID of " . $this->id_record . "");
         }
         return 1;
     } else {
         log_write("warning", "domain_records", "Unable to find domain {$ip_arpa} for address {$ip_address}");
     }
     return 0;
 }
Example #2
0
 function session_init($userid, $username)
 {
     log_debug("user_auth", "Executing session_init({$userid}, {$username})");
     /*
     	We have verified that the user is valid. We now assign them an authentication key, which is
     	like an additional session ID.
     	
     	This key is tied to their IP address, so if their IP changes, the user must re-authenticate.
     	
     	Most of the purpose of this auth key, is already provided by PHP sessions, but this key
     	method, provides additional protection in the event of any of the following scenarios:
     	
     	* PHP being used with session IDs passed via GET (since the attackers IP will most
     	   likely be different)
     	
     	* An exploit in the PHP session handling that allows a user to change their session
     	  information.
     	
     	* An exploit elsewhere in this application which allows the changing of any session variable will
     	  not allow a user to gain different authentication rights.
     	
     	The authentication key is stored in the seporate users_sessions tables, which is capable
     	of supporting concurrent logins. The session table will automatically clean out any expired
     	session records whenever a user logs in.
     	
     	Note: The users_sessions table is intentionally not a memory table, in order to support this application
     	when running on load-balancing clusters with replicated MySQL databases. If this application is
     	running on a standalone server only, a memory table would have been acceptable.
     */
     // get other information - IP address & time
     $ipaddress = $_SERVER["REMOTE_ADDR"];
     $time = time();
     // generate an authentication key
     $feed = "0123456789abcdefghijklmnopqrstuvwxyz";
     $authkey = null;
     for ($i = 0; $i < 40; $i++) {
         $authkey .= substr($feed, rand(0, strlen($feed) - 1), 1);
     }
     // perform session table cleanup - remove any records older than 12 hours
     $time_expired = $time - 43200;
     $sql_obj = new sql_query();
     $sql_obj = $this->getSessionDatabase($sql_obj);
     $sql_obj->string = "DELETE FROM `users_sessions` WHERE time < '{$time_expired}'";
     $sql_obj->execute();
     // if concurrent logins is not enabled, delete any old sessions belonging to this user.
     if (sql_get_singlevalue("SELECT value FROM users_options WHERE userid='" . $userid . "' AND name='concurrent_logins' LIMIT 1") != "on") {
         log_write("debug", "inc_users", "User account does not permit concurrent logins, removing all old sessions");
         $sql_obj = new sql_query();
         $sql_obj = $this->getSessionDatabase($sql_obj);
         $sql_obj->string = "DELETE FROM `users_sessions` WHERE userid='" . $userid . "'";
         $sql_obj->execute();
     }
     // create session entry for user login
     $sql_obj = new sql_query();
     if (ip_type_detect($ipaddress) == 6) {
         $sql_obj->string = "INSERT INTO `users_sessions` (userid, authkey, ipv6, time) VALUES ('{$userid}', '{$authkey}', '{$ipaddress}', '{$time}')";
     } else {
         $sql_obj->string = "INSERT INTO `users_sessions` (userid, authkey, ipv4, time) VALUES ('{$userid}', '{$authkey}', '{$ipaddress}', '{$time}')";
     }
     $sql_obj->execute();
     // set session variables
     $_SESSION["user"]["id"] = $userid;
     $_SESSION["user"]["name"] = $username;
     $_SESSION["user"]["authkey"] = $authkey;
     // fetch user options from the database (if any)
     $sql_obj = new sql_query();
     $sql_obj->string = "SELECT name, value FROM users_options WHERE userid='" . $userid . "'";
     $sql_obj->execute();
     if ($sql_obj->num_rows()) {
         $sql_obj->fetch_array();
         foreach ($sql_obj->data as $data) {
             $_SESSION["user"][$data["name"]] = $data["value"];
         }
     }
     // success
     return 1;
 }
Example #3
0
 	that the reverse request is valid and what the id of the domain is. Really
 	all that we need to do is set the details for the record create/update
 */
 if ($record["reverse_ptr"]) {
     log_write("debug", "process", "Updating reverse PTR record for " . $record["name"] . "--&gt; " . $record["content"] . "");
     $obj_ptr = new domain_records();
     $obj_ptr->id = $record["reverse_ptr_id_domain"];
     // will always be set
     $obj_ptr->id_record = $record["reverse_ptr_id_record"];
     // might be set, if not, a new record will be added
     $obj_ptr->load_data();
     if ($obj_ptr->id_record) {
         $obj_ptr->load_data_record();
     }
     // fetch host portion of IP address
     switch (ip_type_detect($record["content"])) {
         case "6":
             $ip_ptr = ipv6_convert_arpa($record["content"]);
             break;
         case "4":
         default:
             $tmp = explode(".", $record["content"]);
             $ip_ptr = $tmp[3];
             break;
     }
     // standard reverse record details
     $obj_ptr->data_record["type"] = "PTR";
     $obj_ptr->data_record["ttl"] = $record["ttl"];
     $obj_ptr->data_record["name"] = $ip_ptr;
     // make sure we are using the FQDN
     if ($record["name"] == "@" || $record["name"] == "*" || preg_match("/^\\*\\.[A-Za-z0-9:._-]+\$/", $record["name"])) {