mirror of
https://github.com/optim-enterprises-bv/control-pane.git
synced 2025-11-21 16:44:50 +00:00
use file-based cache for profile/interface list
This commit is contained in:
@@ -4,6 +4,8 @@ require_once("cbsd.php");
|
|||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
|
private $_workdir='';
|
||||||
|
|
||||||
/* Список языков, используемых в проекте */
|
/* Список языков, используемых в проекте */
|
||||||
public static $languages=array(
|
public static $languages=array(
|
||||||
'en'=>'English',
|
'en'=>'English',
|
||||||
@@ -185,21 +187,83 @@ class Config
|
|||||||
public $os_interfaces=array();
|
public $os_interfaces=array();
|
||||||
|
|
||||||
function __construct(){
|
function __construct(){
|
||||||
|
|
||||||
|
$this->_workdir=getenv('WORKDIR');
|
||||||
|
$vm_profile_list_file=$this->_workdir.'/tmp/bhyve-vm.json';
|
||||||
|
$cloud_profile_list_file=$this->_workdir.'/tmp/bhyve-cloud.json';
|
||||||
|
$interface_list_file=$this->_workdir.'/tmp/interfaces.json';
|
||||||
|
|
||||||
|
/// check for file/cache first
|
||||||
|
// vm profile (ISO)
|
||||||
|
$vm_profile_list_file_size=0;
|
||||||
|
if(file_exists($vm_profile_list_file)) {
|
||||||
|
$vm_profile_list_file_size=filesize($vm_profile_list_file);
|
||||||
|
if( $vm_profile_list_file_size < 16 ) {
|
||||||
|
// probably empty, renew needed
|
||||||
|
$vm_profile_list_file_size=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cloud profile
|
||||||
|
$cloud_profile_list_file_size=0;
|
||||||
|
// check for file/cache first
|
||||||
|
if(file_exists($cloud_profile_list_file)) {
|
||||||
|
$cloud_profile_list_file_size=filesize($cloud_profile_list_file);
|
||||||
|
if( $cloud_profile_list_file_size < 16 ) {
|
||||||
|
// probably empty, renew needed
|
||||||
|
$cloud_profile_list_file_size=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// interface profile
|
||||||
|
$interface_list_file_size=0;
|
||||||
|
// check for file/cache first
|
||||||
|
if(file_exists($interface_list_file)) {
|
||||||
|
$interface_list_file_size=filesize($interface_list_file);
|
||||||
|
if( $interface_list_file_size < 4 ) {
|
||||||
|
// probably empty, renew needed
|
||||||
|
$interface_list_file_size=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// load vm profile list
|
||||||
|
// vm profile (ISO)
|
||||||
|
if ($vm_profile_list_file_size > 0 ) {
|
||||||
|
Utils::clonos_syslog("config.php: (cached) found vm_profile cache file/size: $vm_profile_list_file exist/$vm_profile_list_file_size");
|
||||||
|
$res['message']=file_get_contents($vm_profile_list_file);
|
||||||
|
$this->os_types=$this->create_bhyve_profiles($res);
|
||||||
|
} else {
|
||||||
|
Utils::clonos_syslog("config.php: vm_profile cache file not found: $vm_profile_list_file");
|
||||||
$res=CBSD::run('get_bhyve_profiles src=vm clonos=1', array());
|
$res=CBSD::run('get_bhyve_profiles src=vm clonos=1', array());
|
||||||
if($res['retval']==0){
|
if($res['retval']==0){
|
||||||
$this->os_types=$this->create_bhyve_profiles($res);
|
$this->os_types=$this->create_bhyve_profiles($res);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cloud profile
|
||||||
|
if ($cloud_profile_list_file_size > 0 ) {
|
||||||
|
Utils::clonos_syslog("config.php: (cached) found cloud_profile cache file/size: $cloud_profile_list_file exist/$cloud_profile_list_file_size");
|
||||||
|
$res1['message']=file_get_contents($cloud_profile_list_file);
|
||||||
|
$this->os_types_obtain=$this->create_bhyve_profiles($res1);
|
||||||
|
} else {
|
||||||
$res1=CBSD::run('get_bhyve_profiles src=cloud', array());
|
$res1=CBSD::run('get_bhyve_profiles src=cloud', array());
|
||||||
if($res1['retval']==0){
|
if($res1['retval']==0){
|
||||||
$this->os_types_obtain=$this->create_bhyve_profiles($res1);
|
$this->os_types_obtain=$this->create_bhyve_profiles($res1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
if ($interface_list_file_size > 0 ) {
|
||||||
|
Utils::clonos_syslog("config.php: (cached) found interfaces cache file/size: $interface_list_file exist/$interface_list_file_size");
|
||||||
|
$res2['message']=file_get_contents($interface_list_file);
|
||||||
|
$this->os_interfaces=$this->create_interfaces($res2);
|
||||||
|
} else {
|
||||||
$res2=CBSD::run('get_interfaces', array());
|
$res2=CBSD::run('get_interfaces', array());
|
||||||
if($res2['retval']==0){
|
if($res2['retval']==0){
|
||||||
$this->os_interfaces=$this->create_interfaces($res2);
|
$this->os_interfaces=$this->create_interfaces($res2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function create_bhyve_profiles($info){
|
function create_bhyve_profiles($info){
|
||||||
$os_names = array();
|
$os_names = array();
|
||||||
@@ -220,7 +284,7 @@ class Config
|
|||||||
function create_interfaces($info){
|
function create_interfaces($info){
|
||||||
$res=json_decode($info['message'],true);
|
$res=json_decode($info['message'],true);
|
||||||
if(!is_null($res) && $res != false){
|
if(!is_null($res) && $res != false){
|
||||||
return $res;
|
return $res['interfaces'];
|
||||||
} else {
|
} else {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ $file_path=$_ds.$root.$_ds.'pages'.$_ds.$uri.$_ds;
|
|||||||
$file_name=$file_path.$lang.'.index.php';
|
$file_name=$file_path.$lang.'.index.php';
|
||||||
$json_name=$file_path.'a.json.php';
|
$json_name=$file_path.'a.json.php';
|
||||||
|
|
||||||
Utils::clonos_syslog("my json_name:". $json_name);
|
|
||||||
|
|
||||||
if(empty($uri)){
|
if(empty($uri)){
|
||||||
header('Location: /'.$menu->first_key.'/',true);
|
header('Location: /'.$menu->first_key.'/',true);
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Reference in New Issue
Block a user