Advertisement
nocwat

Madoko Local patch

Mar 27th, 2023
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.03 KB | None | 0 0
  1. diff --git a/a/madoko-local/src/init.js b/b/madoko-local/src/init.js
  2. index 692d4dc..07d1473 100644
  3. --- a/a/madoko-local/src/init.js
  4. +++ b/b/madoko-local/src/init.js
  5. @@ -99,9 +99,10 @@ Options.on("--help", function() {
  6.  
  7.  function initializeConfig() {
  8.    Options.parse(process.argv);
  9. +  var CmdOptions = Options.opts()
  10.  
  11.    // Home dir
  12. -  if (Options.homedir) config.homedir = Options.homedir;
  13. +  if (CmdOptions.homedir) config.homedir = CmdOptions.homedir;
  14.    config.configdir = Util.combine(config.homedir, ".madoko");
  15.    config.logdir = Util.combine(config.configdir,"log");
  16.  
  17. @@ -109,11 +110,11 @@ function initializeConfig() {
  18.    var configFile  = Path.join(config.configdir,"config.json");
  19.    var localConfig = Util.jsonParse(Util.readFileSync(configFile, {encoding:"utf8"}, "{}" ));
  20.  
  21. -  if (typeof Options.secret === "string") {
  22. +  if (typeof CmdOptions.secret === "string") {
  23.      // use provided secret
  24. -    config.secret = Options.secret;
  25. +    config.secret = CmdOptions.secret;
  26.    }
  27. -  else if (typeof localConfig.secret === "string" && Options.secret !== true) {
  28. +  else if (typeof localConfig.secret === "string" && CmdOptions.secret !== true) {
  29.      config.secret = localConfig.secret;
  30.    }
  31.    else {
  32. @@ -126,14 +127,14 @@ function initializeConfig() {
  33.    }
  34.  
  35.    // Port
  36. -  if (Options.port) config.port = Options.port;
  37. +  if (CmdOptions.port) config.port = CmdOptions.port;
  38.    else if (typeof localConfig.port === "number") config.port = localConfig.port;
  39.  
  40.    // Concurrency
  41. -  if (Options.concurrency) config.concurrency = Options.concurrency;
  42. +  if (CmdOptions.concurrency) config.concurrency = CmdOptions.concurrency;
  43.  
  44.    // Origin
  45. -  if (Options.origin) config.origin = Options.origin;
  46. +  if (CmdOptions.origin) config.origin = CmdOptions.origin;
  47.    else if (typeof localConfig.origin === "string") config.origin = localConfig.origin;
  48.  
  49.    // User
  50. @@ -144,37 +145,36 @@ function initializeConfig() {
  51.    else config.userid = config.username;
  52.  
  53.    // Run
  54. -  if (Options.run) {
  55. -    if (typeof Options.runcmd === "string")
  56. -      config.run = Options.runcmd;
  57. +  if (CmdOptions.run) {
  58. +    if (typeof CmdOptions.runcmd === "string")
  59. +      config.run = CmdOptions.runcmd;
  60.      else
  61.        config.run = "madoko";
  62.  
  63. -    if (typeof Options.runflags === "string") {
  64. -      config.runflags = Options.runflags;
  65. +    if (typeof CmdOptions.runflags === "string") {
  66. +      config.runflags = CmdOptions.runflags;
  67.      }
  68.  
  69. -    if (typeof Options.rmdelay === "number" && Options.rmdelay >= 1) {
  70. -      config.rmdirDelay = Options.rmdelay * second;
  71. +    if (typeof CmdOptions.rmdelay === "number" && CmdOptions.rmdelay >= 1) {
  72. +      config.rmdirDelay = CmdOptions.rmdelay * second;
  73.        console.log("rmdir delay: " + config.rmdirDelay.toString());
  74.      }
  75.    }
  76.  
  77. -
  78.    // Verbose
  79. -  if (Options.verbose === true) {
  80. +  if (CmdOptions.verbose === true) {
  81.      config.verbose = 1;
  82.    }
  83. -  else if (typeof Options.verbose === "number") {
  84. -    config.verbose = Options.verbose;
  85. +  else if (typeof CmdOptions.verbose === "number") {
  86. +    config.verbose = CmdOptions.verbose;
  87.    }
  88.  
  89.    // Verify local directory
  90. -  if (Options.args && Options.args.length===1) {
  91. -    config.mountdir = Options.args[0];
  92. +  if (CmdOptions.args && CmdOptions.args.length===1) {
  93. +    config.mountdir = CmdOptions.args[0];
  94.      config.writebackDir = true;
  95.    }
  96. -  else if (!Options.args || Options.args.length === 0) {
  97. +  else if (!CmdOptions.args || CmdOptions.args.length === 0) {
  98.      if (typeof localConfig.mountdir === "string") config.mountdir = localConfig.mountdir;
  99.      else {
  100.        config.mountdir = process.cwd();
  101. @@ -195,8 +195,8 @@ function initializeConfig() {
  102.    }
  103.  
  104.    // Create rundir
  105. -  if (typeof Options.rundir==="string") {
  106. -    config.rundir = Options.rundir;
  107. +  if (typeof CmdOptions.rundir==="string") {
  108. +    config.rundir = CmdOptions.rundir;
  109.    }
  110.    else {
  111.      config.rundir = config.configdir;
  112. @@ -208,7 +208,7 @@ function initializeConfig() {
  113.    Log.setLog( config.verbose, config.logdir, config.limits.logFlush );
  114.  
  115.    // Launch
  116. -  config.launch = Options.launch;
  117. +  config.launch = CmdOptions.launch;
  118.    return config;
  119.  }
  120.  
  121. diff --git a/a/madoko-local/src/main.js b/b/madoko-local/src/main.js
  122. index 2bb7a74..177617b 100644
  123. --- a/a/madoko-local/src/main.js
  124. +++ b/b/madoko-local/src/main.js
  125. @@ -23,8 +23,6 @@ var Sandbox = require("./sandbox.js");
  126.  var Run     = require("./run.js");
  127.  var App     = require("./app.js");
  128.  
  129. -var localHostIP = "127.0.0.1";
  130. -
  131.  // -------------------------------------------------------------
  132.  // Parse command line and initialize the configuration options
  133.  // -------------------------------------------------------------
  134. @@ -57,7 +55,7 @@ app.use(function(req, res, next){
  135.    }
  136.  
  137.    // extra check: only serve to local host
  138. -  if (req.ip !== req.connection.remoteAddress || req.ip !== localHostIP) {
  139. +  if (req.ip !== req.connection.remoteAddress || (req.ip !== '127.0.0.1' && req.ip !== '::1')) {
  140.      throw new Util.HttpError( "only serving localhost", 403 );
  141.    }
  142.  
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement