diff --git a/scripts/os_stats b/scripts/os_stats index 2ec7a97..f987a56 100755 --- a/scripts/os_stats +++ b/scripts/os_stats @@ -30,6 +30,7 @@ UPTIME=$(uptime -s) LOADAVG=$(cat /proc/loadavg) ARCHITECTURE=$(uname -m) TEMP=$(cat /sys/class/thermal/thermal_zone*/temp) +ACTIVE_WIFI=$(nmcli -t c show --active | grep wireless | cut -d":" -f1) # Memory memTotal=$(egrep '^MemTotal:' /proc/meminfo | awk '{print $2}') @@ -59,6 +60,7 @@ JSON="{ \"loadAverage\": \"$LOADAVG\", \"architecture\": \"$ARCHITECTURE\", \"temperature\": \"$TEMP\", + \"activeWifi\": \"$ACTIVE_WIFI\", \"memory\": { \"total\": $memTotal, diff --git a/scripts/os_stats_fake b/scripts/os_stats_fake index 155eef2..c7efd03 100755 --- a/scripts/os_stats_fake +++ b/scripts/os_stats_fake @@ -8,6 +8,7 @@ cat << EOF "loadAverage": "0.00 0.00 0.00 1/120 2859", "architecture": "armv7l", "temperature": "40656", + "activeWifi": "befree", "memory": { "total": 245760, diff --git a/src/app/app.js b/src/app/app.js index 8c616f9..ff8dd8f 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -10,4 +10,8 @@ app.use('/api/graphql', graphqlApp) if (process.env.NODE_ENV === 'production') app.use(express.static(buildPath)); +app.get('*', function (req, res) { + res.sendFile(buildPath + '/index.html'); +}); + module.exports = app diff --git a/src/graphql/graphqlModules/Mcu/McuWifiDisconnect.js b/src/graphql/graphqlModules/Mcu/McuWifiDisconnect.js new file mode 100644 index 0000000..1efe2d2 --- /dev/null +++ b/src/graphql/graphqlModules/Mcu/McuWifiDisconnect.js @@ -0,0 +1,17 @@ +module.exports.typeDefs = ` + type McuActions { + wifiDisconnect: McuWifiDisconnectOutput! + } + + type McuWifiDisconnectOutput { + error: Error + } +` + +module.exports.resolvers = { + McuActions: { + wifiDisconnect (root, args, { dispatch }) { + return dispatch('api/mcu/wifiDisconnect') + } + } +} \ No newline at end of file diff --git a/src/store/api/mcu/mcuWifiConnect.js b/src/store/api/mcu/mcuWifiConnect.js index 90eb679..ba07d80 100644 --- a/src/store/api/mcu/mcuWifiConnect.js +++ b/src/store/api/mcu/mcuWifiConnect.js @@ -14,7 +14,7 @@ function wifiConnect(ssid, passphrase, errors) { return new Promise((resolve, reject) => { let command = 'sudo nmcli dev wifi connect ' + ssid; if (passphrase) command += ' password ' + passphrase; - if (process.env.NODE_ENV !== 'production') command = 'echo true'; + if (process.env.NODE_ENV !== 'production') command = 'sleep 2 && nmcli dev wifi connect ' + ssid; exec(command, {}, (err, stdout) => { if (err) { diff --git a/src/store/api/mcu/mcuWifiDisconnect.js b/src/store/api/mcu/mcuWifiDisconnect.js new file mode 100644 index 0000000..fe9d789 --- /dev/null +++ b/src/store/api/mcu/mcuWifiDisconnect.js @@ -0,0 +1,31 @@ +const { exec } = require('child_process') + +module.exports = ({ define }) => { + define('wifiDisconnect', async (payload, { knex, errors, utils }) => { + await wifiDisconnect(errors); + return; + }), { + auth: true + } +} + +function wifiDisconnect(ssid, passphrase, errors) { + return new Promise((resolve, reject) => { + let command = 'for i in $(nmcli -t c show |grep wireless | cut -d":" -f2); do nmcli c delete $i; done'; + if (process.env.NODE_ENV !== 'production') command = 'sleep 2 && echo true'; + + exec(command, {}, (err, stdout) => { + if (err) { + reject(err) + } else { + if (stdout.includes('Error')) { + errMsg = stdout.trim().replace(/^.+\(\d+\)\ /g, "").replace(/\.$/g, ""); + reject(new errors.ValidationError(errMsg)); + } + else { + resolve() + } + } + }) + }) +}