Example #1
0
 public static function get_Size($pdo_connection, $catalog_id)
 {
     $db_name = FileConfig::get_Value('db_name', $catalog_id);
     switch (CDB::getDriverName()) {
         case 'mysql':
             // Return N/A for MySQL server prior version 5 (no information_schemas)
             if (version_compare(CDB::getServerVersion(), '5.0.0') >= 0) {
                 // Prepare SQL statment
                 $statment = array('table' => 'information_schema.TABLES', 'fields' => array("table_schema AS 'database', (sum( data_length + index_length) / 1024 / 1024 ) AS 'dbsize'"), 'where' => array("table_schema = '{$db_name}'"), 'groupby' => 'table_schema');
                 $result = CDBUtils::runQuery(CDBQuery::get_Select($statment, $pdo_connection), $pdo_connection);
                 $db_size = $result->fetch();
                 $db_size = $db_size['dbsize'] * 1024 * 1024;
                 return CUtils::Get_Human_Size($db_size);
             } else {
                 echo 'Not supported (' . CDB::getServerVersion() . ') <br />';
             }
             break;
         case 'pgsql':
             $statment = "SELECT pg_database_size('{$db_name}') AS dbsize";
             $result = CDBUtils::runQuery($statment, $pdo_connection);
             $db_size = $result->fetch();
             return CUtils::Get_Human_Size($db_size['dbsize']);
             break;
         case 'sqlite':
             $db_size = filesize(FileConfig::get_Value('db_name', $catalog_id));
             return CUtils::Get_Human_Size($db_size);
             break;
     }
 }
Example #2
0
 public static function getDiskUsage($pdo)
 {
     $fields = array('SUM(Media.VolBytes) as bytes_size');
     $statment = array('table' => 'Media', 'fields' => $fields);
     // Run SQL query
     $result = CDBUtils::runQuery(CDBQuery::get_Select($statment), $pdo);
     $result = $result->fetch();
     return $result['bytes_size'];
 }
Example #3
0
 protected static function count($pdo, $tablename, $filter = null)
 {
     $fields = array('COUNT(*) as row_count');
     // Prepare and execute query
     $statment = CDBQuery::get_Select(array('table' => $tablename, 'fields' => $fields, $filter));
     $result = CDBUtils::runQuery($statment, $pdo);
     $result = $result->fetch();
     return $result['row_count'];
 }
Example #4
0
 public static function count($pdo)
 {
     $fields = array('COUNT(DISTINCT FileSet) as filesets_count');
     $table = 'FileSet';
     // Prepare and execute query
     $statment = CDBQuery::get_Select(array('table' => $table, 'fields' => $fields));
     $result = CDBUtils::runQuery($statment, $pdo);
     $result = $result->fetch();
     return $result['filesets_count'];
 }
Example #5
0
 public static function getPools($pdo)
 {
     $pools = null;
     $table = 'Pool';
     $where = null;
     if (FileConfig::get_Value('hide_empty_pools')) {
         $where[] = "{$table}.NumVols > 0";
     }
     $fields = array('poolid', 'name', 'numvols');
     $result = CDBUtils::runQuery(CDBQuery::get_Select(array('table' => $table, 'fields' => $fields, 'where' => $where)), $pdo);
     foreach ($result->fetchAll() as $pool) {
         $pools[] = $pool;
     }
     return $pools;
 }
Example #6
0
 public static function getClientInfos($pdo, $client_id)
 {
     $client = array();
     $fields = array('name', 'uname');
     $where = array("clientid = {$client_id}");
     $statment = CDBQuery::get_Select(array('table' => 'Client', 'fields' => $fields, 'where' => $where));
     $result = CDBUtils::runQuery($statment, $pdo);
     foreach ($result->fetchAll() as $client) {
         $uname = explode(' ', $client['uname']);
         $client['version'] = $uname[0];
         $uname = explode(',', $uname[2]);
         $temp = explode('-', $uname[0]);
         $client['arch'] = $temp[0];
         $client['os'] = $uname[1];
     }
     return $client;
 }
Example #7
0
 public static function getServerTimestamp()
 {
     if (!is_null(self::$connection)) {
         // Different query for SQlite
         if (self::getDriverName() == 'sqlite') {
             $statment = "SELECT datetime('now') as CurrentDateTime";
         } else {
             $statment = 'SELECT now() as CurrentDateTime';
         }
         $result = CDBUtils::runQuery($statment, self::$connection);
         $result = $result->fetch();
         // Return timestamp
         return strtotime($result['currentdatetime']);
     } else {
         throw new Exception("No connection to database");
     }
 }
