Example #1
0
 /**
  * Resolves hostname
  *
  * @access public
  * @param mixed $address		address object
  * @param boolena $override		override DNS resolving flag
  * @return void
  */
 public function resolve_address($address, $override = false)
 {
     # settings
     $this->get_settings();
     # addresses object
     $Address = new Addresses($this->Database);
     # make sure it is dotted format
     $address->ip = $Address->transform_address($address->ip_addr, "dotted");
     # if dns_nameis set try to check
     if (empty($address->dns_name) || is_null($address->dns_name)) {
         # if permitted in settings
         if ($this->settings->enableDNSresolving == 1 || $override) {
             # resolve
             $resolved = gethostbyaddr($address->ip);
             if ($resolved == $address->ip) {
                 $resolved = "";
             }
             //resolve fails
             return array("class" => "resolved", "name" => $resolved);
         } else {
             return array("class" => "", "name" => "");
         }
     } else {
         return array("class" => "", "name" => $address->dns_name);
     }
 }
function updateAddress($addr, $keep_photo = true)
{
    global $keep_history, $domain_id, $base_from_where, $table, $table_grp_adr, $table_groups;
    $addresses = new Addresses($addr['id']);
    $resultsnumber = $addresses->count();
    $homepage = str_replace('http://', '', $addr['homepage']);
    $is_valid = $resultsnumber > 0;
    if ($is_valid) {
        if ($keep_history) {
            // Get current photo, if "$keep_photo"
            if ($keep_photo) {
                $r = $addresses->nextAddress()->getData();
                $addr['photo'] = $r['photo'];
            }
            $sql = "UPDATE {$table}\r\n\t               SET deprecated = now()\r\n\t\t           WHERE deprecated is null\r\n\t\t             AND id\t       = '" . $addr['id'] . "'\r\n\t\t             AND domain_id = '" . $domain_id . "';";
            $result = mysql_query($sql);
            saveAddress($addr);
        } else {
            $sql = "UPDATE {$table} SET firstname = '" . $addr['firstname'] . "'\r\n\t                            , lastname  = '" . $addr['lastname'] . "'\r\n\t                            , nickname  = '" . $addr['nickname'] . "'\r\n\t                            , company   = '" . $addr['company'] . "'\r\n\t                            , title     = '" . $addr['title'] . "'\r\n\t                            , address   = '" . $addr['address'] . "'\r\n\t                            , home      = '" . $addr['home'] . "'\r\n\t                            , mobile    = '" . $addr['mobile'] . "'\r\n\t                            , work      = '" . $addr['work'] . "'\r\n\t                            , fax       = '" . $addr['fax'] . "'\r\n\t                            , email     = '" . $addr['email'] . "'\r\n\t                            , email2    = '" . $addr['email2'] . "'\r\n\t                            , email3    = '" . $addr['email3'] . "'\r\n\t                            , homepage  = '" . $addr['homepage'] . "'\r\n\t                            , aday      = '" . $addr['aday'] . "'\r\n\t                            , amonth    = '" . $addr['amonth'] . "'\r\n\t                            , ayear     = '" . $addr['ayear'] . "'\r\n\t                            , bday      = '" . $addr['bday'] . "'\r\n\t                            , bmonth    = '" . $addr['bmonth'] . "'\r\n\t                            , byear     = '" . $addr['byear'] . "'\r\n\t                            , address2  = '" . $addr['address2'] . "'\r\n\t                            , phone2    = '" . $addr['phone2'] . "'\r\n\t                            , notes     = '" . $addr['notes'] . "'\r\n\t    " . ($keep_photo ? "" : ", photo     = '" . $addr['photo'] . "'") . "\r\n\t                            , modified  = now()\r\n\t\t                        WHERE id        = '" . $addr['id'] . "'\r\n\t\t                          AND domain_id = '{$domain_id}';";
            $result = mysql_query($sql);
        }
        // header("Location: view?id=$id");
    }
    return $is_valid;
}
 public function run()
 {
     $faker = Faker\Factory::create();
     //Addresses::truncate();
     for ($i = 0; $i < 30; $i++) {
         $addresses = Addresses::create(array('streetName' => $faker->streetName, 'buildingNumber' => $faker->buildingNumber, 'postalCode' => $faker->postcode, 'province' => $faker->state, 'city' => $faker->city, 'country' => $faker->country));
     }
 }
 public function run()
 {
     $faker = Faker\Factory::create();
     //Suppliers::truncate();
     $address = Addresses::all()->lists('id');
     for ($i = 0; $i < 20; $i++) {
         $suppliers = Suppliers::create(array('name' => $faker->company, 'phone' => $faker->phoneNumber, 'email' => $faker->email, 'addressId' => $faker->randomElement($address)));
     }
 }
