示例#1
0
function plugin_weathermap_uninstall()
{
    // This function doesn't seem to ever be called, in Cacti 0.8.8b
    // on the assumption that it will one day work, clear the stored version number from the settings
    // so that an uninstall/reinstall on the plugin would force the db schema to be checked
    WMCactiAPI::setConfigOption("weathermap_version", "");
}
 private function checkForDSStatsTables()
 {
     if (WMCactiAPI::checkForTable('data_source_stats_hourly_last')) {
         return true;
     }
     wm_debug('ReadData CactiDSStats: DSStats database table not found. [DSSTATS003]\\n');
     return false;
 }
 private function checkForTholdTables()
 {
     if (WMCactiAPI::checkForTable('thold_data')) {
         return true;
     }
     wm_debug('ReadData CactiTHold: thold_data database table not found. [THOLD003]\\n');
     return false;
 }
/**
 * @param $mapParameters
 * @param $configDirectory
 * @param $outputDirectory
 * @param $imageFormat
 * @param $quietLogging
 * @param $global_debug
 * @param $mapCount
 * @param $rrdtool_path
 * @param $weathermap_error_suppress
 * @param $weathermap_poller_start_time
 * @param $total_warnings
 * @return array
 */
function weathermap_run_map($mapParameters, $configDirectory, $outputDirectory, $imageFormat, $quietLogging, $global_debug, $mapCount, $rrdtool_path, $weathermap_error_suppress, $weathermap_poller_start_time, $total_warnings)
{
    global $weathermap_debugging;
    global $weathermap_error_suppress;
    // reset the warning counter
    $weathermap_warncount = 0;
    // this is what will prefix log entries for this map
    $logTag = "[Map " . $mapParameters['id'] . "] " . $mapParameters['configfile'];
    wm_debug("{$logTag} - FIRST TOUCH\n");
    $runner = new WeatherMapRunner($configDirectory, $outputDirectory, $mapParameters['configfile'], $mapParameters['filehash'], $imageFormat);
    if ($global_debug === false && ($mapParameters['debug'] == 'on' || $mapParameters['debug'] == 'once')) {
        $weathermap_debugging = true;
        $runner->setDebug(true);
        wm_debug("{$logTag} - Per-map debugging enabled for this map.\n");
    } else {
        $weathermap_debugging = $global_debug;
        $runner->setDebug(false);
    }
    $runner->setRrdtool($rrdtool_path);
    // Log where we are up to so the Cacti UI can tell someone
    WMCactiAPI::setConfigOption("weaathermap_last_started_file", $logTag);
    $runner->LoadMap();
    $mapStartTime = microtime(true);
    weathermap_memory_check("MEM starting {$mapCount}");
    // $weathermapObject = new Weathermap;
    // $weathermapObject->context = "cacti";
    // we can grab the rrdtool path from Cacti's config, in this case
    // $weathermapObject->rrdtool = $rrdtool_path;
    // $weathermapObject->ReadConfig($mapfile);
    $runner->applyAllHints($mapParameters);
    //    weathermap_memory_check("MEM postread");
    //        $weathermapObject->readData();
    //        weathermap_memory_check("MEM postdata");
    if ($quietLogging == 0) {
        wm_warn("About to write image file. If this is the last message in your log, increase memory_limit in php.ini [WMPOLL01]\n", true);
    }
    weathermap_memory_check("MEM pre-render");
    // used to write files before moving them into place
    //    $tempImageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . '.tmp.png';
    //    $imageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . "." . $imageFormat;
    //    $thumbImageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . ".thumb." . $imageFormat;
    //    $thumb48ImageFilename = $outputDirectory . DIRECTORY_SEPARATOR . $mapParameters['filehash'] . ".thumb48." . $imageFormat;
    // Write the image to a temporary file first - it turns out that libpng is not that fast
    // and this way we avoid showing half a map
    // $weathermapObject->drawMapImage($tempImageFilename, $thumbImageFilename, read_config_option("weathermap_thumbsize"));
    $runner->run();
    //        // Firstly, don't move or delete anything if the image saving failed
    //        if (file_exists($tempImageFilename)) {
    //            // Don't try and delete a non-existent file (first run)
    //            if (file_exists($imageFilename)) {
    //                unlink($imageFilename);
    //            }
    //            rename($tempImageFilename, $imageFilename);
    //        }
    //
    //        $gdThumbImage = imagecreatefrompng($thumbImageFilename);
    //        $gdThumb48Image = imagecreatetruecolor(48, 48);
    //        imagecopyresampled($gdThumb48Image, $gdThumbImage, 0, 0, 0, 0, 48, 48, imagesx($gdThumbImage), imagesy($gdThumbImage));
    //        imagepng($gdThumb48Image, $thumb48ImageFilename);
    //        imagedestroy($gdThumb48Image);
    //        imagedestroy($gdThumbImage);
    // $configured_imageuri = $weathermapObject->imageuri;
    // $weathermapObject->imageuri = 'weathermap-cacti-plugin.php?action=viewimage&id=' . $mapParameters['filehash'] . "&time=" . time();
    //        if ($quietLogging == 0) {
    //            wm_warn("Wrote map to $imageFilename and $thumbImageFilename\n", true);
    //        }
    $runner->createAllHTML();
    $runner->writeDataFile();
    // $weathermapObject->writeDataFile($dataFilename);
    // put back the configured imageuri
    // $weathermapObject->imageuri = $configured_imageuri;
    // if an htmloutputfile was configured, output the HTML there too
    // but using the configured imageuri and imagefilename
    //        if ($weathermapObject->htmloutputfile != "") {
    //            $htmlFilename = $weathermapObject->htmloutputfile;
    //
    //            $fileHandle = @fopen($htmlFilename, 'w');
    //
    //            if ($fileHandle !== false) {
    //                fwrite(
    //                    $fileHandle,
    //                    $weathermapObject->makeHTML('weathermap_' . $mapParameters['filehash'] . '_imap')
    //                );
    //                fclose($fileHandle);
    //                wm_debug("Wrote HTML to %s\n", $htmlFilename);
    //            } else {
    //                if (true === file_exists($htmlFilename)) {
    //                    wm_warn('Failed to overwrite ' . $htmlFilename
    //                        . " - permissions of existing file are wrong? [WMPOLL02]\n");
    //                } else {
    //                    wm_warn('Failed to create ' . $htmlFilename
    //                        . " - permissions of output directory are wrong? [WMPOLL03]\n");
    //                }
    //            }
    //        }
    //        if ($weathermapObject->imageoutputfile != "" && $weathermapObject->imageoutputfile != "weathermap.png" && file_exists($imageFilename)) {
    //            // copy the existing file to the configured location too
    //            @copy($imageFilename, $weathermapObject->imageoutputfile);
    //        }
    // If archiving is enabled for this map, then save copies with datestamps, for animation etc
    if ($mapParameters['archiving'] == 'on') {
        // TODO - additionally save a copy with a datestamp file format
        $archiveDatestamp = strftime("%Y-%m-%d-%H-%M", $weathermap_poller_start_time);
        $archiveFilename = $outputDirectory . DIRECTORY_SEPARATOR . sprintf("%s-archive-%s.%s", $mapParameters['filehash'], $archiveDatestamp, $imageFormat);
        @copy($imageFilename, $archiveFilename);
        weathermap_manage_archiving($mapParameters['filehash'] . "-archive-", $outputDirectory);
    }
    db_execute("update weathermap_maps set titlecache='" . mysql_real_escape_string($runner->getProcessedTitle()) . "' where id=" . intval($mapParameters['id']));
    $runner->cleanUp();
    unset($runner);
    // $weathermapObject->cleanUp();
    // unset($weathermapObject);
    $mapEndTime = microtime(true);
    $mapDuration = $mapEndTime - $mapStartTime;
    wm_debug("TIME: %s took %f seconds.\n", $mapParameters['configfile'], $mapDuration);
    weathermap_memory_check("MEM after");
    WMCactiAPI::setConfigOption("weaathermap_last_finished_file", $logTag);
    // if the debug mode was set to once for this map, then that
    // time has now passed, and it can be turned off again.
    $newDebugState = $mapParameters['debug'];
    if ($newDebugState == 'once') {
        $newDebugState = 'off';
    }
    WMCactiAPI::executeDBQuery(sprintf("update weathermap_maps set warncount=%d, runtime=%f, debug='%s',lastrun=NOW() where id=%d", $weathermap_warncount, $mapDuration, $newDebugState, $mapParameters['id']));
    //    $total_warnings += $weathermap_warncount;
    return;
}
 /**
  * @param $request
  */
 protected function handleViewConfig($request, $appObject)
 {
     WMCactiAPI::pageTop();
     $this->wmuiPreviewConfig($request['file']);
     WMCactiAPI::pageBottom();
 }
