You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
6.2 KiB

<html>
<head>
<!-- Materialze style -->
<link rel="stylesheet" type="text/css" href="../../css/adapter.css"/>
<link rel="stylesheet" type="text/css" href="../../lib/css/materialize.css">
<script type="text/javascript" src="../../lib/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
<script type="text/javascript" src="../../js/translate.js"></script>
<script type="text/javascript" src="../../lib/js/materialize.js"></script>
<script type="text/javascript" src="../../js/adapter-settings.js"></script>
<script type="text/javascript" src="words.js"></script>
<script type="text/javascript">
var onChange;
var secret;
function encrypt(key, value) {
var result = '';
for(var i = 0; i < value.length; ++i) {
result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
}
return result;
}
function decrypt(key, value) {
var result = '';
for(var i = 0; i < value.length; ++i) {
result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
}
return result;
}
function setValue(id, value) {
var $value = $('#' + id + '.value');
if ($value.attr('type') === 'checkbox') {
$value.prop('checked', value).on('change', function () {
onChange();
});
} else {
$value.val(value).on('change', function () {
onChange();
}).keyup(function () {
onChange();
});
}
}
function loadHelper(settings, param, subparam) {
if (!settings) return;
if (settings.useChunkPatch === undefined) settings.useChunkPatch = false;
if (settings.timeout === undefined) settings.timeout = 300;
for (var key in settings) {
if (!settings.hasOwnProperty(key)) continue;
if (key === 'pass') {
settings[key] = decrypt(secret, settings[key]);
}
setValue(key, settings[key]);
}
}
// the function loadSettings has to exist ...
function load(settings, _onChange) {
onChange = _onChange;
socket.emit('getObject', 'system.config', function (err, obj) {
secret = (obj.native ? obj.native.secret : '') || 'Zgfr56gFe87jJOM';
loadHelper(settings);
M.updateTextFields();
});
onChange(false);
}
function getSettings() {
var obj = {};
$('.value').each(function () {
var $this = $(this);
var id = $this.attr('id');
if ($this.attr('type') === 'checkbox') {
obj[id] = $this.prop('checked');
} else {
var value = $this.val();
if (id === 'pass') {
value = encrypt(secret, value);
}
obj[id] = value;
}
});
return obj;
}
function save(callback) {
if ($('#pass').val() !== $('#pass_confirm').val()) {
showMessage(_('Password confirmation is not equal with password'));
return;
}
callback(getSettings());
}
</script>
<style>
.adapter-container>div {
margin-bottom: 0 !important;
}
.page {
height: calc(100% - 50px) !important;
}
.marg{
margin-top: 5em;
}
</style>
</head>
<body>
<div class="m adapter-container">
<div class="row">
<div class="col s12">
<div class="row">
<div class="col s6">
<img src="sonoff.png" class="logo">
</div>
</div>
<div class="row">
<div class="col s12">
<h6 class="title translate">Connection settings</h6>
</div>
</div>
<div class="row">
<div class="input-field col s6 m4 l2">
<input id="port" type="number" min="1" max="65565" class="value"/>
<label class="translate" for="port">Port:</label>
</div>
<div class="input-field col s6 m4 l2">
<input id="timeout" type="number" min="1" max="99999" class="value"/>
<label class="translate" for="timeout">Client timeout (sec):</label>
</div>
</div>
<div class="row">
<div class="col s12">
<h6 class="title translate">Authentication settings</h6>
</div>
</div>
<div class="row">
<div class="input-field col s6 m4">
<input id="user" type="text" class="value"/>
<label class="translate" for="user">User:</label>
</div>
<div class="input-field col s6 m4">
<input id="pass" type="password" class="value"/>
<label class="translate" for="pass">Password:</label>
</div>
<div class="input-field col s6 m4">
<input id="pass_confirm" type="password" />
<label class="translate" for="pass_confirm">Password confirmation:</label>
</div>
</div>
<div class="row">
<div class="col s12">
<h6 class="title translate">Auto creation of states</h6>
</div>
</div>
<div class="row">
<div class="input-field col s6 m4">
<input id="TELE_SENSOR" type="checkbox" class="value"/>
<span class="translate" for="user">For tele/SENSOR</span>
</div>
<div class="input-field col s6 m4">
<input id="TELE_STATE" type="checkbox" class="value"/>
<span class="translate" for="TELE_STATE">For tele/STATE</span>
</div>
<div class="input-field col s6 m4">
<input id="STAT_RESULT" type="checkbox" class="value"/>
<span class="translate" for="STAT_RESULT">For stat/RESULT</span>
</div>
</div>
</div>
</div>
</div>
</body>
</html>