alterator-ulogd-0.2/000075500000000000000000000000001072725660700144725ustar00rootroot00000000000000alterator-ulogd-0.2/Makefile000064400000000000000000000013071072725660700161330ustar00rootroot00000000000000NAME=ulogd DESCRIPTION="Network traffic" INSTALL=/usr/bin/install AWK_TRANSLATE = $(shell [ -d backend3 ] && for i in backend3/*; do file $$i | fgrep -qs 'awk script text' && echo $$i; done) all: clean: install: install-backend install-po install-html awk-update-po: $(XGETTEXT) --join-existing --add-comments -o$(POT_NAME) -L awk --keyword=N_ $(AWK_TRANSLATE) for i in $(PO_LANGUAGES);do \ $(MSGMERGE) po/$$i.po $(POT_NAME) -o $$.new.po && mv $$.new.po po/$$i.po; \ done include /usr/share/alterator/build/po.mak include /usr/share/alterator/build/ui2.mak include /usr/share/alterator/build/backend.mak include /usr/share/alterator/build/fbi.mak include /usr/share/alterator/build/html-messages.mak alterator-ulogd-0.2/applications/000075500000000000000000000000001072725660700171605ustar00rootroot00000000000000alterator-ulogd-0.2/applications/ulogd.desktop000064400000000000000000000003741072725660700216710ustar00rootroot00000000000000[Desktop Entry] Encoding=UTF-8 Type=Application Categories=X-Alterator-Statistics Icon=ulogd Terminal=false Name=Network traffic Name[ru_RU]=Сетевой трафик Name[uk_UA]=Сетевой трафик X-Alterator-URI=/ulogd X-Alterator-UI=html alterator-ulogd-0.2/backend3/000075500000000000000000000000001072725660700161445ustar00rootroot00000000000000alterator-ulogd-0.2/backend3/template-ulogd000075500000000000000000000014401072725660700210140ustar00rootroot00000000000000#!/bin/sh #turn off auto expansion set -f _() { LANG=${in_language%%;*}.utf8 gettext "alterator-ulogd" "$1" } . /usr/share/alterator/build/backend3.sh on_message() { case "$in_action" in #information for renderer template) echo '(' echo 'template "form"' echo 'url "ulogd.html"' echo 'help "ulogd.html"' if [ -n "$in_select" ]; then [ -n "$in_from" ] || in_from=-1 [ -n "$in_to" ] || in_to=-1 [ "$in_checkip" = "#t" ] && checkip="checkip" || checkip="" printf ' redirect "/ulogd/%s/%s/%s/%s"' "$in_iface" "$in_from" "$in_to" "$checkip" fi echo ')' ;; info) echo '(' printf ' title "%s"' "$(_ "Network traffic")" printf ' description "%s"' "$(_ "Network traffic statistics")" echo ')' ;; *) echo '#f' ;; esac } message_loop alterator-ulogd-0.2/backend3/ulogd000075500000000000000000000160231072725660700172060ustar00rootroot00000000000000#!/usr/bin/awk -f BEGIN { # split input fields by a colon FS=":" # set default language LANGUAGE="en_US.UTF8" # set translation domain TEXTDOMAIN = "alterator-ulogd" readmsg=0 LOGFILE="/var/log/configd.log" EFW="/etc/net/scripts/contrib/efw" IP="/sbin/ip" SERVPREFIX="/etc/alterator/alterator-firewall-" SQLITE3DB="/var/lib/ulogd/sqlite3.db" SQLITE3="/usr/bin/sqlite3" PROTOCOLS="/etc/protocols" while ((error = getline line < PROTOCOLS) > 0) { if (line ~ /^#/ || line ~ /^[[:space:]]*$/) continue split(line, list, /[[:space:]]+/) if (list[1] && list[2]) protocols[list[1]] = list[2] } # open a persistent connection to the database dbpipe = SQLITE3 " -batch " SQLITE3DB PROCINFO[dbpipe, "pty"] = 1 #close(dbpipe) #exit } # error reporting function function debug(text, errno) { printf "%s " TEXTDOMAIN ": %s: %s\n", strftime("%B %d %H:%M:%S"), text, errno >> LOGFILE fflush(LOGFILE) } # choose if IP is internal ether external function ip_location(addr, ip) { if (match(addr, /^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)$/, ip) == 0) return "wrong" else { # rfc1918 10/8 prefix if (ip[1] == 10) return N_("internal") # rfc1918 172.16/12 prefix else if (ip[1] == 172 && ip[2] >= 16 && ip[2] <= 31) return N_("internal") # rfc1918 192.168/16 prefix else if (ip[1] == 192 && ip[2] == 168) return N_("internal") else return N_("external") } } # list interfaces function iptables_list_ifaces( cmd, error, line, list, iface, ip, loc, ifaces, idx, i, n) { cmd = IP " addr show" while ((error = cmd | getline line) > 0) { if (match(line, /^[[:digit:]]:+[[:space:]]+([^[:space:]]+):/, list) > 0) { iface = list[1] continue } if (match(line, /^[[:space:]]*inet[[:space:]]+([[:digit:].]+)\//, ip) > 0) { loc = ip_location(ip[1]) if (loc != "wrong") ifaces[iface "/" ip[1]] = iface " - " ip[1] " - " loc } } n = asorti(ifaces, idx) for (i = 1; i <= n; i++) { if (idx[i] ~ /^lo\//) continue print "(\"" idx[i] "\" label \"" ifaces[idx[i]] "\")" } if (error == -1) debug("error reading interface list '" cmd "'", errno) close(cmd) } # list services for interface function iptables_list_services(iface, ip, from, to, cmd, error1, error2, file, service, desc, domain, drop, line, list, n, i) { cmd = "ls -1 " SERVPREFIX "*" totalsumin = 0 totalsumout = 0 while ((error1 = cmd | getline file) > 0) { if (file ~ /~$/ || file ~ /\.rpm/) continue desc = "" drop = 0 localsumin = 0 localsumout = 0 while ((error2 = getline line < file) > 0) { if (line ~ /^port/) { split(line, list, /[[:space:]]+/) localsumin += iptables_acct_port(iface, ip, list[2], list[3], "in", from, to) localsumout += iptables_acct_port(iface, ip, list[2], list[3], "out", from, to) continue } if (line !~ /^description\y/) continue if ((n = split(line, list, /[[:space:]]+/)) < 3) continue domain = list[2] desc = list[3] for(i = 4; i <= n; i++) desc = desc " " list[i] } if (error2 == -1) debug("Error reading file '" file "'", ERRNO) close(file) service = gensub(SERVPREFIX, "", "g", file) printf "(\"%s\" service \"%s\" description \"%s\" in \"%0.1f\" out \"%0.1f\")", service, service, N_(desc, domain), localsumin/1024.0, localsumout/1024.0 totalsumin += localsumin totalsumout += localsumout } if (error1 == -1) debug("Error running command '" cmd "'", ERRNO) close(cmd) totalin = iptables_acct_port(iface, ip, "", "", "in", from, to) totalout = iptables_acct_port(iface, ip, "", "", "out", from, to) bytes = 9 printf "(\"other\" service \"other\" description \"%s\" in \"%0.1f\" out \"%0.1f\")", N_("Other"), (totalin-totalsumin)/1024.0, (totalout-totalsumout)/1024.0 printf "(\"total\" service \"total\" description \"%s\" in \"%0.1f\" out \"%0.1f\")", N_("Total"), totalin/1024.0, totalout/1024.0 } function make_date(day, list, date) { if (day && day >= 0 && split(day, list, /-/) > 0) { date = "" for (i = 1; i < 7; i++) if (list[i]) date = date " " list[i] else date = date " 0" return mktime(date) } return -1 } function iptables_acct_port(iface, ip, protocol, port, direction, from, to, cmd, sql, error, bytes) { switch(direction) { case "in": d = "d" c = "i" break case "out": d = "s" c = "o" break default: return 0 } sql = "SELECT SUM(bytes) FROM ulog_daily WHERE prefix='" c "count'" if (iface) sql = sql " AND iface='" iface "'" if (ip) sql = sql " AND " d "addr='" ip "'" if (protocol) sql = sql " AND protocol=" protocols[protocol] if (port) sql = sql " AND " d "port=" port from = make_date(from) if (from != -1) sql = sql " AND time>=" from to = make_date(to) if (to != -1) sql = sql " AND time<" to sql = sql ";" print sql |& dbpipe if ((error = dbpipe |& getline bytes) == -1) debug("Error running command '" cmd "'", ERRNO) if (bytes == "") bytes = 0 return bytes } # show translation # overwriting locale settings function N_(text, domain, list, cmd, line) { if (!domain) domain = TEXTDOMAIN split(LANGUAGE, list, /:/) cmd = "LANGUAGE=\"" LANGUAGE "\" LANG=\"" list[1] ".UTF8\" gettext " domain " \"" text "\"" cmd | getline line close(cmd) return line } # start message reading /^_message:begin$/ { readmsg=1 next } # stop message reading /^_message:end$/ { readmsg=0 # debug("==========", "==========") # for (attribute in params) # debug("params[" attribute "]", params[attribute]) # overwrite current language if (params["language"] != "") LANGUAGE = gensub(/;/, ":", "g", params["language"]) switch (params["action"]) { case "constraints": print "(" printf " name (label \"%s\")", N_("Interface") printf " service (label \"%s\")", N_("Service") printf " in (label \"%s\")", N_("In") printf " out (label \"%s\")", N_("Out") printf " checkip (default #f label \"%s\")", N_("Check IP") print ")" break case "list": print "(" switch (params["_objects"]) { case /\yservices$/: if (split(params["_objects"], list, /\//) > 1) if (list[5] != "checkip") iptables_list_services(list[1], "", list[3], list[4]) else iptables_list_services(list[1], list[2], list[3], list[4]) break default: iptables_list_ifaces() } print ")" break case "read": print "(" if (split(params["_objects"], list, /\//) > 0) { printf " iface \"%s%s\"", list[1], (list[2]) ? "/" list[2] : "" if (list[3] && list[3] != -1) printf " from \"%s\"", list[3] if (list[4] && list[4] != -1) printf " to \"%s\"", list[4] if (list[5] == "checkip") print " checkip #t" } print ")" break case "write": case "new": case "delete": print "()" break default: print "#f" } fflush() # delete attribute/value pairs before next cycle delete params #exit next } # save attribute/value pairs { if (! readmsg) next attribute=$1 value=$2 # join the rest of fields with a colon for (n = 3; n <= NF; n++) value=value ":" $n value = gensub(/([^\\])\\n/, "\\1\n", "g", value) params[attribute]=value } alterator-ulogd-0.2/html/000075500000000000000000000000001072725660700154365ustar00rootroot00000000000000alterator-ulogd-0.2/html/fbi/000075500000000000000000000000001072725660700161765ustar00rootroot00000000000000alterator-ulogd-0.2/html/fbi/scripts/000075500000000000000000000000001072725660700176655ustar00rootroot00000000000000alterator-ulogd-0.2/html/fbi/scripts/ulogd.js000064400000000000000000000070711072725660700213420ustar00rootroot00000000000000function openCalendar(input) { var url = "/fbi/ulogd-calendar.html"; if(input != ' ') url = url + "?input=" + input; calWindow = window.open(url, "calendar", "status=0,toolbar=0,location=0,menubar=0,resizeable=0,scrollbars=0,width=250,height=200,top=100,left=100"); calWindow.focus(); } var selectedDate = 0; var curDate = 0; var elid = 0; var retid = 0; function insertDate(obj) { var month = curDate.getMonth(); var year = curDate.getFullYear(); var day = nodeText(obj); selectedDate = new Date(year,month,day); buildCalendar(); if (++month < 10) month = "0" + month; if (day < 10) day = "0" + day; retid.value = year + "-" + month + "-" + day; window.close(); } function prevMonth (a) { curDate.setMonth(curDate.getMonth()-1); buildCalendar(); } function nextMonth () { curDate.setMonth(curDate.getMonth()+1); buildCalendar(); } function buildCalendar () { if (!elid) return; var monthList = [ { name: _( "January"), days: 31 }, { name: _( "February"), days: -1 }, { name: _( "March"), days: 31 }, { name: _( "April"), days: 30 }, { name: _( "May"), days: 31 }, { name: _( "June"), days: 30 }, { name: _( "July"), days: 31 }, { name: _( "August"), days: 31 }, { name: _( "September"), days: 30 }, { name: _( "October"), days: 31 }, { name: _("November"), days: 30 }, { name: _("December"), days: 31 } ]; var weekList = [ _("Mo"), _("Tu"), _("We"), _("Th"), _("Fr"), _("Sa"), _("Su") ]; var Month = curDate.getMonth(); var Year = curDate.getFullYear(); var weekDay = curDate.getDay() + 0; // 0 for Sunday, 1 for Monday var today = 0; if ( selectedDate && Year == selectedDate.getFullYear() && Month == selectedDate.getMonth() ) today = selectedDate.getDate(); monthList[1].days = ( ((Year%100 != 0) && (Year%4 == 0)) || (Year%400 == 0) ) ? 29 : 28; var out = ""; out += ' '; out += ' '; out += ' '; out += ' '; out += ' '; out += ' '; // Add weeks header line out += ' '; for (var i = 0; i < 7; i++) out += ''; out += ' '; // Build days out += ' '; for (var i = 1; i <= 42; i++) { var day = " "; var x = i - weekDay; if ( (x >= 0) && (x < monthList[Month].days) ) day = x + 1; var dayClass = "day"; if ( day == today ) dayClass = "today"; out += ''; if( (i%7 == 0) && (i < 36) ) out += ''; } out += '
<
'; out += monthList[Month].name + ' ' + Year + ""; out += '
>
' + weekList[i] + '
'; out += day; out += '
'; elid.innerHTML = out; } function makeDate(txt) { var values = txt.split('-'); if (values.length != 3) { var now = new Date(); now.setDate(1); return [ new Date() , now ]; } else return [ new Date(values[0],values[1]-1,values[2]), new Date(values[0],values[1]-1,1) ]; } function initCalendar() { elid = document.getElementById("calendar"); if (!elid) return; var input = document.location.search.match(/^\?input=(\w+)/)[1]; retid = opener.document.getElementById(input); var dates = makeDate(retid.value); selectedDate = dates[0]; curDate = dates[1]; buildCalendar(); } alterator-ulogd-0.2/html/fbi/styles/000075500000000000000000000000001072725660700175215ustar00rootroot00000000000000alterator-ulogd-0.2/html/fbi/styles/ulogd.css000064400000000000000000000007201072725660700213440ustar00rootroot00000000000000#calendar-table { width: 100%; height: 100%; } #calendar-table td { padding: 3px; } #year { font-weight: bold; } .week { border-style:solid; border-width:1px; background-color: white; } .today { border-style:solid; border-width:1px; background-color: pink; } .day { border-style:solid; border-width:1px; } .day:hover { background-color: #A6BDCF; } .grid td,th { border-width:0px; } th { text-align:left; } .btn { text-decoration: none; } alterator-ulogd-0.2/html/fbi/ulogd-calendar.html000064400000000000000000000015061072725660700217470ustar00rootroot00000000000000 Select date