diff --git a/plugins/housekeeper/DiskUsageDashlet.inc.php b/plugins/housekeeper/DiskUsageDashlet.inc.php
index 32f7e56..ba0c402 100755
--- a/plugins/housekeeper/DiskUsageDashlet.inc.php
+++ b/plugins/housekeeper/DiskUsageDashlet.inc.php
@@ -38,165 +38,54 @@
class DiskUsageDashlet extends KTBaseDashlet
{
- private $dfCmd;
- private $usage;
- private $warningPercent;
- private $urgentPercent;
+ private $usage;
- function DiskUsageDashlet()
- {
- $this->sTitle = _kt('Storage Utilization');
- $this->sClass = "ktInfo";
- }
-
- function is_active($oUser)
- {
- $dfCmd = KTUtil::findCommand('externalBinary/df','df');
- if ($dfCmd === false)
- {
- return false;
- }
- $this->dfCmd = $dfCmd;
-
- $config = KTConfig::getSingleton();
- $this->warningPercent = $config->get('DiskUsage/warningThreshold', 15);
- $this->urgentPercent = $config->get('DiskUsage/urgentThreshold', 5);
-
- $got_usage = $this->getUsage();
-
- if ($got_usage == false)
- {
- return false;
- }
-
- return Permission::userIsSystemAdministrator();
- }
-
- function getUsage($refresh=false)
- {
- if (isset($_SESSION['DiskUsage']['problem']))
- {
- return false;
- }
-
- $check = true;
- // check if we have a cached result
- if (isset($_SESSION['DiskUsage']))
- {
- // we will only do the check every 5 minutes
- if (time() - $_SESSION['DiskUsage']['time'] < 5 * 60)
- {
- $check = false;
- $this->usage = $_SESSION['DiskUsage']['usage'];
- }
- }
-
- // we will only check if the result is not cached, or after 5 minutes
- if ($check)
- {
- $cmd = $this->dfCmd;
-
- if (OS_WINDOWS)
- {
- $cmd = str_replace( '/','\\',$cmd);
- $res = KTUtil::pexec("\"$cmd\" -B 1 2>&1");
- $result = implode("\r\n",$res['out']);
- }
- else
- {
- if(strtolower(PHP_OS) == 'darwin'){
- $result = shell_exec($cmd." -k 2>&1");
- }else{
- $result = shell_exec($cmd." -B 1 2>&1");
- }
- }
-
- if (strpos($result, 'cannot read table of mounted file systems') !== false)
- {
- $_SESSION['DiskUsage']['problem'] = true;
- return false;
- }
-
-
- $result = explode("\n", $result);
-
- unset($result[0]); // gets rid of headings
-
- $usage=array();
- foreach($result as $line)
- {
- if (empty($line)) continue;
- preg_match('/(.*)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(.*)/', $line, $matches);
- list($line, $filesystem, $size, $used, $avail, $usedp, $mount) = $matches;
-
- if ($size === 0) continue;
-
- if(strtolower(PHP_OS) == 'darwin'){
- $size = $size * 1024;
- $used = $used * 1024;
- $avail = $avail * 1024;
- }
-
- $colour = '';
- if ($usedp >= 100 - $this->urgentPercent)
- {
- $colour = 'red';
- }
- elseif ($usedp >= 100 - $this->warningPercent)
- {
- $colour = 'orange';
- }
-
- $usage[] = array(
- 'filesystem'=>$filesystem,
- 'size'=>KTUtil::filesizeToString($size),
- 'used'=>KTUtil::filesizeToString($used),
- 'available'=>KTUtil::filesizeToString($avail),
- 'usage'=>$usedp . '%',
- 'mounted'=>$mount,
- 'colour'=>$colour
- );
- }
-
- $this->usage = $usage;
-
- $_SESSION['DiskUsage']['time'] = time();
- $_SESSION['DiskUsage']['usage'] = $this->usage;
- }
+ function DiskUsageDashlet()
+ {
+ $this->sTitle = _kt('Storage Utilization');
+ $this->sClass = "ktInfo";
+ }
- return true;
- }
+ function is_active($oUser)
+ {
+ $usage = unserialize(KTUtil::getSystemSetting('DiskUsage','n/a'));
+ if ($usage == 'n/a') return false;
+ $this->usage = $usage;
+ return Permission::userIsSystemAdministrator();
+ }
- function render()
- {
- $oTemplating =& KTTemplating::getSingleton();
- $oTemplate = $oTemplating->loadTemplate('DiskUsage');
+ function render()
+ {
+ $oTemplating =& KTTemplating::getSingleton();
+ $oTemplate = $oTemplating->loadTemplate('DiskUsage');
- $oRegistry =& KTPluginRegistry::getSingleton();
- $oPlugin =& $oRegistry->getPlugin('ktcore.housekeeper.plugin');
+ $oRegistry =& KTPluginRegistry::getSingleton();
+ $oPlugin =& $oRegistry->getPlugin('ktcore.housekeeper.plugin');
- $config = KTConfig::getSingleton();
- $rootUrl = $config->get('KnowledgeTree/rootUrl');
+ $config = KTConfig::getSingleton();
+ $rootUrl = $config->get('KnowledgeTree/rootUrl');
- $dispatcherURL = $oPlugin->getURLPath('HouseKeeperDispatcher.php');
- if (!empty($rootUrl)) $dispatcherURL = $rootUrl . $dispatcherURL;
- $dispatcherURL = str_replace( '\\', '/', $dispatcherURL);
+ $dispatcherURL = $oPlugin->getURLPath('HouseKeeperDispatcher.php');
+ if (!empty($rootUrl)) $dispatcherURL = $rootUrl . $dispatcherURL;
+ $dispatcherURL = str_replace( '\\', '/', $dispatcherURL);
if ( substr( $dispatcherURL, 0,1 ) != '/')
- {
- $dispatcherURL = '/'.$dispatcherURL;
- }
+ {
+ $dispatcherURL = '/'.$dispatcherURL;
+ }
+
+ $warningPercent = $config->get('DiskUsage/warningThreshold', 15);
+ $urgentPercent = $config->get('DiskUsage/urgentThreshold', 5);
- $aTemplateData = array(
- 'context' => $this,
- 'usages'=>$this->usage,
- 'warnPercent'=>$this->warningPercent,
- 'urgentPercent'=>$this->urgentPercent,
- 'dispatcherURL'=>$dispatcherURL
- );
+ $aTemplateData = array(
+ 'context' => $this,
+ 'usages'=> $this->usage,
+ 'warnPercent'=>$warningPercent,
+ 'urgentPercent'=>$urgentPercent,
+ 'dispatcherURL'=>$dispatcherURL
+ );
return $oTemplate->render($aTemplateData);
}
}
-
?>
diff --git a/plugins/housekeeper/FolderUsageDashlet.inc.php b/plugins/housekeeper/FolderUsageDashlet.inc.php
index a8cfd6a..c3c4b7a 100755
--- a/plugins/housekeeper/FolderUsageDashlet.inc.php
+++ b/plugins/housekeeper/FolderUsageDashlet.inc.php
@@ -38,141 +38,48 @@
class FolderUsageDashlet extends KTBaseDashlet
{
- private $usage;
+ private $usage;
- function FolderUsageDashlet()
- {
- $this->sTitle = _kt('System Folder Utilization');
- $this->sClass = "ktInfo";
- }
+ function FolderUsageDashlet()
+ {
+ $this->sTitle = _kt('System Folder Utilization');
+ $this->sClass = "ktInfo";
+ }
- function is_active($oUser)
- {
- return Permission::userIsSystemAdministrator();
- }
+ function is_active($oUser)
+ {
+ return Permission::userIsSystemAdministrator();
+ }
- function scanPath($path,$pattern)
- {
- $files=0;
- $filesize=0;
+ function render()
+ {
+ $oTemplating =& KTTemplating::getSingleton();
+ $oTemplate = $oTemplating->loadTemplate('FolderUsage');
- if (is_dir($path) && ($dh = opendir($path)))
- {
- while (($file = readdir($dh)) !== false)
- {
- if (substr($file,0,1) == '.')
- {
- continue;
- }
+ $oRegistry =& KTPluginRegistry::getSingleton();
+ $oPlugin =& $oRegistry->getPlugin('ktcore.housekeeper.plugin');
- $full = $path . '/' . $file;
+ $config = KTConfig::getSingleton();
+ $rootUrl = $config->get('KnowledgeTree/rootUrl');
- if (!is_readable($full) || !is_writable($full))
- {
- continue;
- }
-
- if (is_dir($full))
- {
- $result = $this->scanPath($full,$pattern);
- $files += $result['files'];
- $filesize += $result['filesize'];
- continue;
- }
- if ($pattern != '')
- {
- if (preg_match('/' . $pattern . '/', $file) === false)
- {
- continue;
- }
- }
-
- $files++;
- $filesize += filesize($full);
- }
- closedir($dh);
- }
- return array('files'=>$files,'filesize'=>$filesize,'dir'=>$path);
- }
-
- function getUsage()
- {
- $check = true;
- // check if we have a cached result
- if (isset($_SESSION['SystemFolderUsage']))
- {
- // we will only do the check every 5 minutes
- if (time() - $_SESSION['SystemFolderUsage']['time'] < 5 * 60)
- {
- $check = false;
- $this->usage = $_SESSION['SystemFolderUsage']['usage'];
- }
- }
-
- // we will only check if the result is not cached, or after 5 minutes
- if ($check)
- {
- $usage = array();
-
- $oRegistry =& KTPluginRegistry::getSingleton();
- $oPlugin =& $oRegistry->getPlugin('ktcore.housekeeper.plugin');
-
- $folders = $oPlugin->getDirectories();
-
- foreach($folders as $folder)
- {
- $directory = $folder['folder'];
- $pattern = $folder['pattern'];
- $canClean = $folder['canClean'];
- $name = $folder['name'];
-
- $temp = $this->scanPath($directory,$pattern);
-
- $usage[] = array(
- 'description'=>$name,
- 'folder'=>$directory,
- 'files'=>number_format($temp['files'],0,'.',','),
- 'filesize'=>KTUtil::filesizeToString($temp['filesize']),
- 'action'=>$i,
- 'canClean'=>$canClean
- );
- $this->usage = $usage;
- }
-
- $_SESSION['SystemFolderUsage']['time'] = time();
- $_SESSION['SystemFolderUsage']['usage'] = $this->usage;
- }
- }
-
- function render()
- {
- $oTemplating =& KTTemplating::getSingleton();
- $oTemplate = $oTemplating->loadTemplate('FolderUsage');
-
- $oRegistry =& KTPluginRegistry::getSingleton();
- $oPlugin =& $oRegistry->getPlugin('ktcore.housekeeper.plugin');
-
- $config = KTConfig::getSingleton();
- $rootUrl = $config->get('KnowledgeTree/rootUrl');
-
- $dispatcherURL = $oPlugin->getURLPath('HouseKeeperDispatcher.php');
- if (!empty($rootUrl)) $dispatcherURL = $rootUrl . $dispatcherURL;
+ $dispatcherURL = $oPlugin->getURLPath('HouseKeeperDispatcher.php');
+ if (!empty($rootUrl)) $dispatcherURL = $rootUrl . $dispatcherURL;
$dispatcherURL = str_replace( '\\', '/', $dispatcherURL);
if ( substr( $dispatcherURL, 0,1 ) != '/')
- {
- $dispatcherURL = '/'.$dispatcherURL;
- }
+ {
+ $dispatcherURL = '/'.$dispatcherURL;
+ }
- $this->getUsage();
+ $usage = unserialize(KTUtil::getSystemSetting('KTUsage','n/a'));
- $aTemplateData = array(
- 'context' => $this,
- 'usages'=>$this->usage,
- 'dispatcherURL'=>$dispatcherURL
- );
+ $aTemplateData = array(
+ 'context' => $this,
+ 'usages'=>$usage,
+ 'dispatcherURL'=>$dispatcherURL
+ );
- return $oTemplate->render($aTemplateData);
- }
+ return $oTemplate->render($aTemplateData);
+ }
}
diff --git a/plugins/housekeeper/HouseKeeper.inc.php b/plugins/housekeeper/HouseKeeper.inc.php
new file mode 100644
index 0000000..4ed8830
--- /dev/null
+++ b/plugins/housekeeper/HouseKeeper.inc.php
@@ -0,0 +1,350 @@
+.
+ *
+ * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
+ * California 94120-7775, or email info@knowledgetree.com.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "Powered by
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
+ * Contributor( s): ______________________________________
+ *
+ */
+
+class HouseKeeper
+{
+ public static
+ function getDiskUsageStats($update = true)
+ {
+ $config = KTConfig::getSingleton();
+
+ $cmd = KTUtil::findCommand('externalBinary/df','df');
+ if ($cmd === false)
+ {
+ if ($update)
+ KTUtil::setSystemSetting('DiskUsage','n/a');
+ return false;
+ }
+
+
+ $warningPercent = $config->get('DiskUsage/warningThreshold', 15);
+ $urgentPercent = $config->get('DiskUsage/urgentThreshold', 5);
+
+ if (OS_WINDOWS)
+ {
+ $cmd = str_replace( '/','\\',$cmd);
+ $res = KTUtil::pexec("\"$cmd\" -B 1 2>&1");
+ $result = implode("\r\n",$res['out']);
+ }
+ else
+ {
+ if(strtolower(PHP_OS) == 'darwin'){
+ $result = shell_exec($cmd." -k 2>&1");
+ }else{
+ $result = shell_exec($cmd." -B 1 2>&1");
+ }
+ }
+
+ if (strpos($result, 'cannot read table of mounted file systems') !== false)
+ {
+ if ($update)
+ KTUtil::setSystemSetting('DiskUsage','n/a');
+ return false;
+ }
+
+ $result = explode("\n", $result);
+
+ unset($result[0]); // gets rid of headings
+
+ $usage=array();
+ foreach($result as $line)
+ {
+ if (empty($line)) continue;
+ preg_match('/(.*)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(.*)/', $line, $matches);
+ list($line, $filesystem, $size, $used, $avail, $usedp, $mount) = $matches;
+
+ if ($size === 0) continue;
+
+ if(strtolower(PHP_OS) == 'darwin'){
+ $size = $size * 1024;
+ $used = $used * 1024;
+ $avail = $avail * 1024;
+ }
+
+ $colour = '';
+ if ($usedp >= 100 - $urgentPercent)
+ {
+ $colour = 'red';
+ }
+ elseif ($usedp >= 100 - $warningPercent)
+ {
+ $colour = 'orange';
+ }
+
+ $usage[] = array(
+ 'filesystem'=>trim($filesystem),
+ 'size'=>KTUtil::filesizeToString($size),
+ 'used'=>KTUtil::filesizeToString($used),
+ 'available'=>KTUtil::filesizeToString($avail),
+ 'usage'=>$usedp . '%',
+ 'mounted'=>trim($mount),
+ 'colour'=>$colour
+ );
+ }
+
+ if ($update)
+ KTUtil::setSystemSetting('DiskUsage',serialize($usage));
+
+ return $usage;
+ }
+
+ private static
+ function scanPath($path,$pattern)
+ {
+ $files=0;
+ $filesize=0;
+
+ if (is_dir($path) && ($dh = opendir($path)))
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if (substr($file,0,1) == '.')
+ {
+ continue;
+ }
+
+ $full = $path . '/' . $file;
+
+ if (!is_readable($full) || !is_writable($full))
+ {
+ continue;
+ }
+
+ if (is_dir($full))
+ {
+ $result = self::scanPath($full,$pattern);
+ $files += $result['files'];
+ $filesize += $result['filesize'];
+ continue;
+ }
+ if ($pattern != '')
+ {
+ if (preg_match('/' . $pattern . '/', $file) === false)
+ {
+ continue;
+ }
+ }
+
+ $files++;
+ $filesize += filesize($full);
+ }
+ closedir($dh);
+ }
+ return array('files'=>$files,'filesize'=>$filesize,'dir'=>$path);
+ }
+
+
+
+ private static
+ function getDirectories()
+ {
+ $config = KTConfig::getSingleton();
+ $cacheDir = $config->get('cache/cacheDirectory');
+
+ $tempDir = $config->get('urls/tmpDirectory');
+ $logDir = $config->get('urls/logDirectory');
+ $docsDir = $config->get('urls/documentRoot');
+
+ $indexer = Indexer::get();
+ $luceneDir = $indexer->getIndexDirectory();
+
+ $systemDir = OS_UNIX?'/tmp':'c:/windows/temp';
+
+ $folders = array(
+ array(
+ 'name'=>_kt('Smarty Cache'),
+ 'folder'=>$tempDir,
+ 'pattern'=>'^%%.*',
+ 'canClean'=>true
+ ),
+ array(
+ 'name'=>_kt('System Cache'),
+ 'folder'=>$cacheDir,
+ 'pattern'=>'',
+ 'canClean'=>true
+ ),
+ array(
+ 'name'=>_kt('System Logs'),
+ 'folder'=>$logDir,
+ 'pattern'=>'.+\.txt$',
+ 'canClean'=>true
+ ));
+
+ $folders[] =
+ array(
+ 'name'=>_kt('Temporary Folder'),
+ 'folder'=>$tempDir,
+ 'pattern'=>'',
+ 'canClean'=>true
+ );
+
+ $folders[] =
+ array(
+ 'name'=>_kt('System Temporary Folder'),
+ 'folder'=>$systemDir,
+ 'pattern'=>'(sess_.+)?(.+\.log$)?',
+ 'canClean'=>true
+ );
+
+ if (is_dir($docsDir))
+ {
+ $folders[] =
+ array(
+ 'name'=>_kt('Documents'),
+ 'folder'=>$docsDir,
+ 'pattern'=>'',
+ 'canClean'=>false
+ );
+ }
+
+ if (is_dir($luceneDir))
+ {
+ $folders[] =
+ array(
+ 'name'=>_kt('Document Index'),
+ 'folder'=>$luceneDir,
+ 'pattern'=>'',
+ 'canClean'=>false
+ );
+
+ }
+ return $folders;
+ }
+
+
+ public static
+ function getKTUsageStats($update = true)
+ {
+ $usage = array();
+
+ $oRegistry =& KTPluginRegistry::getSingleton();
+ $oPlugin =& $oRegistry->getPlugin('ktcore.housekeeper.plugin');
+
+ $folders = self::getDirectories();
+
+ foreach($folders as $folder)
+ {
+ $directory = $folder['folder'];
+ $pattern = $folder['pattern'];
+ $canClean = $folder['canClean'];
+ $name = $folder['name'];
+
+ $temp = self::scanPath($directory,$pattern);
+
+ $usage[] = array(
+ 'description'=>$name,
+ 'folder'=>$directory,
+ 'files'=>number_format($temp['files'],0,'.',','),
+ 'filesize'=>KTUtil::filesizeToString($temp['filesize']),
+ 'action'=>$i,
+ 'canClean'=>$canClean
+ );
+ }
+
+ if ($update)
+ KTUtil::setSystemSetting('KTUsage',serialize($usage));
+ return $usage;
+ }
+
+ private static $folders = null;
+
+ public static
+ function getDirectory($folder)
+ {
+ if (is_null(self::$folders))
+ {
+ self::$folders = self::getDirectories();
+ }
+ foreach(self::$folders as $dir)
+ {
+ if ($dir['folder'] == $folder)
+ {
+ return $dir;
+ }
+ }
+ return null;
+ }
+
+
+ public static
+ function cleanDirectory($path, $pattern)
+ {
+ if (!is_readable($path))
+ {
+ return;
+ }
+ if ($dh = opendir($path))
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if (substr($file,0,1) == '.')
+ {
+ continue;
+ }
+
+ $full = $path . '/' . $file;
+ if (is_dir($full))
+ {
+ self::cleanDirectory($full,$pattern);
+ if (is_writable($full))
+ {
+ @rmdir($full);
+ }
+ continue;
+ }
+
+ if (!empty($pattern) && !preg_match('/' . $pattern . '/', $file))
+ {
+ continue;
+ }
+
+ if (is_writable($full))
+ {
+ @unlink($full);
+ }
+
+ }
+ closedir($dh);
+ }
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/plugins/housekeeper/HouseKeeperDispatcher.php b/plugins/housekeeper/HouseKeeperDispatcher.php
index 1ef53cb..5c72849 100644
--- a/plugins/housekeeper/HouseKeeperDispatcher.php
+++ b/plugins/housekeeper/HouseKeeperDispatcher.php
@@ -7,31 +7,31 @@
* Document Management Made Simple
* Copyright (C) 2008 KnowledgeTree Inc.
* Portions copyright The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* 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, see
| {i18n}refresh{/i18n} | -
"; - print_r($aVersions); - echo ""; - exit; -*/ - - foreach ($aVersions as $k => $v) { - foreach($aCachedVersions as $j => $l) { - if (($k == $j) && (version_compare($aVersions[$k], $aCachedVersions[$j]) == -1)) - { - //save new name and version - $sVName = $j; - $sVNum = $l; - } - }//end foreach - - }//end foreach - - if ($sVName != "") - { - return "
"; - print_r($aVersions); - echo ""; - exit; -*/ - foreach ($aVersions as $k => $v) { - foreach($aRemoteVersions as $j => $l) { - if (($k == $j) && (version_compare($aVersions[$k], $aRemoteVersions[$j]) == -1)) - { - //save new name and version - $sVName = $j; - $sVNum = $l; - } - } - } - - if ($sVName != "") - { - return "