当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 1 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : [问题]东南大学校友请进,关于bras上网。
帖子发表于 : 2008-09-09 13:08 

注册: 2007-11-18 15:52
帖子: 282
地址: 江苏盛泽医院普外科
送出感谢: 0 次
接收感谢: 0 次
我的BRAS连不上
怎么弄?
我添加好了路由的

用的虎踞龙蟠的代码

#!/bin/sh
#########################################################################
# bras: a bras controller used in Southeast University campus #
# #
# 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 2 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. #
# #
# Copyright (C) 2007 by MinHongbo <minhongbo20@163.com> #
#########################################################################

#set default user information and profiles
USER=
PASSWORD=
L2TPD=/etc/l2tpd
L2TPDCONF=/etc/l2tpd/l2tpd.conf
PPPOPTIONS=/etc/ppp/options.l2tpd
CHAPSECRET=/etc/ppp/chap-secrets
IFCONFIG_ETH0=/etc/sysconfig/network-scripts/ifcfg-eth0
SLEEP=7

#get default GATEWAY
#Note: This may be some problem in other Unix environments such as
#FreeBSD and Solaris for their networkconfig files does not located
#in /etc/sysconfig/network-scripts/*.
#GATEWAY=`awk -F= '{if($0~/GATEWAY/) print $2}' $IFCONFIG_ETH0`

#function: modify_file
#Usage: modify_file FILENAME pattern-to-find replacement-pattern
#Note: replace pattern-to-find in FILENAME with replacement-pattern
modify_file()
{
_FILE=$1
_STRING=$2
_REP=$3
if [ -e $_FILE ];then
sed "s/$_STRING/$_REP/g" $_FILE > $_FILE~
mv $_FILE~ $_FILE
rm -f $_FILE~
else
echo "$_FILE does not exist! Please check it";
fi
}
#login function for bras
logbras()
{
#get user information
DATE=`date +%F`
echo "--------------------------------------------------"
echo " Welcome to SEU Bras $DATE"
echo "--------------------------------------------------"
echo -n "Username: "
read USER
SAVEDSTTY=`stty -g`
stty -echo
echo -n "Password: "
read PASSWORD
stty $SAVEDSTTY
echo ""
echo "--------------------------------------------------"
}
#function: chconfig
#modify three configuration profiles usd in l2tpd with user name and its password
chconfig()
{
#(1)/etc/l2tpd/l2tpd.conf : name = $USER in the "lac seubras" label
if [ -e $L2TPDCONF ]; then
_PATTERN=`sed -n '/lac/, /name = */'p $L2TPDCONF | sed -n '/name = */'p`
_REPLACE="name = $USER"
modify_file "$L2TPDCONF" "$_PATTERN" "$_REPLACE"
else
echo "$L2TPDCONF does not exist!"
fi

#(2)/etc/ppp/options.l2tpd: name = $USER
#first, get ppp's options file
PPPOPTIONS=`sed -n '/lac/, /pppoptfile = */'p $L2TPDCONF | sed -n '/pppoptfile = */'p`
PPPOPTIONS=`echo $PPPOPTIONS | sed -n 's/pppoptfile = //g'p`
if [ -e $PPPOPTIONS ]; then
_PATTERN=`sed -n '/name/'p $PPPOPTIONS`
_REPLACE="name $USER"
modify_file "$PPPOPTIONS" "$_PATTERN" "$_REPLACE"
else
echo "$PPPOPTIONS does not exist!"
fi
#(3)/etc/ppp/chap-secrets: * $USER * "$PASSWORD" *
if [ -e $CHAPSECRET ]; then
sed "/^[a-zA-Z0-9]/d" $CHAPSECRET >$CHAPSECRET~
sed "/# client/ a $USER * \"$PASSWORD\"" $CHAPSECRET~ >$CHAPSECRET
rm -f $CHAPSECRET~
else
echo "$CHAPSECRET does not exit!"
fi
}