Example #8
0
     $days_stored_files[] = array(date("m-d", $day['start']), $stored_files);
 }
 $graph->SetData($days_stored_files, 'bars');
 $graph->SetYTitle("Files");
 // Graph rendering
 $view->assign('graph_stored_files', $graph->Render());
 unset($graph);
 // Get last 10 jobs list
 $query = "SELECT JobId, Level, JobFiles, JobBytes, ReadBytes, JobStatus, StartTime, EndTime, Name ";
 $query .= "FROM Job ";
 $query .= "WHERE Name = '{$backupjob_name}' ";
 $query .= "ORDER BY EndTime DESC ";
 $query .= "LIMIT 7 ";
 $jobs = array();
 $joblevel = array('I' => 'Incr', 'D' => 'Diff', 'F' => 'Full');
 $result = CDBUtils::runQuery($query, $dbSql->db_link);
 foreach ($result->fetchAll() as $job) {
     // Job level description
     $job['joblevel'] = $joblevel[$job['level']];
     // Job execution execution time
     $job['elapsedtime'] = DateTimeUtil::Get_Elapsed_Time($job['starttime'], $job['endtime']);
     // Compression
     if ($job['jobbytes'] > 0) {
         $compression = 1 - $job['jobbytes'] / $job['readbytes'];
         $job['compression'] = number_format($compression, 2);
     } else {
         $job['compression'] = 'N/A';
     }
     // Job speed
     $start = $job['starttime'];
     $end = $job['endtime'];
Example #9
0
            $check['check_result'] = $icon_result[in_array('pgsql', $pdo_drivers)];
            break;
        case 'php-sqlite':
            $check['check_result'] = $icon_result[in_array('sqlite', $pdo_drivers)];
            break;
        case 'php-pdo':
            $check['check_result'] = $icon_result[class_exists('PDO')];
            break;
        case 'smarty-cache':
            $check['check_result'] = $icon_result[is_writable(VIEW_CACHE_DIR)];
            break;
        case 'php-version':
            $check['check_result'] = $icon_result[version_compare(PHP_VERSION, '5.3', '>=')];
            break;
        case 'db-connection':
            $check['check_result'] = $icon_result[CDBUtils::isConnected($dbSql->db_link)];
            break;
        case 'php-timezone':
            $timezone = ini_get('date.timezone');
            if (!empty($timezone)) {
                $check['check_result'] = $icon_result[true];
            } else {
                $check['check_result'] = $icon_result[false];
            }
            break;
    }
}
// Testing graph capabilities
$data = array(array('test', 100), array('test1', 150), array('test1', 180), array('test1', 456));
// Pie graph
$pie_graph = new CGraph("testpage-graph03.jpg");
Example #10
0
    // Last used volumes widget
    // ==============================================================
    $last_volumes = array();
    // Building SQL statment
    $where = array();
    $tmp = "(Media.Volstatus != 'Disabled') ";
    switch (CDB::getDriverName()) {
        case 'mysql':
        case 'pgsql':
            $tmp .= "AND (Media.LastWritten IS NOT NULL)";
            break;
        case 'sqlite':
            $tmp .= "AND (Media.Lastwritten != 0)";
            break;
    }
    $where[] = $tmp;
    $statment = array('table' => 'Media', 'fields' => array('Media.MediaId', 'Media.Volumename', 'Media.Lastwritten', 'Media.VolStatus', 'Media.VolJobs', 'Pool.Name AS poolname'), 'join' => array('table' => 'Pool', 'condition' => 'Media.PoolId = Pool.poolid'), 'where' => $where, 'orderby' => 'Media.Lastwritten DESC', 'limit' => '10');
    // Run the query
    $result = CDBUtils::runQuery(CDBQuery::get_Select($statment), $dbSql->db_link);
    foreach ($result as $volume) {
        $last_volumes[] = $volume;
    }
    $view->assign('volumes_list', $last_volumes);
} catch (Exception $e) {
    CErrorHandler::displayError($e);
}
// Set page name
$current_page = 'Dashboard';
$view->assign('page_name', $current_page);
// Render template
$view->render('index.tpl');
Example #11
0
 public function GetVolumeList()
 {
     $volumes = '';
     $volumes_list = array();
     $query = "";
     //MKO Aggiunto per calcolo TTL
     $time = time();
     $dtF = new DateTime("@0");
     //END MKO
     foreach (Pools_Model::getPools($this->db_link) as $pool) {
         switch ($this->db_driver) {
             case 'sqlite':
             case 'mysql':
                 //MKO Aggiunto per firstwritten per calcolo TTL
                 $query = "SELECT Media.voluseduration, Media.inchanger, Media.slot, Media.firstwritten, Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention\n\t\t\t\t\t\t\t\t\tFROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE Media.poolid = '" . $pool['poolid'] . "' ORDER BY Media.volumename";
                 break;
             case 'pgsql':
                 $query = "SELECT media.voluseduration, media.inchanger, media.slot, media.firstwritten, media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention\n\t\t\t\t\t\t\t\t\tFROM media LEFT JOIN pool ON media.poolid = pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE media.poolid = '" . $pool['poolid'] . "' ORDER BY media.volumename";
                 //END MKO
                 break;
         }
         // end switch
         $volumes = CDBUtils::runQuery($query, $this->db_link);
         if (!array_key_exists($pool['name'], $volumes_list)) {
             $volumes_list[$pool['name']] = array();
         }
         foreach ($volumes->fetchAll() as $volume) {
             if ($volume['lastwritten'] != "0000-00-00 00:00:00") {
                 // Calculate expiration date if the volume is Full
                 if ($volume['volstatus'] == 'Full') {
                     $expire_date = strtotime($volume['lastwritten']) + $volume['volretention'];
                     $volume['expire'] = strftime("%Y-%m-%d", $expire_date);
                 } else {
                     $volume['expire'] = 'N/A';
                 }
                 //MKO Calcolo Append Life
                 $timediff = $time - strtotime($volume['firstwritten']);
                 if ($volume['volstatus'] == 'Append') {
                     $remaining = $volume['voluseduration'] - $timediff;
                     if ($remaining < 0) {
                         $remaining = 0;
                     }
                     $dtT = new DateTime("@{$remaining}");
                     $volume['volstatus'] = $volume['volstatus'] . ' (' . $dtF->diff($dtT)->format('%ad %Hh %im %ss') . ')';
                 }
                 //MKO Calcolo TTL
                 $ttl = $volume['volretention'] - $timediff;
                 $dtT = new DateTime("@{$ttl}");
                 $ttl > 0 ? $volume['ttl'] = $dtF->diff($dtT)->format('%ad %Hh %im %ss') : ($volume['ttl'] = 'Expired');
                 //MKO In Changer
                 $volume['inchanger'] ? $volume['changer'] = 'Slot: ' . $volume['slot'] : ($volume['changer'] = 'No');
                 // Media used bytes in a human format
                 $volume['volbytes'] = CUtils::Get_Human_Size($volume['volbytes']);
             } else {
                 $volume['lastwritten'] = "N/A";
                 $volume['expire'] = "N/A";
                 $volume['volbytes'] = "0 KB";
             }
             $volume['volretention'] = $volume['volretention'] / 60 / 60 / 24 . 'd';
             // Add the media in pool array
             array_push($volumes_list[$pool['name']], $volume);
         }
         // end foreach volumes
     }
     // end foreach pools
     return $volumes_list;
 }
