From 1e1e4ba0863f269d13bc8b07c9b1e72c804bb5df Mon Sep 17 00:00:00 2001 From: do9xe Date: Mon, 8 Jun 2015 00:13:08 +0200 Subject: [PATCH 1/2] gluon-core: add script for node-info at login --- package/gluon-core/files/etc/profile | 16 ++++++++++++++++ package/gluon-core/files/lib/gluon/info.d/core | 9 +++++++++ package/gluon-core/files/lib/gluon/node-info | 5 +++++ 3 files changed, 30 insertions(+) create mode 100644 package/gluon-core/files/etc/profile create mode 100755 package/gluon-core/files/lib/gluon/info.d/core create mode 100755 package/gluon-core/files/lib/gluon/node-info diff --git a/package/gluon-core/files/etc/profile b/package/gluon-core/files/etc/profile new file mode 100644 index 00000000..d4dbe5d3 --- /dev/null +++ b/package/gluon-core/files/etc/profile @@ -0,0 +1,16 @@ +#!/bin/sh +[ -f /etc/banner ] && cat /etc/banner && /lib/gluon/node-info + +export PATH=/usr/bin:/usr/sbin:/bin:/sbin +export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6) +export HOME=${HOME:-/root} +export PS1='\u@\h:\w\$ ' + +[ -x /bin/more ] || alias more=less +[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi + +[ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc + +[ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; } +[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } + diff --git a/package/gluon-core/files/lib/gluon/info.d/core b/package/gluon-core/files/lib/gluon/info.d/core new file mode 100755 index 00000000..fbae891b --- /dev/null +++ b/package/gluon-core/files/lib/gluon/info.d/core @@ -0,0 +1,9 @@ +#!/usr/bin/lua +local util = require("luci.util") +local sys = require("luci.sys") + +local hours = math.floor(sys.uptime() / 3600) +local minutes = math.floor(sys.uptime() / 60) - (hours * 60) + +io.write(" your nodes uptime: " .. hours.. " hours, ".. minutes .. " minutes\n") +io.write(" " .. string.rep("-",53) .."\n") diff --git a/package/gluon-core/files/lib/gluon/node-info b/package/gluon-core/files/lib/gluon/node-info new file mode 100755 index 00000000..bcb2aacc --- /dev/null +++ b/package/gluon-core/files/lib/gluon/node-info @@ -0,0 +1,5 @@ +#!/bin/sh + +for script in /lib/gluon/info.d/*; do + "$script" +done From b92ff5c55d99e38ccf7e922f8dbefb626cbde65f Mon Sep 17 00:00:00 2001 From: do9xe Date: Tue, 9 Jun 2015 10:06:14 +0200 Subject: [PATCH 2/2] gluon-mesh-vpn-fastd: add node-info script --- .../files/lib/gluon/info.d/fastd | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 package/gluon-mesh-vpn-fastd/files/lib/gluon/info.d/fastd diff --git a/package/gluon-mesh-vpn-fastd/files/lib/gluon/info.d/fastd b/package/gluon-mesh-vpn-fastd/files/lib/gluon/info.d/fastd new file mode 100755 index 00000000..10bb1af2 --- /dev/null +++ b/package/gluon-mesh-vpn-fastd/files/lib/gluon/info.d/fastd @@ -0,0 +1,64 @@ +#!/usr/bin/lua + +local util = require("luci.util") +local fs = require("nixio.fs") +local ltn12 = require 'luci.ltn12' +local sys = require("luci.sys") +local json = require("luci.json") +local nixio = require 'nixio' +local platform_info = require("platform_info") + + +local stat, fastd_status = pcall( + function() + local fastd_sock = nixio.socket('unix', 'stream') + assert(fastd_sock:connect('/var/run/fastd.mesh_vpn.socket')) + + decoder = json.Decoder() + ltn12.pump.all(ltn12.source.file(fastd_sock), decoder:sink()) + return decoder:get() + end +) + +io.write(" fastd") + +if stat then + + local running_hours = math.floor((fastd_status.uptime/1000) / 3600) + local running_minutes = math.floor((fastd_status.uptime/1000) / 60) - (running_hours * 60) + io.write(string.format(" is running for %i hours and %i minutes.\n", running_hours, running_minutes)) + + local peers = 0 + local connections = 0 + + for key, peer in pairs(fastd_status.peers) do + peers = peers+1 + + if peer.connection then + connections = connections+1 + end + end + + io.write(string.format(" Connected to %i out of %i peers\n", connections, peers)) + local x = 0 + for key, peer in pairs(fastd_status.peers) do + + if peer.connection then + local connection_hours = math.floor((peer.connection.established/1000) / 3600) + local connection_minutes = math.floor((peer.connection.established/1000) / 60) - (connection_hours * 60) + local peername = string.gsub(peer.name, "mesh_vpn_", " ") + peername = string.gsub(peername, "_", " ") + + x = 1 + io.write(string.format("%s: ",peername)) + io.write(string.format("connected for %i:%i hours\n", connection_hours, connection_minutes)) + end + end + if (x==0) then + io.write(" no Connections\n") + end +else + io.write(" is not running\n") +end + +io.write(" " .. string.rep("-",53) .."\n") \ No newline at end of file