#add intra-campus routes
addroute()
{
echo -n "Adding intra-campus route..."
{
route add -net 172.16.0.0 netmask 255.240.0.0 gw $GATEWAY
route add -net 202.119.0.0 netmask 255.255.224.0 gw $GATEWAY
route add -net 202.119.144.0 netmask 255.255.240.0 gw $GATEWAY
route add -net 211.65.32.0 netmask 255.255.224.0 gw $GATEWAY
route add -net 202.119.24.55 netmask 255.255.255.255 gw $GATEWAY #bras.seu.edu.cn
route add -net 58.192.112.0 netmask 255.255.240.0 gw $GATEWAY #www.seu.edu.cn
route add -net 121.220.0.0 netmask 255.255.0.0 gw $GATEWAY
route add -net 121.248.53.1 netmask 255.255.255.0 gw $GATEWAY
route del default gw $GATEWAY
route add default
} >/dev/null 2>&1
echo " [ OK ]"
}
#del intra-campus routes
delroute()
{
echo -n "Deleting intra-campus routes..."
{
route del -net 172.16.0.0 netmask 255.240.0.0 gw $GATEWAY
route del -net 202.119.0.0 netmask 255.255.224.0 gw $GATEWAY
route del -net 202.119.144.0 netmask 255.255.240.0 gw $GATEWAY
route del -net 211.65.32.0 netmask 255.255.224.0 gw $GATEWAY
route del -net 202.119.24.55 netmask 255.255.255.255 gw $GATEWAY
route del -net 58.192.112.0 netmask 255.255.240.0 gw $GATEWAY
route del -net 121.229.0.0 netmask 255.255.0.0 gw $GATEWAY
route del -net 121.248.53.1 netmask 255.255.255.0 gw $GATEWAY
route del default
route add default gw $GATEWAY
} >/dev/null 2>&1
echo " [ OK ]"
}
#check whether l2tpd is running? if not, launch it.
launch_l2tpd()
{
DATE=`date +%F`
L2TPD=`pstree -p | grep l2tpd | grep -v grep`
if [ -z $L2TPD ]
then
rm -f /var/log/*@l2tpd.log
echo -n "Starting l2tpd..."
l2tpd -D 2> /var/log/"$DATE"@l2tpd.log &
if [ $? = 0 ]
then
sleep 1
echo " [ OK ]"
echo "The logging file is /var/log/$DATE@l2tpd.log."
else
echo " [FAILED]"
exit 1
fi
fi
}
#start seubras services
bras_start()
{
STATUS=`ifconfig -a | grep ppp0`
if [ "$STATUS" ]
then
echo "bras has already been actived!"
exit 0
fi
#First, run l2tpd
launch_l2tpd
#Second, add intra-campus routes
#get username in /etc/ppp/options.l2tpd
CURNAME=`awk '{if($1~/name/) print $2}' $PPPOPTIONS`
echo "$CURNAME login......"
sleep 0.5
addroute
sleep 0.5
#Third, connect bras.seu.edu.cn
echo -n "Connecting to SEU Bras server"
echo 'c seubras' > /var/run/l2tp-control
COUNT=0
until [ "$COUNT" -gt "$SLEEP" ]
do
echo -n ".."
sleep 1
COUNT=`expr $COUNT + 1`
done
STATUS=`ifconfig -a | grep ppp0`
#try 10 times
if [ "$STATUS" ]
then
echo " [ OK ]"
else
echo " [ FAILED ]"
fi
}
#stop seubras services
bras_stop()
{
CURNAME=`awk '{if($1~/name/) print $2}' $PPPOPTIONS`
echo "$CURNAME logout....."
sleep 1
delroute
sleep 1
STATUS=`ifconfig -a | grep ppp0`
if [ -z "$STATUS" ]
then
echo "bras has not been actived!"
exit 0
fi

echo -n "Disconnect from SEU bras server..."
echo 'd seubras' > /var/run/l2tp-control
if [ $? = 0 ]
then
echo " [ OK ]"
else
echo " [ FAILED ]"
fi
}

#switch actions according to $1 argument
case $1 in
route)
addroute
;;
#login seubras using latest loginfo. Alternatively, you can specify user and password by
#modify profiles(l2tpd.conf, options.l2tpd and chap-secrets) manually.
start)
bras_start
;;
#close bras connection
stop)
bras_stop
;;
#restart bras connection
restart)
bras_stop
sleep 1
bras_start
;;
#build a new bras connection with another user.
#It provides a convenient mean of switching different users,
#such as username@a and username@b
login)
logbras
#check if bras has been already launched by look up a ppp0 interface.
#if true, try to stop it.
PPP0=`ifconfig -a | grep ppp0`
if [ ! -z "$PPP0" ]
then
bras_stop
fi
sleep 1
chconfig
bras_start
;;
install)
echo "Copy configuration files..."
if [ ! -d "$L2TPD" ]
then
echo "$L2TPD does not exist."
echo -n "Creating a new directory $l2tpd ..."
mkdir $l2tpd
echo " [ OK ]"
fi
echo "copy l2tpd.conf to $L2TPDCONF" && \
cp configs/l2tpd.conf $L2TPDCONF && \
echo "copy options.l2tpd to $PPPOPTIONS" && \
cp configs/options.l2tpd $PPPOPTIONS && \
echo "copy chap-secrets to $CHAPSECRET" && \
cp configs/chap-secrets $CHAPSECRET && \
echo "OK! You can connect to bras server, try to command: bras login"
;;
help)
sed -n '1,$'p bras-help
;;
*)
echo "Usage: `basename $0 ` [ login | start | stop | restart | route | install ] "
;;
esac


红字是我自己改的部分


结果如图


附件:
-usr-local-sbin-linux-seubras-0.2.png
-usr-local-sbin-linux-seubras-0.2.png [ 49.41 KiB | 被浏览 332 次 ]

页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 1 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 4 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译