Files
minisrv/zefie_wtvp_minisrv/WTVRegister.js
zefie df472ab91f v0.9.13
- wtv-cookie support
 - further development will be in dev branch (may rebase alot)
 - compression not yet ready, leave it disabled
 - update: do not delete WTVSec on last socket, instead recreate on prereg
 - update: clean up SSID session data only if client is not seen for 3 minutes
 - update: add shouldWeCompress() function
 - update: tweak lzpf (still corrupted)
 - update: rename wtv-setup:/get to wtv-setup:/get-settings
 - update: add additional headers to wtv-setup:/get-settings
 - update: add initial blank wtv-music:/get-playlist
 - update wtv-tricks system
   - Info now shows Guest Mode or Subscriber Info
   - Implemented wtv-tricks:/unregister
   - Implemented wtv-tricks:/register
   - Show correct link in wtv-tricks:/tricks based on Guest Mode status
 - config.json: enable compression by default
 - WTVP does not use \r, so swapping the internal header's usage for now. May remove internal header in future update
 - lzpf: this doesn't fix anything but doesn't break it more either :)
  - renamed some functions
  - fixed some param documentation
  - added ConvertToBuffer function
 - WTVSec Updates
  - optimize WordArray to Buffer functions
  - update documentation in WTVSec
  - update WTVSec barrowed function in WTVLzpf
  - removed NewRC4Session, was a pointless alias to SecureOn
2022-11-29 08:27:52 -05:00

48 lines
1.6 KiB
JavaScript

class WTVRegister {
fs = require('fs');
path = require('path');
service_owner = "a minisrv user";
session_store_dir = null;
constructor(service_owner, session_store_dir = null) {
this.service_owner = service_owner;
if (session_store_dir) this.session_store_dir = session_store_dir
}
getServiceOperator(first_letter_lower = false) {
if (this.service_owner == "a minisrv user") {
if (first_letter_lower) return "the operator of this service";
else return "The operator of this service";
} else {
return this.service_owner;
}
}
checkUsernameSanity(username) {
var check1 = /^([A-Za-z0-9\-\_]{5,16})$/.test(username);
var check2 = /^[A-Za-z]/.test(username);
return (check1 && check2);
}
checkUsernameAvailable(username, ssid_sessions) {
var username_match = false;
this.fs.readdirSync(this.session_store_dir).forEach(file => {
if (!file.match(/.*\.json/ig)) return;
if (username_match) return;
try {
var temp_session_data_file = this.fs.readFileSync(this.session_store_dir + this.path.sep + file, 'Utf8');
var temp_session_data = JSON.parse(temp_session_data_file);
if (temp_session_data.subscriber_username == username) username_match = true;
} catch (e) {
console.error(" # Error parsing Session Data JSON", file, e);
username_match = true;
}
});
return !username_match;
}
}
module.exports = WTVRegister;