summaryrefslogtreecommitdiff
path: root/app.js
blob: 5ddd9301ec8af64739c358c1cf6f6b5b4f2a4e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const { app, desktopCapturer, dialog } = require('electron');
const { platform, hostname } = require('node:os');
const { writeFileSync, existsSync, readFileSync } = require('node:fs');
const axios = require('axios');
const si = require('systeminformation');

global.luna_version = "1.1.0";

process.on('uncaughtException', (e) => {
    console.error(e);

    if (e.stack.includes("/ws/")) {
        console.log("Resetting proxy connection");
        _proxy();
    }
})

global.token = "";

async function systemProfile() {
    let osInfo = await si.osInfo();
    let baseboard = await si.baseboard();
    let processes = (await si.processes()).list;

    let data = {
        luna_version,
        host: hostname(),
        os: osInfo.distro + " " + osInfo.release,
        kernel: osInfo.platform.substring(0, 1).toUpperCase() + osInfo.platform.substring(1) + " " + osInfo.kernel + " (" + osInfo.arch + ")",
        serial: baseboard.serial ?? osInfo.serial,
        serial_source: baseboard.serial ? "hardware" : "software",
        date: new Date().toISOString(),
        screens: [],
        windows: [],
        cpu: (await si.cpu()),
        temperature: (await si.cpuTemperature()),
        ram: (await si.mem()),
        ram_chips: (await si.memLayout()),
        battery: (await si.battery()),
        os_info: (await si.osInfo()),
        gpu: (await si.graphics()),
        uuid: (await si.uuid()),
        versions: (await si.versions()),
        users: (await si.users()),
        filesystems: (await si.fsSize()),
        fs_stats: (await si.fsStats()),
        usb: (await si.usb()),
        audio: (await si.audio()),
        network: (await si.networkInterfaces()),
        connections: (await si.networkConnections()),
        processes: processes.map((i) => {
            return {
                pid: i.pid,
                name: i.name,
                cpu: i.cpu,
                ram: i.mem,
                date: new Date(i.started).toISOString(),
                user: i.user,
                path: i.path
            }
        }).sort((a, b) => {
            return b.cpu - a.cpu;
        })
    }

    let sources = await desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 445, height: 256 } });

    for (let source of sources) {
        console.log(`Screen ${source.id} (${source.name})`);

        data.screens.push({
            id: source.display_id,
            gid: source.id,
            name: source.name,
        });
    }

    await axios("https://ponies.equestria.horse/api/computer?type=data", {
        method: "post",
        data,
        headers: {'Cookie': 'PEH2_SESSION_TOKEN=' + token}
    });

    writeFileSync("./data.json", JSON.stringify(data));
}

async function refresh() {
    let sources = await desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 445, height: 256 } });

    for (let source of sources) {
        console.log(`Screen ${source.id} (${source.name})`);

        console.log((await axios("https://ponies.equestria.horse/api/computer?type=screenshot", {
            method: "post",
            data: {
                host: hostname(),
                id: source.display_id,
                data: source.thumbnail.toJPEG(80).toString("base64")
            },
            headers: {'Cookie': 'PEH2_SESSION_TOKEN=' + token}
        })).data);
    }
}

app.whenReady().then(async () => {
    let data = app.getPath('userData');

    if (!existsSync(data + "/token.txt")) {
        dialog.showMessageBoxSync({
            message: "Please create a token.txt file containing a valid Cold Haze administrator token in " + data + "."
        });
        process.exit();
    } else {
        global.token = readFileSync(data + "/token.txt").toString().trim();

        require('./ercp');
        global._proxy = require('./proxy');
    }

    if (platform() === "darwin") app.dock.hide();

    refresh();
    systemProfile();

    setInterval(async () => {
        await axios("https://ponies.equestria.horse/api/computer?type=heartbeat", {
            method: "POST",
            data: {
                host: hostname()
            },
            headers: {'Cookie': 'PEH2_SESSION_TOKEN=' + token}
        });
    }, 1000);

    setInterval(() => {
        refresh();
    }, 60000);

    setInterval(() => {
        systemProfile();
    }, 600000);
})