コード例 #1
0
ファイル: NagiosCgiImporter.php プロジェクト: Evolix/lilac
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $cgiCfg = new NagiosCgiConfiguration();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     foreach ($values as $key => $entries) {
         if (preg_match("/^authorized_for/i", $key)) {
             // We need to pass the entire value over.
             // Collect the entries
             $value = array();
             foreach ($entries as $entry) {
                 $value[] = $entry['value'];
             }
             $value = implode(",", $value);
             if (!method_exists($cgiCfg, $this->fieldMethods[$key])) {
                 $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $entries[0]['line'] . " in file " . $fileName);
                 if (!$config->getVar('continue_error')) {
                     return false;
                 }
             } else {
                 call_user_method($this->fieldMethods[$key], $cgiCfg, $value);
             }
             continue;
         }
         foreach ($entries as $entry) {
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($cgiCfg, $this->fieldMethods[$key])) {
                     $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName);
                     if (!$config->getVar('continue_error')) {
                         return false;
                     }
                 } else {
                     call_user_method($this->fieldMethods[$key], $cgiCfg, $value);
                 }
             }
         }
     }
     // If we got here, it's safe to delete the existing main config and save the new one
     $oldConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
     if ($oldConfig) {
         $oldConfig->clearAllReferences(true);
         $oldConfig->delete();
     }
     $cgiCfg->save();
     $cgiCfg->clearAllReferences(true);
     $job->addNotice("NagiosCgiImporter finished importing cgi configuration.");
     return true;
 }
コード例 #2
0
ファイル: NagiosCgiExporter.php プロジェクト: Evolix/lilac
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosCgiExporter attempting to export cgi configuration.");
     // Grab our cgi config
     $cgiConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
     if (!$cgiConfig) {
         $job->addError("Unable to get CGI Configuration object.  Your Lilac database is corrupt.");
         return false;
     }
     $finalArray = array();
     $values = $cgiConfig->toArray(BasePeer::TYPE_FIELDNAME);
     foreach ($values as $key => $value) {
         if ($key == 'id') {
             continue;
         }
         if ($value === null) {
             continue;
         }
         if ($value === false) {
             $value = '0';
         }
         $finalArray[$key] = $value;
     }
     // get our main config
     $mainConfig = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     $configdir = $mainConfig->getConfigDir();
     $finalArray['main_config_file'] = $configdir . "/nagios.cfg";
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosCgiExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     foreach ($finalArray as $key => $val) {
         fputs($fp, $key . "=" . $val . "\n");
     }
     /*    Added by Romain Dessort (Evolix) on 08/02/2011:
      *
      *  nagios_check_command directive is required by Nagios, but
      *  Lilac does not allow to change this parameter in the web
      *  interface. I set it here.
      */
     fputs($fp, "nagios_check_command=/usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/status.dat 5 '/usr/sbin/nagios3'\n");
     $job->addNotice("NagiosCgiExporter complete.");
     return true;
 }
コード例 #3
0
ファイル: FruityCgiImporter.php プロジェクト: Evolix/lilac
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityCgiImporter beginning to import CGI Configuration.");
     // Cgi configuration
     $res = $this->dbConn->query("SELECT * FROM nagios_cgi");
     // Fruity has just one record in the resources, if we get it, import
     // it.
     $row = $res->fetch(PDO::FETCH_ASSOC);
     // Get our resources obj.
     $cgiConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
     if (!$cgiConfig) {
         $cgiConfig = new NagiosCgiConfiguration();
         $cgiConfig->save();
     }
     foreach ($row as $key => $val) {
         unset($name);
         if ($key == "id" || $key == "show_context_help" || $key == "nagios_check_command") {
             continue;
         }
         // Iterate through and, if we have a valid key, we set it to
         // the NagiosResource obj.
         try {
             $name = NagiosCgiConfigurationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("CGI Configuration Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $cgiConfig->{$method}($val);
         }
     }
     $cgiConfig->save();
     // Save resources configuration
     $job->addNotice("FruityCgiImporter finished importing CGI Configuration.");
 }
コード例 #4
0
ファイル: cgi.php プロジェクト: Evolix/lilac
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/*
Lilac Index Page, Displays Menu, and Statistics
*/
include_once 'includes/config.inc';
$cgiConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
if (!$cgiConfig) {
    $cgiConfig = new NagiosCgiConfiguration();
    $cgiConfig->save();
}
if (isset($_POST['request'])) {
    if ($_POST['request'] == 'update') {
        if (isset($_POST['cgi_config']['physical_html_path'])) {
            $cgiConfig->setPhysicalHtmlPath($_POST['cgi_config']['physical_html_path']);
        }
        if (isset($_POST['cgi_config']['url_html_path'])) {
            $cgiConfig->setUrlHtmlPath($_POST['cgi_config']['url_html_path']);
        }
        if (isset($_POST['cgi_config']['use_authentication'])) {
            $cgiConfig->setUseAuthentication($_POST['cgi_config']['use_authentication']);
        }