/** * create links function * * if rewrite is enabled in settings use rewrite, otherwise ugly links * * levels: page=$1§ion=$2&subnetId=$3&sPage=$4&ipaddrid=$5 */ function create_link($l1 = null, $l2 = null, $l3 = null, $l4 = null, $l5 = null, $install = false) { # get settings global $settings; if (!isset($settings) && !$install) { $settings = getAllSettings(); } # set rewrite if ($settings['prettyLinks'] == "Yes") { if (!is_null($l5)) { $link = "{$l1}/{$l2}/{$l3}/{$l4}/{$l5}/"; } elseif (!is_null($l4)) { $link = "{$l1}/{$l2}/{$l3}/{$l4}/"; } elseif (!is_null($l3)) { $link = "{$l1}/{$l2}/{$l3}/"; } elseif (!is_null($l2)) { $link = "{$l1}/{$l2}/"; } elseif (!is_null($l1)) { $link = "{$l1}/"; } else { $link = ""; } # prepend base $link = BASE . $link; } else { if (!is_null($l5)) { $link = "?page={$l1}§ion={$l2}&subnetId={$l3}&sPage={$l4}&ipaddrid={$l5}"; } elseif (!is_null($l4)) { $link = "?page={$l1}§ion={$l2}&subnetId={$l3}&sPage={$l4}"; } elseif (!is_null($l3)) { $link = "?page={$l1}§ion={$l2}&subnetId={$l3}"; } elseif (!is_null($l2)) { $link = "?page={$l1}§ion={$l2}"; } elseif (!is_null($l1)) { $link = "?page={$l1}"; } else { $link = ""; } } # result return $link; }
<?php /* Script to check status of IP addresses provided in $argv in decimal, returns alive and dead */ //it can only be run from cmd! $sapi_type = php_sapi_name(); if ($sapi_type != "cli") { die; } // include required scripts require_once dirname(__FILE__) . '/../functions.php'; require_once dirname(__FILE__) . '/../scripts/Thread.php'; require_once dirname(__FILE__) . '/config-scan.php'; # get settings $settings = getAllSettings(); // no error reporting! ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT); // test to see if threading is available if (!Thread::available()) { $res['errors'] = "Threading is required for scanning subnets. Please recompile PHP with pcntl extension"; $res = json_encode($res); print_r($res); die; } $count = 1; // number of pings $timeout = 1; // timeout in seconds // set result arrays $alive = array(); // alive hosts
/** * save filtered fields */ function write_custom_filter($table, $out) { $settings = getAllSettings(); if (strlen($settings['hiddenCustomFields']) > 0) { $filterField = json_decode($settings['hiddenCustomFields'], true); } else { $filterField = array(); } # set if (is_null($out)) { unset($filterField[$table]); } else { $filterField[$table] = $out; } # encode $filterField = json_encode($filterField); # write global $database; $query = "update `settings` set `hiddenCustomFields`='{$filterField}';"; try { $database->executeQuery($query); } catch (Exception $e) { $error = $e->getMessage(); print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>"; return false; } return true; }
/** * Check user against AD */ function checkADLogin($username, $password) { /* get All settings */ $settings = getAllSettings(); //include login script include dirname(__FILE__) . "/adLDAP/src/adLDAP.php"; //open connection try { //get settings for connection $ad = getADSettings(); //AD $adldap = new adLDAP(array('base_dn' => $ad['base_dn'], 'account_suffix' => $ad['account_suffix'], 'domain_controllers' => $ad['domain_controllers'], 'use_ssl' => $ad['use_ssl'], 'use_tls' => $ad['use_tls'], 'ad_port' => $ad['ad_port'])); // set OpenLDAP flag if ($settings['domainAuth'] == "2") { $adldap->setUseOpenLDAP(true); } } catch (adLDAPException $e) { die('<div class="alert alert-error">' . $e . '</div>'); } //user authentication $authUser = $adldap->authenticate($username, $password); if ($authUser == true) { global $db; $database = new database($db['host'], $db['user'], $db['pass'], $db['name']); $query = "SELECT id FROM users WHERE username = '******';"; $user_id = $database->getRow($query); if (count($user_id) == 0) { $real_name = str_replace('.', ' ', $username); $real_name = ucwords($real_name); $email = $username . "@enovance.com"; $query = "INSERT INTO users (username, role, real_name, email, domainUser, lang) VALUES ('{$username}', 'Administrator', '{$real_name}', '{$email}', 1, 1);"; $database->executeQuery($query); $user_id = $database->insert_id; if (count($user_id) > 0) { updateLogTable('Created user ' . $username . ' successfully', "", 0); } } $database->close(); if (count($user_id) > 0) { updateLogTable('User ' . $username . ' authenticated against AD.', "", 0); return 'ok'; } else { updateLogTable('Failed to create user .' . $username, "", 2); return "Failed to creater user {$username}"; } } else { updateLogTable('User ' . $username . ' failed to authenticate against AD.', "", 2); $err = $adldap->getLastError(); return 'Failed to authenticate user via AD!'; } }
<?php /** * Mail settings **************************/ /* required functions */ require_once '../../functions/functions.php'; /* verify that user is admin */ checkAdmin(false); /* get settings form post */ $settings = $_POST; $sitesettings = getAllSettings(); /* set mail parameters */ require_once '../../functions/phpMailer/class.phpmailer.php'; // set mail content $mail['html'] = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body style='margin:0px;padding:0px;background:#f9f9f9;border-collapse:collapse;'>"; $mail['html'] .= "phpIPAM test HTML message"; $mail['html'] .= "</body></html>"; $mail['plain'] = "phpIPAM test text message"; //initialize $pmail = new PHPMailer(true); //localhost $pmail->CharSet = "UTF-8"; //set utf8 $pmail->SMTPDebug = 2; //debugging $pmail->Debugoutput = 'html'; //debug type # localhost if ($settings['mtype'] == "localhost") { // initialize try {
/** * Check user against AD */ function checkADLogin($username, $password) { /* get All settings */ $settings = getAllSettings(); # include login script include dirname(__FILE__) . "/adLDAP/src/adLDAP.php"; # open connection try { # get settings for connection $ad = getADSettings(); # AD $adldap = new adLDAP(array('base_dn' => $ad['base_dn'], 'account_suffix' => $ad['account_suffix'], 'domain_controllers' => $ad['domain_controllers'], 'use_ssl' => $ad['use_ssl'], 'use_tls' => $ad['use_tls'], 'ad_port' => $ad['ad_port'])); # set OpenLDAP flag if ($settings['domainAuth'] == "2") { $adldap->setUseOpenLDAP(true); } } catch (adLDAPException $e) { die('<div class="alert alert-danger">' . $e . '</div>'); } # user authentication $authUser = $adldap->authenticate($username, $password); # result if ($authUser == true) { return 'ok'; } else { $err = $adldap->getLastError(); print "<div class='alert alert-danger'>{$err}</div>"; return 'Failed to authenticate user via AD!'; } }
/** * Write new changelog */ function writeChangelog($ctype, $action, $result, $old, $new) { /* set query, open db connection and fetch results */ global $database; # get settings $settings = getAllSettings(); if ($settings['enableChangelog'] == 1) { # get user details $cuser = getActiveUserDetails(); # unset unneeded values and format if ($ctype == "ip_addr") { unset($new['action'], $new['subnet'], $new['type']); } elseif ($ctype == "subnet") { $new['id'] = $new['subnetId']; unset($new['action'], $new['subnetId'], $new['location'], $new['vrfIdOld'], $new['permissions']); # if section does not change if ($new['sectionId'] == $new['sectionIdNew']) { unset($new['sectionIdNew']); unset($new['sectionId']); unset($old['sectionId']); } else { $old['sectionIdNew'] = $old['sectionId']; } //transform subnet if (strlen($new['subnet']) > 0) { $new['subnet'] = Transform2decimal(substr($new['subnet'], 0, strpos($new['subnet'], "/"))); } } elseif ($ctype == "section") { unset($new['action']); } # calculate diff if ($action == "edit") { //old - checkboxes foreach ($old as $k => $v) { if (!isset($new[$k]) && $v == 1) { $new[$k] = 0; } } foreach ($new as $k => $v) { //change if ($old[$k] != $v && $old[$k] != str_replace("\\'", "'", $v)) { //empty if (strlen(@$old[$k]) == 0) { $old[$k] = "NULL"; } if (strlen(@$v) == 0) { $v = "NULL"; } //state if ($k == 'state') { $old[$k] = reformatIPStateText($old[$k]); $v = reformatIPStateText($v); } elseif ($k == 'sectionIdNew') { //get old and new device if ($old[$k] != "NULL") { $dev = getSectionDetailsById($old[$k]); $old[$k] = $dev['name']; } if ($v != "NULL") { $dev = getSectionDetailsById($v); $v = $dev['name']; } } elseif ($k == "masterSubnetId") { if ($old[$k] == 0) { $old[$k] = "Root"; } else { $dev = getSubnetDetailsById($old[$k]); $old[$k] = transform2long($dev['subnet']) . "/{$dev['mask']} [{$dev['description']}]"; } if ($v == 0) { $v = "Root"; } else { $dev = getSubnetDetailsById($v); $v = transform2long($dev['subnet']) . "/{$dev['mask']} [{$dev['description']}]"; } } elseif ($k == 'switch') { if ($old[$k] == 0) { $old[$k] = "None"; } elseif ($old[$k] != "NULL") { $dev = getDeviceDetailsById($old[$k]); $old[$k] = $dev['hostname']; } if ($v == 0) { $v = "None"; } if ($v != "NULL") { $dev = getDeviceDetailsById($v); $v = $dev['hostname']; } } elseif ($k == 'vlanId') { //get old and new device if ($old[$k] == 0) { $old[$k] = "None"; } elseif ($old[$k] != "NULL") { $dev = getVLANById($old[$k]); $old[$k] = $dev['name'] . " [{$dev['number']}]"; } if ($v == 0) { $v = "None"; } elseif ($v != "NULL") { $dev = getVLANById($v); $v = $dev['name'] . " [{$dev['number']}]"; } } elseif ($k == 'vrfId') { //get old and new device if ($old[$k] == 0) { $old[$k] = "None"; } elseif ($old[$k] != "NULL") { $dev = getVRFDetailsById($old[$k]); $old[$k] = $dev['name'] . " [{$dev['description']}]"; } if ($v == 0) { $v = "None"; } elseif ($v != "NULL") { $dev = getVRFDetailsById($v); $v = $dev['name'] . " [{$dev['description']}]"; } } elseif ($k == 'masterSection') { if ($old[$k] == 0) { $old[$k] = "Root"; } else { $dev = getSectionDetailsById($old[$k]); $old[$k] = "{$dev['name']}"; } if ($v == 0) { $v = "Root"; } else { $dev = getSectionDetailsById($v); $v = "{$dev['name']}"; } } elseif ($k == "permissions") { # get old and compare $new['permissions'] = str_replace("\\", "", $new['permissions']); //Remove / # Get all groups: $groups = getAllGroups(); $groups = rekeyGroups($groups); # reformat: $newp = json_decode($new['permissions']); $v = ''; foreach ($newp as $ke => $p) { $v .= "<br>" . $groups[$ke]['g_name'] . " : " . parsePermissions($p); } $old[$k] = ""; } $log["[{$k}]"] = "{$old[$k]} => {$v}"; } } } elseif ($action == "add") { $log['[create]'] = "{$ctype} created"; } elseif ($action == "delete") { $log['[delete]'] = "{$ctype} deleted"; $new['id'] = $old['id']; } elseif ($action == "truncate") { $log['[truncate]'] = "Subnet truncated"; } elseif ($action == "resize") { $log['[resize]'] = "Subnet Resized"; $log['[New mask]'] = "/" . $new['mask']; } elseif ($action == "perm_change") { # get old and compare $new['permissions_change'] = str_replace("\\", "", $new['permissions_change']); //Remove / # Get all groups: $groups = getAllGroups(); $groups = rekeyGroups($groups); # reformat if ($new['permissions_change'] != "null") { $newp = json_decode($new['permissions_change']); foreach ($newp as $k => $p) { $log['[Permissions]'] .= "<br>" . $groups[$k]['g_name'] . " : " . parsePermissions($p); } } } //if change happened write it! if (isset($log)) { # format change foreach (@$log as $k => $l) { $changelog .= "{$k} {$l}\n"; } $changelog = $database->real_escape_string(trim($changelog)); # set insert query $query = "insert into `changelog` (`ctype`,`coid`,`cuser`,`caction`,`cresult`,`cdate`,`cdiff`) values ('{$ctype}', '{$new['id']}', '{$cuser['id']}', '{$action}', '{$result}', NOW(), '{$changelog}');"; # execute try { $database->executeQuery($query); } catch (Exception $e) { $error = $e->getMessage(); return true; } # mail it! # all good return true; } } else { return true; } }
/** * Get all subnets in provided sectionId */ function fetchSubnets($sectionId, $orderType = "subnet", $orderBy = "asc") { global $db; # get variables from config file /* check for sorting in settings and override */ $settings = getAllSettings(); /* get section details to check for ordering */ $section = getSectionDetailsById($sectionId); // section ordering if ($section['subnetOrdering'] != "default" && strlen($section['subnetOrdering']) > 0) { $sort = explode(",", $section['subnetOrdering']); $orderType = $sort[0]; $orderBy = $sort[1]; } elseif (isset($settings['subnetOrdering'])) { $sort = explode(",", $settings['subnetOrdering']); $orderType = $sort[0]; $orderBy = $sort[1]; } /* set query, open db connection and fetch results */ $query = "select * from `subnets` where `sectionId` = '{$sectionId}' ORDER BY `masterSubnetId`,`{$orderType}` {$orderBy};"; $database = new database($db['host'], $db['user'], $db['pass'], $db['name']); /* execute */ try { $subnets = $database->getArray($query); } catch (Exception $e) { $error = $e->getMessage(); print "<div class='alert alert-error'>" . _('Error') . ":{$error}</div>"; return false; } $database->close(); /* return subnets array */ return $subnets; }
/** * Check user against AD */ function checkADLogin($username, $password) { /* first checked if it is defined in database - username and ad option */ global $db; # get variables from config file /* global $ad; */ /* check if user exists in local database */ $database = new database($db['host'], $db['user'], $db['pass'], $db['name']); $query = 'select count(*) as count from users where `username` = binary "' . $username . '" and `domainUser` = "1";'; /* execute */ try { $result = $database->getArray($query); } catch (Exception $e) { $error = $e->getMessage(); print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>"; return false; } /* close database connection */ $database->close(); /* get All settings */ $settings = getAllSettings(); /* if yes try with AD */ if ($result[0]['count'] == "1") { //include login script include dirname(__FILE__) . "/adLDAP/src/adLDAP.php"; //open connection try { //get settings for connection $ad = getADSettings(); //AD $adldap = new adLDAP(array('base_dn' => $ad['base_dn'], 'account_suffix' => $ad['account_suffix'], 'domain_controllers' => $ad['domain_controllers'], 'use_ssl' => $ad['use_ssl'], 'use_tls' => $ad['use_tls'], 'ad_port' => $ad['ad_port'])); // set OpenLDAP flag if ($settings['domainAuth'] == "2") { $adldap->setUseOpenLDAP(true); } } catch (adLDAPException $e) { die('<div class="alert alert-danger">' . $e . '</div>'); } //user authentication $authUser = $adldap->authenticate($username, $password); if ($authUser == true) { updateLogTable('User ' . $username . ' authenticated against AD.', "", 0); return 'ok'; } else { updateLogTable('User ' . $username . ' failed to authenticate against AD.', "", 2); $err = $adldap->getLastError(); print "<div class='alert alert-danger'>{$err}</div>"; return 'Failed to authenticate user via AD!'; } } else { return false; } }
function getAllSettingsFromEmployee($reselleremployee) { return getAllSettings($reselleremployee, 'reselleremployee'); }
} else { if ($function == 'getSettings') { logger("Getting Settings"); getAllSettings($rptuser); sendResponse($finalResult['SettingsInfo'], 'setting'); } else { if ($function == 'saveSettings') { logger("Saving Settings - {$m}, {$d}, {$r}"); saveSettings($rptuser, $m, $d, $r); getAllSettings($rptuser); sendResponse($finalResult['SettingsInfo'], 'setting'); } else { if ($function == 'saveWidgetOrder') { logger("Saving Widget Order - {$p1}, {$p2}, {$p3}, {$p4}"); saveWidgetOrder($rptuser, $p1, $p2, $p3, $p4); getAllSettings($rptuser); sendResponse($finalResult['SettingsInfo'], 'setting'); } else { if ($function == 'saveWidgetOptions') { logger("Saving Widget Options: {$wID}, {$layout}, {$type}, {$color}, {$bgnd}"); saveWidgetOptions($rptuser, $wID, $layout, $type, $color, $bgnd); } else { if ($function == 'execQuery') { // Get query without html entities foreach ($_REQUEST as $key => $val) { if ($key == 'rquery') { $rquery = $val; break; } } $rquery = str_replace("\\\"", "\"", $rquery);