Skip to content

To refactor #169

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
UlisesGascon opened this issue Jun 12, 2019 · 0 comments
Open

To refactor #169

UlisesGascon opened this issue Jun 12, 2019 · 0 comments
Assignees
Labels
♦️ Nivel Avanzado 🚀 Hacks y Trucos 💀 Cosas que programar antes de morir Para todas aquellas cosas que siempre has querido programar y que merecen la pena 🎩 Cultura Hacker

Comments

@UlisesGascon
Copy link
Contributor

const vorpal = require('vorpal')();
const publicIp = require('public-ip');
const iplocation = require("iplocation").default;
const isCameraOn = require('is-camera-on');
const notifier = require('node-notifier');
const macaddress = require('macaddress');
const {execSync, spawn} = require('child_process')
const speedTest = require('speedtest-net');
const isOnline = require('is-online');


const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json')
const db = low(adapter)



function logo () {
    return `
    ██████╗ ██████╗ ██╗██╗   ██╗ █████╗  ██████╗██╗   ██╗
    ██╔══██╗██╔══██╗██║██║   ██║██╔══██╗██╔════╝╚██╗ ██╔╝
    ██████╔╝██████╔╝██║██║   ██║███████║██║      ╚████╔╝ 
    ██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║██║       ╚██╔╝  
    ██║     ██║  ██║██║ ╚████╔╝ ██║  ██║╚██████╗   ██║   
    ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═══╝  ╚═╝  ╚═╝ ╚═════╝   ╚═╝   
    `
}

console.log(logo())

/*
- Public IP?
- Camera? 
- Micro?
*/


vorpal
  .command('status', 'General information about this machine')
  .action(async function(args, callback) {
    const ip = await publicIp.v4()
    this.log('Ip.v4:', ip);
    const ipData = await iplocation(ip);
    this.log('Ip info:', ipData)
    //this.log('Ip.v6:', await publicIp.v6());
    const cameraStatus = await isCameraOn()
    this.log("Camera on?", cameraStatus);
    const macAddresses = macaddress.networkInterfaces()
    this.log("Mac addresses:", macAddresses)
    this.log('This is the status!');
    callback();
  });

vorpal
  .command('env', 'check env data')
  .action(function(args, callback) {
    const envs = execSync('export')
    this.log(envs.toString('utf8'))
    callback()
})

//Network: sudo lsof -i -P | grep -i "listen"
// https://www.npmjs.com/package/systeminformation
//OS info

vorpal
    .command('speed', 'Network Speed')
    .action(async function (args, callback){
        const onlineNow = await isOnline()
        console.log("You are online?",onlineNow);

        if(onlineNow) {
            const test = speedTest({maxTime: 5000});
            test.on('data', data => {
                console.dir(data);
                callback()
              });
               
            test.on('error', err => {
                console.error(err);
            });
        }
    })

vorpal
    .command('ps', 'process Running')
    .action(function(){
        const top = spawn('top', ['-o', 'cpu']);
        top.stdout.setEncoding('utf8');
        top.stdout.on('data', console.log);
    })

vorpal
    .command('watch', 'Looking for your life!')
    .action(async function (args, callback) {
        let cameraStatus = await isCameraOn()

        db.set('camera.onUse', cameraStatus)
        .write()

        setInterval(async () => {
            this.log("Time to check...")
            cameraStatus = await isCameraOn()
            this.log(db.get('camera.onUse').value(), cameraStatus, db.get('camera.onUse') !== cameraStatus)
            if(db.get('camera.onUse').value() !== cameraStatus){
                const cameraIs = cameraStatus ? "on" : "off";
                const cameraEmoji = cameraStatus ? "📸" : "📷";
                notifier.notify({
                    title: '🚨 Privacy!',
                    message: `${cameraEmoji} Camera is ${cameraIs}!`
                })
            };

            db.set('camera.onUse', cameraStatus)
            .write()

        }, 1000)


        //callback()
    })  

vorpal
  .delimiter('Privacy$')
  .show();
{
  "name": "cli-hack",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "iplocation": "^6.1.0",
    "is-camera-on": "^2.0.0",
    "is-online": "^8.2.0",
    "lowdb": "^1.0.0",
    "macaddress": "^0.2.9",
    "node-notifier": "^5.4.0",
    "public-ip": "^3.1.0",
    "speedtest-net": "^1.5.1",
    "vorpal": "^1.12.0"
  }
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
♦️ Nivel Avanzado 🚀 Hacks y Trucos 💀 Cosas que programar antes de morir Para todas aquellas cosas que siempre has querido programar y que merecen la pena 🎩 Cultura Hacker
Projects
None yet
Development

No branches or pull requests

2 participants