v5.0 of the BSDstats script ...
This version brings in optional port reporting. This version is backwards compatible with the older versions, so an upgrade isn't required, except if you wish to enable port reporting
This commit is contained in:
@@ -6,8 +6,7 @@
|
||||
#
|
||||
|
||||
PORTNAME= bsdstats
|
||||
PORTVERSION= 4.8
|
||||
PORTREVISION= 2
|
||||
PORTVERSION= 5.0
|
||||
CATEGORIES= sysutils
|
||||
DISTFILES=
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# $FreeBSD: /tmp/pcvs/ports/sysutils/bsdstats/files/Attic/300.statistics,v 1.33 2006-10-04 04:51:41 scrappy Exp $
|
||||
# $FreeBSD: /tmp/pcvs/ports/sysutils/bsdstats/files/Attic/300.statistics,v 1.34 2006-12-01 13:30:45 scrappy Exp $
|
||||
#
|
||||
|
||||
# If there is a global system configuration file, suck it in.
|
||||
@@ -22,7 +22,7 @@ fi
|
||||
oldmask=$(umask)
|
||||
umask 066
|
||||
|
||||
version="4.7"
|
||||
version="5.0"
|
||||
checkin_server=${monthly_statistics_checkin_server:-"rpt.bsdstats.org"}
|
||||
bsdstats_log=${monthly_statistics_logfile:-"/var/log/bsdstats"}
|
||||
id_token_file='/var/db/bsdstats'
|
||||
@@ -76,6 +76,7 @@ check_dns () {
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
send_devices () {
|
||||
case $(uname) in
|
||||
FreeBSD )
|
||||
@@ -95,6 +96,119 @@ send_devices () {
|
||||
esac
|
||||
}
|
||||
|
||||
send_ports () {
|
||||
case $(uname) in
|
||||
FreeBSD )
|
||||
for line in `/usr/sbin/pkg_info | /usr/bin/awk '{print $1}' `
|
||||
do
|
||||
category=`grep "@comment ORIGIN" /var/db/pkg/${line}/+CONTENTS | sed -E 's/^\@comment ORIGIN:(.+)\/.+/\1/g'`
|
||||
line=$(uri_escape $line)
|
||||
category=$(uri_escape $category)
|
||||
query_string=$query_string`echo \&port[]=${category}:${line}`
|
||||
done
|
||||
|
||||
report_ports
|
||||
;;
|
||||
* )
|
||||
# Not supported
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
report_ports () {
|
||||
# Handle HTTP proxy services
|
||||
#
|
||||
# HTTP_PROXY/http_proxy can take the following form:
|
||||
# [http://][username:password@]proxy[:port][/]
|
||||
# Authentication details may also be provided via HTTP_PROXY_AUTH:
|
||||
# HTTP_PROXY_AUTH="basic:*:username:password"
|
||||
#
|
||||
|
||||
if [ -z "$HTTP_PROXY" -a -n "$http_proxy" ]; then
|
||||
HTTP_PROXY=$http_proxy
|
||||
fi
|
||||
if [ -n "$HTTP_PROXY" ]; then
|
||||
# Attempt to resolve any HTTP authentication
|
||||
if [ -n "$HTTP_PROXY_AUTH" ]; then
|
||||
PROXY_AUTH_USER=`echo $HTTP_PROXY_AUTH | sed -E 's/^.+:\*:(.+):.+$/\1/g'`
|
||||
PROXY_AUTH_PASS=`echo $HTTP_PROXY_AUTH | sed -E 's/^.+:\*:.+:(.+)$/\1/g'`
|
||||
else
|
||||
# Check for authentication within HTTP_PROXY
|
||||
HAS_HTTP_AUTH=`echo $HTTP_PROXY | sed -E 's/^(http:\/\/)?(.+:.+@)?.+/\2/'`
|
||||
if [ -n "$HAS_HTTP_AUTH" ]; then
|
||||
# Found HTTP authentication details
|
||||
PROXY_AUTH_USER=`echo $HAS_HTTP_AUTH | cut -d: -f1`
|
||||
PROXY_AUTH_PASS=`echo $HAS_HTTP_AUTH | cut -d: -f2`
|
||||
fi
|
||||
fi
|
||||
|
||||
# Determine the proxy components
|
||||
PROXY_HOST=`echo $HTTP_PROXY | sed -E 's/^(http:\/\/)?(.+:.+@)?([^@:]+)(:.+)?/\3/'`
|
||||
PROXY_PORT=`echo $HTTP_PROXY | sed -E 's/^(http:\/\/)?(.+:.+@)?(.+):([0-9]+)/\4/' | sed -e 's/[^0-9]//g'`
|
||||
if [ -z "$PROXY_PORT" ]; then
|
||||
# Use default proxy port
|
||||
PROXY_PORT=3128
|
||||
fi
|
||||
fi
|
||||
|
||||
# Determine the host/port netcat should connect to
|
||||
if [ -n "$PROXY_HOST" -a -n "$PROXY_PORT" ]; then
|
||||
nc_host=$PROXY_HOST
|
||||
nc_port=$PROXY_PORT
|
||||
url_prefix="http://${checkin_server}"
|
||||
else
|
||||
nc_host=$checkin_server
|
||||
nc_port=80
|
||||
fi
|
||||
|
||||
# Proxy authentication, if required
|
||||
if [ -n "$PROXY_AUTH_USER" -a -n "$PROXY_AUTH_PASS" ]; then
|
||||
auth_base64=`echo "$PROXY_AUTH_USER:$PROXY_AUTH_PASS" | openssl base64`
|
||||
proxy_auth="Proxy-Authorization: Basic $auth_base64
|
||||
"
|
||||
fi
|
||||
|
||||
|
||||
# Make the request
|
||||
string_length=`echo ${query_string} | wc -m`
|
||||
string_length=`expr ${string_length} - 1`
|
||||
|
||||
echo "POST ${url_prefix}/scripts/report_ports.php HTTP/1.0
|
||||
Host: ${checkin_server}
|
||||
User-Agent: bsdstats ${version}
|
||||
Connection: close
|
||||
${proxy_auth}Content-Type: application/x-www-form-urlencoded
|
||||
Content-Length: ${string_length}
|
||||
|
||||
token=${TOKEN}&key=${KEY}${query_string}" | \
|
||||
/usr/bin/nc $nc_host $nc_port | \
|
||||
grep STATUS= | {
|
||||
local IFS
|
||||
IFS='=
|
||||
'
|
||||
|
||||
while read var val
|
||||
do
|
||||
case $var in
|
||||
STATUS)
|
||||
if [ $val = "OK" ]
|
||||
then
|
||||
echo "[`date`] System Ports reported"
|
||||
else
|
||||
echo "[`date`] System Ports not reported, exiting"
|
||||
exit
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "[`date`] Error with fetch to server"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
done
|
||||
} >> $bsdstats_log
|
||||
|
||||
}
|
||||
|
||||
report_devices () {
|
||||
do_fetch report_devices.php?token=$TOKEN\&key=$KEY$query_string | {
|
||||
local IFS
|
||||
@@ -308,6 +422,16 @@ case "$monthly_statistics_enable" in
|
||||
echo " set monthly_statistics_report_devices=\"YES\" in $periodic_conf"
|
||||
;;
|
||||
esac
|
||||
case "$monthly_statistics_report_ports" in
|
||||
[Yy][Ee][Ss])
|
||||
send_ports
|
||||
echo "Posting monthly ports statistics to $checkin_server"
|
||||
;;
|
||||
*)
|
||||
echo "Posting monthly ports statistics disabled"
|
||||
echo " set monthly_statistics_report_ports=\"YES\" in $periodic_conf"
|
||||
;;
|
||||
esac
|
||||
disable_token
|
||||
;;
|
||||
*)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# $FreeBSD: /tmp/pcvs/ports/sysutils/bsdstats/files/300.statistics.in,v 1.33 2006-10-04 04:51:41 scrappy Exp $
|
||||
# $FreeBSD: /tmp/pcvs/ports/sysutils/bsdstats/files/300.statistics.in,v 1.34 2006-12-01 13:30:45 scrappy Exp $
|
||||
#
|
||||
|
||||
# If there is a global system configuration file, suck it in.
|
||||
@@ -22,7 +22,7 @@ fi
|
||||
oldmask=$(umask)
|
||||
umask 066
|
||||
|
||||
version="4.7"
|
||||
version="5.0"
|
||||
checkin_server=${monthly_statistics_checkin_server:-"rpt.bsdstats.org"}
|
||||
bsdstats_log=${monthly_statistics_logfile:-"/var/log/bsdstats"}
|
||||
id_token_file='/var/db/bsdstats'
|
||||
@@ -76,6 +76,7 @@ check_dns () {
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
send_devices () {
|
||||
case $(uname) in
|
||||
FreeBSD )
|
||||
@@ -95,6 +96,119 @@ send_devices () {
|
||||
esac
|
||||
}
|
||||
|
||||
send_ports () {
|
||||
case $(uname) in
|
||||
FreeBSD )
|
||||
for line in `/usr/sbin/pkg_info | /usr/bin/awk '{print $1}' `
|
||||
do
|
||||
category=`grep "@comment ORIGIN" /var/db/pkg/${line}/+CONTENTS | sed -E 's/^\@comment ORIGIN:(.+)\/.+/\1/g'`
|
||||
line=$(uri_escape $line)
|
||||
category=$(uri_escape $category)
|
||||
query_string=$query_string`echo \&port[]=${category}:${line}`
|
||||
done
|
||||
|
||||
report_ports
|
||||
;;
|
||||
* )
|
||||
# Not supported
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
report_ports () {
|
||||
# Handle HTTP proxy services
|
||||
#
|
||||
# HTTP_PROXY/http_proxy can take the following form:
|
||||
# [http://][username:password@]proxy[:port][/]
|
||||
# Authentication details may also be provided via HTTP_PROXY_AUTH:
|
||||
# HTTP_PROXY_AUTH="basic:*:username:password"
|
||||
#
|
||||
|
||||
if [ -z "$HTTP_PROXY" -a -n "$http_proxy" ]; then
|
||||
HTTP_PROXY=$http_proxy
|
||||
fi
|
||||
if [ -n "$HTTP_PROXY" ]; then
|
||||
# Attempt to resolve any HTTP authentication
|
||||
if [ -n "$HTTP_PROXY_AUTH" ]; then
|
||||
PROXY_AUTH_USER=`echo $HTTP_PROXY_AUTH | sed -E 's/^.+:\*:(.+):.+$/\1/g'`
|
||||
PROXY_AUTH_PASS=`echo $HTTP_PROXY_AUTH | sed -E 's/^.+:\*:.+:(.+)$/\1/g'`
|
||||
else
|
||||
# Check for authentication within HTTP_PROXY
|
||||
HAS_HTTP_AUTH=`echo $HTTP_PROXY | sed -E 's/^(http:\/\/)?(.+:.+@)?.+/\2/'`
|
||||
if [ -n "$HAS_HTTP_AUTH" ]; then
|
||||
# Found HTTP authentication details
|
||||
PROXY_AUTH_USER=`echo $HAS_HTTP_AUTH | cut -d: -f1`
|
||||
PROXY_AUTH_PASS=`echo $HAS_HTTP_AUTH | cut -d: -f2`
|
||||
fi
|
||||
fi
|
||||
|
||||
# Determine the proxy components
|
||||
PROXY_HOST=`echo $HTTP_PROXY | sed -E 's/^(http:\/\/)?(.+:.+@)?([^@:]+)(:.+)?/\3/'`
|
||||
PROXY_PORT=`echo $HTTP_PROXY | sed -E 's/^(http:\/\/)?(.+:.+@)?(.+):([0-9]+)/\4/' | sed -e 's/[^0-9]//g'`
|
||||
if [ -z "$PROXY_PORT" ]; then
|
||||
# Use default proxy port
|
||||
PROXY_PORT=3128
|
||||
fi
|
||||
fi
|
||||
|
||||
# Determine the host/port netcat should connect to
|
||||
if [ -n "$PROXY_HOST" -a -n "$PROXY_PORT" ]; then
|
||||
nc_host=$PROXY_HOST
|
||||
nc_port=$PROXY_PORT
|
||||
url_prefix="http://${checkin_server}"
|
||||
else
|
||||
nc_host=$checkin_server
|
||||
nc_port=80
|
||||
fi
|
||||
|
||||
# Proxy authentication, if required
|
||||
if [ -n "$PROXY_AUTH_USER" -a -n "$PROXY_AUTH_PASS" ]; then
|
||||
auth_base64=`echo "$PROXY_AUTH_USER:$PROXY_AUTH_PASS" | openssl base64`
|
||||
proxy_auth="Proxy-Authorization: Basic $auth_base64
|
||||
"
|
||||
fi
|
||||
|
||||
|
||||
# Make the request
|
||||
string_length=`echo ${query_string} | wc -m`
|
||||
string_length=`expr ${string_length} - 1`
|
||||
|
||||
echo "POST ${url_prefix}/scripts/report_ports.php HTTP/1.0
|
||||
Host: ${checkin_server}
|
||||
User-Agent: bsdstats ${version}
|
||||
Connection: close
|
||||
${proxy_auth}Content-Type: application/x-www-form-urlencoded
|
||||
Content-Length: ${string_length}
|
||||
|
||||
token=${TOKEN}&key=${KEY}${query_string}" | \
|
||||
/usr/bin/nc $nc_host $nc_port | \
|
||||
grep STATUS= | {
|
||||
local IFS
|
||||
IFS='=
|
||||
'
|
||||
|
||||
while read var val
|
||||
do
|
||||
case $var in
|
||||
STATUS)
|
||||
if [ $val = "OK" ]
|
||||
then
|
||||
echo "[`date`] System Ports reported"
|
||||
else
|
||||
echo "[`date`] System Ports not reported, exiting"
|
||||
exit
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "[`date`] Error with fetch to server"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
done
|
||||
} >> $bsdstats_log
|
||||
|
||||
}
|
||||
|
||||
report_devices () {
|
||||
do_fetch report_devices.php?token=$TOKEN\&key=$KEY$query_string | {
|
||||
local IFS
|
||||
@@ -308,6 +422,16 @@ case "$monthly_statistics_enable" in
|
||||
echo " set monthly_statistics_report_devices=\"YES\" in $periodic_conf"
|
||||
;;
|
||||
esac
|
||||
case "$monthly_statistics_report_ports" in
|
||||
[Yy][Ee][Ss])
|
||||
send_ports
|
||||
echo "Posting monthly ports statistics to $checkin_server"
|
||||
;;
|
||||
*)
|
||||
echo "Posting monthly ports statistics disabled"
|
||||
echo " set monthly_statistics_report_ports=\"YES\" in $periodic_conf"
|
||||
;;
|
||||
esac
|
||||
disable_token
|
||||
;;
|
||||
*)
|
||||
|
||||
@@ -16,6 +16,9 @@ To enable the port, edit or create /etc/periodic.conf and add this line:
|
||||
To enable device reporting, add this line:
|
||||
monthly_statistics_report_devices="YES"
|
||||
|
||||
To enable ports reporting, add this line:
|
||||
monthly_statistics_report_ports="YES"
|
||||
|
||||
To run it manually the first time, just run it as:
|
||||
/usr/local/etc/periodic/monthly/300.statistics
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ if [ ":$2" = ":POST-INSTALL" ]; then
|
||||
if yesno "Would you like to send a list of installed hardware as well" n; then
|
||||
echo "monthly_statistics_report_devices=\"YES\"" >> /etc/periodic.conf
|
||||
fi
|
||||
if yesno "Would you like to send a list of installed ports as well" n; then
|
||||
echo "monthly_statistics_report_ports=\"YES\"" >> /etc/periodic.conf
|
||||
fi
|
||||
if yesno "Would you like to run it now" y; then
|
||||
/usr/local/etc/periodic/monthly/300.statistics
|
||||
fi
|
||||
@@ -51,6 +54,9 @@ if [ ":$2" = ":POST-INSTALL" ]; then
|
||||
if yesno "Would you like to send a list of installed hardware as well" n; then
|
||||
echo "monthly_statistics_report_devices=\"YES\"" >> /etc/periodic.conf
|
||||
fi
|
||||
if yesno "Would you like to send a list of installed ports as well" n; then
|
||||
echo "monthly_statistics_report_ports=\"YES\"" >> /etc/periodic.conf
|
||||
fi
|
||||
if yesno "Would you like to run it now" y; then
|
||||
/usr/local/etc/periodic/monthly/300.statistics
|
||||
fi
|
||||
|
||||
@@ -16,6 +16,9 @@ To enable the port, edit or create /etc/periodic.conf and add this line:
|
||||
To enable device reporting, add this line:
|
||||
monthly_statistics_report_devices="YES"
|
||||
|
||||
To enable ports reporting, add this line:
|
||||
monthly_statistics_report_ports="YES"
|
||||
|
||||
To run it manually the first time, just run it as:
|
||||
/usr/local/etc/periodic/monthly/300.statistics
|
||||
|
||||
|
||||
Reference in New Issue
Block a user