1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const express = require("express")
|
13 | , app = express()
|
14 | , http = require("http")
|
15 | , exec = require('exec')
|
16 | , figlet = require('figlet')
|
17 | , fs = require('fs')
|
18 | , request = require('request')
|
19 | , fetch = require('node-fetch')
|
20 | , path = require('path')
|
21 | , os = require('os')
|
22 | , moment = require('moment');
|
23 | app.locals.moment = require('moment');
|
24 |
|
25 |
|
26 | exec("sudo clear", puts);
|
27 |
|
28 |
|
29 | puts();
|
30 | function puts(error, stdout, stderr) {console.log(stdout)}
|
31 | function showCurrentExternalIP(log=true) {
|
32 | return new Promise((resovle)=>{
|
33 | const ipurl = 'http://ifconfig.co/ip';
|
34 | try{
|
35 | const options = {
|
36 | url: ipurl,
|
37 | timeout: 9000
|
38 | };
|
39 | request(options, function (err, resp, body) {
|
40 | if(log)console.log("Current IP: " +body);
|
41 | resovle(body)
|
42 | })
|
43 | }catch (SynatxError)
|
44 | {
|
45 | resovle(false)
|
46 | }
|
47 | })
|
48 | }
|
49 | function startServer(){
|
50 |
|
51 | figlet('HotelPartner', function(err, data) {
|
52 | if (err)
|
53 | console.dir(err);
|
54 |
|
55 | console.log(data)
|
56 | console.log(os.hostname()+ "is running " + moment().format("DD.MM.YYYY HH:mm"));
|
57 |
|
58 | });
|
59 | }
|
60 | function rebootServer() {
|
61 | exec("reboot", puts);
|
62 | exec("echo 123 | sudo -S reboot", puts);
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | module.exports = {
|
69 | "start" :startServer,
|
70 | "reboot" :rebootServer,
|
71 | "fetch" :fetch,
|
72 | "request":request,
|
73 | "os" :os,
|
74 | "http" :http,
|
75 | "time" :moment,
|
76 | "showExternalIP":showCurrentExternalIP
|
77 | };
|
78 |
|
79 |
|
80 |
|
81 |
|