From bf442d3554f1e4b34231c2b9dde8e8c0a8627bc5 Mon Sep 17 00:00:00 2001 From: Felix Klenner Date: Fri, 19 Jul 2024 19:18:16 +0200 Subject: [PATCH] Add websocket server and configs --- README.md | 75 ++++++++++++++++++++++++++++++++++++++++ node_server/main.js | 52 ++++++++++++++++++++++++++++ node_server/package.json | 8 +++++ 3 files changed, 135 insertions(+) create mode 100644 node_server/main.js create mode 100644 node_server/package.json diff --git a/README.md b/README.md index 4c9fc56..26e2d4a 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,81 @@ geoip2 /var/lib/GeoIP/GeoLite2-ASN.mmdb { } ``` +Then the following should be used, to pass this data to php: +``` +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; +fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; +fastcgi_param REQUEST_SCHEME $scheme; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param REMOTE_USER $remote_user; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; + +#for proxy detection +fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for; + +#pass all geoip data +fastcgi_param GEOIP_CONTINENT_CODE $geoip2_data_continent_code; +fastcgi_param GEOIP_CONTINENT_NAME $geoip2_data_continent_name; +fastcgi_param GEOIP_COUNTRY_CODE $geoip2_data_country_code; +fastcgi_param GEOIP_COUNTRY_NAME $geoip2_data_country_name; +fastcgi_param GEOIP_SUBDIVISION $geoip2_data_subdivision; +fastcgi_param GEOIP_CITY_NAME $geoip2_data_city_name; +fastcgi_param GEOIP_POSTAL_CODE $geoip2_data_postal_code; +fastcgi_param GEOIP_LATITUDE $geoip2_data_location_lat; +fastcgi_param GEOIP_LONGITUDE $geoip2_data_location_long; +fastcgi_param GEOIP_ACCURACY $geoip2_data_location_acc; +fastcgi_param GEOIP_TIMEZONE $geoip2_data_location_time; +fastcgi_param GEOIP_ASN $geoip2_data_asn; +``` + + +The following is the nginx config for the server block: +``` +server +{ + listen 80; + listen [::]:80; + listen 443 ssl http2; + listen [::]:443 ssl http2; + + server_name v4.ip.zuim.de v6.ip.zuim.de ip.zuim.de 89.58.44.51 [2a03:4000:67:e03::1]; + + root PROJEKTORDNER + + location /speedtest + { + proxy_pass http://unix:/run/nodejs/speedtest/socket; + proxy_http_version 1.1; + #include include/proxy_params; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + include include/php; + include include/ssl_zuim; +} +``` + Download these files directly and add them in the main folder: - https://ip.zuim.de/0B.zip - https://ip.zuim.de/1MB.zip diff --git a/node_server/main.js b/node_server/main.js new file mode 100644 index 0000000..77c3fe5 --- /dev/null +++ b/node_server/main.js @@ -0,0 +1,52 @@ +var path = "/speedtest"; + +var app = require('express')(); +var http = require('http').Server(app); +var io = require('socket.io')(http, {path: path +//, cors: { +// origin: [/zuim\.de$/, /craftandbuild\.de$/], +// methods: ["GET", "POST"] +// } +}); +var fs = require('fs'); + +io.on('connection', function(socket) +{ + socket.on('pingUp', function(msg) + { + socket.emit('pongDown', msg); + }); + + socket.on('downReq', function(msg) + { + if(new RegExp('[0-9]+').test(msg)) + { + fs.readFile(__dirname + '/data/' + msg, function (err, data) + { + socket.emit('downDataStart', ''); + socket.emit('downData', data); + }); + } + }); + + socket.on('upTest', function(msg) + { + socket.emit('upOk', ''); + }); + + socket.on('pingT', function(msg) + { + socket.emit('pongT', ''); + }); +}); + +//http.listen(3000, function(){ +// console.log('listening on *:3000'); +//}); +var socket = '/var/run/nodejs'+path+"/socket"; +if(fs.existsSync(socket)) + fs.unlinkSync(socket); +http.listen(socket, function() +{ + fs.chmodSync(socket, '666'); +}); diff --git a/node_server/package.json b/node_server/package.json new file mode 100644 index 0000000..5fda05f --- /dev/null +++ b/node_server/package.json @@ -0,0 +1,8 @@ +{ + "name": "ipinfo_server", + "version": "0.0.1", + "dependencies": { + "express": "^4.13.4", + "socket.io": "^4.2.0" + } +}