FreeRADIUS 配置认证记录入数据库

修改 radpostauth 的表结构:

mysql> drop table radpostauth;
mysql> CREATE TABLE radpostauth (
       id int(11) NOT NULL auto_increment,
       username varchar(64) NOT NULL default '',
       pass varchar(64) NOT NULL default '',
       nasipaddress varchar(15) NOT NULL default '',
       clientipaddress varchar(100) NOT NULL default '',
       reply varchar(32) NOT NULL default '',
       replymessage varchar(100) NOT NULL default '',
       authdate timestamp NOT NULL,
       PRIMARY KEY  (id)
       ) ENGINE = INNODB;

Freeradius 3.x 下修改raddb/mods-config/sql/main/mysql/queries.conf

post-auth {
     # Write SQL queries to a logfile. This is potentially useful for bulk inserts
     # when used with the rlm_sql_null driver.
     # logfile = ${logdir}/post-auth.sql
     query = "\
             INSERT INTO ${..postauth_table} \
                     (username, pass, reply, authdate) \
             VALUES ( \
                     '%{SQL-User-Name}', \
                     '%{%{User-Password}:-%{Chap-Password}}', \
                     '%{Calling-Station-Id}', \
                     '%{reply:Packet-Type}', \
                     '%S')"
}

修改为

post-auth {
     # Write SQL queries to a logfile. This is potentially useful for bulk inserts
     # when used with the rlm_sql_null driver.
     # logfile = ${logdir}/post-auth.sql
     query = "\
             INSERT INTO ${..postauth_table} \
                     (username, nasipaddress, clientipaddress, reply, authdate) \
             VALUES ( \
                     '%{SQL-User-Name}', \
                     '%{Client-IP-Address}', \
                     '%{Calling-Station-Id}', \
                     '%{reply:Packet-Type}', \
                     '%S')"
 }

Freeradius 2.x 下
修改/usr/local/radius/etc/raddb/sql/mysql/dialup.conf

postauth_query = "INSERT INTO ${postauth_table} \
                      (username, pass, reply, authdate) \
                      VALUES ( \
                      '%{User-Name}', \
                      '%{%{User-Password}:-%{Chap-Password}}', \
                      '%{reply:Packet-Type}', '%S')"

修改为

postauth_query = "INSERT INTO ${postauth_table} \
                      (username, pass, nasipaddress, clientipaddress, reply, authdate) \
                      VALUES ( \
                      '%{User-Name}', \
                      '%{%{User-Password}:-%{Chap-Password}}', \
                      '%{Client-IP-Address}', \
                      '%{Calling-Station-Id}', \
                      '%{reply:Packet-Type}', \
                      '%S')"

登陆的错误信息到数据库
在/usr/local/radius/etc/raddb/modules/attr_rewrite最末添加如下

attr_rewrite sanereplymessage {
        attribute = Reply-Message
        searchin = reply
        searchfor = "\n|\r"
        replacewith = ""
        ignore_case = no
        new_attribute = no
        max_matches = 10
        append = no
}

修改/usr/local/radius/etc/raddb/sites-enabled/default,在sql前面增加sanereplymessage

Post-Auth-Type REJECT {
 ..
 sanereplymessage
 sql
 ..
 }

那么/usr/local/radius/etc/raddb/sql/mysql/dialup.conf就要修改为如下

postauth_query = "INSERT INTO ${postauth_table} \
                      (username, pass, nasipaddress, clientipaddress, reply, replymessage, authdate) \
                      VALUES ( \
                      '%{User-Name}', \
                      '%{%{User-Password}:-%{Chap-Password}}', \
                      '%{Client-IP-Address}', \
                      '%{Calling-Station-Id}', \
                      '%{reply:Packet-Type}', \
                      '%{Module-Failure-Message}-%{reply:Reply-Message}', \
                      '%S')"

当然需要先在psotauth表里添加相应的字段先.
因为 NAS-IP-Address 很多时候都是 "127.0.0.1" .所以替换dialup.conf中的%{NAS-IP-Address}替换为%{Client-IP-Address}
添加字段

alter table radpostauth add column replymessage varchar(100) after reply;

linux系统dig和nslookup的安装

nslookup是常用来查询本机域名解析情况的命令,但是一些linux系统下默认无此命令。我们可以通过安装一个包来使该命令生效,这个包中也包括dig命令。