Example #12
0
 public static function get_Jobs_List($pdo, $client_id = null)
 {
     $jobs = array();
     $fields = array('Name');
     $where = null;
     // Prepare and execute query
     if (!is_null($client_id)) {
         $where[] = "clientid = '{$client_id}'";
     }
     $statment = array('table' => 'Job', 'fields' => $fields, 'groupby' => 'Name', 'orderby' => 'Name', 'where' => $where);
     $result = CDBUtils::runQuery(CDBQuery::get_Select($statment), $pdo);
     foreach ($result->fetchAll() as $job) {
         $jobs[] = $job['name'];
     }
     return $jobs;
 }
Example #13
0
 public function GetVolumeList()
 {
     $pools = array();
     $query = "";
     foreach (Pools_Model::getPools($this->db_link) as $pool) {
         $pool_name = $pool['name'];
         switch ($this->db_driver) {
             case 'sqlite':
             case 'mysql':
                 $query = "SELECT Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention, Media.slot\n\t\t\t\t\t\t\t\t\tFROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE Media.poolid = '" . $pool['poolid'] . "' ORDER BY Media.volumename";
                 break;
             case 'pgsql':
                 $query = "SELECT media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention, media.slot\n\t\t\t\t\t\t\t\t\tFROM media LEFT JOIN pool ON media.poolid = pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE media.poolid = '" . $pool['poolid'] . "' ORDER BY media.volumename";
                 break;
         }
         // end switch
         $volumes = CDBUtils::runQuery($query, $this->db_link);
         // If we have at least 1 volume in this pool, create sub array for the pool
         if (!array_key_exists($pool_name, $pools)) {
             $pools[$pool_name] = array();
             $pools[$pool_name]['volumes'] = array();
         }
         foreach ($volumes->fetchAll() as $volume) {
             // Set volume default values
             $volume['expire'] = 'n/a';
             // Set value for unused volumes
             if (empty($volume['lastwritten'])) {
                 $volume['lastwritten'] = 'n/a';
             }
             // Media used bytes in a human format
             $volume['volbytes'] = CUtils::Get_Human_Size($volume['volbytes']);
             // If volume have alreday been used
             if ($volume['lastwritten'] != "0000-00-00 00:00:00") {
                 // Calculate expiration date only if the volume is Full
                 if ($volume['volstatus'] == 'Full') {
                     $expire_date = strtotime($volume['lastwritten']) + $volume['volretention'];
                     $volume['expire'] = strftime("%Y-%m-%d", $expire_date);
                 }
             }
             // Push the volume array to the $pool array
             array_push($pools[$pool_name]['volumes'], $volume);
         }
         // end foreach volumes
         // Calulate used bytes for each pool
         $sql = "SELECT SUM(Media.volbytes) FROM Media WHERE Media.PoolId = '" . $pool['poolid'] . "'";
         $result = CDBUtils::runQuery($sql, $this->db_link);
         $result = $result->fetchAll();
         $pools[$pool_name]['total_used_bytes'] = CUtils::Get_Human_Size($result[0]['sum']);
     }
     // end foreach pools
     return $pools;
 }