#!/bin/bash
clear
echo "
============================================================="
echo
echo -e "\e[1;35m\n                 一键搭建tinyproxy+自动生成模式(Zz大佬制作)
\e[0m"
echo -e "\e[1;35m\n                 Onekey管理脚本——yaohuo.me(NNN丶菜鸟修复优化)
\e[0m"
echo "============================================================="
sleep 2
read -p '请问你是要卸载(0)还是安装(1)？[0/1(默认)]: ' is_install
[[ -z "${is_install}" ]] && is_install="1"
if [[ ${is_install} == [1] ]]; then
sleep 1
read -p "输入你要用的端口（请确保端口未被占用）：" port
read -p "输入你喜欢的验证头：" yanzheng
read -p "输入可以免流的Host：" host
pkill tinyproxy
rm -rf ./tiny*
wget https://github.com/M-Hun/tinyproxy/releases/download/X64/tinyproxy
chmod 0777 tinyproxy
echo "User root
Group root
Port $port
yanzhengtou \"$yanzheng\"
Timeout 600
DefaultErrorFile \"/usr/share/tinyproxy/default.html\"
StatFile \"/usr/share/tinyproxy/stats.html\"
Logfile \"/var/log/tinyproxy.log\"
LogLevel Critical 
PidFile \"/var/run/tinyproxy.pid\"
MaxClients 100
MinSpareServers 5
MaxSpareServers 20
StartServers 10
MaxRequestsPerChild 0
">tinyproxy.conf
sleep 1
./tinyproxy -c tinyproxy.conf
echo "如无错误则安装正常"
sleep 1
echo "正在生成模式"
sleep 1
myip=`wget http://ipecho.net/plain -O - -q ; echo`
echo "mode=wap;
listen_port=65080;
daemon=on;
worker_proc=0;
uid=3004;
#论坛网址：https://yaohuo.me
#ID24898 Zz丨ID6813 NNN丶
http_ip=$myip;
http_port=$port;
https_connect=on;
https_ip=$myip;
https_port=$port;
dns_tcp=http;
dns_listen_port=65053;
dns_url=\"119.29.29.29\";
http_del=\"Host,X-Online-Host\";
https_del=\"Host,X-Online-Host\";
#以下模式关键部分 自定义云免才能联网
http_first=\"[method] http://$host[uri] [version]\\r\\nHost: $host\\r\\n$yanzheng~ [host]\\r\\n\";
https_first=\"CONNECT $host:443 [version]\\r\\nHost: $host\\r\\n$yanzheng~ [host]\\r\\n\";
">tiny.conf
clear
echo "
==================================================="
echo 正在创建下载链接...
echo -e "\n下载地址：`curl --upload-file ./tiny.conf https://transfer.sh/tiny.conf`"
sleep 1
rm -rf ./tiny.conf
echo 
echo
echo 请复制上方链接到浏览器下载tiny云代理模式。
echo
echo 上方链接的打开速度可以慢到你无法想象但请你一定要耐心等待，
echo
echo 然后点击网站的“download”下载tiny云代理模式。
echo
echo 停止命令killall tinyproxy丨查询命令netstat -antp
echo
echo -e "\e[1;31m\n注意！百度搜索“IP”结果应显示：$myip\e[0m"
elif [[ ${is_install} == [0] ]]; then
pkill tinyproxy
rm -rf ./tiny*
sleep 1
echo tinyproxy已卸载完毕!——yaohuo.me
else
echo && echo "	已取消……" && echo
fi
