mirror of
https://github.com/optim-enterprises-bv/control-pane.git
synced 2025-11-02 02:48:02 +00:00
debugging old code, WIP
This commit is contained in:
11
php/cbsd.php
11
php/cbsd.php
@@ -17,15 +17,16 @@ class CBSD {
|
|||||||
|
|
||||||
$cmd = vsprintf($cmd, $args); # make sure we deal with a string
|
$cmd = vsprintf($cmd, $args); # make sure we deal with a string
|
||||||
$cmd = strtr($cmd, $defines);
|
$cmd = strtr($cmd, $defines);
|
||||||
|
// olevole: add trim tabs + \r\n
|
||||||
|
$cmd = trim(preg_replace('/\t+|\r|\n/', '', $cmd));
|
||||||
$full_cmd = $prepend.trim($cmd);
|
$full_cmd = $prepend.trim($cmd);
|
||||||
|
|
||||||
if ($cmd != escapeshellcmd($cmd)){
|
if ($cmd != escapeshellcmd($cmd)){
|
||||||
|
Utils::clonos_syslog("cmd.php SHELL ESCAPE:". $cmd);
|
||||||
die("Shell escape attempt");
|
die("Shell escape attempt");
|
||||||
}
|
}
|
||||||
|
|
||||||
// olevole: to generic log_() function
|
Utils::clonos_syslog("cmd.php:". $full_cmd);
|
||||||
// file_put_contents('/tmp/clonos-run_'.date("j.n.Y").'.log', $full_cmd . "\n", FILE_APPEND);
|
|
||||||
|
|
||||||
$process = proc_open($full_cmd,$specs,$pipes,null,null);
|
$process = proc_open($full_cmd,$specs,$pipes,null,null);
|
||||||
|
|
||||||
$error=false;
|
$error=false;
|
||||||
@@ -46,6 +47,8 @@ class CBSD {
|
|||||||
$error_message=$buf;
|
$error_message=$buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::clonos_syslog("cmd.php:"."ret:".$return_value." msg:[".$message."] "."error:[".$error."] "."error_message:[".$error_message." ]");
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'cmd'=>$cmd,
|
'cmd'=>$cmd,
|
||||||
'full_cmd'=>$full_cmd,
|
'full_cmd'=>$full_cmd,
|
||||||
@@ -54,6 +57,8 @@ class CBSD {
|
|||||||
'error'=>$error,
|
'error'=>$error,
|
||||||
'error_message'=>$error_message
|
'error_message'=>$error_message
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
Utils::clonos_syslog("cmd.php: empty process resource");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,8 +79,15 @@ class ClonOS {
|
|||||||
$this->server_name=$_SERVER['SERVER_ADDR'];
|
$this->server_name=$_SERVER['SERVER_ADDR'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// olevole: where $uri came from? is_emtpy
|
||||||
|
// public/index.php:$uri=trim($_SERVER['REQUEST_URI'],'/'); not work?
|
||||||
if (is_null($uri_chunks)) { # TODO Do we need this ?
|
if (is_null($uri_chunks)) { # TODO Do we need this ?
|
||||||
$this->uri_chunks=Utils::gen_uri_chunks($uri);
|
// a.json.php not work ?
|
||||||
|
//Utils::clonos_syslog("clonos.php: \$uri_chunks is empty, force to \$uri values:".$_SERVER['REQUEST_URI']);
|
||||||
|
//$uri=trim($_SERVER['REQUEST_URI'],'/');
|
||||||
|
|
||||||
|
// HP Warning: Undefined variable $uri in /usr/local/www/clonos/php/clonos.php on line 88
|
||||||
|
$this->uri_chunks=Utils::gen_uri_chunks("");
|
||||||
} else {
|
} else {
|
||||||
$this->uri_chunks=$uri_chunks;
|
$this->uri_chunks=$uri_chunks;
|
||||||
}
|
}
|
||||||
@@ -1400,20 +1407,28 @@ class ClonOS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$key_name='/usr/home/olevole/.ssh/authorized_keys';
|
//$key_name='/usr/home/olevole/.ssh/authorized_keys';
|
||||||
if(!isset($form['vm_authkey'])) $form['vm_authkey']=0;
|
if(!isset($form['vm_authkey'])) $form['vm_authkey']=0;
|
||||||
$key_id=(int)$form['vm_authkey'];
|
$key_id=(int)$form['vm_authkey'];
|
||||||
|
Utils::clonos_syslog("clonos.php: key_id: [".$key_id."]");
|
||||||
|
|
||||||
|
if($key_id>0) {
|
||||||
$db=new Db('base','authkey');
|
$db=new Db('base','authkey');
|
||||||
if(!$db->isConnected()) return array('error'=>true,'errorMessage'=>'Database error!');
|
if(!$db->isConnected()) return array('error'=>true,'errorMessage'=>'Database error!');
|
||||||
|
if($nres['name']!==false) $key_name=$nres['name'];
|
||||||
//if($nres['name']!==false) $key_name=$nres['name'];
|
Utils::clonos_syslog("clonos.php:". 'SELECT authkey FROM authkey WHERE idx=?'. array([$key_id, PDO::PARAM_INT]));
|
||||||
$nres=$db->selectOne('SELECT authkey FROM authkey WHERE idx=?', array([$key_id, PDO::PARAM_INT]));
|
$nres=$db->selectOne('SELECT authkey FROM authkey WHERE idx=?', array([$key_id, PDO::PARAM_INT]));
|
||||||
if($nres['authkey']!==false) $authkey=$nres['authkey']; else $authkey='';
|
|
||||||
//var_dump($nres);exit;
|
//var_dump($nres);exit;
|
||||||
|
|
||||||
|
// [22-Jul-2022 13:15:19 UTC] PHP Warning: Trying to access array offset on value of type bool in /usr/local/www/clonos/php/clonos.php on line 1416
|
||||||
|
if($nres['authkey']!==false) $authkey=$nres['authkey']; else $authkey='';
|
||||||
|
} else {
|
||||||
|
$authkey='';
|
||||||
|
}
|
||||||
|
|
||||||
$user_pw=(!empty($form['user_password']))?' ci_user_pw_user='.$form['user_password'].' ':'';
|
$user_pw=(!empty($form['user_password']))?' ci_user_pw_user='.$form['user_password'].' ':'';
|
||||||
|
|
||||||
|
// olevole: SHELL ESCAPE here - tabs + \r\n
|
||||||
$res=CBSD::run( // TODO: THIS SEEMS WRONG pw_user={$form['vm_password']} {$user_pw}vnc_password={$form['vnc_password']}";
|
$res=CBSD::run( // TODO: THIS SEEMS WRONG pw_user={$form['vm_password']} {$user_pw}vnc_password={$form['vnc_password']}";
|
||||||
'task owner=%s mode=new {cbsd_loc} bcreate jname=%s
|
'task owner=%s mode=new {cbsd_loc} bcreate jname=%s
|
||||||
vm_os_profile="%s" imgsize=%s vm_cpus=%s vm_ram=%s vm_os_type=%s mask=%s
|
vm_os_profile="%s" imgsize=%s vm_cpus=%s vm_ram=%s vm_os_type=%s mask=%s
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ class Config
|
|||||||
$this->os_types_obtain=$this->create_bhyve_profiles($res1);
|
$this->os_types_obtain=$this->create_bhyve_profiles($res1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res2=CBSD::run('cbsd 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static function clonos_syslog($msg)
|
||||||
|
{
|
||||||
|
file_put_contents('/tmp/clonos.log', date("j.n.Y").":".$msg . "\n", FILE_APPEND);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function gen_uri_chunks($uri)
|
public static function gen_uri_chunks($uri)
|
||||||
{
|
{
|
||||||
$uri_chunks = [];
|
$uri_chunks = [];
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ $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;
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
if(!empty($this->_vars['hash']))
|
if(!empty($this->_vars['hash']))
|
||||||
{
|
{
|
||||||
|
Utils::clonos_syslog("instance_jail a.json.php: hash not empty:". $this->_vars['hash']);
|
||||||
include('helpers.php');
|
include('helpers.php');
|
||||||
|
|
||||||
|
// $html=str_replace(array("\n","\r","\t"),'',$html);
|
||||||
|
|
||||||
|
//$html=str_replace(array("\n","\r","\t"),'',$html);
|
||||||
|
|
||||||
|
// Utils::clonos_syslog("instance_jail a.json.php: HTML:". $html);
|
||||||
|
//echo $html;
|
||||||
|
|
||||||
|
|
||||||
|
// $html=str_replace(array("\n","\r","\t"),'',$html);
|
||||||
|
// Utils::clonos_syslog("instance_jail a.json.php: HTML:". $html);
|
||||||
|
// echo $html;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +99,14 @@ if($res['retval']==0)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$html=str_replace(array("\n","\r","\t"),'',$html);
|
$html=str_replace(array("\n","\r","\t"),'',$html);
|
||||||
|
|
||||||
|
|
||||||
|
//Utils::clonos_syslog("instance_jail a.json.php: HTML:". $html);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
'tbody'=>$html,
|
'tbody'=>$html,
|
||||||
|
|||||||
@@ -46,5 +46,9 @@ EOT;
|
|||||||
$res_html=(new Forms('',$hash,$db_path))->generate();
|
$res_html=(new Forms('',$hash,$db_path))->generate();
|
||||||
$html.='<h1>Helper: '.$hash.'</h1>'.$res_html;
|
$html.='<h1>Helper: '.$hash.'</h1>'.$res_html;
|
||||||
|
|
||||||
return array('html'=>$this->html);
|
|
||||||
|
//$html=json_encode(array('html'=>$html,'func'=>'fillTab'));
|
||||||
|
// olevole: why return here?
|
||||||
|
// Undefined property: ClonOS::$html in /usr/local/www/clonos/public/pages/instance_jail/helpers.php on line 49
|
||||||
|
//return array('html'=>$this->html);
|
||||||
//echo json_encode(array('html'=>$html,'func'=>'fillTab'));
|
//echo json_encode(array('html'=>$html,'func'=>'fillTab'));
|
||||||
@@ -29,6 +29,9 @@ if(!empty($nodes))foreach($nodes as $node)
|
|||||||
if($db1!==false)
|
if($db1!==false)
|
||||||
{
|
{
|
||||||
$jails=$db1->select("SELECT jname,ip4_addr,status,protected FROM jails WHERE emulator!='bhyve' and hidden!=1 order by jname asc;", []);
|
$jails=$db1->select("SELECT jname,ip4_addr,status,protected FROM jails WHERE emulator!='bhyve' and hidden!=1 order by jname asc;", []);
|
||||||
|
|
||||||
|
Utils::clonos_syslog("jailscontainers a.json.php:" . "SELECT jname,ip4_addr,status,protected FROM jails WHERE emulator!='bhyve' and hidden!=1 order by jname asc;");
|
||||||
|
|
||||||
$allnodes[$node]=$jails;
|
$allnodes[$node]=$jails;
|
||||||
|
|
||||||
$num=$nth & 1;
|
$num=$nth & 1;
|
||||||
@@ -106,6 +109,8 @@ EOT;
|
|||||||
}
|
}
|
||||||
|
|
||||||
$nth++;
|
$nth++;
|
||||||
|
} else {
|
||||||
|
Utils::clonos_syslog("jailscontainers a.json.php: DB1 FALSE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
$username=$this->_user_info['username'];
|
$username=$this->_user_info['username'];
|
||||||
|
|
||||||
$db=new Db('base','cbsdtaskd');
|
$db=new Db('base','cbsdtaskd');
|
||||||
$res=$db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='?' ORDER BY id DESC", array([$username]));
|
Utils::clonos_syslog("tasklog: ". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;");
|
||||||
|
//olevole why array?!
|
||||||
|
//$res=$db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='?' ORDER BY id DESC", array([$username]));
|
||||||
|
|
||||||
|
$res=$db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='".$username."' ORDER BY id DESC", $username);
|
||||||
|
|
||||||
$html='';
|
$html='';
|
||||||
if($res!==false)
|
if($res!==false)
|
||||||
@@ -13,6 +17,8 @@ if($res!==false)
|
|||||||
|
|
||||||
if(!empty($res)) foreach($res as $item)
|
if(!empty($res)) foreach($res as $item)
|
||||||
{
|
{
|
||||||
|
Utils::clonos_syslog("tasklog: HTML");
|
||||||
|
|
||||||
$hres=$this->getTableChunk('tasklog','tbody');
|
$hres=$this->getTableChunk('tasklog','tbody');
|
||||||
if($hres!==false)
|
if($hres!==false)
|
||||||
{
|
{
|
||||||
@@ -57,9 +63,11 @@ if($res!==false)
|
|||||||
$html_tmp=str_replace('#'.$var.'#',$val,$html_tmp);
|
$html_tmp=str_replace('#'.$var.'#',$val,$html_tmp);
|
||||||
|
|
||||||
$html.=$html_tmp;
|
$html.=$html_tmp;
|
||||||
|
//Utils::clonos_syslog("tasklog: HTML: ". $html);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Utils::clonos_syslog("tasklog: \$res query empty result:". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
'tbody'=>$html,
|
'tbody'=>$html,
|
||||||
@@ -74,4 +82,6 @@ if($res!==false)
|
|||||||
'func'=>'fillTable',
|
'func'=>'fillTable',
|
||||||
'id'=>'taskloglist',
|
'id'=>'taskloglist',
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
Utils::clonos_syslog("tasklog: \$res query failed:". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user