AnonSec Shell
Server IP : 185.86.78.101  /  Your IP : 216.73.216.124
Web Server : Apache
System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /www/wwwroot/mifepriston.org/node_modules/bs-snippet-injector/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /www/wwwroot/mifepriston.org/node_modules/bs-snippet-injector/index.js
var fs    = require("fs");
var path  = require("path");

/**
 * @type {string}
 */
var PLUGIN_NAME = "Snippet Injector";

/**
 * @type
 */
var messages = {
    added: function (path) {
        return "{green:Snippet added to {cyan:" + path
    },
    removed: function (path) {
        return "{green:Snippet removed from {cyan:" + path
    },
    exists: function (path) {
        return "{green:Snippet already exists in: {cyan:" + path
    },
    notFound: function (path) {
        return "{red:ERROR:} Closing body tag not found in: {cyan:" + path
    },
    fileNotFound: function (path) {
        return "{red:ERROR:} File not found!: {cyan:" + path
    }
};

/**
 * Main export
 * @type {{name: string, plugin: plugin}}
 */
module.exports = {

    "plugin:name": PLUGIN_NAME,

    plugin: function (opts, bs) {

        opts.file = opts.file || "";

        opts.currentFilePath = path.resolve(opts.file);

        opts.logger = bs.getLogger(PLUGIN_NAME);
        opts.logger.debug("Setting events");

        bs.events.on("service:running", addSnippet.bind(null, bs, opts));
        bs.events.on("service:exit",  removeSnippet.bind(null, bs, opts));
    }
};


/**
 * Add the snippet before a body tag
 * @param {BrowserSync} bs
 * @param {Object} opts - plugin specific options
 */
function addSnippet(bs, opts) {

    var currentFilePath = opts.currentFilePath;

    opts.logger.debug("Reading the file: %s", currentFilePath);

    var read;

    try {
        read = fs.readFileSync(currentFilePath, "utf8");
    } catch (e) {
        opts.errored = true;
        return opts.logger.info(messages.fileNotFound(path.basename(currentFilePath)));
    }

    var found = false;

    if (read.indexOf(bs.options.get("snippet")) > -1) {
        opts.logger.info(messages.exists(currentFilePath));
        return;
    }

    var modded = read.replace(/<\/body>(?![\s\S]*<\/body>)/, function () {
        opts.currentSnippet = wrap(bs.options.get("snippet")) + "\n" + arguments[0];
        found = true;
        return opts.currentSnippet;
    });

    if (found) {
        opts.logger.debug("Writing the file: %s", currentFilePath);
        fs.writeFileSync(currentFilePath, modded);
        opts.logger.info(messages.added(path.basename(currentFilePath)));
    } else {
        opts.logger.info(messages.notFound(path.basename(currentFilePath)));
    }
}

/**
 * @param item snippet
 * @returns {string}
 */
function wrap (item) {
    return "<!-- BS:SNIPPET-->" + item + "<!-- BS:SNIPPET:END-->";
}

/**
 * @param {BrowserSync} bs
 * @param {Object} opts - plugin specific options
 */
function removeSnippet(bs, opts) {

    if (opts.errored) {
        return;
    }

    var read   = fs.readFileSync(opts.currentFilePath, "utf8");
    var modded = read.replace(opts.currentSnippet, function () {
        return "</body>";
    });
    fs.writeFileSync(opts.currentFilePath, modded);
    opts.logger.info(messages.removed(path.basename(opts.currentFilePath)));
}

Anon7 - 2022
AnonSec Team