diff --git a/exec/websocketservice.js b/exec/websocketservice.js index 27777e0199f7e10e2d5315e6e862a1815de3c44c..82a5343534de3582e7a837856605dbfe62071819 100644 --- a/exec/websocketservice.js +++ b/exec/websocketservice.js @@ -93,7 +93,20 @@ try { var ServerData = []; if (UsingHAProxy()) { - // Do HAProxy stuff here + [0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A, 0x21].forEach(function (e) { + FServerSocket.sendBin(e, 1); + }); + if (client.socket.family === PF_INET) { + FServerSocket.sendBin(0x11, 1); + FServerSocket.sendBin(12, 2); + } else if (client.socket.family === PF_INET6) { + FServerSocket.sendBin(0x21, 1); + FServerSocket.sendBin(36, 2); + } + FServerSocket.sendBin(inet_pton(client.ip_address), 4); + FServerSocket.sendBin(inet_pton(TARGET_IP_ADDRESS_GOES_HERE), 4); + FServerSocket.sendBin(client.port, 2); + FServerSocket.sendBin(TargetPort, 2); } // Loop while we're still connected on both ends @@ -599,3 +612,48 @@ function ShakeHandsVersion7() { return false; } } + +function inet_pton (a) { + // http://kevin.vanzonneveld.net + // + original by: Theriault + // * example 1: inet_pton('::'); + // * returns 1: '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' (binary) + // * example 2: inet_pton('127.0.0.1'); + // * returns 2: '\x7F\x00\x00\x01' (binary) + var r, m, x, i, j, f = String.fromCharCode; + m = a.match(/^(?:\d{1,3}(?:\.|$)){4}/); // IPv4 + if (m) { + m = m[0].split('.'); + m = f(m[0]) + f(m[1]) + f(m[2]) + f(m[3]); + // Return if 4 bytes, otherwise false. + return m.length === 4 ? m : false; + } + r = /^((?:[\da-f]{1,4}(?::|)){0,8})(::)?((?:[\da-f]{1,4}(?::|)){0,8})$/; + m = a.match(r); // IPv6 + if (m) { + // Translate each hexadecimal value. + for (j = 1; j < 4; j++) { + // Indice 2 is :: and if no length, continue. + if (j === 2 || m[j].length === 0) { + continue; + } + m[j] = m[j].split(':'); + for (i = 0; i < m[j].length; i++) { + m[j][i] = parseInt(m[j][i], 16); + // Would be NaN if it was blank, return false. + if (isNaN(m[j][i])) { + return false; // Invalid IP. + } + m[j][i] = f(m[j][i] >> 8) + f(m[j][i] & 0xFF); + } + m[j] = m[j].join(''); + } + x = m[1].length + m[3].length; + if (x === 16) { + return m[1] + m[3]; + } else if (x < 16 && m[2].length > 0) { + return m[1] + (new Array(16 - x + 1)).join('\x00') + m[3]; + } + } + return false; // Invalid IP. +}