Example #5
0
<?php

/*
 * Print truncate subnet
 *********************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database, false);
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# create csrf token
$csrf = $User->create_csrf_cookie();
# id must be numeric
if (!is_numeric($_POST['subnetId'])) {
    $Result->show("danger", _("Invalid ID"), true, true);
}
# get subnet details
$subnet = $Subnets->fetch_subnet(null, $_POST['subnetId']);
# verify that user has write permissions for subnet
$subnetPerm = $Subnets->check_permission($User->user, $subnet->id);
if ($subnetPerm < 3) {
    $Result->show("danger", _('You do not have permissions to resize subnet') . '!', true, true);
}
?>
Example #6
0
    # set sorting
    $sort['direction'] = 'asc';
    $sort['field'] = 'ip_addr';
    $sort['directionNext'] = "desc";
} else {
    # use required functions
    require '../../../functions/functions.php';
    # database object
    $Database = new Database_PDO();
    # initialize objects
    $Result = new Result();
    $User = new User($Database);
    $Sections = new Sections($Database);
    $Subnets = new Subnets($Database);
    $Tools = new Tools($Database);
    $Addresses = new Addresses($Database);
    # verify that user is logged in
    $User->check_user_session();
    # set sorting
    $tmp = explode("|", $_POST['direction']);
    $sort['field'] = $tmp[0];
    $sort['direction'] = $tmp[1];
    if ($sort['direction'] == "asc") {
        $sort['directionNext'] = "desc";
    } else {
        $sort['directionNext'] = "asc";
    }
    # subnet-related variables
    $subnet = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
    //subnet details
    $subnet_detailed = $Subnets->get_network_boundaries($subnet['subnet'], $subnet['mask']);
<?php

/**
 * Script to check edited / deleted / new IP addresses
 * If all is ok write to database
 *************************************************/
