Exemple #1
0
function snippetsOptions()
{
    $db = new db();
    $log = ADLog::getInstance();
    /*
     * Extract all snippets for select list below
     */
    $q = "SELECT id, snippetName\n\t\t\t\t\t\tFROM snippets \n\t\t\t\t\t\tORDER BY snippetName ASC";
    $result = $db->q($q);
    $num_rows = mysql_numrows($result);
    if (!$result || $num_rows < 0) {
        $log->Warn("Failure: Problem Displaying snippetsOptions() options (File: " . $_SERVER['PHP_SELF'] . ")");
        echo "Error displaying info for reportsOptions() function";
        return;
    }
    if ($num_rows == 0) {
        $log->Warn("Failure: Problem Displaying snippetsOptions() - no options returned (File: " . $_SERVER['PHP_SELF'] . ")");
        echo "Database table empty";
        return;
    }
    for ($i = 0; $i < $num_rows; $i++) {
        $id = mysql_result($result, $i, "id");
        $snippetName = mysql_result($result, $i, "snippetName");
        echo "<option value=snippetId-" . $id . ">" . $snippetName . "</option>";
    }
}
function availableElems()
{
    $db = new db();
    $log = ADLog::getInstance();
    /*
     * Extract all Policy Elements for select list below
     */
    $q = "SELECT id, elementName FROM compliancePolElem WHERE status = 1 ORDER BY elementName ASC";
    $result = $db->q($q);
    $num_rows = mysql_numrows($result);
    if (!$result || $num_rows < 0) {
        $log->Warn("Failure: Problem Displaying compliancePolElem options (File: " . $_SERVER['PHP_SELF'] . ")");
        echo "Error displaying info for availableElems() function";
        return;
    }
    if ($num_rows == 0) {
        $log->Warn("Failure: Problem Displaying availableElems() - no options returned (File: " . $_SERVER['PHP_SELF'] . ")");
        echo "Database table empty";
        return;
    }
    for ($i = 0; $i < $num_rows; $i++) {
        $id = mysql_result($result, $i, "id");
        $elementName = mysql_result($result, $i, "elementName");
        echo "<option value=" . $id . ">" . $elementName . "</option>";
    }
}
 /**
  * Class Constructor
  * @param  string  $date Full date in 'Ymd' format
  * @param  string  $year Year in 'Y' format
  * @param  string  $year month in 'm' format
  * @param  string  $day month in 'd' format
  * @param  string  $reportDir Final Reports Directory
  * @param  string  $filename Report Filename
  * @param  string  $config_reports_basedir Top Level Reports Directory
  */
 public function __construct($config_reports_basedir, $filename, $reportDir, $serverIp)
 {
     $this->log = ADLog::getInstance();
     // Set some variables for file and folder creation
     $this->date = date('Ymd');
     $this->year = date('Y');
     $this->month = date('M');
     $this->day = date('d');
     $this->reportDate = date('D d M Y');
     $this->reportDir = $reportDir;
     $this->filename = $filename;
     $this->reportFolder = $config_reports_basedir . $reportDir . "/";
     $this->fullReportPath = $config_reports_basedir . $reportDir . "/" . $filename;
     $this->serverIp = $serverIp;
 }
Exemple #4
0
 public function __construct($script, $taskName, $taskDesc = null, $cronPattern)
 {
     require_once "ADLog.class.php";
     $this->log = ADLog::getInstance();
     // Set some variables for file and folder creation
     $this->script = $script;
     $this->taskName = $taskName;
     $this->taskDesc = $taskDesc;
     $this->cronPattern = $cronPattern;
     $this->crontabContent = $this->taskName . PHP_EOL . $this->taskDesc . PHP_EOL . $this->cronPattern . $this->script;
     /* File and DIR variables for global use */
     $this->cronFolder = "/home/rconfig/cronfeed";
     $this->filename = "cronfeed.txt";
     $this->fullpath = $this->cronFolder . "/" . $this->filename;
 }
