From 055a494fe468418bc249ce965b1a7fb00b97d360 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Fri, 21 Nov 2014 22:15:32 +0000 Subject: [PATCH] Add getDiskPercent function to the api Returns the amount of space used --- web/api/app/Controller/HostController.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index 18f3875a0..827ad3449 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -33,4 +33,29 @@ class HostController extends AppController { '_serialize' => array('load') )); } + + function getDiskPercent() { + $this->loadModel('Config'); + $zm_dir_events = $this->Config->find('list', array( + 'conditions' => array('Name' => 'ZM_DIR_EVENTS'), + 'fields' => array('Name', 'Value') + )); + $zm_dir_events = $zm_dir_events['ZM_DIR_EVENTS' ]; + + // Test to see if $zm_dir_events is relative or absolute + if ('/' === "" || strrpos($zm_dir_events, '/', -strlen($zm_dir_events)) !== TRUE) { + // relative - so add the full path + $zm_dir_events = Configure::read('ZM_PATH_WEB') . '/' . $zm_dir_events; + } + + $df = shell_exec( 'df '.$zm_dir_events); + $space = -1; + if ( preg_match( '/\s(\d+)%/ms', $df, $matches ) ) + $space = $matches[1]; + + $this->set(array( + 'space' => $space, + '_serialize' => array('space') + )); + } }