Project:
IPFire
Code Location:
git://git.ipfire.org/network.gitmaster
/
functions.db
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
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
#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # # # ############################################################################### function db_connection_init() { if [ -e "${DB_CONNECTION_FILE}" ]; then return ${EXIT_OK} fi log DEBUG "Creating connection database ${DB_CONNECTION_FILE}." sqlite3 -batch ${DB_CONNECTION_FILE} <<EOF CREATE TABLE log( id INTEGER PRIMARY KEY AUTOINCREMENT, zone TEXT, time INTEGER, state TEXT ); CREATE VIEW current as SELECT zone, time, state FROM log GROUP BY zone; EOF } function db_connection_update() { local zone=${1} local action=${2} shift 2 db_connection_init log DEBUG "Writing connection to database: zone=${zone} action=${action}." sqlite3 -batch ${DB_CONNECTION_FILE} <<EOF INSERT INTO log(zone, time, state) VALUES('${zone}', strftime('%s', 'now', 'utc'), '${action}'); EOF } function db_ppp_init() { local file=${1} if [ -e "${file}" ]; then return ${EXIT_OK} fi log DEBUG "Creating ppp database ${file}." sqlite3 -batch ${file} <<EOF CREATE TABLE accounting( id INTEGER PRIMARY KEY AUTOINCREMENT, time INTEGER, duration INTEGER, rcvd INTEGER, sent INTEGER ); EOF } function db_ppp_update() { local zone=${1} shift local rcvd local sent local duration while [ $# -gt 0 ]; do case "${1}" in --rcvd=*) rcvd=${1#--rcvd=} ;; --sent=*) sent=${1#--sent=} ;; --duration=*) duration=${1#--duration=} ;; esac shift done local file="${LOG_DIR}/ppp_${zone}.db" db_ppp_init ${file} local time=$(( $(date -u +"%s") - ${duration} )) log DEBUG "Writing accounting data: time=${time} duration=${duration} rcvd=${rcvd} sent=${sent}." sqlite3 -batch ${file} <<EOF INSERT INTO accounting(time, duration, rcvd, sent) VALUES('${time}', '${duration}', '${rcvd}', '${sent}'); EOF }
