standardize whitespace
git-svn-id: file:///home/svn/framework3/trunk@9413 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
7824ab661a
commit
c068e8e6dc
|
@ -1,8 +1,8 @@
|
|||
#<?php # This lets us run as a standalone file or as eval'd code
|
||||
function my_print($str) {
|
||||
error_log($str);
|
||||
#print($str ."\n");
|
||||
#flush();
|
||||
error_log($str);
|
||||
#print($str ."\n");
|
||||
#flush();
|
||||
}
|
||||
if (!function_exists("file_get_contents")) {
|
||||
function file_get_contents($file) {
|
||||
|
@ -40,7 +40,6 @@ function hexdump($data, $htmloutput = false, $uppercase = false, $return = false
|
|||
} else {
|
||||
$ascii .= '.';
|
||||
}
|
||||
|
||||
# Add extra column spacing
|
||||
if ($j === 7) {
|
||||
$hexi .= ' ';
|
||||
|
@ -69,7 +68,7 @@ function hexdump($data, $htmloutput = false, $uppercase = false, $return = false
|
|||
$dump .= "\n";
|
||||
|
||||
# Output method
|
||||
if ($return === false) {
|
||||
if ($return === false) {
|
||||
echo $dump;
|
||||
} else {
|
||||
return $dump;
|
||||
|
@ -298,6 +297,9 @@ function my_cmd($cmd) {
|
|||
return shell_exec($cmd);
|
||||
}
|
||||
|
||||
function is_windows() {
|
||||
return (strtoupper(substr(PHP_OS,0,3)) == "WIN");
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
|
@ -507,20 +509,24 @@ if (!function_exists('stdapi_sys_process_get_processes')) {
|
|||
function stdapi_sys_process_get_processes($req, &$pkt) {
|
||||
my_print("doing get_processes");
|
||||
$list = array();
|
||||
# This command produces a line like:
|
||||
# 1553 root /sbin/getty -8 38400 tty1
|
||||
$output = my_cmd("ps a -w -o pid,user,cmd --no-header 2>/dev/null");
|
||||
$lines = explode("\n", trim($output));
|
||||
foreach ($lines as $line) {
|
||||
array_push($list, preg_split("/\s+/", trim($line)));
|
||||
if (is_windows()) {
|
||||
# meh
|
||||
} else {
|
||||
# This command produces a line like:
|
||||
# 1553 root /sbin/getty -8 38400 tty1
|
||||
$output = my_cmd("ps a -w -o pid,user,cmd --no-header 2>/dev/null");
|
||||
$lines = explode("\n", trim($output));
|
||||
foreach ($lines as $line) {
|
||||
array_push($list, preg_split("/\s+/", trim($line)));
|
||||
}
|
||||
}
|
||||
foreach ($list as $proc) {
|
||||
$grp = "";
|
||||
$grp .= tlv_pack(create_tlv(TLV_TYPE_PID, $proc[0]));
|
||||
$grp .= tlv_pack(create_tlv(TLV_TYPE_USER_NAME, $proc[1]));
|
||||
$grp .= tlv_pack(create_tlv(TLV_TYPE_PROCESS_NAME, $proc[2]));
|
||||
# Strip the pid and the user name off the front; the rest will be the
|
||||
# full command line
|
||||
# Strip the pid and the user name off the front; the rest will be the
|
||||
# full command line
|
||||
array_shift($proc);
|
||||
array_shift($proc);
|
||||
$grp .= tlv_pack(create_tlv(TLV_TYPE_PROCESS_PATH, join($proc, " ")));
|
||||
|
@ -541,9 +547,9 @@ function stdapi_sys_process_getpid($req, &$pkt) {
|
|||
|
||||
if (!function_exists('stdapi_sys_process_kill')) {
|
||||
function stdapi_sys_process_kill($req, &$pkt) {
|
||||
# The existence of posix_kill is unlikely (it's a php compile-time option
|
||||
# that isn't enabled by default, but better to try it and avoid shelling
|
||||
# out when unnecessary.
|
||||
# The existence of posix_kill is unlikely (it's a php compile-time option
|
||||
# that isn't enabled by default, but better to try it and avoid shelling
|
||||
# out when unnecessary.
|
||||
my_print("doing kill");
|
||||
$pid_tlv = packet_get_tlv($req, TLV_TYPE_PID);
|
||||
$pid = $pid_tlv['value'];
|
||||
|
@ -625,7 +631,7 @@ function channel_create_stdapi_net_tcp_client($req, &$pkt) {
|
|||
$retries_tlv = packet_get_tlv($req, TLV_TYPE_CONNECT_RETRIES);
|
||||
|
||||
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
$res = socket_connect($sock, $peer_host_tlv['value'], $peer_port_tlv['value']);
|
||||
$res = socket_connect($sock, $peer_host_tlv['value'], $peer_port_tlv['value']);
|
||||
|
||||
if (is_resource($sock)) {
|
||||
array_push($channels, array(0 => $sock, 1 => $sock, 'type' => 'socket'));
|
||||
|
@ -932,31 +938,31 @@ $port = 4444;
|
|||
|
||||
$listen = false;
|
||||
if ($listen) {
|
||||
my_print("Listening on $port");
|
||||
my_print("Listening on $port");
|
||||
|
||||
$setsockopt = 'socket_setopt';
|
||||
if (!is_callable($setsockopt )) {
|
||||
# renamed in PHP 4.3.0
|
||||
$setsockopt = 'socket_set_option';
|
||||
}
|
||||
$setsockopt = 'socket_setopt';
|
||||
if (!is_callable($setsockopt )) {
|
||||
# renamed in PHP 4.3.0
|
||||
$setsockopt = 'socket_set_option';
|
||||
}
|
||||
|
||||
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
# don't care if this fails
|
||||
@$setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, 1);
|
||||
$ret = socket_bind($sock, 0, $port);
|
||||
$ret = socket_listen($sock, 5);
|
||||
$msgsock = socket_accept($sock);
|
||||
socket_close($sock);
|
||||
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
# don't care if this fails
|
||||
@$setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, 1);
|
||||
$ret = socket_bind($sock, 0, $port);
|
||||
$ret = socket_listen($sock, 5);
|
||||
$msgsock = socket_accept($sock);
|
||||
socket_close($sock);
|
||||
|
||||
my_print("Got a socket connection $sock");
|
||||
my_print("Got a socket connection $sock");
|
||||
} else {
|
||||
my_print("Connecting to $port");
|
||||
$ipaddr = '127.0.0.1';
|
||||
$msgsock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
|
||||
$res = socket_connect($msgsock,$ipaddr,$port);
|
||||
if (!$res) {
|
||||
die();
|
||||
}
|
||||
my_print("Connecting to $port");
|
||||
$ipaddr = '127.0.0.1';
|
||||
$msgsock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
|
||||
$res = socket_connect($msgsock,$ipaddr,$port);
|
||||
if (!$res) {
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$socket_readers = array($msgsock);
|
||||
|
@ -984,7 +990,7 @@ while (FALSE !== socket_select($r=$socket_readers, $w=NULL, $e=NULL, 1)) {
|
|||
$request .= socket_read($msgsock, $len-strlen($request), PHP_BINARY_READ);
|
||||
}
|
||||
hexdump(substr($request, 0, $len));
|
||||
my_print("creating response");
|
||||
my_print("creating response");
|
||||
$response = create_response($request);
|
||||
|
||||
socket_write($msgsock, $response);
|
||||
|
|
Loading…
Reference in New Issue