mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-22 17:22:58 +01:00
🔨 Add option to accept self signed certificates
This commit is contained in:
parent
4129f0cbf5
commit
7af0263b6c
@ -1,6 +1,7 @@
|
|||||||
const { createClient } = require("webdav");
|
const { createClient } = require("webdav");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const https = require('https')
|
||||||
|
|
||||||
const statusTools = require('./status');
|
const statusTools = require('./status');
|
||||||
const endpoint = "/remote.php/webdav";
|
const endpoint = "/remote.php/webdav";
|
||||||
@ -21,15 +22,16 @@ class WebdavTools {
|
|||||||
this.password = null;
|
this.password = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(ssl, host, username, password) {
|
init(ssl, host, username, password, accept_selfsigned_cert) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let status = statusTools.getStatus();
|
let status = statusTools.getStatus();
|
||||||
logger.info("Initilizing and checking webdav client...");
|
logger.info("Initilizing and checking webdav client...");
|
||||||
this.baseUrl = (ssl === "true" ? "https" : "http") + "://" + host + endpoint;
|
this.baseUrl = (ssl === "true" ? "https" : "http") + "://" + host + endpoint;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
let agent_option = ssl === "true" ? { rejectUnauthorized: accept_selfsigned_cert === "false" } : {}
|
||||||
try {
|
try {
|
||||||
this.client = createClient(this.baseUrl, { username: username, password: password });
|
this.client = createClient(this.baseUrl, { username: username, password: password }, new https.Agent(agent_option));
|
||||||
|
|
||||||
this.client.getDirectoryContents("/").then(() => {
|
this.client.getDirectoryContents("/").then(() => {
|
||||||
if (status.error_code == 3) {
|
if (status.error_code == 3) {
|
||||||
@ -96,7 +98,9 @@ class WebdavTools {
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Check if theh webdav config is valid, if yes, start init of webdav client
|
||||||
|
*/
|
||||||
confIsValid() {
|
confIsValid() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let status = statusTools.getStatus();
|
let status = statusTools.getStatus();
|
||||||
@ -109,7 +113,12 @@ class WebdavTools {
|
|||||||
status.error_code = null;
|
status.error_code = null;
|
||||||
statusTools.setStatus(status);
|
statusTools.setStatus(status);
|
||||||
}
|
}
|
||||||
this.init(conf.ssl, conf.host, conf.username, conf.password).then(() => {
|
// Check if self_signed option exist
|
||||||
|
if( conf.self_signed == null || conf.self_signed == ''){
|
||||||
|
conf.self_signed = "false";
|
||||||
|
this.setConf(conf);
|
||||||
|
}
|
||||||
|
this.init(conf.ssl, conf.host, conf.username, conf.password, conf.self_signed).then(() => {
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
@ -194,11 +203,14 @@ class WebdavTools {
|
|||||||
logger.info('Uploading snap...');
|
logger.info('Uploading snap...');
|
||||||
let tmpFile = `./temp/${id}.tar`
|
let tmpFile = `./temp/${id}.tar`
|
||||||
let stream = fs.createReadStream(tmpFile);
|
let stream = fs.createReadStream(tmpFile);
|
||||||
|
let conf = this.getConf()
|
||||||
let options = {
|
let options = {
|
||||||
body: stream,
|
body: stream,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password
|
password: this.password,
|
||||||
|
}
|
||||||
|
if(conf.ssl === 'true'){
|
||||||
|
options["https"] = { rejectUnauthorized: conf.self_signed === "false" }
|
||||||
}
|
}
|
||||||
|
|
||||||
got.stream.put(this.baseUrl + encodeURI(path), options).on('uploadProgress', e => {
|
got.stream.put(this.baseUrl + encodeURI(path), options).on('uploadProgress', e => {
|
||||||
|
@ -431,6 +431,15 @@
|
|||||||
$('#backup-snap-keep-read').val($(this).val());
|
$('#backup-snap-keep-read').val($(this).val());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#ssl').change(function(){
|
||||||
|
let div = $('#self_signed').parent().parent().parent();
|
||||||
|
|
||||||
|
if($('#ssl').is(':checked'))
|
||||||
|
div.removeClass("hide")
|
||||||
|
else
|
||||||
|
div.addClass("hide");
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -439,11 +448,12 @@
|
|||||||
function sendNextcloudSettings() {
|
function sendNextcloudSettings() {
|
||||||
loadingModal.open();
|
loadingModal.open();
|
||||||
let ssl = $('#ssl').is(':checked')
|
let ssl = $('#ssl').is(':checked')
|
||||||
|
let self_signed = $('#self_signed').is(':checked')
|
||||||
let hostname = $('#hostname').val();
|
let hostname = $('#hostname').val();
|
||||||
let username = $('#username').val();
|
let username = $('#username').val();
|
||||||
let password = $('#password').val();
|
let password = $('#password').val();
|
||||||
let back_dir = $('#back-dir').val();
|
let back_dir = $('#back-dir').val();
|
||||||
$.post('./api/nextcloud-settings', { ssl: ssl, host: hostname, username: username, password: password, back_dir: back_dir })
|
$.post('./api/nextcloud-settings', { ssl: ssl, host: hostname, username: username, password: password, back_dir: back_dir, self_signed: self_signed })
|
||||||
.done((data) => {
|
.done((data) => {
|
||||||
console.log('Saved');
|
console.log('Saved');
|
||||||
$('#nextcloud_settings_message').parent().addClass("hide");
|
$('#nextcloud_settings_message').parent().addClass("hide");
|
||||||
@ -479,6 +489,11 @@
|
|||||||
loadingModal.open();
|
loadingModal.open();
|
||||||
$.get('./api/nextcloud-settings', (data) => {
|
$.get('./api/nextcloud-settings', (data) => {
|
||||||
$('#ssl').prop("checked", data.ssl == "true");
|
$('#ssl').prop("checked", data.ssl == "true");
|
||||||
|
if(data.ssl == "true"){
|
||||||
|
let div = $('#self_signed').parent().parent().parent();
|
||||||
|
div.removeClass("hide");
|
||||||
|
}
|
||||||
|
$('#self_signed').prop('checked', data.self_signed == "true")
|
||||||
$('#hostname').val(data.host);
|
$('#hostname').val(data.host);
|
||||||
$('#hostname + label').removeClass("active");
|
$('#hostname + label').removeClass("active");
|
||||||
$('#hostname + label').addClass("active");
|
$('#hostname + label').addClass("active");
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" style="margin-bottom: 10px;">
|
<div class="row" style="margin-bottom: 10px;">
|
||||||
<div class="col s12" style="margin-bottom: 10px;">
|
<div class="col m4 s12 " style="margin-bottom: 10px;">
|
||||||
<div style="color: #9e9e9e; display: inline;">SSL</div>
|
<div style="color: #9e9e9e; display: inline;">SSL</div>
|
||||||
<div class="switch" style="display: inline;">
|
<div class="switch" style="display: inline;">
|
||||||
<label>
|
<label>
|
||||||
@ -23,7 +23,15 @@
|
|||||||
<span class="lever"></span>
|
<span class="lever"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col m8 s12 hide" style="margin-bottom: 10px;">
|
||||||
|
<div style="color: #9e9e9e; display: inline;">Accept Self-signed certificate</div>
|
||||||
|
<div class="switch" style="display: inline;">
|
||||||
|
<label>
|
||||||
|
<input id="self_signed" type="checkbox">
|
||||||
|
<span class="lever"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -34,11 +42,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="input-field col s6">
|
<div class="input-field col m6 s12">
|
||||||
<input id="username" type="text" class="white-text">
|
<input id="username" type="text" class="white-text">
|
||||||
<label for="username">Username</label>
|
<label for="username">Username</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-field col s6">
|
<div class="input-field col m6 s12">
|
||||||
<input id="password" type="password" class="white-text">
|
<input id="password" type="password" class="white-text">
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label>
|
||||||
<span class="helper-text">!!! Use App Password !!! See <a target="_blank"
|
<span class="helper-text">!!! Use App Password !!! See <a target="_blank"
|
||||||
|
Loading…
Reference in New Issue
Block a user