initializer buttons done but missing some details
authorFelix <josuer08@gmail.com>
Mon, 18 Nov 2019 23:27:42 +0000 (23:27 +0000)
committerFelix <josuer08@gmail.com>
Mon, 18 Nov 2019 23:27:42 +0000 (23:27 +0000)
fifo
node_modules/.bin/mime [changed from file to symlink]
node_modules/.bin/static [changed from file to symlink]
node_modules/.bin/wscat [changed from file to symlink]
src/routes/index.js
src/views/index.ejs
src/views/starter.ejs

diff --git a/fifo b/fifo
index 6ffbe1419e82c712844d95f3cd3222751e08996b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
--- a/fifo
+++ b/fifo
@@ -1 +0,0 @@
-pingall
deleted file mode 100755 (executable)
index 20b1ffeb2f97648e0faa7e022c98ed9e6a8e9a0d..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env node
-
-var mime = require('./mime.js');
-var file = process.argv[2];
-var type = mime.lookup(file);
-
-process.stdout.write(type + '\n');
-
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..fbb7ee0eed8d1dd0fe3b5a9d6ff41d1c4f044675
--- /dev/null
@@ -0,0 +1 @@
+../mime/cli.js
\ No newline at end of file
deleted file mode 100755 (executable)
index ecdab3fa0c347db0ab4b1466da6e560be6ed350b..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env node
-
-var fs = require('fs'),
-    tty = require('tty'),
-    statik = require('./../lib/node-static');
-
-    var argv = require('optimist')
-        .usage([
-            'USAGE: $0 [-p <port>] [<directory>]',
-            'simple, rfc 2616 compliant file streaming module for node']
-            .join('\n\n'))
-        .option('port', {
-            alias: 'p',
-            'default': 8080,
-            description: 'TCP port at which the files will be served'
-        })
-        .option('host-address', {
-            alias: 'a',
-            'default': '127.0.0.1',
-            description: 'the local network interface at which to listen'
-        })
-        .option('cache', {
-            alias: 'c',
-            description: '"Cache-Control" header setting, defaults to 3600'
-        })
-        .option('version', {
-            alias: 'v',
-            description: 'node-static version'
-        })
-        .option('headers', {
-            alias: 'H',
-            description: 'additional headers (in JSON format)'
-        })
-        .option('header-file', {
-            alias: 'f',
-            description: 'JSON file of additional headers'
-        })
-        .option('gzip', {
-            alias: 'z',
-            description: 'enable compression (tries to serve file of same name plus \'.gz\')'
-        })
-        .option('spa', {
-            description: 'serve the content as a single page app by redirecting all non-file requests to the index html file'
-        })
-        .option('indexFile', {
-            alias: 'i',
-            'default': 'index.html',
-            description: 'specify a custom index file when serving up directories'
-        })
-        .option('help', {
-            alias: 'h',
-            description: 'display this help message'
-        })
-        .argv;
-
-    var dir = argv._[0] || '.';
-
-    var colors = require('colors');
-
-    var log = function(request, response, statusCode) {
-        var d = new Date();
-        var seconds = d.getSeconds() < 10? '0'+d.getSeconds() : d.getSeconds(),
-            datestr = d.getHours() + ':' + d.getMinutes() + ':' + seconds,
-            line = datestr + ' [' + response.statusCode + ']: ' + request.url,
-            colorized = line;
-        if (tty.isatty(process.stdout.fd))
-            colorized = (response.statusCode >= 500) ? line.red.bold :
-                        (response.statusCode >= 400) ? line.red :
-                        line;
-        console.log(colorized);
-    };
-
-    var file, options;
-
-if (argv.help) {
-    require('optimist').showHelp(console.log);
-    process.exit(0);
-}
-
-if (argv.version) {
-    console.log('node-static', statik.version.join('.'));
-    process.exit(0);
-}
-
-if (argv.cache) {
-    (options = options || {}).cache = argv.cache;
-}
-
-if (argv.headers) {
-    (options = options || {}).headers = JSON.parse(argv.headers);
-}
-
-if (argv['header-file']) {
-    (options = options || {}).headers =
-        JSON.parse(fs.readFileSync(argv['header-file']));
-}
-
-if (argv.gzip) {
-    (options = options || {}).gzip = true;
-}
-
-if (argv.indexFile) {
-    (options = options || {}).indexFile = argv['indexFile'];
-}
-
-file = new(statik.Server)(dir, options);
-
-require('http').createServer(function (request, response) {
-    request.addListener('end', function () {
-        var callback = function(e, rsp) {
-          if (e && e.status === 404) {
-              response.writeHead(e.status, e.headers);
-              response.end("Not Found");
-              log(request, response);
-          } else {
-              log(request, response);
-          }
-        };
-
-        if (argv['spa'] && request.url.indexOf(".") == -1) {
-            file.serveFile(argv['indexFile'], 200, {}, request, response);
-        } else {
-            file.serve(request, response, callback);
-        }
-    }).resume();
-}).listen(+argv.port, argv['host-address']);
-
-console.log('serving "' + dir + '" at http://' + argv['host-address'] + ':' + argv.port);
-if (argv.spa) {
-  console.log('serving as a single page app (all non-file requests redirect to ' + argv['indexFile'] +')');
-}
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..66f6f8a942a83628f745c840cff4078b84d52825
--- /dev/null
@@ -0,0 +1 @@
+../node-static/bin/cli.js
\ No newline at end of file
deleted file mode 100755 (executable)
index 48f0889f3af31dce5fcf7e824e0e8ac3dc7163bf..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1,367 +0,0 @@
-#!/usr/bin/env node
-
-/*!
- * ws: a node.js websocket client
- * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
- * MIT Licensed
- */
-
-const EventEmitter = require('events');
-const fs = require('fs');
-const program = require('commander');
-const read = require('read');
-const readline = require('readline');
-const tty = require('tty');
-const WebSocket = require('ws');
-
-/**
- * InputReader - processes console input.
- *
- * @extends EventEmitter
- */
-class Console extends EventEmitter {
-  constructor() {
-    super();
-
-    this.stdin = process.stdin;
-    this.stdout = process.stdout;
-
-    this.readlineInterface = readline.createInterface(this.stdin, this.stdout);
-
-    this.readlineInterface
-      .on('line', data => {
-        this.emit('line', data);
-      })
-      .on('close', () => {
-        this.emit('close');
-      });
-
-    this._resetInput = () => {
-      this.clear();
-    };
-  }
-
-  static get Colors() {
-    return {
-      Red: '\u001b[31m',
-      Green: '\u001b[32m',
-      Yellow: '\u001b[33m',
-      Blue: '\u001b[34m',
-      Default: '\u001b[39m'
-    };
-  }
-
-  static get Types() {
-    return {
-      Incoming: '< ',
-      Control: '',
-      Error: 'error: '
-    };
-  }
-
-  prompt() {
-    this.readlineInterface.prompt();
-  }
-
-  print(type, msg, color) {
-    if (tty.isatty(1)) {
-      this.clear();
-
-      if (program.execute) color = type = '';
-      else if (!program.color) color = '';
-
-      this.stdout.write(color + type + msg + Console.Colors.Default + '\n');
-      this.prompt();
-    } else if (type === Console.Types.Incoming) {
-      this.stdout.write(msg + '\n');
-    } else {
-      // is a control message and we're not in a tty... drop it.
-    }
-  }
-
-  clear() {
-    if (tty.isatty(1)) {
-      this.stdout.write('\u001b[2K\u001b[3D');
-    }
-  }
-
-  pause() {
-    this.stdin.on('keypress', this._resetInput);
-  }
-
-  resume() {
-    this.stdin.removeListener('keypress', this._resetInput);
-  }
-}
-
-function collect(val, memo) {
-  memo.push(val);
-  return memo;
-}
-
-function noop() {}
-
-/**
- * The actual application
- */
-const version = require('../package.json').version;
-
-program
-  .version(version)
-  .usage('[options] (--listen <port> | --connect <url>)')
-  .option('-l, --listen <port>', 'listen on port')
-  .option('-c, --connect <url>', 'connect to a websocket server')
-  .option('-p, --protocol <version>', 'optional protocol version')
-  .option('-o, --origin <origin>', 'optional origin')
-  .option('-x, --execute <command>', 'execute command after connecting')
-  .option('-w, --wait <seconds>', 'wait given seconds after executing command')
-  .option('--host <host>', 'optional host')
-  .option('-s, --subprotocol <protocol>', 'optional subprotocol', collect, [])
-  .option('-n, --no-check', 'Do not check for unauthorized certificates')
-  .option(
-    '-H, --header <header:value>',
-    'Set an HTTP header. Repeat to set multiple. (--connect only)',
-    collect,
-    []
-  )
-  .option(
-    '--auth <username:password>',
-    'Add basic HTTP authentication header. (--connect only)'
-  )
-  .option('--ca <ca>', 'Specify a Certificate Authority (--connect only)')
-  .option('--cert <cert>', 'Specify a Client SSL Certificate (--connect only)')
-  .option(
-    '--key <key>',
-    "Specify a Client SSL Certificate's key (--connect only)"
-  )
-  .option(
-    '--passphrase [passphrase]',
-    "Specify a Client SSL Certificate Key's passphrase (--connect only). " +
-      "If you don't provide a value, it will be prompted for."
-  )
-  .option('--no-color', 'Run without color')
-  .option(
-    '--slash',
-    'Enable slash commands for control frames ' +
-      '(/ping, /pong, /close [code [, reason]])'
-  )
-  .parse(process.argv);
-
-if (program.listen && program.connect) {
-  console.error('\u001b[33merror: use either --listen or --connect\u001b[39m');
-  process.exit(-1);
-}
-
-if (program.listen) {
-  const wsConsole = new Console();
-  wsConsole.pause();
-
-  let ws = null;
-  const wss = new WebSocket.Server({ port: program.listen }, () => {
-    wsConsole.print(
-      Console.Types.Control,
-      `listening on port ${program.listen} (press CTRL+C to quit)`,
-      Console.Colors.Green
-    );
-    wsConsole.clear();
-  });
-
-  wsConsole.on('close', () => {
-    if (ws) ws.close();
-    process.exit(0);
-  });
-
-  wsConsole.on('line', data => {
-    if (ws) {
-      ws.send(data);
-      wsConsole.prompt();
-    }
-  });
-
-  wss.on('connection', newClient => {
-    if (ws) return newClient.terminate();
-
-    ws = newClient;
-    wsConsole.resume();
-    wsConsole.prompt();
-    wsConsole.print(
-      Console.Types.Control,
-      'client connected',
-      Console.Colors.Green
-    );
-
-    ws.on('close', code => {
-      wsConsole.print(
-        Console.Types.Control,
-        `disconnected (code: ${code})`,
-        Console.Colors.Green
-      );
-      wsConsole.clear();
-      wsConsole.pause();
-      ws = null;
-    });
-
-    ws.on('error', err => {
-      wsConsole.print(Console.Types.Error, err.message, Console.Colors.Yellow);
-    });
-
-    ws.on('message', data => {
-      wsConsole.print(Console.Types.Incoming, data, Console.Colors.Blue);
-    });
-  });
-
-  wss.on('error', err => {
-    wsConsole.print(Console.Types.Error, err.message, Console.Colors.Yellow);
-    process.exit(-1);
-  });
-} else if (program.connect) {
-  const options = {};
-  const cont = () => {
-    const wsConsole = new Console();
-
-    const headers = program.header.reduce((acc, cur) => {
-      const i = cur.indexOf(':');
-      const key = cur.slice(0, i);
-      const value = cur.slice(i + 1);
-      acc[key] = value;
-      return acc;
-    }, {});
-
-    if (program.auth) {
-      headers.Authorization =
-        'Basic ' + Buffer.from(program.auth).toString('base64');
-    }
-    if (program.host) headers.Host = program.host;
-    if (program.protocol) options.protocolVersion = +program.protocol;
-    if (program.origin) options.origin = program.origin;
-    if (!program.check) options.rejectUnauthorized = program.check;
-    if (program.ca) options.ca = fs.readFileSync(program.ca);
-    if (program.cert) options.cert = fs.readFileSync(program.cert);
-    if (program.key) options.key = fs.readFileSync(program.key);
-
-    let connectUrl = program.connect;
-    if (!connectUrl.match(/\w+:\/\/.*$/i)) {
-      connectUrl = `ws://${connectUrl}`;
-    }
-
-    options.headers = headers;
-    const ws = new WebSocket(connectUrl, program.subprotocol, options);
-
-    ws.on('open', () => {
-      if (program.execute) {
-        ws.send(program.execute);
-        setTimeout(() => {
-          ws.close();
-        }, program.wait ? program.wait * 1000 : 2000);
-      } else {
-        wsConsole.print(
-          Console.Types.Control,
-          'connected (press CTRL+C to quit)',
-          Console.Colors.Green
-        );
-
-        wsConsole.on('line', data => {
-          if (program.slash && data[0] === '/') {
-            const toks = data.split(/\s+/);
-            switch (toks[0].substr(1)) {
-              case 'ping':
-                ws.ping(noop);
-                break;
-              case 'pong':
-                ws.pong(noop);
-                break;
-              case 'close': {
-                let closeStatusCode = 1000;
-                let closeReason = '';
-                if (toks.length >= 2) {
-                  closeStatusCode = parseInt(toks[1]);
-                }
-                if (toks.length >= 3) {
-                  closeReason = toks.slice(2).join(' ');
-                }
-                if (closeReason.length > 0) {
-                  ws.close(closeStatusCode, closeReason);
-                } else {
-                  ws.close(closeStatusCode);
-                }
-                break;
-              }
-              default:
-                wsConsole.print(
-                  Console.Types.Error,
-                  'Unrecognized slash command.',
-                  Console.Colors.Yellow
-                );
-            }
-          } else {
-            ws.send(data);
-          }
-          wsConsole.prompt();
-        });
-      }
-    });
-
-    ws.on('close', code => {
-      if (!program.execute) {
-        wsConsole.print(
-          Console.Types.Control,
-          `disconnected (code: ${code})`,
-          Console.Colors.Green
-        );
-      }
-      wsConsole.clear();
-      process.exit();
-    });
-
-    ws.on('error', err => {
-      wsConsole.print(Console.Types.Error, err.message, Console.Colors.Yellow);
-      process.exit(-1);
-    });
-
-    ws.on('message', data => {
-      wsConsole.print(Console.Types.Incoming, data, Console.Colors.Blue);
-    });
-
-    ws.on('ping', () => {
-      wsConsole.print(
-        Console.Types.Incoming,
-        'Received ping',
-        Console.Colors.Blue
-      );
-    });
-
-    ws.on('pong', () => {
-      wsConsole.print(
-        Console.Types.Incoming,
-        'Received pong',
-        Console.Colors.Blue
-      );
-    });
-
-    wsConsole.on('close', () => {
-      ws.close();
-      process.exit();
-    });
-  };
-
-  if (program.passphrase === true) {
-    read(
-      {
-        prompt: 'Passphrase: ',
-        silent: true,
-        replace: '*'
-      },
-      (err, passphrase) => {
-        options.passphrase = passphrase;
-        cont();
-      }
-    );
-  } else if (typeof program.passphrase === 'string') {
-    options.passphrase = program.passphrase;
-    cont();
-  } else {
-    cont();
-  }
-} else {
-  program.help();
-}
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..5392fc9d1daad3de7eb35e17be7940fa91ef4aa3
--- /dev/null
@@ -0,0 +1 @@
+../wscat/bin/wscat
\ No newline at end of file
index 371ba2c4837f08b4b9e31bd1288ce3e301477168..5b5f42a91c9703685541122862f108c036ac110b 100644 (file)
@@ -33,7 +33,7 @@ router.get('/free', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
   var child;
-  child = exec("free -b | grep Mem |  awk  '{print $7}'", function(error, stdout, stderr) {
+  child = exec("free -b | grep Mem |  awk  '{print $3}'", function(error, stdout, stderr) {
     console.log("free");
     res.send(stdout);
   });
@@ -44,7 +44,7 @@ router.get('/mpstat', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
   var child;
-  child = exec("mpstat 1 1| grep all | awk '{print $13}'", function(error, stdout, stderr) {
+  child = exec("mpstat 1 1| grep all | grep Average | awk '{print $12}'", function(error, stdout, stderr) {
     console.log("mpstat");
     res.send(stdout);
   });
@@ -55,7 +55,7 @@ router.get('/ifstat', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
   var child;
-  child = exec("ifstat -n -b -i wlp2s0  0.3 1 | grep [0-9]$", function(error, stdout, stderr) {
+  child = exec("ifstat -n -b -i eth0  0.3 1 | grep [0-9]$", function(error, stdout, stderr) {
     console.log("ifstat");
     res.send(stdout);
   });
@@ -71,6 +71,15 @@ router.get('/gettopo', (req, res) => {
   });
 });
 
+router.get('/iperf', (req, res) => {
+  var sys = require('sys')
+  var exec = require('child_process').exec;
+  var child;
+  child = exec("cd /home/pi && echo iperf > fifo", function(error, stdout, stderr) {
+    console.log("pingall");
+    res.send(stdout);
+  });
+});
 router.get('/pingall', (req, res) => {
   var sys = require('sys')
   var exec = require('child_process').exec;
@@ -151,7 +160,7 @@ router.get('/startcontroller', (req, res) => {
   var child;
   //cd /home/pi && setsid $(cat /home/pi/ejecutarcontroller.sh | grep sudo) >/dev/null 2>&1 < /dev/null &
   //cd /home/pi && ./ejecutarcontroller.sh > /dev/null 2>&1 < /dev/null &  //comando anterior
-  child = exec("cd /home/pi && rm controllerout && touch controllerout && ./ejecutarcontroller.sh > controllerout 2>&1 &", function(error, stdout, stderr) {
+  child = exec("cd /home/pi && touch controllerout && ./ejecutarcontroller.sh > controllerout 2>&1 &", function(error, stdout, stderr) {
     console.log("controller started");
     res.send(stdout);
   });
@@ -182,7 +191,7 @@ router.get('/startvsorc', (req, res) => {
     console.log(stdout + stderr);
     answer+=stdout;
   });
-  child1 = exec("cd /home/pi && mkfifo fifo && rm aichivo && touch aichivo", function(error, stdout, stderr) {
+  child1 = exec("cd /home/pi && mkfifo fifo && touch aichivo", function(error, stdout, stderr) {
     console.log(stdout + stderr);
     answer+=stdout;
   });
index 555073014d75204288d8df625f2609ecf5dd27d6..63ba29720e8ff34d151f227968249a878d691feb 100644 (file)
@@ -15,7 +15,7 @@
   <div class="realtime">
 
     <div class="wrapper RAM">
-      <div class="navbar navbar-dark bg-light"><span>Memoria libre en el sistema</span></div>
+      <div class="navbar navbar-dark bg-light"><span>Uso de memoria del sistema</span></div>
       <div id="ram"></div>
       <!-- <script src="js/health/functions.js"></script> -->
       <script>
 </footer>
 
 
-</html>
\ No newline at end of file
+</html>
index 3528815030c7396a3bbf6ac1f160795320392ba8..c760c6b89e7dd95f1c7b38baf4087073d4ebcb21 100644 (file)
       let vsorcout = document.getElementById('vsorcout') //salida del vsorc
       let controllerout = document.getElementById('controllerout') //salida del controlador
 
-      let intervalController = null;
-      let intervalVsorc = null
+      let timeVsorc = 1000;
+      let timeController = 1000;
+      //Estos time son para especificar cada cuantos ms se pedira leer la data de los archivos aichivo y controllerout
 
-      function startcontroller() {
+      let intervalController = null;//Para tener el id del interval para obtener data del controller
+      let intervalVsorc = null; //Para tener el id del interval para obtener data del vsorc
 
+      function startcontroller() {
         let xhr = new XMLHttpRequest();
         xhr.open('GET', '/startcontroller', true);
         //console.log(xhr); //para ver en la consola
@@ -79,7 +82,7 @@
           }
         }
         xhr.send();
-        intervalController=setInterval(getcontrollerdata, 500);
+        intervalController=setInterval(getcontrollerdata, timeController);
       }
 
       function stopcontroller() {
           }
         }
         xhr.send();
-        intervalVsorc = setInterval(getvsorcdata, 2000);
+        intervalVsorc = setInterval(getvsorcdata, timeVsorc);
       }
 
       function stopvsorc() {
             console.log("pingall");
 
 
+          }
+        }
+        xhr.send();
+      }
+
+      function iperf() {
+        let xhr = new XMLHttpRequest();
+        xhr.open('GET', '/iperf', true);
+        xhr.onload = function() {
+          if (xhr.status == 200) { //can use this.status instead
+            //console.log(xhr.responseText);// para ver en la consola
+            vsorcout.value+=xhr.response;
+            console.log("pingall");
+
+
           }
         }
         xhr.send();