class Shell

Constants

COLOR_ERROR

COLOR_SUCCESS

COLOR_WARNING

COLOR_NOTICE

ROOT_USER

private COLOR_CODES

CMD_OUTPUT_STANDARD

CMD_OUTPUT_ERROR

CMD_OUTPUT_BOTH

Methods

bool
command_exist(string $cmd)

Check if a certain command exists in Linux

mixed
execute_cmd(string $cmd, bool $return_array = true, string $return_output = Shell::CMD_OUTPUT_STANDARD, int $error_code = null)

No description

mixed
execute_cmd_in_background(string $cmd, bool $return_array = true, bool|string $log_file = false, bool $low_prio = true)

No description

static array
getConfiguredProcessOwners()

Returns the configured process owners with their linux userinfo

static string
getProcessOwner()

Return current process owner

array
get_daemon_process_id(string $daemon_name)

No description

SystemCron|false
get_module_cron_object(string $module)

Loads the specified module cron object and returns it

array
get_process_id(string $process_name)

No description

static bool
isProcessOwnedByRoot()

Is the current process run by the root user?

bool
is_process_running(int $pid)

No description

bool
kill_process_id(int $pid, bool $forced = false)

No description

restart_all_daemons()

Restart all daemons

bool
restart_daemon_process(string $daemon_name, bool $force = false)

Restarts the passed daemon

schedule_cron(string $module, string $cron, int $schedule_time = null)

Schedules the cron to be started within the next three minutes, regardless of its regular execution time

search(mixed $filename, mixed $grep, $context = 0)

Search for a token in the passed file and return the corresponding lines

string
secure_shell_input(string $input)

No description

static bool
setProcessOwner(string $userName = \XF_WEBSERVER_UID)

Set UID and GID according to configured WEBSERVER process owner This function will only work if the current process owner is root

array|bool
start_cron($module, $cron)

No description

bool|mixed
start_daemon_process(string $daemon_name)

No description

void
stdOut(string $message, string $logLevel = LOG_INFO, string $colorType = null)

No description

bool
stop_daemon_process(string $daemon_name, bool $forced = false)

No description

array
tail(string $filename, int $lines = 50)

No description

Details

at line 428
bool command_exist(string $cmd)

Check if a certain command exists in Linux

Parameters

string $cmd

Return Value

bool

True if Command was available

at line 321
mixed execute_cmd(string $cmd, bool $return_array = true, string $return_output = Shell::CMD_OUTPUT_STANDARD, int $error_code = null)

No description

Parameters

string $cmd

Command to execute

bool $return_array

Set to false if you need the raw output

string $return_output

Defines which outputs you would like to get returned [standard|error|both]

int $error_code

Return Value

mixed

Returns an array with the output lines, Returns false if no output is returned

at line 371
mixed execute_cmd_in_background(string $cmd, bool $return_array = true, bool|string $log_file = false, bool $low_prio = true)

No description

Parameters

string $cmd

Command to execute

bool $return_array

Set to false if you need the raw output

bool|string $log_file

Logfile path if you want the output to be written to a logfile

bool $low_prio

Set to true if you want the process to be run with low priority, or false for regular priority

Return Value

mixed

Returns an array with the output lines, Returns false if no output is returned

at line 479
static array getConfiguredProcessOwners()

Returns the configured process owners with their linux userinfo

Return Value

array

at line 462
static string getProcessOwner()

Return current process owner

Return Value

string

name of the process owner

at line 37
array get_daemon_process_id(string $daemon_name)

No description

Parameters

string $daemon_name

Module Name

Return Value

array

List of PIDs

at line 77
SystemCron|false get_module_cron_object(string $module)

Loads the specified module cron object and returns it

Parameters

string $module

Name of the module to load the cron of

Return Value

SystemCron|false

Returns Object or FALSE if not available

Exceptions

Exception

at line 253
array get_process_id(string $process_name)

No description

Parameters

string $process_name

Process Name

Return Value

array

List of PIDs

at line 471
static bool isProcessOwnedByRoot()

Is the current process run by the root user?

Return Value

bool

at line 266
bool is_process_running(int $pid)

No description

Parameters

int $pid

PID

Return Value

bool

at line 283
bool kill_process_id(int $pid, bool $forced = false)

No description

Parameters

int $pid

Process ID

bool $forced

Set to TRUE if you like to force the shutdown of the process. The process will be halted immediately (! No clean shutdown !)

Return Value

bool

Returns TRUE on success or FALSE on failure.

at line 234
restart_all_daemons()

Restart all daemons

at line 204
bool restart_daemon_process(string $daemon_name, bool $force = false)

Restarts the passed daemon

Parameters

string $daemon_name

Module Name

bool $force

Force restart (kill process), if stop wont work.

Return Value

bool

at line 129
schedule_cron(string $module, string $cron, int $schedule_time = null)

Schedules the cron to be started within the next three minutes, regardless of its regular execution time

Parameters

string $module

The module name of the cron

string $cron

The cron id

int $schedule_time

Timestamp

Search for a token in the passed file and return the corresponding lines

Parameters

mixed $filename
mixed $grep
$context

at line 303
string secure_shell_input(string $input)

No description

Parameters

string $input

Input

Return Value

string

at line 509
static bool setProcessOwner(string $userName = \XF_WEBSERVER_UID)

Set UID and GID according to configured WEBSERVER process owner This function will only work if the current process owner is root

This is important for security reasons

Parameters

string $userName

XF_WEBSERVER_UID or XF_SYSTEM_UID

Return Value

bool

Returns TRUE on success or FALSE on failure.

at line 51
array|bool start_cron($module, $cron)

No description

Parameters

$module
$cron

Return Value

array|bool

Exceptions

Exception

at line 147
bool|mixed start_daemon_process(string $daemon_name)

No description

Parameters

string $daemon_name

Daemon Module Name

Return Value

bool|mixed

at line 444
void stdOut(string $message, string $logLevel = LOG_INFO, string $colorType = null)

No description

Parameters

string $message
string $logLevel
string $colorType

Return Value

void

at line 181
bool stop_daemon_process(string $daemon_name, bool $forced = false)

No description

Parameters

string $daemon_name

Module Name

bool $forced

Return Value

bool

Returns true if the process could be stopped

at line 397
array tail(string $filename, int $lines = 50)

No description

Parameters

string $filename

Filename

int $lines

Number of Lines

Return Value

array

Last x lines of the tailed file