-
Notifications
You must be signed in to change notification settings - Fork 1
/
radius-log
executable file
·151 lines (118 loc) · 2.19 KB
/
radius-log
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
143
144
145
146
147
148
149
150
151
#! /bin/bash
. /etc/freeradius-bash-admin.conf
_last_logins() {
_mysql "
SELECT username, authdate, nasip
FROM radpostauth
WHERE reply = 'Access-Accept'
AND nasip <> ''
ORDER BY authdate DESC
LIMIT 100;
"
}
_user_count() {
INTERVAL="$@"
if [ -z "$INTERVAL" ] ; then
INTERVAL="1 WEEK"
fi
_mysql "
SELECT
CONCAT_WS(' ', u.firstname, u.lastname) as Name,
r.username AS Username,
COUNT(r.username) AS Count
FROM radpostauth AS r
JOIN infouser AS u
ON u.username = r.username
WHERE r.reply = 'Access-Accept'
AND r.nasip <> ''
AND r.authdate > CURDATE() - INTERVAL $INTERVAL
GROUP BY r.username
ORDER BY Count DESC;
"
}
_user_log() {
_mysql "
SELECT *
FROM radpostauth
ORDER BY authdate DESC
LIMIT 500;
"
}
_nas_count() {
_mysql "
SELECT nas.shortname, COUNT(nas.id) AS logincount
FROM nas
LEFT JOIN radpostauth
ON radpostauth.nasip = nas.nasname
GROUP BY nas.id;
"
}
_db_values() {
TABLE="$1"
if [ -z "$TABLE" ]; then
echo "Select table!"
_mysql "SHOW TABLES;"
exit 1
fi
_mysql "
SELECT *
FROM $TABLE
LIMIT 500;
"
}
_db_layout() {
TABLE="$1"
if [ -z "$TABLE" ]; then
echo "Select table!"
_mysql "SHOW TABLES;"
exit 1
fi
echo "
# Table '$TABLE'
"
_mysql "DESCRIBE $TABLE;"
}
_log_file() {
tail -n 100 -f /var/log/freeradius/radius.log
}
_usage() {
echo "Usage: radius-log <options>
-> Show log informations.
Options:
last-logins : Show last user logins.
user-count <interval> : E. g.: \"1 week\" or \"2 month\"
user-log : Show user log.
nas-count : Show NAS count.
db-values <table> : Show database values.
db-layout <table> : Show database table layout.
log-file : Show log file.
"
}
case $1 in
last-logins)
_last_logins
;;
user-count)
shift
_user_count "$@"
;;
user-log)
_user_log
;;
nas-count)
_nas_count
;;
db-values)
_db_values "$2"
;;
db-layout)
_db_layout "$2"
;;
log-file)
_log_file
;;
*)
_usage
;;
esac
# vim: set ts=2 sw=2 sts=2 et :