Browse Source

Add Shadowsocks

lj2007331 9 years ago
parent
commit
f7673f1ac5
3 changed files with 216 additions and 113 deletions
  1. 1 1
      functions/upgrade_phpmyadmin.sh
  2. 215 0
      shadowsocks.sh
  3. 0 112
      vpn_centos.sh

+ 1 - 1
functions/upgrade_phpmyadmin.sh

@@ -14,7 +14,7 @@ do
         echo
         read -p "Please input upgrade phpMyAdmin Version(example: 4.1.5): " phpMyAdmin_version
 	if [ "$phpMyAdmin_version" != "$Old_phpMyAdmin_version" ];then
-	        [ ! -e "phpMyAdmin-${phpMyAdmin_version}-all-languages.tar.gz" ] && wget -c http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/$phpMyAdmin_version/phpMyAdmin-${phpMyAdmin_version}-all-languages.tar.gz > /dev/null 2>&1
+	        [ ! -e "phpMyAdmin-${phpMyAdmin_version}-all-languages.tar.gz" ] && wget -c https://files.phpmyadmin.net/phpMyAdmin/$phpMyAdmin_version/phpMyAdmin-${phpMyAdmin_version}-all-languages.tar.gz > /dev/null 2>&1
 	        if [ -e "phpMyAdmin-${phpMyAdmin_version}-all-languages.tar.gz" ];then
 	                echo -e "Download \033[32mphpMyAdmin-${phpMyAdmin_version}-all-languages.tar.gz\033[0m successfully! "
 	                break

+ 215 - 0
shadowsocks.sh

