Skip to content

Commit

Permalink
Version 1.3.6
Browse files Browse the repository at this point in the history
-- Added a top menu
-- In windows setup package was added a new version of streamlink (pre-installed)
  • Loading branch information
asabino2 committed Jan 15, 2023
1 parent 9029bb7 commit e4a8446
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "streamproxy",
"version": "1.3.5",
"version": "1.3.6",
"description": "Stream Proxy - A proxy for your streams",
"keywords": [
"streamproxy",
Expand Down
93 changes: 80 additions & 13 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ process.on('exit', function() {
// prevent server shutdown on error
process.on('uncaughtException', (err, origin) => {
log(

process.stderr.fd,
`Caught exception: ${err}\n` +
`Exception origin: ${origin}`
);
Expand Down Expand Up @@ -1552,6 +1550,7 @@ app.get('/log', (req, res) => {
</script>
</header>
<body onload="startTimer()">
${CreateMenu(auth)}
<button onclick="clearlog()">Clear Log</button>
<textarea
readonly
Expand Down Expand Up @@ -1614,16 +1613,18 @@ app.get('/login', (req, res) => {
if (basicAuth(req, res).authenticated == false) { //if authentication is required and fail, return 401
return false;
}
res.send("User authenticate");
//res.send("User authenticate");
res.redirect('/');
})



app.get('/logout', (req, res) => {

res.set('WWW-Authenticate', 'Basic realm="401"') // change this
res.status(401).send('Logout ok.') // custom message

//res.status(401).send('Logout ok.') // custom message
//res.status(401).redirect('/');
res.status(401).send('logout ok <script language="javascript">window.location = "/"</script>');



Expand Down Expand Up @@ -1829,7 +1830,7 @@ app.get('/status', (req, res) => {
</script>
</head>
<body onload="startTimer()">
${CreateMenu(auth)}
<div id="status"></div>
<div id="snackbar"></div>
`
Expand Down Expand Up @@ -2176,6 +2177,7 @@ app.get('/streamserver/list', (req, res) => {
</script>
</head>
<body onload="startTimer()">
${CreateMenu(auth)}
<button onclick="startStreamServer('*')" class="listbutton listbutton-green" id="startAll"><i class="fa fa-play space-right"></i> Start All</button>
<button onclick="stopStreamServer('*')" class="listbutton listbutton-red" id="stopAll"><i class="fa fa-stop space-right"></i> Stop All</button>
<button onclick="addStreamServer()" class="listbutton listbutton-blue" id="addStreamServer"><i class="fa fa-plus"></i> Add Stream Server</button>
Expand Down Expand Up @@ -2369,6 +2371,7 @@ function startTimer() {
</script>
</head>
<body onload="startTimer()">
${CreateMenu(auth)}
<button onclick="addUser()" class="listbutton listbutton-blue" id="addStreamServer"><i class="fa fa-plus"></i> Add User</button>
<div id="status"></div>
<div id="snackbar"></div>`
Expand Down Expand Up @@ -2444,18 +2447,18 @@ app.get('/status/*', (req, res) => {
})


app.get('/', (req, res) => {
app.get('/about', (req, res) => {
var auth = basicAuth(req, res);
if (auth.authenticated == false || auth.authorized != true) {
return false;
}

res.set({ 'Server': 'streamproxy' });
res.redirect("/about");
res.redirect("/");
});

// help page, captured from github pages
app.get('/about', async function(req, res) {
app.get('/', async function(req, res) {
var auth = basicAuth(req, res);
if (auth.authenticated == false || auth.authorized != true) {
return false;
Expand All @@ -2470,19 +2473,28 @@ app.get('/about', async function(req, res) {
const portreplacer = new RegExp(portsearch, 'g');
const localhostreplacer = new RegExp(localhostsearch, 'g');
res.set({ 'Server': 'streamproxy' });
res.set({ 'Access-Control-Allow-Origin': '*' });
appsetheader(res);
https.get('https://raw.githubusercontent.com/asabino2/streamproxy/master/README.md', (resp) => {
let data = '';

// A chunk of data has been received.
let menuStyle = CreateMenuStyle();
let menu = CreateMenu(auth);
data += `<header>
<style>
${menuStyle}
</style>
</header>
<body>
${menu}`
// A chunk of data has been received.
resp.on('data', (chunk) => {
data += chunk;

});

// The whole response has been received. Print out the result.
resp.on('end', () => {

data += `</body>`
data = data.replace(serverreplacer, req.hostname);
data = data.replace(portreplacer, port);
data = data.replace(localhostreplacer, req.hostname + ":" + port);
Expand Down Expand Up @@ -2517,6 +2529,7 @@ app.get('/docs/api', (req, res) => {

app.get('/styles.css', (req, res) => {
var data = "";
var menuStyle = CreateMenuStyle();
data = `
a {
Expand Down Expand Up @@ -2675,7 +2688,10 @@ app.get('/styles.css', (req, res) => {
background-color: gray;
}
/* list button end */`;
/* list button end */
${menuStyle}
`;
res.send(data);
});

Expand Down Expand Up @@ -5483,7 +5499,58 @@ function loadAuthRoles() {

}

function CreateMenu(auth) {
var html = '';
//var auth = basicAuth(req, res);
html = '<nav class="navigator">'
html += '<ul class="menuclass">'

if (auth.authenticated == true && auth.user != 'anonymous') {
html += '<li class="menuoptions"><a href="/logout">Logout</a></li>'
html += '<li class="menuoptions"><a href="/streamserver/list">Stream Servers</a></li>'
html += '<li class="menuoptions"><a href="/user/list">Users</a></li>'
html += '<li class="menuoptions"><a href="/status">Status</a></li>'
html += '<li class="menuoptions"><a href="/log">Logs</a></li>'
html += '<li class="menuoptions"><a href="/docs/api/">API Documentation</a></li>'
} else {
html += '<li class="menuoptions"><a href="/login">Login</a></li>'
}
html += '</ul>'
html += '</nav>'
return html;
}


function CreateMenuStyle() {
var html = '';
html = `/* menu style */
.navigator {
background-color: #333;
}
.menuclass {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.menuoptions {
float: left;
}
.menuoptions a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.menuoptions a:hover {
background-color: #111;
}`
return html;
}

/* end of program */

0 comments on commit e4a8446

Please sign in to comment.