-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eda8453
commit e503733
Showing
11 changed files
with
581 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
CONF_DIR=/usr/local/etc/config | ||
ADDON_DIR=/usr/local/addons/redmatic | ||
WWW_DIR=/usr/local/etc/config/addons/www/redmatic | ||
|
||
NODE=$ADDON_DIR/bin/node | ||
|
||
export PATH=$ADDON_DIR/bin:$PATH | ||
export NO_UPDATE_NOTIFIER=true | ||
|
||
RED_DIR=$ADDON_DIR/lib/node_modules/node-red | ||
RED=$RED_DIR/red.js | ||
|
||
SETTINGS=$ADDON_DIR/lib/settings.js | ||
|
||
$NODE $RED -s $SETTINGS 2>&1 | logger -p user.info -t node-red |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.alert { | ||
width: 300px; | ||
margin: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/tclsh | ||
|
||
load tclrega.so | ||
|
||
catch { | ||
set input $env(QUERY_STRING) | ||
set pairs [split $input &] | ||
foreach pair $pairs { | ||
if {0 != [regexp "^(\[^=]*)=(.*)$" $pair dummy varname val]} { | ||
set $varname $val | ||
} | ||
} | ||
} | ||
|
||
if {[info exists sid] > 0} { | ||
# Session prüfen | ||
if { | ||
([string index $sid 0] != "@") | ||
|| ([string index $sid [expr [string length $sid] -1]] != "@") | ||
|| ([string length $sid] != 12)} { | ||
puts {error: session invalid} | ||
} else { | ||
regsub -all {@} $sid "" sid | ||
set res [lindex [rega_script "Write(system.GetSessionVarStr('$sid'));"] 1] | ||
if {$res != ""} { | ||
# gültige Session | ||
set fp [open "/usr/local/addons/redmatic/etc/settings.json" r] | ||
puts -nonewline [read $fp] | ||
close $fp | ||
} else { | ||
puts {error: session invalid} | ||
} | ||
} | ||
} else { | ||
puts {error: no session} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
$(document).ready(() => { | ||
const bcrypt = dcodeIO.bcrypt; | ||
|
||
const $loglevel = $('#loglevel'); | ||
|
||
const $adminauthType = $('#adminauth-type'); | ||
const $adminauthCreds = $('#adminauth-credentials'); | ||
const $adminauthUser = $('#adminauth-user'); | ||
const $adminauthPass1 = $('#adminauth-pass1'); | ||
const $adminauthPass2 = $('#adminauth-pass2'); | ||
const $adminauthSet = $('#adminauth-set'); | ||
|
||
const $nodeauthType = $('#nodeauth-type'); | ||
const $nodeauthCreds = $('#nodeauth-credentials'); | ||
const $nodeauthUser = $('#nodeauth-user'); | ||
const $nodeauthPass1 = $('#nodeauth-pass1'); | ||
const $nodeauthPass2 = $('#nodeauth-pass2'); | ||
const $nodeauthSet = $('#nodeauth-set'); | ||
|
||
const $staticauthType = $('#staticauth-type'); | ||
const $staticauthCreds = $('#staticauth-credentials'); | ||
const $staticauthUser = $('#staticauth-user'); | ||
const $staticauthPass1 = $('#staticauth-pass1'); | ||
const $staticauthPass2 = $('#staticauth-pass2'); | ||
const $staticauthSet = $('#staticauth-set'); | ||
|
||
const $alertSaved = $('#alert-saved'); | ||
const $alertError = $('#alert-error'); | ||
const $alertRestart = $('#alert-restart'); | ||
|
||
const $restart = $('#restart'); | ||
|
||
let config; | ||
|
||
function alert($elem) { | ||
$elem.addClass('show'); | ||
setTimeout(() => { | ||
$elem.removeClass('show'); | ||
}, 1600); | ||
} | ||
|
||
function save() { | ||
console.log(config); | ||
$.post({ | ||
url: 'setconfig.cgi' + location.search, | ||
data: JSON.stringify(config), | ||
success: function (data) { | ||
console.log(data); | ||
if ($.trim(data) === 'ok') { | ||
alert($alertSaved); | ||
} else { | ||
alert($alertError); | ||
} | ||
} | ||
}).fail(() => { | ||
alert($alertError); | ||
}); | ||
} | ||
|
||
$.get('getconfig.cgi' + location.search, (data, success) => { | ||
config = JSON.parse(data); | ||
console.log(config, success); | ||
$loglevel.val(config.logging.console.level); | ||
|
||
if (config.adminAuth) { | ||
$adminauthType.val(config.adminAuth.type); | ||
$adminauthCreds.show(); | ||
$adminauthUser.val(config.adminAuth.users[0].username); | ||
} | ||
|
||
if (config.httpNodeAuth) { | ||
$nodeauthType.val('basic'); | ||
$nodeauthCreds.show(); | ||
$nodeauthUser.val(config.httpNodeAuth.user); | ||
} | ||
|
||
if (config.httpStaticAuth) { | ||
$staticauthType.val('basic'); | ||
$staticauthCreds.show(); | ||
$staticauthUser.val(config.httpStaticAuth.user); | ||
} | ||
|
||
}); | ||
|
||
$loglevel.change(() => { | ||
config.logging.console.level = $loglevel.val(); | ||
save(); | ||
}); | ||
|
||
$adminauthType.change(() => { | ||
switch ($adminauthType.val()) { | ||
case 'credentials': | ||
$adminauthCreds.show(); | ||
break; | ||
default: | ||
$adminauthCreds.hide(); | ||
delete config.adminAuth; | ||
save(); | ||
} | ||
}); | ||
|
||
$nodeauthType.change(() => { | ||
switch ($nodeauthType.val()) { | ||
case 'basic': | ||
$nodeauthCreds.show(); | ||
break; | ||
default: | ||
$nodeauthCreds.hide(); | ||
delete config.httpNodeAuth; | ||
save(); | ||
} | ||
}); | ||
|
||
$staticauthType.change(() => { | ||
switch ($staticauthType.val()) { | ||
case 'basic': | ||
$staticauthCreds.show(); | ||
break; | ||
default: | ||
$staticauthCreds.hide(); | ||
delete config.httpStaticAuth; | ||
save(); | ||
} | ||
}); | ||
|
||
$adminauthSet.click(() => { | ||
const user = $.trim($adminauthUser.val()); | ||
const pw1 = $adminauthPass1.val(); | ||
const pw2 = $adminauthPass2.val(); | ||
|
||
let valid = true; | ||
|
||
if (!user) { | ||
$adminauthUser.addClass('is-invalid'); | ||
valid = false; | ||
} else { | ||
$adminauthUser.removeClass('is-invalid'); | ||
} | ||
|
||
if (!pw1 || pw1 !== pw2) { | ||
$adminauthPass1.addClass('is-invalid'); | ||
$adminauthPass2.addClass('is-invalid'); | ||
valid = false; | ||
} else { | ||
$adminauthPass1.removeClass('is-invalid'); | ||
$adminauthPass2.removeClass('is-invalid'); | ||
} | ||
|
||
if (valid) { | ||
config = Object.assign(config, { | ||
adminAuth: { | ||
type: 'credentials', | ||
users: [{ | ||
username: user, | ||
password: bcrypt.hashSync(pw1, 8), | ||
permissions: '*' | ||
}] | ||
} | ||
}); | ||
save(); | ||
} | ||
}); | ||
|
||
$staticauthSet.click(() => { | ||
const user = $.trim($staticauthUser.val()); | ||
const pw1 = $staticauthPass1.val(); | ||
const pw2 = $staticauthPass2.val(); | ||
|
||
let valid = true; | ||
|
||
if (!user) { | ||
$staticauthUser.addClass('is-invalid'); | ||
valid = false; | ||
} else { | ||
$staticauthUser.removeClass('is-invalid'); | ||
} | ||
|
||
if (!pw1 || pw1 !== pw2) { | ||
$staticauthPass1.addClass('is-invalid'); | ||
$staticauthPass2.addClass('is-invalid'); | ||
valid = false; | ||
} else { | ||
$staticauthPass1.removeClass('is-invalid'); | ||
$staticauthPass2.removeClass('is-invalid'); | ||
} | ||
|
||
if (valid) { | ||
config = Object.assign(config, { | ||
httpStaticAuth: { | ||
user, | ||
pass: bcrypt.hashSync(pw1, 8), | ||
} | ||
}); | ||
save(); | ||
} | ||
}); | ||
|
||
$nodeauthSet.click(() => { | ||
const user = $.trim($nodeauthUser.val()); | ||
const pw1 = $nodeauthPass1.val(); | ||
const pw2 = $nodeauthPass2.val(); | ||
|
||
let valid = true; | ||
|
||
if (!user) { | ||
$nodeauthUser.addClass('is-invalid'); | ||
valid = false; | ||
} else { | ||
$nodeauthUser.removeClass('is-invalid'); | ||
} | ||
|
||
if (!pw1 || pw1 !== pw2) { | ||
$nodeauthPass1.addClass('is-invalid'); | ||
$nodeauthPass2.addClass('is-invalid'); | ||
valid = false; | ||
} else { | ||
$nodeauthPass1.removeClass('is-invalid'); | ||
$nodeauthPass2.removeClass('is-invalid'); | ||
} | ||
|
||
if (valid) { | ||
config = Object.assign(config, { | ||
httpNodeAuth: { | ||
user, | ||
pass: bcrypt.hashSync(pw1, 8), | ||
} | ||
}); | ||
save(); | ||
} | ||
}); | ||
|
||
$restart.click(() => { | ||
$restart.addClass('disabled'); | ||
$.get({ | ||
url: 'restart.cgi' + location.search, | ||
success: data => { | ||
$restart.removeClass('disabled'); | ||
if (data.match(/Starting Node-RED: OK/)) { | ||
alert($alertRestart); | ||
} else { | ||
alert($alertError); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "redmatic-www", | ||
"private": true, | ||
"dependencies": { | ||
"bcryptjs": "^2.4.3", | ||
"bootstrap": "^4.1.1", | ||
"jquery": "^3.3.1" | ||
} | ||
} |
Oops, something went wrong.