Exemple #5
0
function categories($id = null)
{
    // $id is set if from is reloaded with errors so that selected item is pre-populated after form reload
    $db = new db();
    $log = ADLog::getInstance();
    /*
     * Extract Categories for select list below
     */
    $q = "SELECT * FROM categories WHERE status = 1";
    $result = $db->q($q);
    $num_rows = mysql_numrows($result);
    if (!$result || $num_rows < 0) {
        echo "Error displaying info";
        $log->Warn("Failure: Problem Displaying categories options (File: " . $_SERVER['PHP_SELF'] . ")");
        return;
    }
    if ($num_rows == 0) {
        echo "Database table empty";
        $log->Warn("Failure: Database table returned empty on categories - no options returned (File: " . $_SERVER['PHP_SELF'] . ")");
        return;
    }
    if ($id == null) {
        echo "<option value=\"\" selected>Select a Category </option>";
    } else {
        echo "<option value=\"\">Select a Category </option>";
    }
    for ($i = 0; $i < $num_rows; $i++) {
        $catId = mysql_result($result, $i, "id");
        $catName = mysql_result($result, $i, "categoryName");
        if ($id == $catId && $id != null) {
            echo "<option value=" . $catId . " selected>" . $catName . "</option>";
        } else {
            echo "<option value=" . $catId . ">" . $catName . "</option>";
        }
    }
}
Exemple #6
0
<?php

// PHP Includes
include "../config/config.inc.php";
include "../config/functions.inc.php";
include "../classes/usersession.class.php";
include "../classes/db.class.php";
/* Turn on event logging */
include "../classes/ADLog.class.php";
$log = ADLog::getInstance();
/**
 * User has NOT logged in, so redirect to main login page
 */
