#!/bin/sh # # Nanjing Telecome Lan Network Connecter # # Copyright (c) 2005 datouxia # # 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. # # if you support this project , Visit my site @ http://lis.dena.com.cn # echo "Nanjing Telecom Lan Network Ver 0.09 NewDream @ lis.dena.com.cn [GPL]" # Infomation # #---------------------------------------------------------------------# #----Basic User Sets---- LoginServerIP="10.27.1.81" Username="k00000000" #Edit this blank as your Username Password="0000000" #Edit this blank as your Password CheckLoginState="true" #----Special System Fix---- IsMACOS="false" #Only Support Login & Logout #-----Advance User Sets---- CheckOffLineAutoRestart="true" CheckPingHost="www.jsinfo.net" CheckPingTimes="2" DDNSService="true" DDNSHost="0000.2288.org" DDNSUsername="00000000" DDNSPassword="00000000" #----Developer Sets---- WebSuccSignal="webauthsucc" SimulateSystem="(compatible; MSIE 6.0; Windows 98)" OutPutTempFileName="newdream.tmp" CmdOutPutCookie=" -c "$OutPutTempFileName" " CurlProgram="curl" VirtualAloneMode="false" LoginResult="false" SystemRCFilelocation="/etc/rc.local" # Functions # #---------------------------------------------------------------------# GetLoginInfo() { if [ $VirtualAloneMode = "true" ]; then tmplogininfo=$($CurlProgram -q http://$LoginServerIP/servlet/scpservlet.CloseReqServlet -s -S -A "$SimulateSystem" -e "/index.jsp") loginip=$(echo $tmplogininfo|awk 'BEGIN{ FS="ClientIP="; }{ print $2 }'|awk 'BEGIN{ FS="\">"; }{ print $1 }') else if [ "$IsMACOS" = "true" ]; then loginip=$(ifconfig|awk '/inet/{print $2}'|grep '[0-9]\{3\}\.[0-9]\{3\}\.') else loginip=$(ifconfig|awk '{ print $2 }'|awk '/addr/{ print $1 }'|awk 'BEGIN{ FS=":"; }{ print $2;getline }') fi fi } LoginNetWork() { loginresult=$($CurlProgram -q https://$LoginServerIP/servlet/scpservlet.UserDataReqLoginServlet -s -S -g$CmdOutPutCookie-k -A "$SimulateSystem" -e "/index.jsp" -d "id=$Username&password=$Password&ip=$loginip&ClientIP=&servicetype=201%2B&ipmode=1&LocalIP=") } OfflineNetWork() { TmpVirtualAloneMode=$VirtualAloneMode VirtualAloneMode="true" GetLoginInfo VirtualAloneMode=$TmpVirtualAloneMode offlineresult=$($CurlProgram -q http://$LoginServerIP/servlet/m00.logout -s -S -A "$SimulateSystem" -d "ClientIP=$loginip") echo "Offline Success" } GetAuthResult() { authresult=$($CurlProgram -q http://$LoginServerIP/redirect.jsp -s -S -g -b $OutPutTempFileName -k -A "$SimulateSystem" -e "/servlet/scpservlet.UserDataReqLoginServlet"|awk 'BEGIN{ FS="/"; }/show/{ print $5 }'|awk 'BEGIN{ FS="."; }{ print $1 }') if [ "$authresult" = "$WebSuccSignal" ]; then LoginResult="true" echo "Login Success" else LoginResult="false" echo "Login Failure! Please check Account\Password\Using the router" fi } CopyFile() { if [ -f "/usr/bin/newdream" ]; then echo "Main file existed,please use uninstall first" else echo "Coping File" cp newdream /usr/bin/ echo "OK" echo "Edit file for starting with system" rclocaltmpstr=$(cat $SystemRCFilelocation) tmpaddedstr="$rclocaltmpstr /usr/bin/newdream" echo "$tmpaddedstr" > $SystemRCFilelocation echo "OK" echo "Install complete,Thanks for using." fi } DeleteFile() { rm -f /usr/bin/newdream sed -e '/\/usr\/bin\/newdream/d' $SystemRCFilelocation > $OutPutTempFileName rm -f $SystemRCFilelocation mv $OutPutTempFileName $SystemRCFilelocation echo "Uninstall complete,Enjoy it." } ShowHelp() { echo "With no perfix , I will connect the network;" echo "-c (Check) I'll check the online condition for you." echo "-i (Install) I'll setup myself for booting;" echo "-u (Uninstall) I'll uninstall myself." echo "-o (Offline) I'll make offline from the network." } CheckOnline() { PingResult=$(ping -c $CheckPingTimes $CheckPingHost 2>$OutPutTempFileName) PingResult=$(cat $OutPutTempFileName) rm -f $OutPutTempFileName if [ "$PingResult" = "" ]; then echo "Online" else echo "$PingResult" echo "Not Online" if [ "$CheckOfflineAutoRestart" = "true" ]; then Main fi fi } DDNSLogin() { echo "Try to link $DDNSHost to $loginip" DDNSLoginInfo=$($CurlProgram -q -u$DDNSUsername:$DDNSPassword -s -S -g -A"$SimulateSystem" "http://members.3322.org/dyndns/update?system=dyndns&hostname=$DDNSHost&myip=$loginip&wildcard=YES") echo $DDNSLoginInfo } # Main Function # #---------------------------------------------------------------------# Main() { GetLoginInfo echo "Login $Username @ $loginip" if [ "$CheckLoginState" = "true" ]; then LoginNetWork GetAuthResult rm -f $OutPutTempFileName else CmdOutPutCookie=" " LoginNetWork LoginResult="true" echo "Login Information has been sent yet." fi if [ "$LoginResult" = "true" ]; then if [ "$DDNSService" = "true" ]; then DDNSLogin fi else echo "Something wrong happed.I'll try DDNS function next time." fi } # Kernel # #---------------------------------------------------------------------# if [ "$1" = "" ]; then Main else case $1 in "Help" | "-?" ) ShowHelp ;; "Install" | "-i" ) CopyFile ;; "Uninstall" | "-u" ) DeleteFile ;; "Check" | "-c" ) CheckOnline ;; "Offline" | "-o" ) OfflineNetWork ;; *) echo "Please type the -? prefix for more informations" ;; esac fi