@@ -0,0 +1,215 @@
+#!/bin/bash
+#
+# Author:  yeho <lj2007331 AT gmail.com>
+# Blog:  http://blog.linuxeye.com
+#
+# Install Shadowsocks(Python) Server 
+
+# Check if user is root
+[ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; } 
+
+export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+clear
+printf "
+#######################################################################
+#       OneinStack for CentOS/RadHat 6+ Debian 6+ and Ubuntu 12+      #
+#                  Install Shadowsocks(Python) Server                 #
+#       For more information please visit http://oneinstack.com       #
+#######################################################################
+"
+
+[ ! -d src ] && mkdir src
+cd src
+. ../options.conf
+. ../functions/download.sh
+. ../functions/check_os.sh
+
+Public_IP=`../functions/get_public_ip.py`
+
+if [ "$OS" == 'CentOS' ];then
+	[ -z "$(grep -E ' 7\.| 6\.' /etc/redhat-release)" ] && { echo -e "\033[31mShadowsocks only support CentOS6,7 or Debian or Ubuntu! \033[0m"; exit 1; }
+fi
+
+Install_shadowsocks(){
+if [ "$OS" == 'CentOS' ]; then
+	for Package in wget unzip openssl-devel gcc swig python python-devel python-setuptools autoconf libtool libevent automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel
+        do
+                yum -y install $Package
+        done
+else
+	apt-get -y update
+        for Package in python-dev python-pip curl wget unzip gcc swig automake make perl cpio
+        do
+                apt-get -y install $Package
+        done
+fi
+
+src_url=http://mirrors.linuxeye.com/lnmp/src/ez_setup.py && Download_src
+src_url=http://mirrors.linuxeye.com/lnmp/init/Shadowsocks-init && Download_src
+
+which pip > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	OS_CentOS='python ez_setup.py install \n
+easy_install pip'
+	OS_command
+fi
+
+if [ -f /usr/bin/pip ]; then
+	pip install M2Crypto
+	pip install greenlet
+	pip install gevent
+	pip install shadowsocks
+	if [ -f /usr/bin/ssserver -o -f /usr/local/bin/ssserver ]; then
+		/bin/cp Shadowsocks-init /etc/init.d/shadowsocks
+		chmod +x /etc/init.d/shadowsocks
+		OS_CentOS='chkconfig --add shadowsocks \n
+chkconfig shadowsocks on'
+		OS_Debian_Ubuntu="update-rc.d shadowsocks defaults"
+		OS_command
+		[ ! -e /usr/bin/ssserver -a -e /usr/local/bin/ssserver ] && sed -i 's@Shadowsocks_bin=.*@Shadowsocks_bin=/usr/local/bin/ssserver@' /etc/init.d/shadowsocks
+	else
+		echo
+		echo "Shadowsocks install failed! Please visit http://oneinstack.com"
+		exit 1
+	fi
+fi
+}
+
+Uninstall_shadowsocks(){
+while :
+do
+        echo
+        read -p "Do you want to uninstall Shadowsocks? [y/n]: " Shadowsocks_yn 
+        if [ "$Shadowsocks_yn" != 'y' -a "$Shadowsocks_yn" != 'n' ];then
+                echo -e "\033[31minput error! Please only input 'y' or 'n'\033[0m"
+        else
+                break
+        fi
+done
+
+if [ "$Shadowsocks_yn" == 'y' ]; then
+    [ -n "`ps -ef | grep -v grep | grep -i "ssserver"`" ] && /etc/init.d/shadowsocks stop
+    OS_CentOS='chkconfig --del shadowsocks'
+    OS_Debian_Ubuntu="update-rc.d -f shadowsocks remove"
+    OS_command
+
+    /bin/rm -rf /etc/shadowsocks.json /var/run/shadowsocks.pid /etc/init.d/shadowsocks
+    pip uninstall -y shadowsocks
+    if [ $? -eq 0 ]; then
+        echo -e "\033[32mShadowsocks uninstall success! \033[0m"
+    else
+        echo -e "\033[31mShadowsocks uninstall failed! \033[0m"
+    fi
+else
+    echo -e "\033[32mShadowsocks uninstall cancelled! \033[0m"
+fi
+}
+
+AddUser_shadowsocks(){
+while :
+do
+        echo
+        read -p "Please input password for shadowsocks: " Shadowsocks_password
+        [ -n "`echo $Shadowsocks_password | grep '[+|&]'`" ] && { echo -e "\033[31minput error,not contain a plus sign (+) and & \033[0m"; continue; }
+        (( ${#Shadowsocks_password} >= 5 )) && break || echo -e "\033[31mshadowsocks password least 5 characters! \033[0m"
+done
+}
+
+Iptables_set(){
+if [ -e '/etc/sysconfig/iptables' ];then
+	Shadowsocks_Already_port=`grep -oE '90[0-9][0-9]' /etc/sysconfig/iptables | head -n 1`
+elif [ -e '/etc/iptables.up.rules' ];then
+	Shadowsocks_Already_port=`grep -oE '90[0-9][0-9]' /etc/iptables.up.rules | head -n 1`
+fi
+
+if [ -n "$Shadowsocks_Already_port" ];then
+	Shadowsocks_Default_port=`expr $Shadowsocks_Already_port + 1`
+else
+	Shadowsocks_Default_port=9001
+fi
+
+while :
+do
+        echo
+        read -p "Please input Shadowsocks port(Default: $Shadowsocks_Default_port): " Shadowsocks_port
+        [ -z "$Shadowsocks_port" ] && Shadowsocks_port=$Shadowsocks_Default_port
+        if [ $Shadowsocks_port -ge 9001 >/dev/null 2>&1 -a $Shadowsocks_port -le 9099 >/dev/null 2>&1 ];then
+                break
+        else
+                echo -e "\033[31minput error! Input range: 9001~9099\033[0m"
+        fi
+done
+
+if [ -e '/etc/sysconfig/iptables' ];then
+        if [ -z "`grep -E $Shadowsocks_port /etc/sysconfig/iptables`" ];then
+                iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport $Shadowsocks_port -j ACCEPT
+        fi
+elif [ -e '/etc/iptables.up.rules' ];then
+        if [ -z "`grep -E $Shadowsocks_port /etc/iptables.up.rules`" ];then
+                iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport $Shadowsocks_port -j ACCEPT
+        fi
+else
+	echo -e "\033[31mThis port is already in iptables\033[0m"
+fi
+
+OS_CentOS='service iptables save'
+OS_Debian_Ubuntu='iptables-save > /etc/iptables.up.rules'
+OS_command
+}
+
+Config_shadowsocks(){
+cat > /etc/shadowsocks.json<<EOF
+{
+    "server":"0.0.0.0",
+    "local_address":"127.0.0.1",
+    "local_port":1080,
+    "port_password":{
+	"$Shadowsocks_port":"$Shadowsocks_password"
+    },
+    "timeout":300,
+    "method":"aes-256-cfb",
+    "fast_open":false
+}
+EOF
+}
+
+AddUser_Config_shadowsocks(){
+[ ! -e /etc/shadowsocks.json ] && { echo -e "\033[31mShadowsocks is not installed\033[0m"; exit 1; }
+[ -z "`grep \"$Shadowsocks_port\" /etc/shadowsocks.json`" ] && sed -i "s@\"port_password\":{@\"port_password\":{\n\t\"$Shadowsocks_port\":\"$Shadowsocks_password\",@" /etc/shadowsocks.json || { echo -e "\033[31mThis port is already in /etc/shadowsocks.json\033[0m"; exit 1; } 
+}
+
+Print_User_shadowsocks(){
+echo
+echo -e "Your Server IP: \033[032m$Public_IP\033[0m"
+echo -e "Your Server Port: \033[032m$Shadowsocks_port\033[0m"
+echo -e "Your Password: \033[032m$Shadowsocks_password\033[0m"
+echo -e "Your Local IP: \033[032m127.0.0.1\033[0m"
+echo -e "Your Local Port: \033[032m1080\033[0m"
+echo -e "Your Encryption Method: \033[032maes-256-cfb\033[0m"
+}
+
+case "$1" in
+install)
+	AddUser_shadowsocks
+	Iptables_set
+	Install_shadowsocks
+	Config_shadowsocks
+	service shadowsocks start 
+        Print_User_shadowsocks
+	;;
+adduser)
+	AddUser_shadowsocks
+	Iptables_set
+	AddUser_Config_shadowsocks
+	service shadowsocks restart
+	Print_User_shadowsocks
+	;;
+uninstall)
+	Uninstall_shadowsocks
+	;;
+*)
+	echo
+	echo -e $"\033[035mUsage:\033[0m \033[032m $0 {install|adduser|uninstall}\033[0m"
+	echo
+	exit 1
+esac

