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-changeName.js (1911B)


      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 newname = args[3]
     23  if (ipv6_val.test(ip) || hostname_val.test(ip)) {
     24    backend.changeName(ip, key, newname, "")
     25    console.log(chalk.green("Hostname changed successfully!"));
     26  }else {
     27    console.error(chalk.bold.red('Please set correct IPv6 or Hostname'));
     28    process.exit(1);
     29  }
     30 }
     31 if (args.length === 4) {
     32   var ip = args[1]
     33   var key = args[2]
     34   var token = args[3]
     35   var newname = args[4]
     36   if (ipv6_val.test(ip) || hostname_val.test(ip)) {
     37     backend.changeName(ip, key, newname, token)
     38     console.log(chalk.green("Hostname changed successfully!"));
     39   }else {
     40     console.error(chalk.bold.red('Please set correct IPv6 or Hostname'));
     41     process.exit(1);
     42   }
     43 }
     44 
     45 console.log();