# validate $_POST['id'] values if (!preg_match('/^[0-9]+$/i', $_POST['id'])) { $Result->show("danger", _("Invalid ID. Do not manipulate the POST values!"), true); } # validate $_POST['action'] values if ($_POST['action'] != 'add' && $_POST['action'] != 'edit' && $_POST['action'] != 'delete') { $Result->show("danger", _("Invalid action. Do not manipulate the POST values!"), true); } # disable edit on delete $readonly = $_POST['action'] == "delete" ? "disabled" : ""; # fetch all firewall zones $firewallZones = $Zones->get_zones(); # fetch settings $firewallZoneSettings = json_decode($User->settings->firewallZoneSettings, true); # fetch all devices $devices = $Tools->fetch_multiple_objects("devices", "type", $firewallZoneSettings['deviceType']); # fetch old mapping if ($_POST['action'] != 'add') { $mapping = $Zones->get_zone_mapping($_POST['id']); } ?> <!-- header --> <div class="pHeader"><?php print _('Add a mapping between a firewall device and a firewall zone'); ?> </div> <!-- content --> <div class="pContent"> <!-- form --> <form id="mappingEdit">
# all done, mail diff? if (sizeof($address_change) > 0 && $send_mail) { if (!is_object(@$Scan)) { $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); } # check for recipients foreach ($Tools->fetch_multiple_objects("users", "role", "Administrator") as $admin) { if ($admin->mailNotify == "Yes") { $recepients[] = array("name" => $admin->real_name, "email" => $admin->email); } } # none? if (!isset($recepients)) { die; } # fetch mailer settings $mail_settings = $Tools->fetch_object("settingsMail", "id", 1); # fake user object, needed for create_link $User = new StdClass(); @($User->settings->prettyLinks = $Scan->settings->prettyLinks); # initialize mailer $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings);
# initialize user object $Database = new Database_PDO(); $User = new User($Database); $Tools = new Tools($Database); $Sections = new Sections($Database); $Result = new Result(); } # verify that user is logged in $User->check_user_session(); # fetch all permitted domains $permitted_domains = $Sections->fetch_section_domains($_POST['sectionId']); # fetch all belonging vlans $cnt = 0; foreach ($permitted_domains as $k => $d) { // fetch vlans and append $vlans = $Tools->fetch_multiple_objects("vlans", "domainId", $d, "number"); //fetch domain $domain = $Tools->fetch_object("vlanDomains", "id", $d); //save to array $out[$d]['domain'] = $domain; $out[$d]['vlans'] = $vlans; //count add $cnt++; } //filter out empty $permitted_domains = array_filter($out); ?> <select name="vlanId" class="form-control input-sm input-w-auto"> <option disabled="disabled"><?php print _('Select VLAN');
$User = new User($Database); $Tools = new Tools($Database); $Sections = new Sections($Database); $Result = new Result(); } # verify that user is logged in $User->check_user_session(); # fetch all permitted domains $permitted_nameservers = $Sections->fetch_section_nameserver_sets($_POST['sectionId']); # fetch all belonging nameserver set $cnt = 0; # Only parse nameserver if any exists if ($permitted_nameservers != false) { foreach ($permitted_nameservers as $k => $n) { // fetch nameserver sets and append $nameserver_set = $Tools->fetch_multiple_objects("nameservers", "id", $n, "name", "namesrv1", "namesrv2", "namesrv3"); //save to array $nsout[$n] = $nameserver_set; //count add $cnt++; } //filter out empty $permitted_nameservers = array_filter($nsout); } ?> <select name="nameserverId" class="form-control input-sm input-w-auto"> <optgroup label='<?php print _('Select nameserver set'); ?> '>
/** * Checks if subnet usage is over threshold and sends alert * * @access private * @param mixed $address * @return void */ private function threshold_check($address) { $address = (object) $address; $content = array(); $content_plain = array(); # fetch settings $this->get_settings(); # enabled ? if ($this->settings->enableThreshold == "1") { # object if (!is_object($this->Subnets)) { $this->Subnets = new Subnets($this->Database); } # fetch subnet $subnet = $this->Subnets->fetch_subnet("id", $address->subnetId); # threshold set ? if ($subnet->threshold > 0) { # count number of hosts in subnet $used_hosts = $this->count_subnet_addresses($address->subnetId); # calculate subnet usage $subnet_usage = $this->Subnets->calculate_subnet_usage($used_hosts, $subnet->mask, $subnet->subnet, $subnet->isFull); # if over send mail if (gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0))) > $subnet->threshold) { // fetch mail settings $Tools = new Tools($this->Database); $admins = $Tools->fetch_multiple_objects("users", "role", "Administrator"); // if some recipients if ($admins !== false) { // mail settings $mail_settings = $Tools->fetch_object("settingsMail", "id", 1); // mail class $phpipam_mail = new phpipam_mail($this->settings, $mail_settings); // send $phpipam_mail->initialize_mailer(); // set parameters $subject = "Subnet threshold limit reached" . " (" . $this->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask . ")"; $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;'>"; $content[] = "<tr><td style='padding:5px;margin:0px;color:#333;font-size:16px;text-shadow:1px 1px 1px white;border-bottom:1px solid #eeeeee;' colspan='2'>{$this->mail_font_style}<strong>{$subject}</font></td></tr>"; $content[] = '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . _('Subnet') . '</a></font></td> <td style="padding: 0px;padding-left:15px;margin:0px;line-height:18px;text-align:left;padding-top:10px;"><a href="' . $this->createURL() . '' . create_link("subnets", $subnet->sectionId, $subnet->id) . '">' . $this->mail_font_style_href . $this->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask . '</font></a></td></tr>'; $content[] = '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . _('Description') . '</font></td> <td style="padding: 0px;padding-left:15px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . $subnet->description . '</font></td></tr>'; $content[] = '<tr><td style="padding: 0px;padding-left:10px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . _('Usage') . ' (%)</font></td> <td style="padding: 0px;padding-left:15px;margin:0px;line-height:18px;text-align:left;">' . $this->mail_font_style . '' . gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0))) . '</font></td></tr>'; $content[] = "</table>"; // plain $content_plain[] = "{$subject}" . "\r\n------------------------------\r\n"; $content_plain[] = _("Subnet") . ": " . $this->transform_address($subnet->subnet, "dotted") . "/" . $subnet->mask; $content_plain[] = _("Usage") . " (%) : " . gmp_strval(gmp_sub(100, (int) round($subnet_usage['freehosts_percent'], 0))); # set content $content = $phpipam_mail->generate_message(implode("\r\n", $content)); $content_plain = implode("\r\n", $content_plain); # try to send try { $phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName); //add all admins to CC $recipients = $this->changelog_mail_get_recipients($subnet->id); if ($recipients !== false) { foreach ($recipients as $a) { $phpipam_mail->Php_mailer->addAddress($a->email); } $phpipam_mail->Php_mailer->Subject = $subject; $phpipam_mail->Php_mailer->msgHTML($content); $phpipam_mail->Php_mailer->AltBody = $content_plain; //send $phpipam_mail->Php_mailer->send(); } else { return true; } } catch (phpmailerException $e) { $this->Result->show("danger", "Mailer Error: " . $e->errorMessage(), true); } catch (Exception $e) { $this->Result->show("danger", "Mailer Error: " . $e->errorMessage(), true); } } } } else { return true; } } else { return true; } }
$User = new User($Database); $Admin = new Admin($Database); $Tools = new Tools($Database); $Result = new Result(); # verify that user is logged in $User->check_user_session(); # scan disabled if ($User->settings->enableSNMP != "1") { $Result->show("danger", _("SNMP module disbled"), true, true); } # admin check if ($User->is_admin() !== true) { $Result->show("danger", _('Admin privileges required'), true, true); } # fetch devices that use get_routing_table query $scan_devices = $Tools->fetch_multiple_objects("devices", "snmp_queries", "%get_vrf_table%", "id", true, true); // if none set die if ($scan_devices === false) { $Result->show("danger", _("No devices for SNMP VRF query available"), true, true); } ?> <!-- header --> <div class='pHeader'><?php print _("Select devices"); ?> </div> <!-- content --> <div class='pContent'> <h4><?php
} if (!is_numeric($_POST['subnetId'])) { $Result->show("danger", "Invalid subnet Id", true, $ajax_loaded); } $section = $Subnets->fetch_object("sections", "id", $_POST['sectionId']); if ($section === false) { $Result->show("danger", "Invalid section Id", true, $ajax_loaded); } # check section permissions if ($Subnets->check_permission($User->user, $_POST['sectionId']) != 3) { $Result->show("danger", _('You do not have permissions to add new subnet in this section') . "!", true, $ajax_loaded); } // no errors error_reporting(E_ERROR); # fetch devices that use get_routing_table query $devices_used = $Tools->fetch_multiple_objects("devices", "snmp_queries", "%get_routing_table%", "id", true, true); # recolaculate ids for info foreach ($devices_used as $d) { $devices_info[$d->id] = $d; } // if none set die if ($devices_used === false) { $Result->show("danger", "No devices for SNMP route table query available" . "!", true, $ajax_loaded); } // ok, we have devices, connect to each device and do query foreach ($devices_used as $d) { // init $Snmp->set_snmp_device($d); // execute try { $res = $Snmp->get_query("get_routing_table");
if ($User->is_admin() !== true) { $Result->show("danger", _('Admin privileges required'), true); } # set class $Snmp = new phpipamSNMP(); # domain Id must be int if (!is_numeric($_POST['domainId'])) { $Result->show("danger", _("Invalid domain Id"), true); } # fetch domain $domain = $Tools->fetch_object("vlanDomains", "id", $_POST['domainId']); if ($domain === false) { $Result->show("danger", _("Invalid domain Id"), true); } # get existing vlans $existing_vlans = $Tools->fetch_multiple_objects("vlans", "domainId", $domain->id, "vlanId"); if ($existing_vlans !== false) { foreach ($existing_vlans as $v) { $ex_vlans[$v->number] = $name; } } // no errors error_reporting(E_ERROR); # set devices foreach ($_POST as $k => $p) { if (strpos($k, "device-") !== false) { # fetch device $device = $Tools->fetch_object("devices", "id", str_replace("device-", "", $k)); if ($device !== false) { $scan_devices[] = $device; }
$Snmp = new phpipamSNMP(); $Result = new Result(); # verify that user is logged in $User->check_user_session(); # scan disabled if ($User->settings->enableSNMP != "1") { $Result->show("danger", "SNMP module disbled", true, true, false, true); } # check section permissions if ($Sections->check_permission($User->user, $_POST['sectionId']) != 3) { $Result->show("danger", _('You do not have permissions to add new subnet in this section') . "!", true, true); } // no errors error_reporting(E_ERROR); # fetch devices that use get_routing_table query $devices_used = $Tools->fetch_multiple_objects("devices", "snmp_queries", "%get_routing_table%", "id", true, true); # fetch all IPv4 masks $masks = $Subnets->get_ipv4_masks(); // if none set die if ($devices_used === false) { $Result->show("danger", _("No devices for SNMP route table query available") . "!", true, true, false, true); } // ok, we have devices, connect to each device and do query foreach ($devices_used as $d) { // init $Snmp->set_snmp_device($d); // execute try { $res = $Snmp->get_query("get_routing_table"); // remove those not in subnet if (sizeof($res) > 0) {