From eabc2fcaddbe29fac759bbb8667b8bd9e925a580 Mon Sep 17 00:00:00 2001 From: nielsbaloe Date: Sun, 2 Jun 2019 14:59:24 +0200 Subject: [PATCH] Update index.php --- index.php | 82 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/index.php b/index.php index 518e734..b193b59 100644 --- a/index.php +++ b/index.php @@ -4,9 +4,14 @@ // to identify the user. With websockets there is no need for unique IDs, // you just save the sockets itsself. session_start(); +if (!ctype_alnum(session_id()) || !preg_match('/^(?:[a-z0-9_-]|\.(?!\.))+$/iD', session_id())) { + die(); +} + // 'eventsource' in the URL is used to distinguish // the HTML from the real eventsource calls in this single file. +// Everything is in one file, you know. if (!isset($_GET['eventSource'])) { // show HTML CSS and Javascript ?> @@ -45,8 +50,8 @@ if (!isset($_GET['eventSource'])) { // show HTML CSS and Javascript var localStream=null; var ws=null; - // 'eventsource' parameter is used to distinguish - // the HTML form the real eventsource calls + // 'eventsource' parameter is only used to distinguish + // the HTML form the real eventsource calls. var URL = 'index.php?eventSource=yes'; var localVideo = document.getElementById('localVideo'); var remoteVideo = document.getElementById('remoteVideo'); @@ -92,7 +97,7 @@ if (!isset($_GET['eventSource'])) { // show HTML CSS and Javascript // Websocket-hack: onmessage is extended for receiving // multiple events at once for speed, because the polling - // frequency of EventSource is just once every few seconds. + // frequency of EventSource is low. ws.onmessage = function(e) { if (e.data.includes("_MULTIPLEVENTS_")) { multiple = e.data.split("_MULTIPLEVENTS_"); @@ -142,9 +147,10 @@ if (!isset($_GET['eventSource'])) { // show HTML CSS and Javascript case 'client-answer': if (pc==null) { console.error('Before processing the client-answer, I need a client-offer'); + break; } - pc.setRemoteDescription(new RTCSessionDescription(data),function(){}, function(e){ - console.log("Problem while doing client-answer: ",e); + pc.setRemoteDescription(new RTCSessionDescription(data),function(){}, + function(e) { console.log("Problem while doing client-answer: ",e); }); break; case 'client-offer': @@ -168,7 +174,12 @@ if (!isset($_GET['eventSource'])) { // show HTML CSS and Javascript }); break; case 'client-candidate': - pc.addIceCandidate(new RTCIceCandidate(data), function(){}, function(e){console.log("Problem adding ice candidate: "+e);}); + if (pc==null) { + console.error('Before processing the client-answer, I need a client-offer'); + break; + } + pc.addIceCandidate(new RTCIceCandidate(data), function(){}, + function(e) { console.log("Problem adding ice candidate: "+e);}); break; } }; @@ -210,68 +221,87 @@ if (!isset($_GET['eventSource'])) { // show HTML CSS and Javascript