Ubuntu:

# sudo apt-get install dnsutils

Debian:

# apt-get update
# apt-get install dnsutils

Fedora / Centos:

# yum install bind-utils

Centos下对Shell.sh脚本加密

shc是一个加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件,用shell脚本对系统进行自动化维护,简单,便捷而且可移植性好.,但shell脚本是可读写的,很有可能会泄露敏感信息,如用户名,密码,路径,IP等.,同样,在shell脚本运行时会也泄露敏感信息.这就很好的解决了上述问题.

shc 安装

yum -y install shc

如果yum不能安装,请移步官方下载rpm包 http://pkgs.repoforge.org/shc/

使用方法:

shc -r -f script-name 注意:要有-r选项, -f 后跟要加密的脚本名.

运行后会生成两个文件,script-name.x 和 script-name.x.c

script-name.x是加密后的可执行的二进制文件.

./script-name 即可运行.

script-name.x.c是生成script-name.x的原文件(c语言)

shell中的日期时间处理

在Shell中的一些常见的处理时间的方法,这里记录一下。

$ date                        #获得当前日期
Sat Sep  6 23:31:48 CST 2014

$ date +%Y%m%d                #获得当前日期
20140906

$ date +%Y.%m.%d-%H:%M:%S     #获得当前日期
2014.09.06-23:32:56

$ date -d "-1 week" +%Y%m%d   #获取上周今日的日期
20140830

$ date -d "+3 day" +%Y%m%d    #获得3天后的日期
20140909

$ date -d "+1 month" +%Y%m%d  #获得1个月后的日期
20141006

$ date -d "+2 month 20131231" +%Y%m%d  #获得2013年12月31日以后2个月的日期
20140303

data命令参数详解

%% 输出%符号
%a 当前域的星期缩写 (Sun..Sat)
%A 当前域的星期全写 (Sunday..Saturday)
%b 当前域的月份缩写(Jan..Dec)
%B 当前域的月份全称 (January..December)
%c 当前域的默认时间格式 (Sat Nov 04 12:02:33 EST 1989)
%C n百年 [00-99]
%d 两位的天 (01..31)
%D 短时间格式 (mm/dd/yy)
%e 短格式天 ( 1..31)
%F 文件时间格式 same as %Y-%m-%d
%h same as %b
%H 24小时制的小时 (00..23)
%I 12小时制的小时 (01..12)
%j 一年中的第几天 (001..366)
%k 短格式24小时制的小时 ( 0..23)
%l 短格式12小时制的小时 ( 1..12)
%m 双位月份 (01..12)
%M 双位分钟 (00..59)
%n 换行
%N 十亿分之一秒(000000000..999999999)
%p 大写的当前域的上下午指示 (blank in many locales)
%P 小写的当前域的上下午指示 (blank in many locales)
%r 12小时制的时间表示(时:分:秒,双位) time, 12-hour (hh:mm:ss [AP]M)
%R 24小时制的时间表示 (时:分,双位)time, 24-hour (hh:mm)
%s 自基础时间 1970-01-01 00:00:00 到当前时刻的秒数(a GNU extension)
%S 双位秒 second (00..60);
%t 横向制表位(tab)
%T 24小时制时间表示(hh:mm:ss)
%u 数字表示的星期(从星期一开始 1-7)
%U 一年中的第几周星期天为开始 (00..53)
%V 一年中的第几周星期一为开始 (01..53)
%w 一周中的第几天 星期天为开始 (0..6)
%W 一年中的第几周星期一为开始 (00..53)
%x 本地日期格式 (mm/dd/yy)
%X 本地时间格式 (%H:%M:%S)
%y 两位的年(00..99)
%Y 年 (1970…)
%Z : 显示时区

=====================================
批量输出一段日期内的每一天

#!/bin/sh
#riqizizeng
datebeg=$1
dateend=$2
#read datebeg
#read dateend
beg_s=`date -d "$datebeg" +%s`
end_s=`date -d "$dateend" +%s`
while [ "$beg_s" -le "$end_s" ]
do
    date -d @$beg_s +"%Y%m%d"
    beg_s=$((beg_s+86400))
done

以下是运行结果

./every.sh 20120130 20120401
20120130
20120131
20120201
20120202
20120203
20120204
……
……
……
20120327
20120328
20120329
20120330
20120331
20120401