# include required scripts
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
$Log = new Logging($Database, $User->settings);
$Zones = new FirewallZones($Database);
$Ping = new Scan($Database);
# verify that user is logged in
$User->check_user_session();
# validate csrf cookie
$User->csrf_cookie("validate", "address", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
# validate action
$Tools->validate_action($_POST['action']);
$action = $_POST['action'];
//reset delete action form visual visual
if (isset($_POST['action-visual'])) {
    if (@$_POST['action-visual'] == "delete") {
        $action = "delete";
    }
}
Example #8
0
<?php

/**
 *	Generate XLS file for subnet
 *********************************/
# include required scripts
require dirname(__FILE__) . '/../../../functions/functions.php';
require dirname(__FILE__) . '/../../../functions/PEAR/Spreadsheet/Excel/Writer.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$User->check_user_session();
# we dont need any errors!
//ini_set('display_errors', 0);
# fetch subnet details
$subnet = (array) $Subnets->fetch_subnet(null, $_GET['subnetId']);
# fetch all IP addresses in subnet
$addresses = $Addresses->fetch_subnet_addresses($_GET['subnetId'], "ip_addr", "asc");
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
# Create a workbook
$filename = "phpipam_subnet_export.xls";
$workbook = new Spreadsheet_Excel_Writer();
//formatting headers
$format_header =& $workbook->addFormat();
$format_header->setBold();
Example #9
0
/*
 * Script to display search results
 **********************************/
# for ajax-loaded pages
if (!isset($Subnets)) {
    # include required scripts
    require dirname(__FILE__) . '/../../../functions/functions.php';
    # initialize required objects
    $Database = new Database_PDO();
    $Result = new Result();
    $User = new User($Database);
    $Subnets = new Subnets($Database);
    $Sections = new Sections($Database);
    $Tools = new Tools($Database);
    $Addresses = new Addresses($Database);
}
# set searchterm
if (isset($_REQUEST['ip'])) {
    // trim
    $_REQUEST['ip'] = trim($_REQUEST['ip']);
    // escape
    $_REQUEST['ip'] = htmlspecialchars($_REQUEST['ip']);
    $search_term = @$search_term == "search" ? "" : $_REQUEST['ip'];
}
# verify that user is logged in
$User->check_user_session();
# change * to % for database wildchar
$search_term = trim($search_term);
$search_term = str_replace("*", "%", $search_term);
//initialize Pear IPv6 object
Example #10
0
 /**
  * Reformat possible nun-full IPv4 address for search
  *
  *	e.g. 10.10.10 -> 10.10.10.0 - 10.10.10.255
  *
  * @access public
  * @param mixed $address
  * @return array high/low decimal address
  */
 public function reformat_IPv4_for_search($address)
 {
     # remove % sign if present
     $address = str_replace("%", "", $address);
     # we need Addresses class
     $Addresses = new Addresses($this->Database);
     # if subnet is provided we have all data
     if (strpos($address, "/") > 0) {
         # Initialize PEAR NET object
         $this->initialize_pear_net_IPv4();
         $net = $this->Net_IPv4->parseAddress($ip);
         $result['low'] = $Addresses->transform_to_decimal($net->network);
         $result['high'] = $Addresses->transform_to_decimal($net->broadcast);
     } else {
         # if subnet is not provided maye wildcard is, so explode it to array
         $address = array_filter(explode(".", $address));
         # 4 pieces is ok, host
         if (sizeof($address) == 4) {
             $result['low'] = $result['high'] = $Addresses->transform_to_decimal(implode(".", $address));
         } elseif (sizeof($address) == 3) {
             $result['low'] = $Addresses->transform_to_decimal(implode(".", array_merge($address, array(0))));
             $result['high'] = $Addresses->transform_to_decimal(implode(".", array_merge($address, array(255))));
         } elseif (sizeof($address) == 2) {
             $result['low'] = $Addresses->transform_to_decimal(implode(".", array_merge($address, array(0, 0))));
             $result['high'] = $Addresses->transform_to_decimal(implode(".", array_merge($address, array(255, 255))));
         } elseif (sizeof($address) == 1) {
             $result['low'] = $Addresses->transform_to_decimal(implode(".", array_merge($address, array(0, 0, 0))));
             $result['high'] = $Addresses->transform_to_decimal(implode(".", array_merge($address, array(255, 255, 255))));
         } else {
             $result['low'] = implode(".", $address);
             $result['high'] = implode(".", $address);
         }
     }
     # return result array low/high
     return $result;
 }
Example #11
0
$homeAddr = $addrs->getColumn('homeAddress');
$homeAddr->setColumn('city', 'san francisco');
$homeAddr->setColumn('street', '1234 x street');
$homeAddr->setColumn('zip', '94107');
// work address
$workAddr = $addrs->getColumn('workAddress');
$workAddr->setColumn('city', 'san jose');
$workAddr->setColumn('street', '9876 y drive');
// custom labelled supercolumn
$customAddr = new Address('customAddress');
$customAddr->setColumn('city', 'another city');
$addrs->addSuper($customAddr);
if (!$addrs->save()) {
    die($addrs->lastError());
}
unset($addrs);
// Load the saved Addresses
$addrs = new Addresses();
if (!$addrs->load($keyID)) {
    die($addrs->lastError());
}
// Show our loaded CF in JSON format, including key path
echo '<pre>' . $addrs->toJSON(TRUE) . '</pre>';
// Example export -> import of JSON structure from loaded data into new object
$addrsClone = new Addresses();
// Populates data from JSON export (therefore must exclude key path)
$addrsClone->populate($addrs->toJSON());
// Set key
$addrsClone->setKeyID($keyID);
// Show the JSON for our CF with cloned data.  This and the prior echo should match
echo '<pre>' . $addrsClone->toJSON(TRUE) . '</pre>';
Example #12
0
 /**
  * Get the reviews data map coordinates
  */
 public static function getXMLDataMap($locale = 1)
 {
     $data = array();
     $j = 0;
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $records = Doctrine_Query::create()->from('Reviews r')->leftJoin('r.Products p')->leftJoin("p.ProductsData pd WITH pd.language_id = {$locale}")->where("active = ?", true)->andWhere('latitude <> ?', "")->andWhere('longitude <> ?', "")->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     foreach ($records as $record) {
         $text = "<div id=\"mycontent\">";
         $text .= "<div id=\"bodyContent\">";
         $text .= "<h4><a href=\"/" . $record['Products']['uri'] . ".html\">" . $record['Products']['ProductsData'][0]['name'] . "</a></h4>";
         for ($i = 0; $i < $record['stars']; $i++) {
             $text .= "*";
         }
         $text .= "<br/><br/>" . $record['review'] . "<br/>";
         $text .= "<p><b>inviato da " . $record['nick'] . "</b> il " . Shineisp_Commons_Utilities::formatDateOut($record['publishedat']) . "</p>";
         $text .= "</div></div>";
         $data['marker'][$j]['@attributes'] = array('lat' => $record['latitude'], 'lng' => $record['longitude']);
         $data['marker'][$j]['text']['@cdata'] = $text;
         $j++;
     }
     $customers = Addresses::getMapCoords();
     foreach ($customers as $record) {
         if (!empty($record['company'])) {
             $text = "";
             #$text = "<div id=\"mycontent\">";
             #$text .= "<div id=\"bodyContent\">";
             #$text .= "<p>". $translator->_('%s has choosen our company as I.T. partners', "<b>" . $record['company']. "</b>") . "</p>";
             #$text .= "</div></div>";
             $data['marker'][$j]['@attributes'] = array('lat' => $record['latitude'], 'lng' => $record['longitude'], 'icontype' => "purple");
             $data['marker'][$j]['text']['@cdata'] = $text;
             $j++;
         }
     }
     $xml = Shineisp_Commons_Array2XML::createXML('markers', $data);
     $xml->save(PUBLIC_PATH . "/documents/reviews.xml");
     return true;
 }
Example #13
0
 *
 *
 *	In case of problems set reset_debugging to true
 *
 *  Statuses:
 *      0 = online
 *      2 = offline
 *
 */
# include required scripts
require dirname(__FILE__) . '/../functions.php';
require dirname(__FILE__) . '/../../functions/classes/class.Thread.php';
# initialize objects
$Database = new Database_PDO();
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Scan = new Scan($Database);
$Result = new Result();
// set exit flag to true
$Scan->ping_set_exit(true);
// set debugging
$Scan->reset_debugging(false);
// fetch agent
$agent = $Tools->fetch_object("scanAgents", "id", 1);
// change scan type?
// $Scan->reset_scan_method ("fping");
// set ping statuses
$statuses = explode(";", $Scan->settings->pingStatus);
// set mail override flag
$send_mail = true;
Example #14
0
<?php

/**
 *	Script that checks if IP is alive
 */
# include required scripts
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
$Ping = new Scan($Database, $User->settings);
# verify that user is logged in
$User->check_user_session();
# validate post
is_numeric($_POST['subnetId']) ?: $Result->show("danger", _("Invalid ID"), true);
is_numeric($_POST['id']) || strlen($_POST['id']) == 0 ?: $Result->show("danger", _("Invalid ID"), true);
# set and check permissions
$subnet_permission = $Subnets->check_permission($User->user, $_POST['subnetId']);
$subnet_permission > 2 ?: $Result->show("danger", _('Cannot edit IP address details') . '! <br>' . _('You do not have write access for this network'), true, true);
# fetch address
$address = (array) $Addresses->fetch_address(null, $_POST['id']);
# try to ping it
$pingRes = $Ping->ping_address($address['ip']);
# update last seen if success
if ($pingRes == 0) {
    @$Ping->ping_update_lastseen($address['id']);
}
Example #15
0
<?php

/*
 * insert new hosts to database
 *******************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database);
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# subnet Id must be a integer
if (!is_numeric($_POST['subnetId']) || $_POST['subnetId'] == 0) {
    $Result->show("danger", _("Invalid ID"), true);
}
# verify that user has write permissionss for subnet
if ($Subnets->check_permission($User->user, $_POST['subnetId']) != 3) {
    $Result->show("danger", _('You do not have permissions to modify hosts in this subnet') . "!", true, true);
}
# ok, lets get results form post array!
foreach ($_POST as $key => $line) {
    // IP address
    if (substr($key, 0, 2) == "ip") {
        $res[substr($key, 2)]['ip_addr'] = $line;
    }
    // description
Example #16
0
<?php

/**
 * Script to print edit / delete / new IP address
 *
 * Fetches info from database
 *************************************************/
# include required scripts
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$User->check_user_session();
# create csrf token
$csrf = $User->create_csrf_cookie();
# validate action
$Tools->validate_action($_POST['action']);
# validate post
is_numeric($_POST['subnetId']) ?: $Result->show("danger", _("Invalid subnet ID"), true, true);
is_numeric($_POST['id']) || strlen($_POST['id']) == 0 ?: $Result->show("danger", _("Invalid ID"), true, true);
# get posted values
$subnetId = $_POST['subnetId'];
$action = $_POST['action'];
$id = $_POST['id'];
# fetch subnet
$subnet = (array) $Subnets->fetch_subnet(null, $subnetId);
Example #17
0
 /**
  * Checks if it ok to split subnet
  *
  * @access private
  * @param mixed $subnet_old
  * @param mixed $number
  * @param string $group
  * @param string $strict
  * @return void
  */
 private function verify_subnet_split($subnet_old, $number, $group, $strict)
 {
     # addresses class
     $Addresses = new Addresses($this->Database);
     # get new mask - how much we need to add to old mask?
     switch ($number) {
         case "2":
             $mask_diff = 1;
             break;
         case "4":
             $mask_diff = 2;
             break;
         case "8":
             $mask_diff = 3;
             break;
         case "16":
             $mask_diff = 4;
             break;
         case "32":
             $mask_diff = 5;
             break;
         case "64":
             $mask_diff = 6;
             break;
         case "128":
             $mask_diff = 7;
             break;
         case "256":
             $mask_diff = 8;
             break;
             //otherwise die
         //otherwise die
         default:
             $Result->show("danger", _("Invalid number of subnets"), true);
     }
     //set new mask
     $mask = $subnet_old->mask + $mask_diff;
     //set number of subnets
     $number_of_subnets = pow(2, $mask_diff);
     //set max hosts per new subnet
     $max_hosts = $this->get_max_hosts($mask, $this->identify_address($this->transform_to_dotted($subnet_old->subnet)), false);
     # create array of new subnets based on number of subnets (number)
     for ($m = 0; $m < $number_of_subnets; $m++) {
         $newsubnets[$m] = (array) $subnet_old;
         $newsubnets[$m]['id'] = $m;
         $newsubnets[$m]['mask'] = $mask;
         // if group is selected rewrite the masterSubnetId!
         if ($group == "yes") {
             $newsubnets[$m]['masterSubnetId'] = $subnet_old->id;
         }
         // recalculate subnet
         if ($m > 0) {
             $newsubnets[$m]['subnet'] = gmp_strval(gmp_add($newsubnets[$m - 1]['subnet'], $max_hosts));
         }
     }
     // recalculate old hosts to put it to right subnet
     $addresses = $Addresses->fetch_subnet_addresses($subnet_old->id, "ip_addr", "asc");
     # get all IP addresses
     $subSize = sizeof($newsubnets);
     # how many times to check
     $n = 0;
     # ip address count
     // loop
     foreach ($addresses as $ip) {
         //cast
         $ip = (array) $ip;
         # check to which it belongs
         for ($m = 0; $m < $subSize; $m++) {
             # check if between this and next - strict
             if ($strict == "yes") {
                 # check if last
                 if ($m + 1 == $subSize) {
                     if ($ip['ip_addr'] > $newsubnets[$m]['subnet']) {
                         $addresses[$n]->subnetId = $newsubnets[$m]['id'];
                     }
                 } elseif ($ip['ip_addr'] > $newsubnets[$m]['subnet'] && $ip['ip_addr'] < @$newsubnets[$m + 1]['subnet']) {
                     $addresses[$n]->subnetId = $newsubnets[$m]['id'];
                 }
             } else {
                 # check if last
                 if ($m + 1 == $subSize) {
                     if ($ip['ip_addr'] >= $newsubnets[$m]['subnet']) {
                         $addresses[$n]->subnetId = $newsubnets[$m]['id'];
                     }
                 } elseif ($ip['ip_addr'] >= $newsubnets[$m]['subnet'] && $ip['ip_addr'] < $newsubnets[$m + 1]['subnet']) {
                     $addresses[$n]->subnetId = $newsubnets[$m]['id'];
                 }
             }
         }
         # if subnetId is still the same save to error
         if ($addresses[$n]->subnetId == $subnet_old->id) {
             $this->Result->show("danger", _('Wrong IP addresses (subnet or broadcast)') . ' - ' . $this->transform_to_dotted($ip['ip_addr']), true);
         }
         # next IP address
         $n++;
     }
     # check if new overlap (e.g. was added twice)
     $nested_subnets = $this->fetch_subnet_slaves($subnet_old->id);
     if ($nested_subnets !== false) {
         //loop through all current slaves and check
         foreach ($nested_subnets as $nested_subnet) {
             //check all new
             foreach ($newsubnets as $new_subnet) {
                 $new_subnet = (object) $new_subnet;
                 if ($this->verify_overlapping($this->transform_to_dotted($new_subnet->subnet) . "/" . $new_subnet->mask, $this->transform_to_dotted($nested_subnet->subnet) . "/" . $nested_subnet->mask) === true) {
                     $Result->show("danger", _("Subnet overlapping - ") . $this->transform_to_dotted($new_subnet->subnet) . "/" . $new_subnet->mask . " overlapps with " . $this->transform_to_dotted($nested_subnet->subnet) . "/" . $nested_subnet->mask, true);
                 }
             }
         }
     }
     # all good, return result array of newsubnets and addresses
     return array(0 => $newsubnets, 1 => $addresses);
 }
Example #18
0
<?php

/**
 * Script to confirm / reject IP address request
 ***********************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database, false);
$Addresses = new Addresses($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# strip input tags
$_POST = $Admin->strip_input_tags($_POST);
# validate csrf cookie
$User->csrf_cookie("validate", "requests", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
# verify permissions
if ($Subnets->check_permission($User->user, $_POST['subnetId']) != 3) {
    $Result->show("danger", _('You do not have permissions to process this request') . "!", true);
}
# fetch custom fields
$custom = $Tools->fetch_custom_fields('ipaddresses');
if (sizeof($custom) > 0) {
    foreach ($custom as $myField) {
        if (isset($_POST[$myField['name']])) {
            $_POST[$myField['name']] = $_POST[$myField['name']];
<?php

/**
 *	Export search results
 ****************************/
# include required scripts
require dirname(__FILE__) . '/../../../functions/functions.php';
require dirname(__FILE__) . '/../../../functions/PEAR/Spreadsheet/Excel/Writer.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Sections = new Sections($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$User->check_user_session();
# fetch search term
$search_term = $_REQUEST['search_term'];
//initialize Pear IPv6 object
require_once dirname(__FILE__) . '/../../../functions/PEAR/Net/IPv6.php';
$Net_IPv6 = new Net_IPv6();
// ipv6 ?
if ($Net_IPv6->checkIPv6($search_term) != false) {
    $type = "IPv6";
} elseif (strlen($search_term) == 17 && substr_count($search_term, ":") == 5) {
    $type = "mac";
    //count : -> must be 5
} else {
    if (strlen($search_term) == 12 && substr_count($search_term, ":") == 0 && substr_count($search_term, ".") == 0) {
Example #20
0
<?php

/**
 *	Generate XLS file
 *********************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
require dirname(__FILE__) . '/../../../functions/PEAR/Spreadsheet/Excel/Writer.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Sections = new Sections($Database);
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
// Create a workbook
$filename = "phpipam_IP_adress_export_" . date("Y-m-d") . ".xls";
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setVersion(8);
//fetch sections, and for each section write new tab, inside tab write all values!
$sections = $Sections->fetch_sections();
//we need to reformat state!
$ip_types = $Addresses->addresses_types_fetch();
//fetch devices and reorder
$devices = $Tools->fetch_all_objects("devices", "hostname");
$devices_indexed = array();
if ($devices !== false) {
    foreach ($devices as $d) {
Example #21
0
<?php

/**
 * Function to add / edit / delete subnet
 ********************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database, false);
$Subnets = new Subnets($Database);
$Sections = new Sections($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# ID must be numeric
if ($_POST['action'] == "add") {
    if (!is_numeric($_POST['sectionId'])) {
        $Result->show("danger", _("Invalid ID"), true);
    }
} else {
    if (!is_numeric($_POST['subnetId'])) {
        $Result->show("danger", _("Invalid ID"), true);
    }
    if (!is_numeric($_POST['sectionId'])) {
        $Result->show("danger", _("Invalid ID"), true);
    }
}
Example #22
0
<?php

/*
 *	Script to inserte imported file to database!
 **********************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# classes
$Database = new Database_PDO();
$User = new User($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
$Subnets = new Subnets($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# permissions
$permission = $Subnets->check_permission($User->user, $_POST['subnetId']);
# die if write not permitted
if ($permission < 2) {
    $Result->show("danger", _('You cannot write to this subnet'), true);
}
# check integer
is_numeric($_POST['subnetId']) ?: $Result->show("danger", _("Invalid subnet ID"), true);
# set filetype
$filetype = end(explode(".", $_POST['filetype']));
# get custom fields
$custom_address_fields = $Tools->fetch_custom_fields('ipaddresses');
# CSV
if (strtolower($filetype) == "csv") {
    /* get file to string */
Example #23
0
    //add to scan_subnets as result
    foreach ($scan_subnets as $sk => $s) {
        if (isset($add_tmp[$s->id])) {
            $scan_subnets[$sk]->discovered = $add_tmp[$s->id];
        }
    }
}
# print change
if ($Scan->debugging) {
    "\nDiscovered addresses:\n----------\n";
    print_r($scan_subnets);
}
# reinitialize objects
$Database = new Database_PDO();
$Admin = new Admin($Database, false);
$Addresses = new Addresses($Database);
$Subnets = new Subnets($Database);
$DNS = new DNS($Database);
$Scan = new Scan($Database);
$Result = new Result();
# insert to database
$discovered = 0;
//for mailing
foreach ($scan_subnets as $s) {
    if (sizeof(@$s->discovered) > 0) {
        foreach ($s->discovered as $ip) {
            // fetch subnet
            $subnet = $Subnets->fetch_subnet("id", $s->id);
            $nsid = $subnet === false ? false : $subnet->nameserverId;
            // try to resolve hostname
            $hostname = $DNS->resolve_address($ip, false, true, $nsid);
Example #24
0
<?php

/**
 * Function to add / edit / delete section
 ********************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database, false);
$Subnets = new Subnets($Database);
$Sections = new Sections($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# ID must be numeric
if ($_POST['action'] == "add") {
    if (!is_numeric($_POST['sectionId'])) {
        $Result->show("danger", _("Invalid ID"), true);
    }
} else {
    if (!is_numeric($_POST['subnetId'])) {
        $Result->show("danger", _("Invalid ID"), true);
    }
}
# verify that user has permissions to add subnet
if ($_POST['action'] == "add") {
    if ($Sections->check_permission($User->user, $_POST['sectionId']) != 3) {
Example #25
0
<?php

/**
 * Script to print mail notification form
 ********************************************/
# include required scripts
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize required objects
$Database = new Database_PDO();
$Result = new Result();
$User = new User($Database);
$Subnets = new Subnets($Database);
$Tools = new Tools($Database);
$Addresses = new Addresses($Database);
# verify that user is logged in
$User->check_user_session();
# id must be numeric
is_numeric($_POST['id']) || strlen($_POST['id']) == 0 ?: $Result->show("danger", _("Invalid ID"), true);
# get IP address id
$id = $_POST['id'];
# fetch address, subnet, vlan and nameservers
$address = (array) $Addresses->fetch_address(null, $id);
$subnet = (array) $Subnets->fetch_subnet(null, $address['subnetId']);
$vlan = (array) $Tools->fetch_object("vlans", "vlanId", $subnet['vlanId']);
$nameservers = (array) $Tools->fetch_object("nameservers", "id", $subnet['nameserverId']);
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('ipaddresses');
# checks
sizeof($address) > 0 ?: $Result->show("danger", _("Invalid ID"), true);
sizeof($subnet) > 0 ?: $Result->show("danger", _("Invalid subnet"), true);
# set title
Example #26
0
    # set sorting
    $sort['direction'] = 'asc';
    $sort['field'] = 'ip_addr';
    $sort['directionNext'] = "desc";
} else {
    # use required functions
    require '../../../functions/functions.php';
    # database object
    $Database = new Database_PDO();
    # initialize objects
    $Result = new Result();
    $User = new User($Database);
    $Sections = new Sections($Database);
    $Subnets = new Subnets($Database);
    $Tools = new Tools($Database);
    $Addresses = new Addresses($Database);
    # verify that user is logged in
    $User->check_user_session();
    # set sorting
    $tmp = explode("|", $_POST['direction']);
    $sort['field'] = $tmp[0];
    $sort['direction'] = $tmp[1];
    if ($sort['direction'] == "asc") {
        $sort['directionNext'] = "desc";
    } else {
        $sort['directionNext'] = "asc";
    }
    # subnet-related variables
    $subnet = (array) $Subnets->fetch_subnet(null, $_POST['subnetId']);
    //subnet details
    $subnet_detailed = $Subnets->get_network_boundaries($subnet['subnet'], $subnet['mask']);
Example #27
0
 /**
  * Fetches changelog for addresses in subnet for all slave subnets
  *
  * @access public
  * @param mixed $subnetId
  * @param int $limit (default: 50)
  * @return void
  */
 public function fetch_subnet_addresses_changelog_recursive($subnetId, $limit = 50)
 {
     # get all addresses ids
     $ips = array();
     $Addresses = new Addresses($this->Database);
     $ips = $Addresses->fetch_subnet_addresses_recursive($subnetId, false);
     # fetch changelog for IPs
     if (sizeof($ips) > 0) {
         # query
         $query = "select\n\t\t    \t\t\t`u`.`real_name`,`o`.`id`,`o`.`ip_addr`,`o`.`description`,`o`.`id`,`o`.`subnetId`,`c`.`caction`,`c`.`cresult`,`c`.`cdate`,`c`.`cdiff`\n\t\t\t\t\t\tfrom `changelog` as `c`, `users` as `u`, `ipaddresses` as `o`\n\t\t\t\t\t\twhere `c`.`cuser` = `u`.`id` and `c`.`coid`=`o`.`id`\n\t\t\t\t\t\tand (";
         $args = array();
         foreach ($ips as $ip) {
             $query .= "`c`.`coid` = ? or ";
             $args[] = $ip->id;
         }
         $query = substr($query, 0, -3);
         $query .= ") and `c`.`ctype` = 'ip_addr' order by `c`.`cid` desc limit {$limit};";
         # fetch
         try {
             $logs = $this->Database->getObjectsQuery($query, array_filter($args));
         } catch (Exception $e) {
             $this->Result->show("danger", $e->getMessage(), false);
             return false;
         }
         # return result
         return $logs;
     } else {
         return false;
     }
 }
Example #28
0
<?php

/**
 * Function to add / edit / delete section
 *************************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database);
$Sections = new Sections($Database);
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# If confirm is not set print delete warning
if ($_POST['action'] == "delete" && !isset($_POST['deleteconfirm'])) {
    //for ajax to prevent reload
    print "<div style='display:none'>alert alert-danger</div>";
    //result
    print "<div class='alert alert-warning'>";
    //fetch all subsections
    $subsections = $Sections->fetch_subsections($_POST['id']);
    //print what will be deleted
    if (sizeof($subsections) > 0) {
        $subnets = $Subnets->fetch_section_subnets($_POST['id']);
        //fetch all subnets in section
        $num_subnets = sizeof($subnets);
        //number of subnets to be deleted
Example #29
0
 *
 *	Script must be run from cron, here is a crontab example for 15 minutes scanning:
 * 		*\/15 * * * *  /usr/local/bin/php /<sitepath>/functions/scripts/pingCheck.php > /dev/null 2>&1
 *
 *
 *	In case of problems set reset_debugging to true
 *
 */
# include required scripts
require dirname(__FILE__) . '/../functions.php';
require dirname(__FILE__) . '/../../functions/classes/class.Thread.php';
require dirname(__FILE__) . '/../../functions/classes/class.Mail.php';
# initialize objects
$Database = new Database_PDO();
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Scan = new Scan($Database);
$Result = new Result();
// set exit flag to true
$Scan->ping_set_exit(true);
// set debugging
$Scan->reset_debugging(false);
// change scan type?
// $Scan->reset_scan_method ("pear");
// set ping statuses
$statuses = explode(";", $Scan->settings->pingStatus);
// set mail override flag
$send_mail = true;
// response for mailing
$address_change = array();
<?php

# include required scripts
require dirname(__FILE__) . '/../functions.php';
# limit
$limit = 80;
// 80 percent threshold
# initialize objects
$Database = new Database_PDO();
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Tools = new Tools($Database);
$Result = new Result();
# fetch all subnets
$all_subnets = $Tools->fetch_all_objects("subnets");
# loop and check usage for each, make sure it does not have any parent
foreach ($all_subnets as $k => $s) {
    // marked as full should not be checked
    if ($s->isFull != 1) {
        // parent check
        if (!$Subnets->has_slaves($s->id)) {
            // count number of addresses
            $cnt = $Addresses->count_subnet_addresses($s->id);
            // calculate usage
            $usage = $Subnets->calculate_subnet_usage($cnt, $s->mask, $s->subnet, $s->isFull);
            // if more than $threshold report
            if ($usage['freehosts_percent'] < 100 - $limit) {
                // this subnet has high usage, save it to array
                $out[$k]['subnet'] = $Subnets->transform_address($s->subnet, "dotted") . "/" . $s->mask;
                $out[$k]['description'] = $s->description;
                $out[$k]['usage'] = $usage;