mirror of
https://github.com/myvesta/vesta
synced 2025-07-06 04:51:54 -07:00
myvesta_echo php function
This commit is contained in:
parent
a47603156d
commit
3bafc5b064
2 changed files with 30 additions and 20 deletions
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
$myvesta_echo_done=false;
|
||||
|
||||
if (isset($_SERVER['SHLVL'])) $SHLVL=intval($_SERVER['SHLVL']);
|
||||
else $SHLVL=3;
|
||||
|
||||
|
@ -27,14 +29,11 @@ for ($i=2; $i<$counter; $i++) {
|
|||
$r=call_user_func_array($func, $params);
|
||||
if (is_bool($r)) {
|
||||
if ($r) {
|
||||
if ($SHLVL<3) echo "\n";
|
||||
exit(0);
|
||||
myvesta_exit (0);
|
||||
} else {
|
||||
if ($SHLVL<3) echo "\n";
|
||||
exit(MYVESTA_ERROR_GENERAL);
|
||||
myvesta_exit (MYVESTA_ERROR_GENERAL);
|
||||
}
|
||||
} else {
|
||||
echo $r;
|
||||
if ($SHLVL<3) echo "\n";
|
||||
exit(0);
|
||||
myvesta_echo ($r);
|
||||
myvesta_exit (0);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
|
||||
$myvesta_current_user=exec('whoami', $myvesta_output, $myvesta_return_var);
|
||||
if ($myvesta_current_user != 'root') {echo "ERROR: You must be root to execute this script\n"; exit(1);}
|
||||
|
||||
$myvesta_exit_on_error=true;
|
||||
define('MYVESTA_ERROR_PERMISSION_DENIED', 1);
|
||||
define('MYVESTA_ERROR_MISSING_ARGUMENTS', 2);
|
||||
|
@ -10,9 +7,29 @@ define('MYVESTA_ERROR_FILE_DOES_NOT_EXISTS', 3);
|
|||
define('MYVESTA_ERROR_STRING_NOT_FOUND', 4);
|
||||
define('MYVESTA_ERROR_GENERAL', 5);
|
||||
|
||||
function myvesta_echo($str) {
|
||||
global $myvesta_echo_done, $myvesta_last_echo;
|
||||
$myvesta_echo_done=true;
|
||||
$myvesta_last_echo=$str;
|
||||
echo $str;
|
||||
}
|
||||
|
||||
function myvesta_exit($code) {
|
||||
global $SHLVL, $myvesta_echo_done, $myvesta_last_echo;
|
||||
// myvesta_echo ("==================== ".$argv[0].": ".$code." ====================\n");
|
||||
if ($SHLVL<3 && $myvesta_echo_done==true) {
|
||||
$last_char=substr($myvesta_last_echo, -1, 1);
|
||||
if ($last_char!="\n") echo "\n";
|
||||
}
|
||||
exit($code);
|
||||
}
|
||||
|
||||
$myvesta_current_user=exec('whoami', $myvesta_output, $myvesta_return_var);
|
||||
if ($myvesta_current_user != 'root') {myvesta_echo ("ERROR: You must be root to execute this script"); myvesta_exit(1);}
|
||||
|
||||
function myvesta_throw_error($code, $message) {
|
||||
global $myvesta_exit_on_error;
|
||||
if ($message!=='') echo "ERROR: ".$message."\n";
|
||||
if ($message!=='') myvesta_echo ("ERROR: ".$message);
|
||||
if ($myvesta_exit_on_error) myvesta_exit($code);
|
||||
return $code;
|
||||
}
|
||||
|
@ -29,7 +46,7 @@ function myvesta_check_args ($requried_arguments, $arguments) {
|
|||
$argument_counter=count($argv);
|
||||
$argument_counter--;
|
||||
$argv[0]=str_replace('/usr/local/vesta/bin/', '', $argv[0]);
|
||||
// echo "-------------------- ".$argv[0]." --------------------\n";
|
||||
// myvesta_echo ( "-------------------- ".$argv[0]." --------------------\n");
|
||||
if ($argument_counter<$requried_arguments) {
|
||||
$arguments=str_replace(" ", "' '", $arguments);
|
||||
$arguments="'".$arguments."'";
|
||||
|
@ -53,14 +70,8 @@ function myvesta_fix_args() {
|
|||
}
|
||||
}
|
||||
|
||||
function myvesta_exit($code) {
|
||||
// global $argv;
|
||||
// echo "==================== ".$argv[0].": ".$code." ====================\n";
|
||||
exit($code);
|
||||
}
|
||||
|
||||
function myvesta_test_func () {
|
||||
$args=func_get_args();
|
||||
echo "You said: ";
|
||||
echo trim(print_r ($args, true));
|
||||
myvesta_echo ("You said: ");
|
||||
myvesta_echo (trim(print_r ($args, true)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue