diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-21 23:52:46 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-21 23:52:46 +0200 |
commit | 3f5589dd1fe00148b46fbe9cd191776c8ee6291d (patch) | |
tree | efd65f55d1ffe2b2066be65a1012a63d86e374df | |
parent | 67217883912688dfdf76ed11a99ed1006b733063 (diff) | |
download | booru-3f5589dd1fe00148b46fbe9cd191776c8ee6291d.tar.gz booru-3f5589dd1fe00148b46fbe9cd191776c8ee6291d.tar.bz2 booru-3f5589dd1fe00148b46fbe9cd191776c8ee6291d.zip |
Updated 6 files, added 3 files and renamed nsfw/not/index.php (automated)
-rw-r--r-- | .idea/deployment.xml | 6 | ||||
-rw-r--r-- | _shakeapi/client.js | 4 | ||||
-rw-r--r-- | _shakeapi/node_modules/.package-lock.json | 8 | ||||
-rw-r--r-- | _shakeapi/node_modules/uuid-v4/index.js | 28 | ||||
-rw-r--r-- | _shakeapi/node_modules/uuid-v4/package.json | 13 | ||||
-rw-r--r-- | _shakeapi/node_modules/uuid-v4/readme.md | 33 | ||||
-rw-r--r-- | _shakeapi/package-lock.json | 14 | ||||
-rw-r--r-- | _shakeapi/package.json | 1 | ||||
-rw-r--r-- | _shakeapi/server.js | 40 | ||||
-rw-r--r-- | nsfw/sp2/4/index.php (renamed from nsfw/not/index.php) | 2 |
10 files changed, 140 insertions, 9 deletions
diff --git a/.idea/deployment.xml b/.idea/deployment.xml index 006a3a1..940f994 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> - <component name="PublishConfigData" autoUpload="Always" serverName="Minteck.org" remoteFilesAllowedToDisappearOnAutoupload="false"> + <component name="PublishConfigData" autoUpload="Always" serverName="zephyrheights" remoteFilesAllowedToDisappearOnAutoupload="false"> <serverData> - <paths name="Minteck.org"> + <paths name="zephyrheights"> <serverdata> <mappings> - <mapping deploy="/pool/web/booru" local="$PROJECT_DIR$" web="/" /> + <mapping deploy="/mnt/booru" local="$PROJECT_DIR$" web="/" /> </mappings> </serverdata> </paths> diff --git a/_shakeapi/client.js b/_shakeapi/client.js index 15b85cb..a04d1af 100644 --- a/_shakeapi/client.js +++ b/_shakeapi/client.js @@ -13,7 +13,7 @@ function connect() { key: watchID })); } else if (data.type === "shake") { - if (new Date().getTime() - lastShake > 450) { + if (new Date().getTime() - lastShake > 250) { console.log("Accepted"); shakeHandler(); lastShake = new Date().getTime(); @@ -22,6 +22,8 @@ function connect() { } } else if (data.type === "accepted") { shakeConnectionHandler(); + } else if (data.type === "disconnect") { + location.reload(); } else { ws.close(); shakeErrorHandler(); diff --git a/_shakeapi/node_modules/.package-lock.json b/_shakeapi/node_modules/.package-lock.json index 0914748..5e02f05 100644 --- a/_shakeapi/node_modules/.package-lock.json +++ b/_shakeapi/node_modules/.package-lock.json @@ -3,6 +3,14 @@ "lockfileVersion": 2, "requires": true, "packages": { + "node_modules/uuid-v4": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/uuid-v4/-/uuid-v4-0.1.0.tgz", + "integrity": "sha512-m11RYDtowtAIihBXMoGajOEKpAXrKbpKlpmxqyztMYQNGSY5nZAZ/oYch/w2HNS1RMA4WLGcZvuD8/wFMuCEzA==", + "engines": { + "node": "*" + } + }, "node_modules/ws": { "version": "8.13.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", diff --git a/_shakeapi/node_modules/uuid-v4/index.js b/_shakeapi/node_modules/uuid-v4/index.js new file mode 100644 index 0000000..ce0a0bb --- /dev/null +++ b/_shakeapi/node_modules/uuid-v4/index.js @@ -0,0 +1,28 @@ + +exports = module.exports = function() { + var ret = '', value; + for (var i = 0; i < 32; i++) { + value = exports.random() * 16 | 0; + // Insert the hypens + if (i > 4 && i < 21 && ! (i % 4)) { + ret += '-'; + } + // Add the next random character + ret += ( + (i === 12) ? 4 : ( + (i === 16) ? (value & 3 | 8) : value + ) + ).toString(16); + } + return ret; +}; + +var uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/; +exports.isUUID = function(uuid) { + return uuidRegex.test(uuid); +}; + +exports.random = function() { + return Math.random(); +}; + diff --git a/_shakeapi/node_modules/uuid-v4/package.json b/_shakeapi/node_modules/uuid-v4/package.json new file mode 100644 index 0000000..4badb74 --- /dev/null +++ b/_shakeapi/node_modules/uuid-v4/package.json @@ -0,0 +1,13 @@ +{ + "author": "James Brumond <james@jbrumond.me> (http://jbrumond.me)", + "name": "uuid-v4", + "description": "A simple v4 UUID generator", + "version": "0.1.0", + "main": "index.js", + "dependencies": {}, + "devDependencies": {}, + "optionalDependencies": {}, + "engines": { + "node": "*" + } +} diff --git a/_shakeapi/node_modules/uuid-v4/readme.md b/_shakeapi/node_modules/uuid-v4/readme.md new file mode 100644 index 0000000..0b8110f --- /dev/null +++ b/_shakeapi/node_modules/uuid-v4/readme.md @@ -0,0 +1,33 @@ +# uuid-v4 + +A Node.js module for generating and validation V4 UUIDs + +## Install + +```bash +$ npm install uuid-v4 +``` + +## Usage + +```javascript +var uuid = require('uuid-v4'); + +// Generate a new UUID +var myUUID = uuid(); + +// Validate a UUID as proper V4 format +uuid.isUUID(myUUID); // true +``` + +## MIT License + +Copyright (c) 2012 James Brumond + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + diff --git a/_shakeapi/package-lock.json b/_shakeapi/package-lock.json index 5261c17..3e7b052 100644 --- a/_shakeapi/package-lock.json +++ b/_shakeapi/package-lock.json @@ -5,9 +5,18 @@ "packages": { "": { "dependencies": { + "uuid-v4": "^0.1.0", "ws": "^8.13.0" } }, + "node_modules/uuid-v4": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/uuid-v4/-/uuid-v4-0.1.0.tgz", + "integrity": "sha512-m11RYDtowtAIihBXMoGajOEKpAXrKbpKlpmxqyztMYQNGSY5nZAZ/oYch/w2HNS1RMA4WLGcZvuD8/wFMuCEzA==", + "engines": { + "node": "*" + } + }, "node_modules/ws": { "version": "8.13.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", @@ -30,6 +39,11 @@ } }, "dependencies": { + "uuid-v4": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/uuid-v4/-/uuid-v4-0.1.0.tgz", + "integrity": "sha512-m11RYDtowtAIihBXMoGajOEKpAXrKbpKlpmxqyztMYQNGSY5nZAZ/oYch/w2HNS1RMA4WLGcZvuD8/wFMuCEzA==" + }, "ws": { "version": "8.13.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", diff --git a/_shakeapi/package.json b/_shakeapi/package.json index f19286e..8e43107 100644 --- a/_shakeapi/package.json +++ b/_shakeapi/package.json @@ -1,5 +1,6 @@ { "dependencies": { + "uuid-v4": "^0.1.0", "ws": "^8.13.0" } } diff --git a/_shakeapi/server.js b/_shakeapi/server.js index 84ff2df..3ebde8d 100644 --- a/_shakeapi/server.js +++ b/_shakeapi/server.js @@ -2,9 +2,11 @@ const { WebSocketServer } = require('ws'); const devices = {}; const wss = new WebSocketServer({ port: 8080 }); +const uuid = require('uuid-v4'); wss.on('connection', function connection(ws, req) { const ip = req.headers['x-forwarded-for'].split(',')[0].trim(); + const id = uuid(); if (!devices[ip]) devices[ip] = null; ws.on('error', console.error); @@ -21,17 +23,23 @@ wss.on('connection', function connection(ws, req) { ws.watch = true; ws.loaded = true; - devices[ip] = { + if (!devices[ip]) devices[ip] = { type: "watch", socket: ws, code: data.code, - clients: [] + clients: {} } } else if (data.key) { if (devices[ip] && devices[ip].code === data.key) { ws.watch = false; ws.loaded = true; - devices[ip].clients.push(ws); + + devices[ip].clients[id] = ws; + devices[ip].socket.send(JSON.stringify({ + type: "status", + enabled: true, + count: devices[ip].clients.length + })); ws.send(JSON.stringify({ type: "accepted" @@ -47,7 +55,7 @@ wss.on('connection', function connection(ws, req) { })); } } else if (data.type === "shake" && ws.loaded && ws.watch) { - for (let socket of devices[ip].clients) { + for (let socket of Object.values(devices[ip].clients)) { try { if (socket.loaded && !socket.watch) { socket.send(JSON.stringify({ @@ -68,6 +76,30 @@ wss.on('connection', function connection(ws, req) { console.log("----------"); }); + ws.on('close', () => { + if (!ws.watch) { + console.log("Remove " + id); + if (devices[ip]) delete devices[ip].clients[id]; + + if (Object.values(devices[ip].clients).filter(i => i).length <= 0) devices[ip].socket.send(JSON.stringify({ + type: "status", + enabled: false + })); + } else { + for (let socket of Object.values(devices[ip].clients)) { + try { + if (socket.loaded && !socket.watch) { + socket.send(JSON.stringify({ + type: "disconnect" + })); + } + } catch (e) {} + } + + delete devices[ip]; + } + }); + ws.send(JSON.stringify({ type: "init" })); diff --git a/nsfw/not/index.php b/nsfw/sp2/4/index.php index f1660fc..3ea9337 100644 --- a/nsfw/not/index.php +++ b/nsfw/sp2/4/index.php @@ -3,4 +3,4 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $allowNsfw; if (!$allowNsfw) header("Location: /nsfw/home") and die(); -if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/proprietary/notification.php")) require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/proprietary/notification.php"; +if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/proprietary/app3-v2.php")) require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/proprietary/app4-v2.php"; |