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-changeGeo.js (2968B)


      1 var program = require('commander');
      2 var backend = require("./backend/commands.js");
      3 var chalk_lib = require('chalk');
      4 var ipv6 = require('ip-address').Address6;
      5 var chalk = new chalk_lib.constructor({enabled: true});
      6 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])$/
      7 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]))$/
      8 var lat_long_val = /^(\-?\d+(\.\d+)?).\s*(\-?\d+(\.\d+)?)$/
      9 
     10 
     11 program
     12   .parse(process.argv);
     13 
     14 var args = program.args;
     15 
     16 console.log();
     17 
     18 if (args.length < 5) {
     19   console.error(chalk.bold.red('Please set all required Arguments'));
     20   process.exit(1);
     21 }
     22 if (args.length === 5) {
     23   var ip = args[1]
     24   var key = args[2]
     25   var lat = args[3]
     26   var long = args[4]
     27   var alt = args[5]
     28   var ipv6_val = new ipv6(ip);
     29   if (ipv6_val.isValid() || hostname_val.test(ip)) {
     30     if (lat_long_val.test(lat)) {
     31       if (lat_long_val.test(long)) {
     32         backend.changeGeo(ip, key, lat, long, alt, "")
     33         console.log(chalk.green("Geolocation changed successfully!"));
     34       }else {
     35         console.error(chalk.bold.red('Please set correct Latitude (See http://stackoverflow.com/a/18690202/4929236)'));
     36         process.exit(1);
     37       }
     38     }else {
     39       console.error(chalk.bold.red('Please set correct Email'));
     40       process.exit(1);
     41     }
     42   }else {
     43     console.error(chalk.bold.red('Please set correct IPv6 or Hostname'));
     44     process.exit(1);
     45   }
     46 }
     47 if (args.length === 7) {
     48   var ip = args[0]
     49   var key = args[1]
     50   var token = args[2]
     51   var ccode = args[3]
     52   var lat = args[4]
     53   var long = args[5]
     54   var alt = args[6]
     55   var ipv6_val = new ipv6(ip);
     56   if (ipv6_val.isValid() || hostname_val.test(ip)) {
     57     if (lat_long_val.test(lat)) {
     58       if (lat_long_val.test(long)) {
     59         backend.changeGeo(ip, key, lat, long, alt, token, ccode)
     60         console.log(chalk.green("Geolocation changed successfully!"));
     61       }else {
     62         console.error(chalk.bold.red('Please set correct Longitude (See http://stackoverflow.com/a/18690202/4929236)'));
     63         process.exit(1);
     64       }
     65     }else {
     66       console.error(chalk.bold.red('Please set correct Latitude (See http://stackoverflow.com/a/18690202/4929236)'));
     67       process.exit(1);
     68     }
     69   }else {
     70     console.error(chalk.bold.red('Please set correct IPv6 or Hostname'));
     71     process.exit(1);
     72   }
     73 }
     74 
     75 console.log();