if (!$session->logged_in) {
    header("Location: " . $config_basedir . "login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	
	<title>rConfig - Configuration Management</title>
	<meta name="description" content="Configuration management utility for CLI based devices">
	<meta name="copyright" content="Copyright (c) 2012 - rConfig">
	<meta name="author" content="Stephen Stack">
	
	<!-- Add ICO -->
	<link rel="Shortcut Icon" href="<?php 
echo $config_basedir;
?>
Exemple #7
0
 /**
  * getDefaultCredsManualSet - Get value set for using default credentials with manual uploads & downloads
  */
 function getDefaultCredsManualSet()
 {
     session_start();
     require_once "../../../classes/db.class.php";
     require_once "../../../classes/ADLog.class.php";
     $db = new db();
     $log = ADLog::getInstance();
     if (isset($_GET['getDefaultCredsManualSet'])) {
         /* Update settings table with new option */
         // echo $option;
         $q = $db->q("SELECT useDefaultCredsManualSet FROM settings WHERE ID = '1'");
         $result = mysql_fetch_assoc($q);
         $useDefaultCredsManualSet = $result['useDefaultCredsManualSet'];
         /* Update successful */
         $response = $useDefaultCredsManualSet;
         echo json_encode($response);
     }
 }
Exemple #8
0
 /**
  *  Write a config snippet to to a device using SSH
  */
 public function writeSnippetSSH($snippetArr, $prompt)
 {
     $log = ADLog::getInstance();
     if (!($ssh = new Net_SSH2($this->_hostname, 22, $this->_timeout))) {
         $output = "Failure: Unable to connect to {$this->_hostname}\n";
         $log->Conn("Failure: Unable to connect to " . $this->_hostname . " - (File: " . $_SERVER['PHP_SELF'] . ")");
         return false;
     }
     if (!$ssh->login($this->_username, $this->_password)) {
         $output = "Error: Authentication Failed for {$this->_hostname}\n";
         $log->Conn("Error: Authentication Failed for {$this->_hostname} (File: " . $_SERVER['PHP_SELF'] . ")");
         return false;
     }
     $output = '';
     if ($this->_enableMode === 'on') {
         // $ssh->write("\n"); // 1st linebreak after above prompt check
         $ssh->read('/.*>/', NET_SSH2_READ_REGEX);
         // read out to '>'
         $ssh->write("enable\n");
         $ssh->read('/.*:/', NET_SSH2_READ_REGEX);
         $ssh->write($this->_enableModePassword . "\n");
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
         foreach ($snippetArr as $key => $command) {
             $ssh->write($command . "\n");
             $output .= $ssh->read('/.*#/', NET_SSH2_READ_REGEX);
             // read out to '#'
         }
         $ssh->write("\n");
         // to line break after command output
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
     } else {
         // $ssh->write("\n"); // 1st linebreak after above prompt check
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
         foreach ($snippetArr as $key => $command) {
             $ssh->write($command . "\n");
             $output .= $ssh->read('/.*#/', NET_SSH2_READ_REGEX);
             // read out to '#' because the prompt will change depending on the deployed config
         }
         $ssh->write("\n");
         // to line break after command output
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
     }
     $ssh->disconnect();
     return $output;
 }
Exemple #9
0
 /**
  * sendNewPass - Sends the newly generated password
  * to the user's email address that was specified at
  * sign-up.
  */
 function sendNewPass($user, $smtpRecipientAddr, $pass)
 {
     require "phpmailer/class.phpmailer.php";
     require "db.class.php";
     require "ADLog.class.php";
     require "../config/config.inc.php";
     // declare DB Class
     $db = new db();
     // declare Logging Class
     $log = ADLog::getInstance();
     // $log->logDir = $config_log_basedir; // set correct log dir
     $q = $db->q("SELECT smtpServerAddr, smtpFromAddr, smtpRecipientAddr, smtpAuth, smtpAuthUser, smtpAuthPass FROM settings");
     $result = mysql_fetch_assoc($q);
     $smtpServerAddr = $result['smtpServerAddr'];
     $smtpFromAddr = $result['smtpFromAddr'];
     // $smtpRecipientAddr = $result['smtpRecipientAddr'];
     if ($result['smtpAuth'] == 1) {
         $smtpAuth = $result['smtpAuth'];
         $smtpAuthUser = $result['smtpAuthUser'];
         $smtpAuthPass = $result['smtpAuthPass'];
     }
     $mail = new PHPMailer(true);
     //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
     $body = $user . ",<br/><br/>" . "A new password has been generated for you " . "at your request to log in rConfig.<br/><br/>" . "Username: "******"<br/>" . "New Password: "******"<br/><br/>" . "It is recommended that you change your password " . "to something that is easier to remember, which " . "can be done by going to the My Account page " . "after signing in.<br/><br/>" . "- rConfig Administrator";
     try {
         $mail->IsSMTP();
         // telling the class to use SMTP
         if ($result['smtpAuth'] == 1) {
             $mail->SMTPAuth = true;
             // enable SMTP authentication
             $mail->Username = $smtpAuthUser;
             // SMTP account username
             $mail->Password = $smtpAuthPass;
             // SMTP account password
         }
         $mail->SMTPKeepAlive = true;
         // SMTP connection will not close after each email sent
         $mail->Host = $smtpServerAddr;
         // sets the SMTP server
         $mail->Port = 25;
         // set the SMTP port for the server
         $mail->SetFrom($smtpFromAddr, $smtpFromAddr);
         $mail->Subject = "rConfig - Your new password";
         $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
         // optional, comment out and test
         $mail->MsgHTML($body);
         $mail->AddAddress($smtpRecipientAddr);
         if (!$mail->Send()) {
             $log->Fatal('Fatal:  Mailer Error (' . str_replace("@", "&#64;", $smtpRecipientAddr) . ') ' . $mail->ErrorInfo . " Error:(File: " . $_SERVER['PHP_SELF'] . ")");
         } else {
             $log->Info('Info: Email Report sent to :' . $smtpRecipientAddr . ' (' . str_replace("@", "&#64;", $smtpRecipientAddr) . ')' . " Error:(File: " . $_SERVER['PHP_SELF'] . ")");
         }
         // Clear all addresses and attachments for next loop
         $mail->ClearAddresses();
         $mail->ClearAttachments();
         $ret = true;
     } catch (phpmailerException $e) {
         $ret = $e->errorMessage();
         //Pretty error messages from PHPMailer
         $log->Fatal($e->errorMessage() . " Error:(File: " . $_SERVER['PHP_SELF'] . ")");
         $ret = false;
     } catch (Exception $e) {
         $ret = $e->getMessage();
         //Boring error messages from anything else!
         $log->Fatal($e->getMessage() . " Error:(File: " . $_SERVER['PHP_SELF'] . ")");
         $ret = false;
     }
     return $ret;
 }