├── LICENSE ├── .gitignore ├── README.md ├── README-en.md └── frp-setup.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Mehrad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Django # 2 | *.log 3 | *.pot 4 | *.pyc 5 | __pycache__ 6 | db.sqlite3 7 | media 8 | 9 | # Backup files # 10 | *.bak 11 | 12 | # If you are using PyCharm # 13 | .idea/ 14 | 15 | # File-based project format 16 | *.iws 17 | 18 | # IntelliJ 19 | out/ 20 | 21 | # JIRA plugin 22 | atlassian-ide-plugin.xml 23 | 24 | # Python # 25 | *.py[cod] 26 | *$py.class 27 | 28 | # Distribution / packaging 29 | .Python build/ 30 | develop-eggs/ 31 | dist/ 32 | downloads/ 33 | eggs/ 34 | .eggs/ 35 | lib/ 36 | lib64/ 37 | parts/ 38 | sdist/ 39 | var/ 40 | wheels/ 41 | *.whl 42 | *.egg-info/ 43 | .installed.cfg 44 | *.egg 45 | *.manifest 46 | *.spec 47 | 48 | # Installer logs 49 | pip-log.txt 50 | pip-delete-this-directory.txt 51 | 52 | # Unit test / coverage reports 53 | htmlcov/ 54 | .tox/ 55 | .coverage 56 | .coverage.* 57 | .cache 58 | .pytest_cache/ 59 | nosetests.xml 60 | coverage.xml 61 | *.cover 62 | .hypothesis/ 63 | 64 | # Jupyter Notebook 65 | .ipynb_checkpoints 66 | 67 | # pyenv 68 | .python-version 69 | 70 | # celery 71 | celerybeat-schedule.* 72 | 73 | # SageMath parsed files 74 | *.sage.py 75 | 76 | # Environments 77 | .env 78 | .venv 79 | env/ 80 | venv/ 81 | ENV/ 82 | env.bak/ 83 | venv.bak/ 84 | 85 | # mkdocs documentation 86 | /site 87 | 88 | # mypy 89 | .mypy_cache/ 90 | 91 | # Sublime Text # 92 | *.tmlanguage.cache 93 | *.tmPreferences.cache 94 | *.stTheme.cache 95 | *.sublime-workspace 96 | *.sublime-project 97 | 98 | # sftp configuration file 99 | sftp-config.json 100 | 101 | # Package control specific files Package 102 | Control.last-run 103 | Control.ca-list 104 | Control.ca-bundle 105 | Control.system-ca-bundle 106 | GitHub.sublime-settings 107 | 108 | # Visual Studio Code # 109 | .vscode/* 110 | !.vscode/settings.json 111 | !.vscode/tasks.json 112 | !.vscode/launch.json 113 | !.vscode/extensions.json 114 | .history 115 | 116 | #personal files 117 | .personal/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 🌍 **زبان**: فارسی | [English](README-en.md) 2 | 3 | 4 | 5 | # اسکریپت مدیریت و نصب آسان 6 | 7 | اسکریپت کامل و ساده‌سازی‌شده برای نصب، پیکربندی و مدیریت تانل ریورس FRP یک ابزار پروکسی معکوس قدرتمند و سریع برای عبور از NAT. 8 | 9 | این اسکریپت همه مراحل نصب و راه‌اندازی FRP رو به‌صورت خودکار انجام میده و یه منوی کاربرپسند برای مدیریت سرور و کلاینت‌های FRP داره. 10 | 11 | 12 | 13 | 📚 **مستندات رسمی FRP**: [GoFRP Official Docs](https://gofrp.org/docs/) 14 | 15 | --- 16 | 17 | ## امکانات 18 | 19 | ✨ **نصب با یک کلیک** – آخرین نسخه FRP رو به‌صورت خودکار دانلود و نصب می‌کنه 20 | 21 | 🖥️ **راه‌اندازی تعاملی** – منوی راهنما برای تنظیم راحت سرور و کلاینت 22 | 23 | ⚙️ **پیکربندی پیشرفته** – امکان مرور، دیدن و ویرایش فایل‌های پیکربندی 24 | 25 | 📊 **مانیتور وضعیت** – مشاهده سرویس‌های در حال اجرا و فایل‌های پیکربندی 26 | 27 | 🔧 **مدیریت سرویس‌ها** – شروع، توقف و کنترل سرویس‌ها از طریق systemd 28 | 29 | 📦 **کاهش حجم پیلود پکت‌ها** – با استفاده از آپشن TCP Compression، حجم پکت ها کاهش یافته و ترافیک مصرفی کمتر می‌شود 30 | 31 | 🔹**توجه**: این قابلیت به‌صورت پیش‌فرض توسط اسکریپت فعال شده است 32 | 33 | --- 34 | 35 | **نکته ای درباره کانکشن هندلینگ و مصرف رم** 36 | 37 | ممکنه توی سروری با سرعت ۱۵۰ مگابیت بر ثانیه، مصرف رم بین ۱ تا ۲ گیگ رو ببینین. این کاملاً طبیعی و عمدی طراحی شده. 38 | 39 | برخلاف پروژه‌هایی که فقط دنبال مصرف کمتر رم هستن، FRP تمرکزش روی مدیریت درست اتصال‌ها، بافرها و وضعیت ارتباط‌هاست. این طراحی باعث می‌شه حتی در زمان فشار زیاد یا قطعی‌های لحظه‌ای، جدول اتصال‌ها پر نشه. ما مواردی از پروژه های دیگه دیدیم که سیستم‌هایی با مدیریت ضعیف کانکشن طراحی کردند، فقط با یه قطعی کوتاه، بیش از ۱۵۰۰۰ اتصال یتیم رها کردن. 40 | 41 | در مقابل، FRP طوری طراحی شده که افت اتصال‌ها رو خیلی سریع هندل کنه — توی تست‌های ما کمتر از ۱ ثانیه طول کشیده تا به حالت پایدار برگرده. توی این سیستم، پایداری و عملکرد بالا خیلی مهم‌تر از صرفه‌جویی چند صد مگابایتی در رم در نظر گرفته شده. 42 | 43 | **نکته ای درباره مولتی پلکسینگ TCPMux** 44 | 45 | در صورت نیاز به پشتیبانی از تعداد زیاد کاربران یا حجم بالای ترافیک، توصیه می‌شود از مولتی پلکسینگ ( TCPMux ) استفاده نکنید. طبق تست‌های ما، در شرایط ترافیک بالا، غیرفعال بودن مولتی پلکسینگ باعث بهبود محسوس کیفیت می‌شود. 46 | 47 | --- 48 | 49 | ## شروع سریع 50 | 51 | ### نصب 52 | 53 | **⚠️ حتماً اسکریپت رو به‌صورت روت اجرا کنین:** 54 | 55 | ```bash 56 | bash <(curl -Ls https://raw.githubusercontent.com/mikeesierrah/frp-script/main/frp-setup.sh) 57 | ``` 58 | 59 | --- 60 | 61 | ## پیکربندی 62 | 63 | ### سرور 64 | 65 | فایل‌های سرور در مسیر `/root/frp/server/` با این الگو ذخیره می‌شن: 66 | 67 | ``` 68 | server-.toml 69 | ``` 70 | 71 | ### کلاینت 72 | 73 | فایل‌های کلاینت در مسیر `/root/frp/client/` با الگوی زیر: 74 | 75 | ``` 76 | client-.toml 77 | ``` 78 | 79 | ### مدیریت سرویس‌ها 80 | 81 | سرویس‌ها با systemd و با الگوی زیر ساخته می‌شن: 82 | 83 | * سرور: `frps@server-port` 84 | * کلاینت: `frpc@client-port` 85 | 86 | --- 87 | 88 | ## نمونه استفاده 89 | 90 | ### (ایران) راه‌اندازی سرور 91 | 92 | 1. اسکریپت رو اجرا کن و گزینه ۱ (نصب FRP) رو بزن 93 | 2. گزینه ۲ (راه‌اندازی سرور) رو انتخاب کن 94 | 3. پورت و توکن احراز هویت رو وارد کن 95 | 4. سرور به‌صورت خودکار اجرا می‌شه 96 | 97 | ### (خارج) راه‌اندازی کلاینت 98 | 99 | 1. مطمئن شو FRP نصب شده (گزینه ۱) 100 | 2. گزینه ۳ (راه‌اندازی کلاینت) رو بزن 101 | 3. مشخصات سرور و پورت‌های لوکال رو وارد کن 102 | 4. اتصال خودکار برقرار می‌شه 103 | 104 | ### مدیریت تنظیمات فعلی 105 | 106 | 1. گزینه ۴ (پیکربندی پیشرفته) رو بزن 107 | 2. انتخاب کن کلاینت یا سرور 108 | 3. فایل تنظیمات رو انتخاب و ویرایش کن 109 | 4. بعد از ویرایش، سرویس خودکار ری‌استارت می‌شه 110 | 111 | --- 112 | 113 | ## رفع مشکلات 114 | 115 | ### بررسی وضعیت سرویس‌ها 116 | 117 | ```bash 118 | # نمایش همه سرویس‌های FRP 119 | systemctl list-units | grep frp 120 | 121 | # وضعیت یه سرویس خاص 122 | systemctl status frps@server-7000 123 | systemctl status frpc@client-7000 124 | ``` 125 | 126 | ### مشاهده لاگ‌ها 127 | 128 | ```bash 129 | # لاگ سرور 130 | journalctl -u frps@server-7000 -f 131 | 132 | # لاگ کلاینت 133 | journalctl -u frpc@client-7000 -f 134 | ``` 135 | 136 | ### پیکربندی دستی 137 | 138 | فایل‌های پیکربندی در مسیر زیر ذخیره می‌شن: 139 | 140 | **سرور**: `root/frp/server/*.toml` 141 | 142 | **کلاینت**: `root/frp/client/*.toml` 143 | 144 | --- 145 | 146 | ## نکته مهم 147 | 148 | **این اسکریپت فقط امکانات پایه FRP رو برای سادگی فراهم می‌کنه.** 149 | 150 | FRP قابلیت‌های خیلی پیشرفته‌تری داره مثل: 151 | 152 | 🔄 **لودبالانسینگ برای پخش ترافیک** 153 | 154 | 🔀 **پورت مالتی پلکسینگ برای استفاده چند سرویس از یه پورت** 155 | 156 | 🌐**ارسال IP واقعی کاربر به سرور مناسب آیپی لیمیت** 157 | 158 | 📊 **محدودسازی پهنای باند هر پورت و پراکسی** 159 | 160 | 🎯 **مسیریابی با دامنه، مسیر و هدر** 161 | 162 | ⚡ **اتصال دائم و بهینه شده** 163 | 164 | 🛡️ **روش های احراز هویت متنوع** 165 | 166 | 📈 **داشبورد مانیتورینگ داخلی** 167 | 168 | 🔧 **سیستم افزونه ها برای گسترش قابلیت ها** 169 | 170 | --- 171 | 172 | **پس این اسکریپت چی رو پوشش میده؟** 173 | 174 | برای راه اندازی سریع و ساده، این اسکریپت فقط تنظیمات پایه و معقول FRP رو ایجاد می کنه و هدفش ستاپ سریع این هسته برای تست و بررسیه و این که راحت تر بتونید کانفیگ خودتون رو انجام بدید 175 | 176 | --- 177 | 178 | ## کاربران حرفه‌ای 179 | 180 | اگه نیازهای خاصی دارین مثل: 181 | 182 | * لود بالانس پیشرفته 183 | * احراز هویت سفارشی 184 | * دستکاری هدرها 185 | * کنترل ترافیک دقیق 186 | * چند کاربره بودن 187 | * اتصال افزونه‌ها 188 | 189 | **حتماً به مستندات رسمی مراجعه کنین:** 190 | [اینجا کلیک کنید](https://gofrp.org/en/docs/) 191 | 192 | و از طریق گزینه "پیکربندی پیشرفته" در همین اسکریپت فایل‌ها رو دستی ویرایش کنین. 193 | 194 | --- 195 | 196 | ## حمایت مالی 197 | 198 | اگه این اسکریپت به کارت اومد، و خواستی حمایتی کنی : 199 | 200 | 💝 **۵ دلار به یه نیازمند کمک کن** 201 | 202 | ☕ **از توسعه‌دهنده FRP تو گیت‌هاب حمایت کن**: [fatedier/frp](https://github.com/fatedier/frp) 203 | 204 | -------------------------------------------------------------------------------- /README-en.md: -------------------------------------------------------------------------------- 1 | 🌍 **Languages**: English | [فارسی](README.md) 2 | 3 | # Easy FRP 4 | 5 | A comprehensive bash script that simplifies the installation, configuration, and management of [FRP (Fast Reverse Proxy)](https://github.com/fatedier/frp) - a high-performance reverse proxy application focused on NAT penetration. 6 | 7 | This script automates the entire FRP setup process and provides an intuitive menu-driven interface for managing your FRP deployments. 8 | 9 | **Built for [FRP](https://github.com/fatedier/frp) by [fatedier](https://github.com/fatedier)** 10 | 11 | 📚 **Documentation:** [GoFRP Official Docs](https://gofrp.org/en/docs/) 12 | 13 | ## Features 14 | 15 | ✨ **One-Click Installation** - Automatically downloads and installs the latest FRP version 16 | 🖥️ **Interactive Setup** - Menu-driven configuration for both server and client 17 | ⚙️ **Advanced Configuration** - Browse, view, and edit existing configurations 18 | 🔧 **Service Management** - Start, stop, and manage systemd services 19 | 📊 **Status Monitoring** - View running services and configuration files 20 | 21 | **About RAM Usage :** 22 | 23 | You might notice 1–2 GB of RAM usage per 150 Mbps constant usage, depending on user activity and the number of active connections. This is completely expected and intentional. 24 | 25 | Unlike other projects that focus only on minimizing RAM usage, FRP prioritize proper connection context, handling, and buffer management. This design ensures your connection table doesn’t fill up, even under high load or when facing sudden drops. Poorly managed systems might leave behind 15,000+ orphaned connections just from a brief interruption — we've seen it happen. 26 | 27 | In contrast, FRP is built to handle drops and recover extremely fast (under 1 second in our tests). It's a well-thought-out system where connection handling takes precedence over saving a few hundred megabytes of RAM — because stability and performance matter far more. 28 | 29 | ## Quick Start 30 | 31 | ### Install 32 | 33 | **⚠️ Run the script as root** 34 | 35 | ```bash 36 | bash <(curl -Ls https://raw.githubusercontent.com/mikeesierrah/frp-script/main/frp-setup.sh) 37 | ``` 38 | 39 | ## Configuration 40 | 41 | ### Server Configuration 42 | Servers are configured in `/root/frp/server/` with the naming pattern: 43 | ``` 44 | server-.toml 45 | ``` 46 | 47 | ### Client Configuration 48 | Clients are configured in `/root/frp/client/` with the naming pattern: 49 | ``` 50 | client-.toml 51 | ``` 52 | 53 | ### Service Management 54 | Services follow systemd template naming: 55 | - Server services: `frps@server-` 56 | - Client services: `frpc@client-` 57 | 58 | ## Example Usage 59 | 60 | ### Basic Server Setup 61 | 1. Run the script and choose option 1 (Install FRP) 62 | 2. Choose option 2 (Setup FRP Server) 63 | 3. Configure your desired port and authentication token 64 | 4. Server will start automatically 65 | 66 | ### Basic Client Setup 67 | 1. Ensure FRP is installed (option 1) 68 | 2. Choose option 3 (Setup FRP Client) 69 | 3. Enter your server details and local ports to expose 70 | 4. Client will connect automatically 71 | 72 | ### Managing Existing Configurations 73 | 1. Choose option 4 (Advanced Configuration) 74 | 2. Select Server or Client configuration 75 | 3. Pick the configuration file to edit 76 | 4. Service will restart automatically after editing 77 | 78 | ## Troubleshooting 79 | 80 | ### Check Service Status 81 | ```bash 82 | # View all FRP services 83 | systemctl list-units | grep frp 84 | 85 | # Check specific service 86 | systemctl status frps@server-7000 87 | systemctl status frpc@client-7000 88 | ``` 89 | 90 | ### View Logs 91 | ```bash 92 | # Server logs 93 | journalctl -u frps@server-7000 -f 94 | 95 | # Client logs 96 | journalctl -u frpc@client-7000 -f 97 | ``` 98 | 99 | ### Manual Configuration 100 | Configuration files are located at: 101 | - **Server**: `/root/frp/server/*.toml` 102 | - **Client**: `/root/frp/client/*.toml` 103 | 104 | ## Important Note 105 | 106 | **This script implements only the basic functionality of FRP for simplicity and speed.** 107 | 108 | FRP is an incredibly powerful and feature-rich reverse proxy solution with extensive capabilities including: 109 | 110 | 🔄 **Load Balancing** - Distribute traffic across multiple backend servers 111 | 🔀 **Port Multiplexing** - Share single ports across multiple services 112 | 🌐 **Real IP Forwarding** - Pass client IP addresses via X-Forwarded-For headers (perfect for IP limiting) 113 | 📊 **Bandwidth Limiting** - Control traffic flow for each proxy 114 | 🎯 **Custom Routing** - Route based on domains, paths, and headers 115 | ⚡ **Connection Pooling** - Optimize performance with persistent connections 116 | 🛡️ **Authentication Methods** - Token, OIDC, and custom auth systems 117 | 📈 **Monitoring & Metrics** - Built-in dashboard and statistics 118 | 🔧 **Plugin System** - Extend functionality with custom plugins 119 | 120 | ### What This Script Covers 121 | 122 | For the sake of **simplicity and quick deployment**, this script maps sensible default values for basic FRP setups. The configurations generated here represent just the tip of the iceberg - **one of the simplest possible implementations** of what FRP can do. 123 | 124 | ### For Power Users 125 | 126 | If you're a power user with specific requirements such as: 127 | - Complex load balancing scenarios 128 | - Advanced authentication mechanisms 129 | - Custom header manipulation 130 | - Bandwidth controls and traffic shaping 131 | - Multi-tenant deployments 132 | - Plugin integrations 133 | 134 | **Please refer to the [official FRP documentation](https://gofrp.org/en/docs/)** and manually edit the generated configuration files using the "Advanced Configuration" option in this script. 135 | 136 | The purpose of this script is that it gets you started quickly with working configurations that you can then customize to unlock FRP's full potential. 137 | 138 | ## Contributing 139 | 140 | Found a bug or want to contribute? Feel free to: 141 | 1. Open an issue 142 | 2. Submit a pull request 143 | 3. Suggest improvements 144 | 145 | ## Donation 146 | 147 | If this script helped you, consider: 148 | - 💝 **Donating $5 to someone in need** - spread kindness! 149 | - ☕ **Supporting the FRP developers** at [fatedier/frp](https://github.com/fatedier/frp) 150 | 151 | ## License 152 | 153 | This script is provided as-is under the MIT License. FRP itself is licensed under the Apache License 2.0. 154 | 155 | **FRP Project**: https://github.com/fatedier/frp 156 | **FRP Documentation**: https://gofrp.org/en/docs/ 157 | **Original Author**: [fatedier](https://github.com/fatedier) 158 | 159 | 160 | -------------------------------------------------------------------------------- /frp-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Colors for output 5 | RED='\033[0;31m' 6 | GREEN='\033[0;32m' 7 | YELLOW='\033[1;33m' 8 | BLUE='\033[0;34m' 9 | NC='\033[0m' # No Color 10 | 11 | # Script installation path 12 | INSTALL_PATH="/usr/local/bin/frp-manager" 13 | SCRIPT_PATH="$(readlink -f "$0")" 14 | 15 | # Helper functions 16 | print_header() { 17 | echo -e "${BLUE}=================================${NC}" 18 | echo -e "${BLUE} FRP Management Tool ${NC}" 19 | echo -e "${BLUE}=================================${NC}" 20 | echo 21 | } 22 | 23 | print_success() { 24 | echo -e "${GREEN}[✓] $1${NC}" 25 | } 26 | 27 | print_info() { 28 | echo -e "${BLUE}[+] $1${NC}" 29 | } 30 | 31 | print_warning() { 32 | echo -e "${YELLOW}[!] $1${NC}" 33 | } 34 | 35 | print_error() { 36 | echo -e "${RED}[✗] $1${NC}" 37 | } 38 | 39 | # Cron for Garbage Collection / doesnt terminate process just triggers Garbage Collection and Ensuring BBR and FQ are Enabled 40 | optimize() { 41 | local -r cron_job="0 */3 * * * pkill -10 -x frpc; pkill -10 -x frps" 42 | local -r sysctl_conf="/etc/sysctl.conf" 43 | local -r bbr_module="/etc/modules-load.d/bbr.conf" 44 | 45 | # Ensure cron job exists (idempotent) 46 | sudo crontab -l 2>/dev/null | grep -Fq "${cron_job}" || { 47 | (sudo crontab -l 2>/dev/null; echo "${cron_job}") | sudo crontab - 48 | } 49 | 50 | # Configure BBR if not already optimal 51 | [[ "$(sysctl -n net.core.default_qdisc)" == "fq" && 52 | "$(sysctl -n net.ipv4.tcp_congestion_control)" == "bbr" ]] && return 53 | 54 | # Apply BBR configuration atomically 55 | { 56 | echo "net.core.default_qdisc=fq" 57 | echo "net.ipv4.tcp_congestion_control=bbr" 58 | } | sudo tee -a "${sysctl_conf}" >/dev/null 59 | 60 | echo "tcp_bbr" | sudo tee "${bbr_module}" >/dev/null 61 | 62 | sudo modprobe tcp_bbr 2>/dev/null || true 63 | sudo sysctl -p >/dev/null 64 | } 65 | 66 | # Reduce I/O by disabling rsyslog and making journald volatile 67 | reduce_io() { 68 | print_info "Reducing I/O by logging only to memory..." 69 | sudo systemctl disable --now rsyslog && sudo sed -i 's/^#Storage=.*/Storage=volatile/' /etc/systemd/journald.conf && sudo sed -i 's/^#SystemMaxUse=.*/SystemMaxUse=50M/' /etc/systemd/journald.conf && sudo sed -i 's/^#SystemKeepFree=.*/SystemKeepFree=5M/' /etc/systemd/journald.conf && sudo systemctl restart systemd-journald 70 | print_success "I/O reduced - logs are now stored in volatile memory." 71 | } 72 | 73 | # Remove all system logs 74 | remove_logs() { 75 | print_warning "This will permanently delete all system logs!" 76 | read -p "Are you sure you want to continue? (yes/no): " confirm 77 | 78 | if [[ "$confirm" != "yes" ]]; then 79 | print_info "Log removal cancelled." 80 | return 81 | fi 82 | 83 | print_info "Removing all system logs..." 84 | 85 | # Clear journal logs 86 | sudo journalctl --vacuum-time=1s 87 | 88 | # Remove log files in /var/log 89 | sudo find /var/log -type f -name "*.log" -exec truncate -s 0 {} \; 2>/dev/null 90 | sudo find /var/log -type f -name "*.log.*" -delete 2>/dev/null 91 | 92 | # Remove other common log locations 93 | sudo find /var/log -type f \( -name "*.gz" -o -name "*.1" -o -name "*.2" -o -name "*.3" -o -name "*.4" -o -name "*.5" -o -name "*.6" -o -name "*.7" -o -name "*.8" -o -name "*.9" \) -delete 2>/dev/null 94 | 95 | # Clear wtmp and btmp logs 96 | sudo truncate -s 0 /var/log/wtmp 2>/dev/null 97 | sudo truncate -s 0 /var/log/btmp 2>/dev/null 98 | 99 | print_success "All system logs have been removed." 100 | } 101 | 102 | # Utilities menu 103 | utilities_menu() { 104 | while true; do 105 | clear 106 | print_header 107 | echo "FRP Manager Utilities" 108 | echo "---------------------" 109 | echo 110 | echo "1) Optimize System (BBR, FQ)" 111 | echo "2) OS logs Only In Memory (Reduce disk I/O)" 112 | echo "3) Remove All System logs (Clears Storage)" 113 | echo "4) Back to Main Menu" 114 | echo 115 | 116 | read -p "Choose an option [1-4]: " util_choice 117 | echo 118 | 119 | case $util_choice in 120 | 1) 121 | optimize 122 | print_success "System optimization completed." 123 | read -p "Press Enter to continue..." 124 | ;; 125 | 2) 126 | reduce_io 127 | read -p "Press Enter to continue..." 128 | ;; 129 | 3) 130 | remove_logs 131 | read -p "Press Enter to continue..." 132 | ;; 133 | 4) 134 | return 135 | ;; 136 | *) 137 | print_error "Invalid option. Please choose 1-4." 138 | read -p "Press Enter to continue..." 139 | ;; 140 | esac 141 | done 142 | } 143 | 144 | # Self-install the script as a command 145 | install_script() { 146 | if [[ "$SCRIPT_PATH" == "$INSTALL_PATH" ]]; then 147 | print_info "Script is already installed as frp-manager command." 148 | return 149 | fi 150 | 151 | print_info "Installing script as frp-manager command..." 152 | curl -L https://raw.githubusercontent.com/mikeesierrah/frp-script/main/frp-setup.sh -o "$INSTALL_PATH" 153 | sudo chmod +x "$INSTALL_PATH" 154 | 155 | # Comment out the call to install_script in the installed version 156 | sed -i 's/^install_script$/# install_script/' "$INSTALL_PATH" 157 | 158 | # Comment out the call to optimize in the installed version 159 | sed -i 's/^optimize$/# optimize/' "$INSTALL_PATH" 160 | 161 | print_success "Script installed as frp-manager. You can now run it by typing 'frp-manager' in terminal." 162 | } 163 | 164 | # Force installation as frp-manager command 165 | install_script 166 | 167 | # Install FRP 168 | install_frp() { 169 | print_info "Starting FRP installation..." 170 | 171 | # Detect platform 172 | arch=$(uname -m) 173 | case "$arch" in 174 | x86_64) arch="amd64" ;; 175 | aarch64) arch="arm64" ;; 176 | armv7l|armv6l) arch="arm" ;; 177 | *) print_error "Unsupported arch: $arch"; exit 1 ;; 178 | esac 179 | 180 | os=$(uname -s | tr '[:upper:]' '[:lower:]') 181 | platform="${os}_${arch}" 182 | 183 | # Get latest version 184 | print_info "Fetching latest FRP version..." 185 | version=$(curl -s https://api.github.com/repos/fatedier/frp/releases/latest | grep tag_name | cut -d '"' -f4 | sed 's/v//') 186 | url="https://github.com/fatedier/frp/releases/download/v${version}/frp_${version}_${platform}.tar.gz" 187 | 188 | print_info "Downloading $url" 189 | curl -L "$url" -o "/tmp/frp.tar.gz" 190 | 191 | print_info "Extracting..." 192 | tar -xzf /tmp/frp.tar.gz -C /tmp 193 | 194 | print_info "Installing frpc and frps..." 195 | cp /tmp/frp_${version}_${platform}/frpc /usr/local/bin/ 196 | cp /tmp/frp_${version}_${platform}/frps /usr/local/bin/ 197 | chmod +x /usr/local/bin/frpc /usr/local/bin/frps 198 | 199 | print_info "Creating config folders..." 200 | mkdir -p /root/frp/server 201 | mkdir -p /root/frp/client 202 | 203 | print_info "Writing frps@.service..." 204 | cat > /etc/systemd/system/frps@.service < /etc/systemd/system/frpc@.service < "$config" 306 | 307 | print_info "Enabling and starting frps@server-$bindPort..." 308 | systemctl enable --now frps@server-$bindPort 309 | 310 | print_success "Server setup complete." 311 | } 312 | 313 | # Setup FRP Client 314 | setup_client() { 315 | print_info "FRP Client Setup" 316 | 317 | read -p "Server IP (v4 or v6): " server_ip 318 | 319 | read -p "Server port [7000]: " server_port 320 | server_port=${server_port:-7000} 321 | 322 | read -p "Auth token [mikeesierrah]: " auth_token 323 | auth_token=${auth_token:-mikeesierrah} 324 | 325 | echo "Choose transport protocol:" 326 | echo "1) tcp" 327 | echo "2) websocket" 328 | echo "3) quic" 329 | echo "4) kcp" 330 | read -p "Option [1]: " transport_option 331 | case $transport_option in 332 | 2) transport="websocket" ;; 333 | 3) transport="quic" ;; 334 | 4) transport="kcp" ;; 335 | 1|"") transport="tcp" ;; 336 | *) transport="tcp" ;; 337 | esac 338 | 339 | read -p "Enable TCP Mux (y/n) [n]: " use_mux 340 | use_mux=${use_mux:-n} 341 | 342 | read -p "Local ports to expose (e.g. 22,6000-6006,6007): " port_input 343 | 344 | config_name="client-$server_port.toml" 345 | mkdir -p /root/frp/client/ 346 | 347 | cat > "/root/frp/client/$config_name" </dev/null)" ]]; then 400 | print_warning "No server configurations found in /root/frp/server/" 401 | return 402 | fi 403 | 404 | print_info "Available server configurations:" 405 | echo 406 | configs=($(ls /root/frp/server/*.toml 2>/dev/null | xargs -n1 basename)) 407 | for i in "${!configs[@]}"; do 408 | echo "$((i+1))) ${configs[$i]}" 409 | done 410 | echo "$((${#configs[@]}+1))) Back" 411 | echo 412 | 413 | read -p "Select configuration to edit [1-$((${#configs[@]}+1))]: " server_choice 414 | 415 | if [[ $server_choice -eq $((${#configs[@]}+1)) ]]; then 416 | return 417 | elif [[ $server_choice -ge 1 && $server_choice -le ${#configs[@]} ]]; then 418 | selected_config="${configs[$((server_choice-1))]}" 419 | config_path="/root/frp/server/$selected_config" 420 | 421 | print_info "Current configuration ($selected_config):" 422 | echo "----------------------------------------" 423 | cat "$config_path" 424 | echo "----------------------------------------" 425 | echo 426 | 427 | read -p "Edit this file? (y/n) [n]: " edit_choice 428 | if [[ "$edit_choice" =~ ^[Yy]$ ]]; then 429 | ${EDITOR:-nano} "$config_path" 430 | 431 | # Restart service if it's running 432 | service_name="${selected_config%.toml}" 433 | if systemctl is-active --quiet "frps@$service_name"; then 434 | print_info "Restarting service frps@$service_name..." 435 | systemctl restart "frps@$service_name" 436 | print_success "Service restarted." 437 | fi 438 | fi 439 | fi 440 | ;; 441 | 2) 442 | if [[ ! -d "/root/frp/client" ]] || [[ -z "$(ls -A /root/frp/client/ 2>/dev/null)" ]]; then 443 | print_warning "No client configurations found in /root/frp/client/" 444 | return 445 | fi 446 | 447 | print_info "Available client configurations:" 448 | echo 449 | configs=($(ls /root/frp/client/*.toml 2>/dev/null | xargs -n1 basename)) 450 | for i in "${!configs[@]}"; do 451 | echo "$((i+1))) ${configs[$i]}" 452 | done 453 | echo "$((${#configs[@]}+1))) Back" 454 | echo 455 | 456 | read -p "Select configuration to edit [1-$((${#configs[@]}+1))]: " client_choice 457 | 458 | if [[ $client_choice -eq $((${#configs[@]}+1)) ]]; then 459 | return 460 | elif [[ $client_choice -ge 1 && $client_choice -le ${#configs[@]} ]]; then 461 | selected_config="${configs[$((client_choice-1))]}" 462 | config_path="/root/frp/client/$selected_config" 463 | 464 | print_info "Current configuration ($selected_config):" 465 | echo "----------------------------------------" 466 | cat "$config_path" 467 | echo "----------------------------------------" 468 | echo 469 | 470 | read -p "Edit this file? (y/n) [n]: " edit_choice 471 | if [[ "$edit_choice" =~ ^[Yy]$ ]]; then 472 | ${EDITOR:-nano} "$config_path" 473 | 474 | # Restart service if it's running 475 | service_name="${selected_config%.toml}" 476 | if systemctl is-active --quiet "frpc@$service_name"; then 477 | print_info "Restarting service frpc@$service_name..." 478 | systemctl restart "frpc@$service_name" 479 | print_success "Service restarted." 480 | fi 481 | fi 482 | fi 483 | ;; 484 | 3) 485 | return 486 | ;; 487 | *) 488 | print_error "Invalid option" 489 | ;; 490 | esac 491 | } 492 | 493 | # Stop services 494 | stop_services() { 495 | print_info "Stopping FRP services..." 496 | 497 | # Stop all running frps services 498 | running_servers=$(systemctl list-units --type=service --state=running | grep "frps@" | awk '{print $1}' || true) 499 | if [[ -n "$running_servers" ]]; then 500 | print_info "Stopping server services..." 501 | for service in $running_servers; do 502 | print_info "Stopping $service..." 503 | systemctl stop "$service" 504 | done 505 | fi 506 | 507 | # Stop all running frpc services 508 | running_clients=$(systemctl list-units --type=service --state=running | grep "frpc@" | awk '{print $1}' || true) 509 | if [[ -n "$running_clients" ]]; then 510 | print_info "Stopping client services..." 511 | for service in $running_clients; do 512 | print_info "Stopping $service..." 513 | systemctl stop "$service" 514 | done 515 | fi 516 | 517 | print_success "All FRP services stopped." 518 | } 519 | 520 | # Remove FRP completely 521 | remove_frp() { 522 | print_warning "This will completely remove FRP and all configurations!" 523 | read -p "Are you sure? (yes/no): " confirm 524 | 525 | if [[ "$confirm" != "yes" ]]; then 526 | print_info "Removal cancelled." 527 | return 528 | fi 529 | 530 | print_info "Stopping all FRP services..." 531 | stop_services 532 | 533 | print_info "Disabling and removing services..." 534 | # Disable and remove all frp services 535 | enabled_servers=$(systemctl list-unit-files | grep "frps@" | awk '{print $1}' || true) 536 | for service in $enabled_servers; do 537 | systemctl disable "$service" 2>/dev/null || true 538 | done 539 | 540 | enabled_clients=$(systemctl list-unit-files | grep "frpc@" | awk '{print $1}' || true) 541 | for service in $enabled_clients; do 542 | systemctl disable "$service" 2>/dev/null || true 543 | done 544 | 545 | print_info "Removing service files..." 546 | rm -f /etc/systemd/system/frps@.service 547 | rm -f /etc/systemd/system/frpc@.service 548 | 549 | print_info "Removing binaries..." 550 | rm -f /usr/local/bin/frpc 551 | rm -f /usr/local/bin/frps 552 | 553 | print_info "Removing configuration directories..." 554 | rm -rf /root/frp/ 555 | 556 | print_info "Reloading systemd..." 557 | systemctl daemon-reload 558 | 559 | print_success "FRP completely removed from system." 560 | } 561 | 562 | # Show service status 563 | show_status() { 564 | print_info "FRP Service Status" 565 | echo 566 | 567 | # Check if binaries exist 568 | if [[ ! -f "/usr/local/bin/frpc" ]] || [[ ! -f "/usr/local/bin/frps" ]]; then 569 | print_warning "FRP is not installed." 570 | return 571 | fi 572 | 573 | print_info "Installed FRP version:" 574 | /usr/local/bin/frps --version 2>/dev/null || echo "Unable to determine version" 575 | echo 576 | 577 | print_info "Running services:" 578 | systemctl list-units --type=service --state=running | grep -E "frp[sc]@" || echo "No FRP services running" 579 | echo 580 | 581 | print_info "Enabled services:" 582 | systemctl list-unit-files | grep -E "frp[sc]@.*enabled" || echo "No FRP services enabled" 583 | echo 584 | 585 | print_info "Configuration files:" 586 | echo "Server configs:" 587 | ls -la /root/frp/server/ 2>/dev/null || echo " No server configs found" 588 | echo "Client configs:" 589 | ls -la /root/frp/client/ 2>/dev/null || echo " No client configs found" 590 | } 591 | 592 | # Main menu 593 | main_menu() { 594 | while true; do 595 | clear 596 | print_header 597 | 598 | echo "1) Install FRP" 599 | echo "2) Setup FRP Server" 600 | echo "3) Setup FRP Client" 601 | echo "4) Advanced Configuration" 602 | echo "5) Show Status" 603 | echo "6) Stop All Services" 604 | echo "7) Optimization Utilities" 605 | echo "8) Remove FRP" 606 | echo "9) Exit" 607 | echo 608 | 609 | read -p "Choose an option [1-9]: " choice 610 | echo 611 | 612 | case $choice in 613 | 1) 614 | install_frp 615 | read -p "Press Enter to continue..." 616 | ;; 617 | 2) 618 | setup_server 619 | read -p "Press Enter to continue..." 620 | ;; 621 | 3) 622 | setup_client 623 | read -p "Press Enter to continue..." 624 | ;; 625 | 4) 626 | advanced_config 627 | read -p "Press Enter to continue..." 628 | ;; 629 | 5) 630 | show_status 631 | read -p "Press Enter to continue..." 632 | ;; 633 | 6) 634 | stop_services 635 | read -p "Press Enter to continue..." 636 | ;; 637 | 7) 638 | utilities_menu 639 | ;; 640 | 8) 641 | remove_frp 642 | read -p "Press Enter to continue..." 643 | ;; 644 | 9) 645 | print_success "Goodbye!" 646 | exit 0 647 | ;; 648 | *) 649 | print_error "Invalid option. Please choose 1-9." 650 | read -p "Press Enter to continue..." 651 | ;; 652 | esac 653 | done 654 | } 655 | 656 | # Check if running as root 657 | if [[ $EUID -ne 0 ]]; then 658 | print_error "This script must be run as root (use sudo)" 659 | exit 1 660 | fi 661 | 662 | # Ensure optimization 663 | optimize 664 | # Start the main menu 665 | main_menu 666 | --------------------------------------------------------------------------------