-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvncimg.php
More file actions
86 lines (75 loc) · 2.26 KB
/
vncimg.php
File metadata and controls
86 lines (75 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require('./phpvnc.php');
declare(ticks = 1);
ignore_user_abort(false);
ob_implicit_flush(true);
pcntl_signal(SIGTERM, "sig_handler");
function sig_handler($signo) {
if ($signo == SIGTERM)
_cleanup();
die();
}
function _cleanup() {
global $config;
$host = $_SESSION['host'];
debug("mjpeg stream to $host terminated, cleaning up.");
//$segment = shm_attach($config->shm->key, $config->shm->size, $config->shm->permissions);
//shm_remove($segment);
}
function errorImage($width, $height, $text) {
// taken from http://cl1.php.net/manual/es/function.imagestring.php#90481
// Set font size
$font_size = 5;
$ts=explode("\n",$text);
/*$width=0;
foreach ($ts as $k=>$string) { //compute width
$width=max($width,strlen($string));
}
// Create image width dependant on width of the string
$width = imagefontwidth($font_size)*$width;
// Set height to that of the font
$height = imagefontheight($font_size)*count($ts);*/
$el=imagefontheight($font_size);
$em=imagefontwidth($font_size);
// Create the image pallette
$img = imagecreatetruecolor($width,$height);
// Dark red background
$bg = imagecolorallocate($img, 0xAA, 0x00, 0x00);
imagefilledrectangle($img, 0, 0,$width ,$height , $bg);
// White font color
$color = imagecolorallocate($img, 255, 255, 255);
foreach ($ts as $k=>$string) {
// Length of the string
$len = strlen($string);
// Y-coordinate of character, X changes, Y is static
$ypos = 0;
// Loop through the string
for($i=0;$i<$len;$i++){
// Position of the character horizontally
$xpos = $i * $em;
$ypos = $k * $el;
// Draw character
imagechar($img, $font_size, $xpos, $ypos, $string, $color);
// Remove character from string
$string = substr($string, 1);
}
}
return($img);
}
register_shutdown_function('_cleanup');
session_start();
$host = $_SESSION['host'];
$port = $_SESSION['port'];
$passwd = $_SESSION['passwd'];
$socket = $_SESSION['socket'];
$tls = $_SESSION['tls'];
$client = new vncClient();
$auth = $client->auth($host, $port, $passwd, $tls);
if ($auth === false) {
$img = errorImage(640, 480, "\n ERROR:\n Could not connect to remote RFB.\n\n " . $client->errstr);
header('Content-type: image/jpeg');
imagejpeg($img);
die();
}
$init = $client->serverInit();
$stat = $client->streamImage('jpeg', $socket);