gluon-remote-node

Node Version of gluon remote
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-remote-node.git
Log | Files | Refs | README | LICENSE

gluon_web_remote-MOW.js (1908B)


      1 var program = require('commander');
      2 var backend = require("./backend/commands.js");
      3 var chalk_lib = require('chalk');
      4 var chalk = new chalk_lib.constructor({enabled: true});
      5 var hostname_val = /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/
      6 var ipv6_val = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/
      7 
      8 program
      9   .parse(process.argv);
     10 
     11 var args = program.args;
     12 
     13 console.log();
     14 
     15 if (args.length < 3) {
     16   console.error(chalk.bold.red('Please set all required Arguments'));
     17   process.exit(1);
     18 }
     19 if (args.length === 3) {
     20   var ip = args[1]
     21   var key = args[2]
     22   var switchPosition = args[3]
     23   if (switchPosition === "on") {
     24     if (ipv6_val.test(ip) || hostname_val.test(ip)) {
     25       backend.activateMOW(ip, key)
     26       console.log(chalk.green("Mesh on Wan activated successfully!"));
     27     }else {
     28       console.error(chalk.bold.red('Please set correct IPv6 or Hostname'));
     29       process.exit(1);
     30     }
     31   }else if (switchPosition === "off") {
     32     if (ipv6_val.test(ip) || hostname_val.test(ip)) {
     33       backend.deactivateMOW(ip, key)
     34       console.log(chalk.green("Mesh on Wan deactivated successfully!"));
     35     }else {
     36       console.error(chalk.bold.red('Please set correct IPv6 or Hostname'));
     37       process.exit(1);
     38     }
     39   }
     40 }
     41 
     42 console.log();