<?php

/** This file is from Weathermap version 0.97d */
$guest_account = true;
chdir('../../');
require_once "./include/auth.php";
// include the weathermap class so that we can get the version
require_once dirname(__FILE__) . "/lib/globals.php";
require_once dirname(__FILE__) . "/lib/cacti-plugin-user.php";
require_once dirname(__FILE__) . "/lib/cacti-plugin-common.php";
require_once dirname(__FILE__) . "/lib/WMCactiAPI.class.php";
$action = "";
if (isset($_POST['action'])) {
    $action = $_POST['action'];
} elseif (isset($_GET['action'])) {
    $action = $_GET['action'];
}
$plugin = new WeatherMapCactiUserPlugin($config, $colors, WMCactiAPI::getConfigOption("weathermap_image_format", "png"));
$plugin->dispatchRequest($action, $_REQUEST, null);
// vim:ts=4:sw=4:
 private function processImages()
 {
     // Firstly, don't move or delete anything if the image saving failed
     if (file_exists($this->workingImageFileName)) {
         // Don't try and delete a non-existent file (first run)
         if (file_exists($this->imageOutputFileName)) {
             unlink($this->imageOutputFileName);
         }
         rename($this->workingImageFileName, $this->imageOutputFileName);
     }
     $gdThumbImage = imagecreatefrompng($this->thumbnailImageFileName);
     // TODO - this might not be a PNG
     $gdThumb48Image = imagecreatetruecolor(48, 48);
     imagecopyresampled($gdThumb48Image, $gdThumbImage, 0, 0, 0, 0, 48, 48, imagesx($gdThumbImage), imagesy($gdThumbImage));
     imagepng($gdThumb48Image, $this->thumbimagefile2);
     // TODO - this might not be a PNG
     imagedestroy($gdThumb48Image);
     imagedestroy($gdThumbImage);
     $alternateImageOutputFile = $this->mapObject->imageoutputfile;
     if ($alternateImageOutputFile != "" && $alternateImageOutputFile != "weathermap.png" && file_exists($this->imageOutputFileName)) {
         // copy the existing file to the configured location too
         @copy($this->imageOutputFileName, $alternateImageOutputFile);
     }
     if (intval($this->mapObject->thumb_width) > 0) {
         WMCactiAPI::executeDBQuery(sprintf("update weathermap_maps set thumb_width='%d', thumb_height='%d' where id=%d", $this->mapObject->thumb_width, $this->mapObject->thumb_height, $this->mapID));
     }
 }
    private function outputCycleInitialisation($showFullscreen)
    {
        $refreshTime = WMCactiAPI::getConfigOption("weathermap_cycle_refresh", 20);
        $pollerInterval = WMCactiAPI::getConfigOption("poller_interval", 300);
        ?>

        <script src='vendor/jquery/dist/jquery.min.js'></script>
        <script src='vendor/jquery-idletimer/dist/idle-timer.min.js'></script>
        <script src="cacti-resources/map-cycle.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                WMcycler.start({
                    fullscreen: <?php 
        echo $showFullscreen ? "1" : "0";
        ?>
,
                    poller_cycle: <?php 
        echo $pollerInterval * 1000;
        ?>
,
                    isFiltered: true,
                    fullScreenURL: '',
                    period: <?php 
        echo $refreshTime * 1000;
        ?>
                });
            });
        </script>
        <?php 
    }