]>
git.ipfire.org Git - people/stevee/network.git/blob - src/functions/functions.db
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 function db_connection_init
() {
23 if [ -e "${DB_CONNECTION_FILE}" ]; then
27 log DEBUG
"Creating connection database ${DB_CONNECTION_FILE}."
29 sqlite3
-batch ${DB_CONNECTION_FILE} <<EOF
31 id INTEGER PRIMARY KEY AUTOINCREMENT,
37 CREATE VIEW current as
38 SELECT zone, time, state FROM log GROUP BY zone;
43 function db_connection_update
() {
50 log DEBUG
"Writing connection to database: zone=${zone} action=${action}."
52 sqlite3
-batch ${DB_CONNECTION_FILE} <<EOF
53 INSERT INTO log(zone, time, state)
54 VALUES('${zone}', strftime('%s', 'now', 'utc'), '${action}');
58 function db_ppp_init
() {
61 if [ -e "${file}" ]; then
65 log DEBUG
"Creating ppp database ${file}."
67 sqlite3
-batch ${file} <<EOF
68 CREATE TABLE accounting(
69 id INTEGER PRIMARY KEY AUTOINCREMENT,
78 function db_ppp_update
() {
86 while [ $# -gt 0 ]; do
95 duration
=${1#--duration=}
101 local file="${LOG_DIR}/ppp_${zone}.db"
105 local time=$
(( $
(date -u +"%s") - ${duration} ))
107 log DEBUG
"Writing accounting data: time=${time} duration=${duration} rcvd=${rcvd} sent=${sent}."
109 sqlite3
-batch ${file} <<EOF
110 INSERT INTO accounting(time, duration, rcvd, sent)
111 VALUES('${time}', '${duration}', '${rcvd}', '${sent}');