Current File : //etc/zpanel/panel/etc/apps/filemanager/include/common_function.php |
<?php
class CommonFunction
{
public static function create_guid()
{
$microTime = microtime();
list($a_dec, $a_sec) = explode(' ', $microTime);
$dec_hex = dechex($a_dec * 1000000);
$sec_hex = dechex($a_sec);
CommonFunction::ensure_length($dec_hex, 5);
CommonFunction::ensure_length($sec_hex, 6);
$guid = '';
$guid .= $dec_hex;
$guid .= CommonFunction::create_guid_section(3);
$guid .= '-';
$guid .= CommonFunction::create_guid_section(4);
$guid .= '-';
$guid .= CommonFunction::create_guid_section(4);
$guid .= '-';
$guid .= CommonFunction::create_guid_section(4);
$guid .= '-';
$guid .= $sec_hex;
$guid .= CommonFunction::create_guid_section(6);
return $guid;
}
public static function create_guid_section($characters)
{
$return = '';
for ($i = 0; $i < $characters; ++$i) {
$return .= dechex(mt_rand(0, 15));
}
return $return;
}
public static function ensure_length(&$string, $length)
{
$strlen = strlen($string);
if ($strlen < $length) {
$string = str_pad($string, $length, '0');
} elseif ($strlen > $length) {
$string = substr($string, 0, $length);
}
}
public static function file_delete_socket($cmd_detail)
{
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
return false;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 300, "usec" =>0));
$in="command ".$cmd_detail;
$out = '';
if(@socket_write($socket, $in, strlen($in)))
{
sleep(1);
socket_close($socket);
}
else
{
socket_close($socket);
}
//return true;
}
public static function file_read_socket($cmd_detail)
{
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
return false;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 300, "usec" =>0));
$in="command ".$cmd_detail;
$out = '';
if(@ socket_write($socket, $in, strlen($in)))
{
sleep(1);
$s_data = socket_read($socket,1024);
socket_close($socket);
return $s_data;
}
else
{
socket_close($socket);
return false;
}
}
public static function is_Session_Exist()
{
if ( php_sapi_name() !== 'cli' ) {
if ( version_compare(phpversion(), '5.4.0', '>=') ) {
return (session_status() === PHP_SESSION_ACTIVE || session_status() === PHP_SESSION_NONE) ? TRUE : FALSE;
} else {
return session_id() === '' ? FALSE : TRUE;
}
}
return FALSE;
}
public static function check_Session()
{
if (CommonFunction::is_Session_Exist() === FALSE )
{
session_start();
}
}
public static function remove_space($mtxt)
{
$mtxt1 = trim(preg_replace('/\s+/', '', $mtxt));
return $mtxt1;
}
public static function trim_space($mtxt)
{
$mtxt1 = trim(preg_replace('/\s+/', ' ', $mtxt));
return $mtxt1;
}
}
?>