Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #106

Merged
merged 8 commits into from
Jun 16, 2024
Merged

Dev #106

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,14 @@ Usage: /etc/init.d/frps {start|stop|restart|status|config|version}
kcp_bind_port --> kcpBindPort
etc..
```

### [1.0.3] - 2024-06-16

#### Amendment
* Amend function name to frps

#### Changed
* Change curl common to get server ip from wget common



66 changes: 66 additions & 0 deletions generate-certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# 创建证书存放目录
mkdir -p /etc/pki/tls/frp/ca
mkdir -p /etc/pki/tls/frp/frps
mkdir -p /etc/pki/tls/frp/frpc

# 创建 OpenSSL 配置文件
cat > /etc/pki/tls/frp/my-openssl.cnf << EOF
[ ca ]
default_ca = CA_default
[ CA_default ]
x509_extensions = usr_cert
[ req ]
default_bits = 2048
default_md = sha256
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca
string_mask = utf8only
[ req_distinguished_name ]
[ req_attributes ]
[ usr_cert ]
basicConstraints = CA:FALSE
nsComment = "OpenSSL Generated Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = CA:true
EOF

# 生成默认 CA
echo "====> Generating CA key and certificate"
openssl genrsa -out /etc/pki/tls/frp/ca/ca.key 2048
openssl req -x509 -new -nodes -key /etc/pki/tls/frp/ca/ca.key -subj "/CN=example.ca.com" -days 5000 -out /etc/pki/tls/frp/ca/ca.crt

# 生成服务器证书
echo "====> Generating server key and certificate"
openssl genrsa -out /etc/pki/tls/frp/frps/server.key 2048
openssl req -new -sha256 -key /etc/pki/tls/frp/frps/server.key \
-subj "/C=XX/ST=DEFAULT/L=DEFAULT/O=DEFAULT/CN=server.com" \
-reqexts SAN \
-config <(cat /etc/pki/tls/frp/my-openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:localhost,IP:${defIP}")) \
-out /etc/pki/tls/frp/frps/server.csr
openssl x509 -req -days 365 -sha256 \
-in /etc/pki/tls/frp/frps/server.csr -CA /etc/pki/tls/frp/ca/ca.crt -CAkey /etc/pki/tls/frp/ca/ca.key -CAcreateserial \
-extfile <(printf "subjectAltName=DNS:localhost,IP:${defIP}") \
-out /etc/pki/tls/frp/frps/server.crt

# 生成客户端证书
echo "====> Generating client key and certificate"
openssl genrsa -out /etc/pki/tls/frp/frpc/client.key 2048
openssl req -new -sha256 -key /etc/pki/tls/frp/frpc/client.key \
-subj "/C=XX/ST=DEFAULT/L=DEFAULT/O=DEFAULT/CN=client.com" \
-reqexts SAN \
-config <(cat /etc/pki/tls/frp/my-openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:localhost"))\
-out /etc/pki/tls/frp/frpc/client.csr
openssl x509 -req -days 365 -sha256 \
-in /etc/pki/tls/frp/frpc/client.csr -CA /etc/pki/tls/frp/ca/ca.crt -CAkey /etc/pki/tls/frp/ca/ca.key -CAcreateserial \
-extfile <(printf "subjectAltName=DNS:localhost") \
-out /etc/pki/tls/frp/frpc/client.crt

echo "Certificate generation completed."
50 changes: 25 additions & 25 deletions install-frps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export github_latest_version_api="https://api.github.com/repos/fatedier/frp/rele

# Program information
program_name="frps"
version="1.0.2"
version="1.0.3"
str_program_dir="/usr/local/${program_name}"
program_init="/etc/init.d/${program_name}"
program_config_file="frps.toml"
Expand All @@ -25,7 +25,7 @@ str_install_shell="https://raw.githubusercontent.com/Mvscode/frps-onekey/master/
# Function to check for shell updates
shell_update() {
# Clear the terminal
fun_clangcn "clear"
fun_frps "clear"

# Echo a message to indicate that we're checking for shell updates
echo "Checking for shell updates..."
Expand Down Expand Up @@ -55,15 +55,15 @@ shell_update() {
echo -e " [${COLOR_GREEN}OK${COLOR_END}]"
echo
# Echo a message to instruct the user to re-run the script
echo -e "${COLOR_GREEN}Please re-run${COLOR_END} ${COLOR_PINK}$0 ${clang_action}${COLOR_END}"
echo -e "${COLOR_GREEN}Please re-run${COLOR_END} ${COLOR_PINK}$0 ${frps_action}${COLOR_END}"
echo
exit 1
fi
exit 1
fi
fi
}
fun_clangcn(){
fun_frps(){
local clear_flag=""
clear_flag=$1
if [[ ${clear_flag} == "clear" ]]; then
Expand All @@ -89,7 +89,7 @@ fun_set_text_color(){
# Check if user is root
rootness(){
if [[ $EUID -ne 0 ]]; then
fun_clangcn
fun_frps
echo "Error:This script must be run as root!" 1>&2
exit 1
fi
Expand Down Expand Up @@ -385,19 +385,19 @@ fun_input_subdomain_host(){
[ -z "${input_subdomain_host}" ] && input_subdomain_host="${def_subdomain_host}"
}

pre_install_clang(){
fun_clangcn
pre_install_frps(){
fun_frps
echo -e "Check your server setting, please wait..."
disable_selinux
if [ -s ${str_program_dir}/${program_name} ] && [ -s ${program_init} ]; then
echo "${program_name} is installed!"
else
clear
fun_clangcn
fun_frps
fun_getServer
fun_getVer
echo -e "Loading You Server IP, please wait..."
defIP=$(wget -qO- ip.clang.cn | sed -r 's/\r//')
defIP=$(curl -s https://api.ipify.org)
echo -e "You Server IP:${COLOR_GREEN}${defIP}${COLOR_END}"
echo -e "————————————————————————————————————————————"
echo -e " ${COLOR_RED}Please input your server setting:${COLOR_END}"
Expand Down Expand Up @@ -559,11 +559,11 @@ pre_install_clang(){
echo "Press any key to start...or Press Ctrl+c to cancel"

char=`get_char`
install_program_server_clang
install_program_server_frps
fi
}
# ====== install server ======
install_program_server_clang(){
install_program_server_frps(){
[ ! -d ${str_program_dir} ] && mkdir -p ${str_program_dir}
cd ${str_program_dir}
echo "${program_name} install path:$PWD"
Expand Down Expand Up @@ -870,7 +870,7 @@ fi
echo " done"
[ -s ${program_init} ] && ln -s ${program_init} /usr/bin/${program_name}
${program_init} start
fun_clangcn
fun_frps
#install successfully
echo ""
echo "Congratulations, ${program_name} install completed!"
Expand Down Expand Up @@ -902,7 +902,7 @@ fi
exit 0
}
############################### configure ##################################
configure_program_server_clang(){
configure_program_server_frps(){
if [ -s ${str_program_dir}/${program_config_file} ]; then
vi ${str_program_dir}/${program_config_file}
else
Expand All @@ -911,8 +911,8 @@ configure_program_server_clang(){
fi
}
############################### uninstall ##################################
uninstall_program_server_clang(){
fun_clangcn
uninstall_program_server_frps(){
fun_frps
if [ -s ${program_init} ] || [ -s ${str_program_dir}/${program_name} ] ; then
echo "============== Uninstall ${program_name} =============="
str_uninstall="n"
Expand Down Expand Up @@ -945,7 +945,7 @@ uninstall_program_server_clang(){
exit 0
}
############################### update ##################################
update_config_clang(){
update_config_frps(){
if [ ! -r "${str_program_dir}/${program_config_file}" ]; then
echo "config file ${str_program_dir}/${program_config_file} not found."
else
Expand Down Expand Up @@ -1043,12 +1043,12 @@ update_config_clang(){
fi
fi
}
update_program_server_clang() {
fun_clangcn "clear"
update_program_server_frps() {
fun_frps "clear"

if [ -s "$program_init" ] || [ -s "$str_program_dir/$program_name" ]; then
echo "============== Update $program_name =============="
update_config_clang
update_config_frps
checkos
check_centosversion
check_os_bit
Expand Down Expand Up @@ -1120,26 +1120,26 @@ shell_update
# Initialization
action=$1
if [ -z "$action" ]; then
fun_clangcn
fun_frps
echo "Arguments error! [$action ]"
echo "Usage: $(basename "$0") {install|uninstall|update|config}"
RET_VAL=1
else
case "$action" in
install)
pre_install_clang 2>&1 | tee /root/${program_name}-install.log
pre_install_frps 2>&1 | tee /root/${program_name}-install.log
;;
config)
configure_program_server_clang
configure_program_server_frps
;;
uninstall)
uninstall_program_server_clang 2>&1 | tee /root/${program_name}-uninstall.log
uninstall_program_server_frps 2>&1 | tee /root/${program_name}-uninstall.log
;;
update)
update_program_server_clang 2>&1 | tee /root/${program_name}-update.log
update_program_server_frps 2>&1 | tee /root/${program_name}-update.log
;;
*)
fun_clangcn
fun_frps
echo "Arguments error! [$action ]"
echo "Usage: $(basename "$0") {install|uninstall|update|config}"
RET_VAL=1
Expand Down