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,OAFV,gBAGjB,IAAI,EAAO,EAAU,gBACrB,EAAQ,GAAK,CAAC,KAAM,EAAU,KAAM,QAAS,EAAU,QAAS,OAAQ,EAAY,WAAY,EACpG,CACA,EAAI,KAAK,EAAQ,IAIrB,IAAI,IAAI,QAAQ,OAAO,KAAK,KAAK,UAAW,YAC5C,iBAAiB,WAAW,IAAK,UAAW,YAG5C,WAAW,OAAO,WAAW,WACzB,QAAQ,IAAI,8BAA+B,UAC/C,IACA,YAAY,OAAO,YAAY,WAC3B,QAAQ,IAAI,+BAAgC,WAChD","file":"/npm/gatewayhub@1.0.12345/gateway.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/gatewayhub@1.0.12345/gateway.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n\"use strict\";\n\nrequire('yoctolib-es2017/yocto_api.js');\nrequire('yoctolib-es2017/yocto_network.js');\n\nconst path = require('path');\nconst fs = require('fs');\nconst http = require('http');\nconst https = require('https');\nconst express = require('express');\nconst app = express();\nconst express_ws = require(\"express-ws\");\nconst bodyParser = require('body-parser');\nconst session = require('express-session');\nconst MemoryStore = require('memorystore')(session);\nconst passport = require('passport');\nconst LocalStrategy = require('passport-local').Strategy;\n\n\n\n\nconst argv = require('yargs')\n    .usage('Usage: $0 [options]')\n    .example('$0 -c config.conf --http_port 44080 --https_port 44443', '')\n    .alias('c', 'config')\n    .describe('c', 'A config file')\n    .help('h')\n    .alias('h', 'help')\n    .default('c', 'gateway.conf')\n    .default('http_port', 44080)\n    .default('https_port', 44443)\n    .default('key_file', 'key.pem')\n    .default('cert_file', 'cert.pem')\n    .argv;\n\nif (argv.version) {\n    console.log(\"gatewayhub v1.0.44086\");\n    process.exit(0);\n}\n\n// Setup ports\nconst http_port = (argv._.length < 1 ? argv.http_port : parseInt(argv._[0]));\nconst https_port = (argv._.length < 2 ? argv.https_port : parseInt(argv._[1]));\n\n\nconst subdomains = require('./subdomain.js');\nconst subdomainsManger = new subdomains.YSubdomainManager(app, argv.c, http_port, https_port);\n// noinspection JSIgnoredPromiseFromCall\nYAPI.LogUnhandledPromiseRejections();\n\n// Instantiate a Web server with both HTTP/WS and HTTPS/WSS support\nconst httpServer = http.createServer(app);\n// noinspection JSUnusedLocalSymbols\nconst wsServer = express_ws(app, httpServer);\nlet use_https = false;\nif (!fs.existsSync(argv.key_file) || !fs.existsSync(argv.cert_file)) {\n    console.log(\"Warning: No key.pem and cert.pem file found\\n\");\n    console.log(\"In order to enable the secure interface https, you will also have to put\");\n    console.log(\"in the same directory the certificates to be used: two files named cert.pem\");\n    console.log(\"and key.pem, which are usually provided by our SSL certificate provider or\");\n    console.log(\"hosting provider. In case you just want to make a test, you can also use\");\n    console.log(\"self-signed certificates created using OpenSSL, by typing the following\");\n    console.log(\"command (on a single line):\");\n    console.log(\"openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem\");\n    process.exit(1);\n}\nconst options = {\n    key: fs.readFileSync(argv.key_file),\n    cert: fs.readFileSync(argv.cert_file)\n};\nconst httpsServer = https.createServer(options, app);\n// noinspection JSUnusedLocalSymbols\nconst wssServer = express_ws(app, httpsServer);\n\n// Configure the local strategy for use by Passport.\n//\n// The local strategy require a `verify` function which receives the credentials\n// (`username` and `password`) submitted by the user.  The function must verify\n// that the password is correct and then invoke `cb` with a user object, which\n// will be set at `req.user` in route handlers after authentication.\npassport.use('local-login', new LocalStrategy(\n    function (username, password, done) {\n        process.nextTick(function () {\n            let user = subdomainsManger.FindUser(username, false);\n            if (!user) { return done(null, false); }\n            if (user.pass !== password) {\n                return done(null, false);\n            }\n            return done(null, user);\n        });\n    }));\n\n\n// Configure Passport authenticated session persistence.\n//\n// In order to restore authentication state across HTTP requests, Passport needs\n// to serialize users into and deserialize users out of the session.  The\n// typical implementation of this is as simple as supplying the user ID when\n// serializing, and querying the user record by ID from the database when\n// deserializing.\npassport.serializeUser(function (user, cb) {\n    cb(null, user.id);\n});\n\npassport.deserializeUser(function (id, cb) {\n    process.nextTick(function () {\n        let user = subdomainsManger.FindById(id, false);\n        cb(null, user);\n    });\n});\n\n// Setup Express app server\napp.use(bodyParser.urlencoded({extended: false}));\napp.use(session({\n    resave: true,\n    saveUninitialized: false,\n    secret: 'ycook_secret',\n    cookie: {maxAge: 3600000},\n    store: new MemoryStore({\n        checkPeriod: 86400000 // prune expired entries every 24h\n    }),\n}));\n\n// Initialize Passport and restore authentication state, if any, from the\n// session.\napp.use(passport.initialize());\napp.use(passport.session());\n\n\napp.set('views', path.join(__dirname, 'data'));\napp.set('view engine', 'pug');\napp.get('/', (req, res, next) => {     // Redirect simple HTTP requests to HTTPS for security\n    if (req.protocol === 'http') {\n        res.redirect(301, 'https://' + req.hostname + ':' + https_port + req.url);\n    } else {\n        next();\n    }\n});\n\n\napp.get('/login', (req, res, next) => {\n    if (subdomainsManger.IsFirstLogin()) {\n        return res.redirect(\"/firstlogin\");\n    } else {\n        res.render('login', {\n            \"FORM\": req.body,\n            \"Server\": req.hostname + ':' + https_port\n        });\n    }\n});\n\napp.post('/login',\n    passport.authenticate(\"local-login\", {failureRedirect: '/login'}),\n    function (req, res) {\n        return res.redirect('/');\n    });\n\napp.get('/logout',\n    function (req, res) {\n        req.logout();\n        res.redirect('/');\n    });\n\napp.get('/firstlogin', (req, res, next) => {\n    if (subdomainsManger.IsFirstLogin()) {\n        res.render('first_login', {\n            \"FORM\": req.body,\n            \"YSubdomain\": subdomainsManger,\n            \"Server\": req.hostname + ':' + https_port\n        });\n    }\n});\n\n\napp.post('/firstlogin', function (req, res) {\n    if (subdomainsManger.IsFirstLogin()) {\n        if (req.body.action && req.body.action.match(/[\\-+].+/)) {\n            subdomainsManger.HandleSubdomainMgmtAction(req.body.action, req.body.username, req.body.password, http_port, https_port);\n        }\n    }\n    return res.redirect('/');\n});\n\n\n// route middleware to ensure user is logged in\nfunction isLoggedIn(req, res, next)\n{\n    if (req.isAuthenticated())\n        return next();\n    return res.redirect('/login');\n}\n\n\napp.all('/', isLoggedIn, (req, res) => {\n    if (subdomainsManger.IsFirstLogin()) {\n        return res.redirect(\"/firstlogin\");\n    }\n\n    // Handle login page\n    if (subdomainsManger.IsAdmin(req.user.user, req.user.pass)) {\n        if (req.body.action && req.body.action.match(/[\\-+].+/)) {\n            subdomainsManger.HandleSubdomainMgmtAction(req.body.action, req.user.user, req.user.pass, http_port, https_port);\n        }\n    }\n    res.render('main', {\n        \"FORM\": req.body,\n        \"USER\": {username: req.user.user, userpass: req.user.pass},\n        \"YSubdomain\": subdomainsManger,\n        \"Server\": req.hostname + ':' + https_port\n    });\n});\n\n\napp.get('/iframe.html', isLoggedIn, (req, res) => {\n    res.sendFile(path.join(__dirname, 'data/iframe.html'));\n});\n\napp.get('/ajax.json', isLoggedIn, (req, res) => {\n    let outlist = [];\n    let subdomains = subdomainsManger.GetSubdomainsFor(req.user.user, req.user.pass);\n    for (let i = 0; i < subdomains.length; i++) {\n        let subdomain = subdomainsManger.GetSubdomain(subdomains[i]);\n        let client_val;\n        if (!subdomain.yapi)\n            client_val = \"(hub offline)\";\n        else\n            client_val = subdomain.client;\n        let link = subdomain.getRemoteLink();\n        outlist[i] = {name: subdomain.name, netname: subdomain.netname, client: client_val, remotelink: link};\n    }\n    res.json(outlist);\n});\n\n\napp.use(express.static(path.join(__dirname, 'public')));\nsubdomainsManger.LoadConfig(app, http_port, https_port);\n\n// Start web server\nhttpServer.listen(http_port, function () {\n    console.log('HTTP Server running on port', http_port);\n});\nhttpsServer.listen(https_port, function () {\n    console.log('HTTPS Server running on port', https_port);\n});\n\n"]}