Skip to content

Commit

Permalink
Follow up #2852 (#3527)
Browse files Browse the repository at this point in the history
  • Loading branch information
louislam committed Aug 4, 2023
1 parent bce4835 commit c6e68fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Database {

static path;

static dockerTLSDir;

/**
* @type {boolean}
*/
Expand Down Expand Up @@ -112,6 +114,11 @@ class Database {
fs.mkdirSync(Database.screenshotDir, { recursive: true });
}

Database.dockerTLSDir = path.join(Database.dataDir, "docker-tls/");
if (! fs.existsSync(Database.dockerTLSDir)) {
fs.mkdirSync(Database.dockerTLSDir, { recursive: true });
}

log.info("db", `Data Dir: ${Database.dataDir}`);
}

Expand Down
20 changes: 10 additions & 10 deletions server/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const { R } = require("redbean-node");
const version = require("../package.json").version;
const https = require("https");
const fs = require("fs");
const path = require("path");
const Database = require("./database");

class DockerHost {

static CertificateBasePath = process.env.DOCKER_TLS_DIR_PATH || "data/docker-tls/";
static CertificateFileNameCA = process.env.DOCKER_TLS_FILE_NAME_CA || "ca.pem";
static CertificateFileNameCert = process.env.DOCKER_TLS_FILE_NAME_CA || "cert.pem";
static CertificateFileNameKey = process.env.DOCKER_TLS_FILE_NAME_CA || "key.pem";
static CertificateFileNameCA = "ca.pem";
static CertificateFileNameCert = "cert.pem";
static CertificateFileNameKey = "key.pem";

/**
* Save a docker host
Expand Down Expand Up @@ -67,7 +68,6 @@ class DockerHost {
* @returns {number} Total amount of containers on the host
*/
static async testDockerHost(dockerHost) {

const options = {
url: "/containers/json?all=true",
headers: {
Expand Down Expand Up @@ -141,11 +141,11 @@ class DockerHost {
};
let certOptions = {};

let dirName = url.replace(/^https:\/\/([^/:]+)(\/|:).*$/, "$1");
let dirPath = DockerHost.CertificateBasePath + dirName + "/";
let caPath = dirPath + DockerHost.CertificateFileNameCA;
let certPath = dirPath + DockerHost.CertificateFileNameCert;
let keyPath = dirPath + DockerHost.CertificateFileNameKey;
let dirName = (new URL(url)).hostname;

let caPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameCA);
let certPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameCert);
let keyPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameKey);

if (dockerType === "tcp" && fs.existsSync(caPath) && fs.existsSync(certPath) && fs.existsSync(keyPath)) {
let ca = fs.readFileSync(caPath);
Expand Down

0 comments on commit c6e68fa

Please sign in to comment.