+ 0 - 112
vpn_centos.sh

@@ -1,112 +0,0 @@
-#!/bin/bash
-#
-# Author:  yeho <lj2007331 AT gmail.com>
-# Blog:  http://blog.linuxeye.com
-#
-# Installs a PPTP VPN-only system for CentOS
-
-# Check if user is root
-[ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; } 
-
-export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-clear
-printf "
-#######################################################################
-#       OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+      #
-#            Installs a PPTP VPN-only system for CentOS               #
-#       For more information please visit http://oneinstack.com       #
-#######################################################################
-"
-
-[ ! -e '/usr/bin/curl' ] && yum -y install curl
-
-VPN_IP=`curl ipv4.icanhazip.com`
-
-VPN_USER="linuxeye"
-VPN_PASS="linuxeye"
-
-VPN_LOCAL="192.168.0.150"
-VPN_REMOTE="192.168.0.151-200"
-
-while :
-do
-        echo
-        read -p "Please input username: " VPN_USER 
-        [ -n "$VPN_USER" ] && break
-done
-
-while :
-do
-        echo
-        read -p "Please input password: " VPN_PASS
-        [ -n "$VPN_PASS" ] && break
-done
-clear
-
-
-if [ -f /etc/redhat-release -a -n "`grep ' 7\.' /etc/redhat-release`" ];then
-        #CentOS_REL=7
-	if [ ! -e /etc/yum.repos.d/epel.repo ];then
-		cat > /etc/yum.repos.d/epel.repo << EOF
-[epel]
-name=Extra Packages for Enterprise Linux 7 - \$basearch
-#baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
-mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
-failovermethod=priority
-enabled=1
-gpgcheck=0
-EOF
-fi
-        for Package in wget make openssl gcc-c++ ppp pptpd iptables iptables-services 
-        do
-                yum -y install $Package
-        done
-        echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
-elif [ -f /etc/redhat-release -a -n "`grep ' 6\.' /etc/redhat-release`" ];then
-        #CentOS_REL=6
-        for Package in wget make openssl gcc-c++ iptables ppp 
-        do
-                yum -y install $Package
-        done
-	sed -i 's@net.ipv4.ip_forward.*@net.ipv4.ip_forward = 1@g' /etc/sysctl.conf
-	rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
-	yum -y install pptpd
-else
-        echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m"
-        exit 1
-fi
-
-
-echo "1" > /proc/sys/net/ipv4/ip_forward
-
-sysctl -p /etc/sysctl.conf
-
-[ -z "`grep '^localip' /etc/pptpd.conf`" ] && echo "localip $VPN_LOCAL" >> /etc/pptpd.conf # Local IP address of your VPN server
-[ -z "`grep '^remoteip' /etc/pptpd.conf`" ] && echo "remoteip $VPN_REMOTE" >> /etc/pptpd.conf # Scope for your home network
-
-if [ -z "`grep '^ms-dns' /etc/ppp/options.pptpd`" ];then
-	echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd # Google DNS Primary
-	echo "ms-dns 209.244.0.3" >> /etc/ppp/options.pptpd # Level3 Primary
-	echo "ms-dns 208.67.222.222" >> /etc/ppp/options.pptpd # OpenDNS Primary
-fi
-
-echo "$VPN_USER pptpd $VPN_PASS *" >> /etc/ppp/chap-secrets
-
-ETH=`route | grep default | awk '{print $NF}'`
-[ -z "`grep '1723 -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPT
-[ -z "`grep 'gre -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 5 -p gre -j ACCEPT 
-iptables -t nat -A POSTROUTING -o $ETH -j MASQUERADE
-iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356
-service iptables save
-sed -i 's@^-A INPUT -j REJECT --reject-with icmp-host-prohibited@#-A INPUT -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables 
-sed -i 's@^-A FORWARD -j REJECT --reject-with icmp-host-prohibited@#-A FORWARD -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables 
-service iptables restart
-
-service pptpd restart
-chkconfig pptpd on
-clear
-
-echo -e "You can now connect to your VPN via your external IP \033[32m${VPN_IP}\033[0m"
-
-echo -e "Username: \033[32m${VPN_USER}\033[0m"
-echo -e "Password: \033[32m${VPN_PASS}\033[0m"