for i in $(find web -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^....//g'); do
install -m 644 "web/$i" "${web_path}__/$i"
done
+
+# hardlink for nginx managed websocket files.
+ln "${web_path}__/xynt_test01.php" "${web_path}__/xynt_test01_wss.php"
+
if [ "$test_add" = "TRUE" ]; then
for i in $(find webtest -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^........//g'); do
install -m 644 "webtest/$i" "${web_path}__/$i"
class Transport_websocket {
protected $magicGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
- function Transport_websocket() {
+ function Transport_websocket($secure = FALSE) {
$this->headerOriginRequired = false;
$this->headerSecWebSocketProtocolRequired = false;
$this->headerSecWebSocketExtensionsRequired = false;
}
if (!isset($headers['Host']) || !$this->checkHost($headers['Host'])) {
+ // error_log('bad 1');
$headers_out['HTTP-Response'] = "400 Bad Request";
}
if (!isset($headers['Upgrade']) || strtolower($headers['Upgrade']) != 'websocket') {
+ // error_log('bad 2 ' . $headers['Upgrade']);
$headers_out['HTTP-Response'] = "400 Bad Request";
}
if (!isset($headers['Connection']) || strpos(strtolower($headers['Connection']), 'upgrade') === FALSE) {
+ // error_log('bad 3');
$headers_out['HTTP-Response'] = "400 Bad Request";
}
if (!isset($headers['Sec-Websocket-Key'])) {
+ // error_log('bad 4');
$headers_out['HTTP-Response'] = "400 Bad Request";
} else {
}
if ( ($this->headerSecWebSocketProtocolRequired && !isset($headers['Sec-Websocket-Protocol']))
|| ($this->headerSecWebSocketProtocolRequired &&
!$this->checkWebsocProtocol($headers['Sec-Websocket-Protocol']))) {
+ // error_log('bad 5');
$headers_out['HTTP-Response'] = "400 Bad Request";
}
if ( ($this->headerSecWebSocketExtensionsRequired && !isset($headers['Sec-Websocket-Extensions']))
|| ($this->headerSecWebSocketExtensionsRequired &&
!$this->checkWebsocExtensions($headers['Sec-Websocket-Extensions'])) ) {
+ // error_log('bad 6');
$headers_out['HTTP-Response'] = "400 Bad Request";
}
}
// alert("host: ["+host+"] path: ["+path+"]");
- if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/') {
+ console.log('URL: ' + url);
+ if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/' || url.substring(0,5) == 'wss:/') {
return (url);
}
else if (url.substring(0,1) == '/') {
//
function transport_ws(doc, xynt_streaming, page)
{
- this.name = "WebSocket";
+ // if four arguments manage if WS or WSS connection
+ if (arguments.length > 3)
+ this.is_secure = arguments[3];
+ else
+ this.is_secure = false;
+
+ if (this.is_secure)
+ this.name = "WebSocketSecure";
+ else
+ this.name = "WebSocket";
this.ctx_new = "";
var self = this;
this.failed = false;
this.xynt_streaming = xynt_streaming;
try {
-this.xynt_streaming.log("PAGE: "+page);
+ this.xynt_streaming.log("PAGE: "+page);
this.ws = new WebSocket(page);
this.ws.onopen = function () {
self.xynt_streaming.log("onopen");
transp_port = this.transp_port;
}
- if (transp_type == "websocket") {
- var end_proto, first_slash;
+ if (transp_type == "websocket" || transp_type == "websocketsec") {
+ var end_proto, first_slash, newpage;
// change protocol
this.log("precha ["+this.page+"]");
- end_proto = this.page.indexOf("://");
- first_slash = this.page.substring(end_proto+3).indexOf("/");
+ if (transp_type == "websocketsec") {
+ newpage = this.page.replace(/\.php$/g, "_wss.php").replace(/\.php\?/g, "_wss.php?");
+ }
+ else {
+ newpage = this.page;
+ }
+ end_proto = newpage.indexOf("://");
+ first_slash = newpage.substring(end_proto+3).indexOf("/");
- page = "ws://" + this.page.substring(end_proto+3, end_proto+3+first_slash) + ":" + transp_port + this.page.substring(end_proto+3 + first_slash);
+ page = (transp_type == "websocketsec" ? "wss://" : "ws://")
+ + newpage.substring(end_proto+3, end_proto+3 + first_slash) + ":"
+ + transp_port + newpage.substring(end_proto+3 + first_slash);
+ // this.log("MOP WS: " + page);
}
else {
page = this.page;
try {
// transport instantiation
- if (transp_type == "websocket") {
+ if (transp_type == "websocketsec") {
+ page = url_append_args(page, "transp", "websocketsec");
+ this.transp = new transport_ws(this.doc, this, page, true);
+ }
+ else if (transp_type == "websocket") {
page = url_append_args(page, "transp", "websocket");
this.transp = new transport_ws(this.doc, this, page);
}
<?php
+foreach (array('isstream', 'f_test', 'f_trans', 'f_port', 'f_fback', 'sess', 'stat',
+ 'subst', 'step', 'from', 'transp') as $i) {
+ if (isset($_REQUEST[$i])) {
+ $$i = $_REQUEST[$i];
+ }
+}
$desc = array( "Semplice: da 1 a 9 ogni secondo, poi ricomincia (status sempre verde).",
"Continuo: da 1 a N ogni secondo, ricomincia ogni 9 (status sempre verde).",
return (TRUE);
}
-$transs = array( "iframe", "websocket", "xhr", "htmlfile" );
+$transs = array( "iframe", "websocket", "websocketsec", "xhr", "htmlfile" );
+$trans_ports = array( "iframe"=>80, "websocket"=>80, "websocketsec"=>443, "xhr"=>80, "htmlfile"=>80 );
if (!isset($f_trans))
$f_trans = $transs[0];
$f_test = 1;
if (!isset($f_port))
- $f_port = 80;
+ $f_port = NULL;
if (!isset($f_fback))
$f_fback = 0;
}
if (isset($isstream) && $isstream == "true") {
-
require_once("Obj/transports.phh");
if (isset($transp) && $transp == "websocket") {
$trobj = new Transport_websocket();
}
+ else if (isset($transp) && $transp == "websocketsec") {
+ $trobj = new Transport_websocket(TRUE);
+ }
else if (isset($transp) && $transp == "xhr") {
$trobj = new Transport_xhr();
}
$init_string .= chr(mt_rand(65, 90));
}
$headers_in = getallheaders();
+ // error_log(print_r($headers_in, TRUE));
$headers = array();
foreach ($headers_in as $header_in => $value) {
$headers[mb_convert_case($header_in, MB_CASE_TITLE, 'UTF-8')] = $value;
fclose($fp);
}
- if (isset($transp) && $transp == "websocket") {
+ if (isset($transp) && ($transp == "websocket" || $transp == "websocketsec")) {
header_remove('Connection');
header_remove('Content-Encoding');
header_remove('Content-Type');
var gst = new globst();
window.onload = function() {
- xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", <?php echo "$f_port";?>, <?php echo "$f_fback";?>, console, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=<?php echo "$f_test";?>', function(com){eval(com);});
+ xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", <?php
+ echo ($f_port == NULL ? "${trans_ports[$f_trans]}" : "$f_port" );?>, <?php echo "$f_fback";?>, console, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=<?php echo "$f_test";?>', function(com){eval(com);});
xstm.hbit_set(heartbit);
xstm.start();
}
<div>
<?php
-
-
printf("<table>");
for ($test = 1 ; $test <= count($desc) ; $test++) {
printf("<tr>");
foreach ($transs as $trans) {
- printf("<td style=\"padding: 8px; border: 1px solid black;\"><a href=\"?f_trans=%s&f_test=%d&f_port=%d&f_fback=%d\">Test %s %02d (port %d (fb %d))</a></td>", $trans, $test, $f_port, $f_fback, $trans, $test, $f_port, $f_fback);
+ printf("<td style=\"padding: 8px; border: 1px solid black;\"><a href=\"?f_trans=%s&f_test=%d%s&f_fback=%d\">Test %s %02d (port %d (fb %d))</a></td>", $trans, $test,
+ ($f_port == NULL ? "" : sprintf("&f_port=%d", $f_port)), $f_fback, $trans, $test,
+ ($f_port == NULL ? $trans_ports[$trans] : $f_port ), $f_fback);
}
printf("</tr>\n");
}