mirror of
https://github.com/QSCTech/zjunet.git
synced 2026-01-22 11:44:48 +08:00
Compare commits
101 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff6ed1ab75 | ||
|
|
89810b80c9 | ||
|
|
7bd9e67936 | ||
|
|
cfd6c16f60 | ||
|
|
9b7f791fd4 | ||
|
|
0e5b349cfb | ||
|
|
e46b04691a | ||
| 51240ecc87 | |||
|
|
d601644df2 | ||
|
|
9b02ca93eb | ||
|
|
426663b9c1 | ||
|
|
51ae7a6ceb | ||
|
|
3316d0fa01 | ||
|
|
2bfab862d5 | ||
|
|
0b789525d1 | ||
|
|
e59b4d96db | ||
|
|
acf3e2a1e2 | ||
|
|
18f55d6120 | ||
|
|
195210365e | ||
|
|
e531ed2f97 | ||
|
|
f8ca63933e | ||
|
|
a587c43bd1 | ||
|
|
731be425a6 | ||
|
|
6c635487a2 | ||
|
|
fce9e2a69d | ||
|
|
fc48eff092 | ||
|
|
887de1b822 | ||
|
|
701a17a1e2 | ||
|
|
2fa9b0a1e8 | ||
|
|
f179d6817f | ||
|
|
d8c9413580 | ||
|
|
b446175d51 | ||
|
|
c44a4105d4 | ||
|
|
a294ecaed0 | ||
|
|
69a1633e8a | ||
|
|
17d91a4157 | ||
|
|
9c4ca315ce | ||
|
|
6747ef8c4a | ||
|
|
d5bf090f4b | ||
|
|
8f0095c8fe | ||
|
|
2576d68dd0 | ||
|
|
c3f67f4692 | ||
|
|
6e3ee5d8bb | ||
|
|
dad2e3ecd5 | ||
|
|
f10b11227e | ||
|
|
781f6d53bd | ||
|
|
4ddf258160 | ||
|
|
3b55503c9e | ||
|
|
a71c73f0b6 | ||
|
|
2b2a115530 | ||
|
|
c904e7b4e9 | ||
|
|
5a4a9dd447 | ||
|
|
88eb1ae76a | ||
|
|
1f164325e9 | ||
|
|
b00e7eb0cc | ||
|
|
874aa34ddd | ||
|
|
9754ff1d66 | ||
|
|
0a0d021e5f | ||
|
|
c0ed2005bd | ||
|
|
dba5a57ac0 | ||
|
|
2e6992d954 | ||
|
|
2fa0536743 | ||
|
|
794113d7f2 | ||
|
|
29ae0561f3 | ||
|
|
f7d70fc5dd | ||
|
|
e00192add6 | ||
|
|
0a1fc71944 | ||
|
|
eac29e8bc4 | ||
|
|
371fa9323a | ||
|
|
bd13094e67 | ||
|
|
0ba55b0593 | ||
|
|
ea2e77a4f9 | ||
|
|
1d189dee13 | ||
|
|
a4b4e82907 | ||
|
|
fbbdec2ced | ||
|
|
6c9f18e4ec | ||
|
|
92e4f60ea2 | ||
|
|
818d8fed52 | ||
|
|
e8eb8c1530 | ||
|
|
a423aba8f1 | ||
|
|
03836b3a97 | ||
|
|
1e84afc66e | ||
|
|
70af9fc900 | ||
|
|
3daa7163e9 | ||
|
|
1ede8b984f | ||
|
|
e9f1d1598b | ||
|
|
52befaea3f | ||
|
|
687fb73e41 | ||
|
|
533f6fb82a | ||
|
|
5e28d08fcf | ||
|
|
6a58107239 | ||
|
|
257a06a5d1 | ||
|
|
e423f6a6f8 | ||
|
|
5c387ad192 | ||
|
|
8b6cfbf6b2 | ||
|
|
e1c3bf4375 | ||
|
|
e42e7f7a3a | ||
|
|
088248ed5c | ||
|
|
0d30f95dec | ||
|
|
e77bb0dcd3 | ||
|
|
db137857de |
32
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
32
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a bug report to help us locate problems
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
## Environment
|
||||
Please complete the following information:
|
||||
- **OS:** [OS name and version, e.g. Ubuntu 20.10, CentOS 8]
|
||||
- **zjunet:** [output of `zjunet -v`, e.g. 0.3.3-3]
|
||||
- **xl2tpd:** [output of `xl2tpd -v`, e.g. 1.3.16]
|
||||
- **network type:** [wired or wireless or ...]
|
||||
- other softwares or the network condition that may related to this bug
|
||||
|
||||
## Bug description
|
||||
A clear and concise description of what the bug is and how to reproduce it.
|
||||
|
||||
## Output
|
||||
|
||||
Full output of command line tools.
|
||||
|
||||
If applicable, add screenshots to help explain the problem.
|
||||
|
||||
```
|
||||
[user@host ~]# zjunet XXXX
|
||||
...
|
||||
```
|
||||
|
||||
## Notes
|
||||
Add other information that may related to this bug.
|
||||
14
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
14
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest a new idea for this project
|
||||
title: ''
|
||||
labels: feature
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
## Description
|
||||
A brief explanation of the feature.
|
||||
|
||||
## Motivation
|
||||
Why such feature is worthy? What use cases does it support?
|
||||
|
||||
38
.github/workflows/packaging.yml
vendored
Normal file
38
.github/workflows/packaging.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# This workflow build packages for release
|
||||
|
||||
name: Packaging
|
||||
|
||||
# Controls when the action will run. Triggers the workflow when releases created or modified
|
||||
on:
|
||||
create:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '^3.7' # request python 3.7+ for datetime.datetime.fromisoformat
|
||||
|
||||
- name: Build Packages
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install urllib3
|
||||
cd build
|
||||
./build.sh
|
||||
|
||||
- name: Archive Packages
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Release Packages
|
||||
path: |
|
||||
build/debian/zjunet_*.deb
|
||||
build/rpm/zjunet-*.rpm
|
||||
build/openwrt/zjunet_*.opk
|
||||
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,2 +1,13 @@
|
||||
|
||||
# Packages
|
||||
*.deb
|
||||
*.opk
|
||||
*.rpm
|
||||
|
||||
# Rubbish
|
||||
*.swp
|
||||
|
||||
build/debian/debian
|
||||
build/rpm/zjunet-*
|
||||
build/rpm/zjunet.spec
|
||||
build/openwrt/debian
|
||||
|
||||
23
.gitlab-ci.yml
Normal file
23
.gitlab-ci.yml
Normal file
@ -0,0 +1,23 @@
|
||||
image: ubuntu:jammy
|
||||
|
||||
stages:
|
||||
- build
|
||||
|
||||
compile:
|
||||
stage: build
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- sed -i 's|http.*.ubuntu.com|http://mirrors.zju.edu.cn|' /etc/apt/sources.list
|
||||
- apt-get update && apt-get -y --no-install-recommends install ca-certificates build-essential fakeroot git dpkg-dev rpm python3 python-is-python3 python3-urllib3
|
||||
- mkdir artifacts
|
||||
- pushd build
|
||||
- ./build.sh
|
||||
- popd
|
||||
- cp build/debian/*.deb artifacts/
|
||||
- cp build/openwrt/*.opk artifacts/
|
||||
- cp build/rpm/*.rpm artifacts/
|
||||
artifacts:
|
||||
paths:
|
||||
- /artifacts
|
||||
|
||||
129
README.md
129
README.md
@ -1,5 +1,7 @@
|
||||
# zjunet
|
||||
|
||||
[查看中文README](README.zh.md)
|
||||
|
||||
Command Line Scripts for ZJU (VPN / WLAN / DNS)
|
||||
|
||||
## Features
|
||||
@ -8,91 +10,140 @@ Command Line Scripts for ZJU (VPN / WLAN / DNS)
|
||||
|
||||
- ZJUWLAN
|
||||
|
||||
- 路由器支持(written in Bourne Shell)
|
||||
- Router support
|
||||
|
||||
- 多拨支持(多账户负载均衡)
|
||||
- Overlap network dialing (with load balance)
|
||||
|
||||
- ZJUWLAN 与 ZJUVPN 带宽叠加(1 WLAN + N VPN,在 ZJUWLAN 下)
|
||||
- Overlap bandwidth of ZJUWLAN and ZJU VPN (1 WLAN + N VPN, Using ZJUWLAN)
|
||||
|
||||
- DNS 自动测试设置(适用于 DNS 坏掉的情况)
|
||||
- Automatic DNS setting (in case DNS do not work)
|
||||
|
||||
## Requirements
|
||||
|
||||
- xl2tpd
|
||||
|
||||
- curl
|
||||
- `dig` (Different package on different platform)
|
||||
|
||||
## Install
|
||||
## Installation
|
||||
|
||||
### Debian / Ubuntu
|
||||
If you meet any problem during or after the installation, check Troubleshooting section below in this documentation.
|
||||
|
||||
https://github.com/QSCTech/zjunet/releases
|
||||
下载 deb,双击安装就是。
|
||||
### Debian / Ubuntu (deb)
|
||||
|
||||
### Openwrt
|
||||
|
||||
https://github.com/QSCTech/zjunet/releases
|
||||
下载 opk,然后 `opkg install` 就是。
|
||||
|
||||
### From source
|
||||
|
||||
一般来说 master 分支是稳定的,dev 分支会有破坏性变更。
|
||||
1. Configure ZJU mirrors from manual. [Ubuntu](https://mirror.zju.edu.cn/docs/ubuntu/)/[Debian](https://mirror.zju.edu.cn/docs/debian/)
|
||||
2. Run these command.
|
||||
|
||||
``` bash
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjumirrors.pgp | sudo tee /etc/apt/trusted.gpg.d/zjumirrors.asc
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjunet.list | sudo tee /etc/apt/sources.list.d/zjunet.list
|
||||
sudo apt-get update
|
||||
sudo apt-get install zjunet
|
||||
```
|
||||
|
||||
3. The installation has completed.
|
||||
4. If you are setting up a server, we suggest you run `zjunet wlan disable` to disable WLAN capability.
|
||||
|
||||
### Fedora / CentOS (rpm)
|
||||
|
||||
1. Configure ZJU mirrors from manual. [Fedora](https://mirror.zju.edu.cn/docs/fedora/)/[CentOS](https://mirror.zju.edu.cn/docs/centos/)
|
||||
2. Configure [EPEL of ZJU mirrors](https://mirrors.zju.edu.cn/epel/) (Taking CentOS installation as an example)
|
||||
1. Run `yum install epel-release` to install EPEL.
|
||||
2. Edit `/etc/yum.repos.d/epel.repo` , uncomment lines begin with `#baseurl=` (Remove leading `#` sign) and comment lines begin with `mirrorlist=` (Prepend `#` sign)
|
||||
3. Edit `/etc/yum.repos.d/epel.repo` , replace `https://download.fedoraproject.org/pub` with `https://mirrors.zju.edu.cn` .
|
||||
|
||||
3. Run these command.
|
||||
|
||||
```bash
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjumirrors.pgp | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-ZJUMIRRORS
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjunet.repo | sudo tee /etc/yum.repos.d/zjunet.repo
|
||||
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZJUMIRRORS
|
||||
sudo yum install zjunet
|
||||
```
|
||||
|
||||
4. The installation has completed.
|
||||
5. If you are setting up a server, we suggest you run `zjunet wlan disable` to disable WLAN capability.
|
||||
|
||||
### OpenWrt (opk)
|
||||
|
||||
Download .opk package from [Release Page](https://github.com/QSCTech/zjunet/releases) (onto your router),
|
||||
Run `opkg install ./zjunet_<version>_all.opk`.
|
||||
|
||||
### Arch Linux (AUR)
|
||||
|
||||
Simply run `yay zjunet` to build the package from AUR and install it.
|
||||
|
||||
Keep in mind that a fresh install without internet connection is almost impossible.
|
||||
Please complete installation before connecting to the intranet.
|
||||
|
||||
### Other Linux (Build from source code)
|
||||
|
||||
```bash
|
||||
xl2tpd -v; dig -v # Check installation of dependencies. There should be 3 version numbers.
|
||||
# Under proper directory
|
||||
git clone https://github.com/QSCTech/zjunet.git
|
||||
cd zjunet
|
||||
sudo ./install.sh
|
||||
# If update is necessary, run `git pull` and `sudo ./install.sh`
|
||||
# If you are setting up a server, we suggest you run `zjunet wlan disable` to disable WLAN capability.
|
||||
```
|
||||
|
||||
## Known Issues
|
||||
**ATTENTION** Requirement check will **NOT** be done running `./install.sh`.
|
||||
Please run `xl2tpd -v` and `dig -v` to verify the installation.
|
||||
|
||||
### 丢包
|
||||
## Troubleshooting
|
||||
|
||||
在有的机子上会丢包(因为用的是 nexthop )。
|
||||
等有空了也许会换成 iptables 来解决这个问题。
|
||||
### Packet lose
|
||||
|
||||
### ppp0 may disappear on openwrt
|
||||
This is a known issue.
|
||||
When overlapping VPN and ZJUWLAN, network packet may be lost.
|
||||
(because of nexthop in routing table).
|
||||
|
||||
make /etc/ppp/options's lcp-echo-failure larger.
|
||||
Contributions to this issue are welcomed. (Maybe using `iptables`)
|
||||
|
||||
see also https://github.com/QSCTech/zjunet/issues/39
|
||||
### ppp0 may disappears on OpenWrt
|
||||
|
||||
## Openwrt
|
||||
Set lcp-echo-failure larger in /etc/ppp/options.
|
||||
|
||||
Install xl2tpd:
|
||||
See also #39
|
||||
|
||||
https://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/packages/
|
||||
### Other problems?
|
||||
|
||||
## Dev
|
||||
Please send mail to tech@zjuqsc.com if you have any other problem.
|
||||
|
||||
QSCer 可以直接向这个 repo push 而不用发 pull request。
|
||||
有什么疑虑可以提 issue 问一下,
|
||||
或者直接来办公室找我(zenozeng)。
|
||||
## Contribute to this project
|
||||
|
||||
master分支就是开发分支。
|
||||
但是请保证bump version的时候要稳定。
|
||||
QSCers may Push directly without sending Pull Requests。
|
||||
|
||||
### Build
|
||||
Please write an Issue if you have worries. Contact maintainer directly if necessary.
|
||||
|
||||
**PRs from non-QSCers are also welcomed.**
|
||||
|
||||
### Packaging Instruction
|
||||
|
||||
*(Not finished yet)*
|
||||
|
||||
#### Debian
|
||||
|
||||
```bash
|
||||
sudo apt-get install build-essential autoconf automake autotools-dev dh-make debhelper devscripts fakeroot xutils lintian pbuilder
|
||||
sudo apt-get install build-essential autoconf automake autotools-dev dh-make \
|
||||
debhelper devscripts fakeroot xutils lintian pbuilder rpm
|
||||
cd build
|
||||
./build.sh
|
||||
```
|
||||
|
||||
##### see also
|
||||
##### See Also
|
||||
|
||||
- http://www.webupd8.org/2010/01/how-to-create-deb-package-ubuntu-debian.html
|
||||
|
||||
- http://tldp.org/HOWTO/html_single/Debian-Binary-Package-Building-HOWTO/
|
||||
|
||||
#### Openwrt
|
||||
#### OpenWrt
|
||||
|
||||
##### see also
|
||||
##### See Also
|
||||
|
||||
- http://lists.openmoko.org/pipermail/devel/2008-July/000496.html
|
||||
|
||||
## Links
|
||||
### Links
|
||||
|
||||
- [Array in unix Bourne Shell](http://unix.stackexchange.com/questions/137566/array-in-unix-bourne-shell)
|
||||
|
||||
|
||||
139
README.zh.md
Normal file
139
README.zh.md
Normal file
@ -0,0 +1,139 @@
|
||||
# zjunet
|
||||
|
||||
适用于 ZJU 的 VPN, WLAN 和 DNS 命令行工具。
|
||||
|
||||
## 功能
|
||||
|
||||
- 支持 ZJU VPN 连接。
|
||||
|
||||
- 支持 ZJUWLAN 连接。
|
||||
|
||||
- 路由器支持。
|
||||
|
||||
- 多拨支持(多账户负载均衡)。
|
||||
|
||||
- ZJUWLAN 与 ZJUVPN 带宽叠加(1 WLAN + N VPN,在 ZJUWLAN 下)
|
||||
|
||||
- DNS 自动测试设置(适用于 DNS 坏掉的情况)
|
||||
|
||||
## 依赖
|
||||
|
||||
- xl2tpd
|
||||
|
||||
- `dig` (在不同平台的包不同)
|
||||
|
||||
## 安装
|
||||
|
||||
根据发行版的不同,安装方式略有区别。为了更好的为您提供服务,建议您从求是潮网站的仓库下载。
|
||||
(求是潮网站在校内也可以访问,安装时不需要先从仓库手动下载。)
|
||||
|
||||
考虑到需要安装 zjunet 的机器通常没有办法访问外网,建议配合 [浙大源](https://mirrors.zju.edu.cn/) 安装。
|
||||
|
||||
下面将按照不同的发行版分别列出安装步骤。如果你在安装前后遇到任何问题,请向下浏览本文件的“疑难解答”部分。
|
||||
|
||||
### Debian / Ubuntu (deb)
|
||||
|
||||
1. 使用浙大源配置内网软件包镜像。 [Ubuntu](https://mirror.zju.edu.cn/docs/ubuntu/)/[Debian](https://mirror.zju.edu.cn/docs/debian/).
|
||||
2. 依次输入并执行下列命令:
|
||||
|
||||
``` bash
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjumirrors.pgp | sudo tee /etc/apt/trusted.gpg.d/zjumirrors.asc
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjunet.list | sudo tee /etc/apt/sources.list.d/zjunet.list
|
||||
sudo apt-get update
|
||||
sudo apt-get install zjunet
|
||||
```
|
||||
|
||||
3. 安装结束!您可以输入 `zjunet version` 查看安装的版本,输入 `zjunet usage` 查看用法。
|
||||
4. 如果你是服务器用户,建议运行 `zjunet wlan disable` 来彻底禁用 WLAN 功能。
|
||||
|
||||
### Fedora / CentOS (rpm)
|
||||
|
||||
1. 使用浙大源配置内网软件包镜像。 [Fedora](https://mirror.zju.edu.cn/docs/fedora/)/[CentOS](https://mirror.zju.edu.cn/docs/centos/)
|
||||
2. 执行这些步骤以使用 [浙大源 EPEL](https://mirrors.zju.edu.cn/epel/) (以 CentOS 为例):
|
||||
1. 运行 `yum install epel-release` 以安装 EPEL 。
|
||||
2. 编辑 `/etc/yum.repos.d/epel.repo` ,将所有以 `#baseurl=` 开头的行取消注释(删除行首 `#` 符号)并注释以 `mirrorlist=` 开头的行(在行首添加 `#` 符号)
|
||||
3. 继续编辑 `/etc/yum.repos.d/epel.repo` ,将所有 `https://download.fedoraproject.org/pub` 替换为 `https://mirrors.zju.edu.cn`。
|
||||
|
||||
3. 依次输入并执行下列命令:
|
||||
|
||||
```bash
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjumirrors.pgp | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-ZJUMIRRORS
|
||||
curl https://mirrors.zju.edu.cn/openzjunet/zjunet.repo | sudo tee /etc/yum.repos.d/zjunet.repo
|
||||
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZJUMIRRORS
|
||||
sudo yum install zjunet
|
||||
```
|
||||
|
||||
4. 安装结束!您可以输入 `zjunet version` 查看安装的版本,输入 `zjunet usage` 查看用法。
|
||||
5. 如果你是服务器用户,建议运行 `zjunet wlan disable` 来彻底禁用 WLAN 功能。
|
||||
|
||||
### OpenWrt (opk)
|
||||
|
||||
从 [Releases 页](https://github.com/QSCTech/zjunet/releases) 下载 opk 包到路由器上,
|
||||
运行 `opkg install ./zjunet_(版本)_all.opk` 。
|
||||
|
||||
### Arch Linux (AUR)
|
||||
|
||||
直接运行 `yay zjunet` 即可下载并安装。
|
||||
|
||||
请记住,在没有互联网连接的环境中是几乎不可能安装好的。
|
||||
请在连接到校内网前,在有互联网连接的环境中先完成安装。
|
||||
|
||||
### 其他 Linux (源代码安装)
|
||||
|
||||
```bash
|
||||
xl2tpd -v; dig -v # 检查依赖命令的安装情况。这句命令将输出三个版本号。
|
||||
# 在合适的目录下
|
||||
git clone https://github.com/QSCTech/zjunet.git
|
||||
cd zjunet
|
||||
sudo ./install.sh
|
||||
# 如果想要更新请在 zjunet 目录下运行 git pull 并再次 sudo ./install.sh
|
||||
# 如果你是服务器用户,建议运行 `zjunet wlan disable` 来彻底禁用 WLAN 功能。
|
||||
```
|
||||
|
||||
**注意** 运行 `./install.sh` 时 **不会** 确认必要依赖是否已经安装。
|
||||
您应当先运行 `xl2tpd -v` 、 `dig -v` 确认安装。
|
||||
|
||||
## 疑难解答
|
||||
|
||||
### 出现了 `xl2tpd-control: command not found` 的提示但直接运行 `xl2tpd-control` 有效
|
||||
|
||||
出现这种情况通常是由于 `sudo` 的 `secure path` 被启用。
|
||||
|
||||
请编辑 `/etc/sudoers` 并在 `Defaults secure_path=xxxxxxx` 行添加 `xl2tpd-control` 所在路径(运行 `which xl2tpd-control` 查看)。编辑后的这行类似这样:
|
||||
|
||||
```
|
||||
Defaults secure_path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin"
|
||||
```
|
||||
|
||||
你可以运行 `sudo env | grep PATH` 来验证配置。显示的内容应当包括刚才添加的路径。
|
||||
|
||||
### 丢包
|
||||
|
||||
这是一个已知问题。在同时连接 VPN 和 ZJUWLAN 时,
|
||||
在有的机子上会丢包(因为设定的路由使用了 nexthop )。
|
||||
|
||||
暂时没有人来解决这个问题,欢迎有志者贡献(可以考虑用 `iptables` )
|
||||
|
||||
### OpenWrt 上的 ppp0 消失了
|
||||
|
||||
将 /etc/ppp/options 中的 lcp-echo-failure 调大。
|
||||
|
||||
可见于 #39
|
||||
|
||||
### 我还有其它问题
|
||||
|
||||
如果你还有其它问题,请与我们联系。
|
||||
|
||||
您可以发送邮件至 tech@zjuqsc.com 。
|
||||
|
||||
## 如何贡献
|
||||
|
||||
求是潮成员可以直接向这个仓库 Push 而不用发起 Pull requests。
|
||||
|
||||
有任何疑虑都可以提 Issue ,也可以与现任 Maintainer 联系。
|
||||
|
||||
**本项目也接受非求是潮成员发起的 PR 。**
|
||||
|
||||
### 开发指南
|
||||
|
||||
开发信息请查看 [英文 README](README.md#packaging-instruction) 。
|
||||
5
bin/zjunet
Normal file
5
bin/zjunet
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
/usr/lib/zjunet/zjunet.sh "$@"
|
||||
42
build/build-pkgbuild.sh
Executable file
42
build/build-pkgbuild.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
PKGNAME=zjunet
|
||||
PKGVER=$(cat $(dirname $0)/../VERSION)
|
||||
PKGVER_NOREL=${PKGVER%%-*}
|
||||
PKGREL=${PKGVER:$((${#PKGVER_NOREL}+1))}
|
||||
if [[ -z $PKGREL ]]; then
|
||||
PKGREL=1
|
||||
fi
|
||||
|
||||
set -xe
|
||||
|
||||
wget https://github.com/QSCTech/$PKGNAME/archive/v$PKGVER.tar.gz -O $PKGNAME-$PKGVER.tar.gz
|
||||
|
||||
FILE_MD5=$(md5sum $PKGNAME-$PKGVER.tar.gz | cut -f1 -d' ')
|
||||
FILE_SHA1=$(sha1sum $PKGNAME-$PKGVER.tar.gz | cut -f1 -d' ')
|
||||
FILE_SHA256=$(sha256sum $PKGNAME-$PKGVER.tar.gz | cut -f1 -d' ')
|
||||
|
||||
cat > PKGBUILD <<EOF
|
||||
# Maintainer: Azuk 443 <me@azuk.top>
|
||||
|
||||
pkgname=$PKGNAME
|
||||
pkgver=$PKGVER_NOREL
|
||||
pkgrel=$PKGREL
|
||||
pkgdesc="Command Line Scripts for ZJU"
|
||||
url="https://github.com/QSCTech/$PKGNAME"
|
||||
arch=('any')
|
||||
license=('GPL')
|
||||
depends=('xl2tpd>=1.3.7' 'dnsutils')
|
||||
source=("$PKGNAME-$PKGVER.tar.gz::https://github.com/QSCTech/$PKGNAME/archive/v$PKGVER.tar.gz")
|
||||
md5sums=('$FILE_MD5')
|
||||
sha1sums=('$FILE_SHA1')
|
||||
sha256sums=('$FILE_SHA256')
|
||||
|
||||
package() {
|
||||
cd "\$srcdir/$PKGNAME-$PKGVER"
|
||||
DESTDIR=\$pkgdir PREFIX=/usr ./install.sh
|
||||
}
|
||||
EOF
|
||||
|
||||
makepkg $*
|
||||
makepkg --printsrcinfo > .SRCINFO
|
||||
@ -1,12 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=0.2.1-0
|
||||
VERSION=$(cat ../VERSION)
|
||||
|
||||
cd debian
|
||||
./build.sh $VERSION > /dev/null
|
||||
fail() {
|
||||
echo -e "\033[31mERROR: Failed to build $1\033[0m" 1>&2
|
||||
}
|
||||
|
||||
cd ../openwrt
|
||||
./build.sh $VERSION > /dev/null
|
||||
if [[ $# -gt 0 ]]; then
|
||||
for arg in $*; do
|
||||
case $arg in
|
||||
rpm)
|
||||
USE_RPM=1
|
||||
;;
|
||||
debian)
|
||||
USE_DEB=1
|
||||
;;
|
||||
openwrt)
|
||||
USE_OPK=1
|
||||
;;
|
||||
*)
|
||||
echo "Invalid package $arg"
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
else
|
||||
USE_RPM=1
|
||||
USE_DEB=1
|
||||
USE_OPK=1
|
||||
fi
|
||||
|
||||
cd ..
|
||||
find . -regextype posix-egrep -regex ".*\.(opk|deb)$"
|
||||
if [[ ! -z $USE_RPM ]]; then
|
||||
pushd rpm > /dev/null
|
||||
./build.sh $VERSION || fail 'RPM package'
|
||||
popd > /dev/null
|
||||
fi
|
||||
|
||||
if [[ ! -z $USE_DEB ]]; then
|
||||
pushd debian > /dev/null
|
||||
./build.sh $VERSION || fail 'Debian package'
|
||||
popd > /dev/null
|
||||
fi
|
||||
|
||||
if [[ ! -z $USE_OPK ]]; then
|
||||
pushd openwrt > /dev/null
|
||||
./build.sh $VERSION || fail 'OpenWrt package'
|
||||
popd > /dev/null
|
||||
fi
|
||||
|
||||
echo -ne "\033[0;32m"
|
||||
find . -regextype posix-egrep -regex ".*\.(opk|deb|rpm)$"
|
||||
echo -ne "\033[0m"
|
||||
|
||||
127
build/changelog.py
Executable file
127
build/changelog.py
Executable file
@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import base64
|
||||
import datetime
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
|
||||
try:
|
||||
import urllib3
|
||||
http = urllib3.PoolManager()
|
||||
def makereq(url, headers):
|
||||
return http.request('GET', url, headers=headers)
|
||||
except ImportError:
|
||||
import urllib2 as request
|
||||
class MyResponse:
|
||||
def __init__(self, status, data):
|
||||
self.status = status
|
||||
self.data = data
|
||||
def makereq(url, headers):
|
||||
f = request.urlopen(request.Request(url, headers=headers))
|
||||
return MyResponse(f.getcode(), f.read().decode('utf-8'))
|
||||
|
||||
|
||||
if 'fromisoformat' in dir(datetime.datetime):
|
||||
def get_time(s):
|
||||
return datetime.datetime.fromisoformat(s.replace('Z', '+00:00'))
|
||||
else:
|
||||
try:
|
||||
from dateutil.parser import parser
|
||||
def get_time(s):
|
||||
return parser().parse(s)
|
||||
except ImportError:
|
||||
def get_time(s):
|
||||
return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
|
||||
GITHUB_AUTH = None
|
||||
tok = os.getenv('GITHUB_TOKEN')
|
||||
usn = os.getenv('GITHUB_USERNAME')
|
||||
psw = os.getenv('GITHUB_PASSWORD')
|
||||
if tok is not None:
|
||||
GITHUB_AUTH = 'token {}'.format(tok)
|
||||
elif usn is not None and psw is not None:
|
||||
GITHUB_AUTH = 'Basic {}'.format(base64.b64encode('{}:{}'.format(usn, psw).encode('utf-8')).decode('utf-8'))
|
||||
|
||||
def get(url):
|
||||
headers = {
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
'User-Agent': 'zjunet-build-agent/0.1',
|
||||
}
|
||||
if GITHUB_AUTH is not None:
|
||||
headers['Authorization'] = GITHUB_AUTH
|
||||
r = makereq(url, headers=headers)
|
||||
assert r.status // 100 == 2, 'HTTP Status {} != 2xx while requesting {}'.format(r.status, url)
|
||||
if r.status != 200:
|
||||
print('WARNING: HTTP {} while requesting {}'.format(r.status, url))
|
||||
return r.data
|
||||
|
||||
def api_get(url):
|
||||
return json.loads(get('https://api.github.com/' + url))
|
||||
|
||||
author_cache = {}
|
||||
def get_author(name):
|
||||
if name in author_cache:
|
||||
return author_cache[name]
|
||||
print('Reading data for {}'.format(name), end=' : ', file=sys.stderr)
|
||||
data = api_get('users/{}'.format(name))
|
||||
data = {
|
||||
'name': data['name'],
|
||||
'email': data['email'],
|
||||
}
|
||||
author_cache[name] = data
|
||||
print('{} <{}>'.format(data['name'], data['email']), file=sys.stderr)
|
||||
return data
|
||||
|
||||
def get_changelog(owner, name):
|
||||
print('Reading releases of {1} in {0}'.format(owner, name), file=sys.stderr)
|
||||
releases = api_get('repos/{}/{}/releases'.format(owner, name))
|
||||
releases = filter(lambda v: not v['draft'] and not v['prerelease'], releases)
|
||||
|
||||
data = []
|
||||
for rel in releases:
|
||||
name = rel['name'] or rel['tag_name']
|
||||
item = {
|
||||
'time': get_time(rel['published_at']),
|
||||
'name': name,
|
||||
'version': name[name.rfind('v') + 1:].split(','),
|
||||
'author': get_author(rel['author']['login']),
|
||||
'changes': None,
|
||||
}
|
||||
tbody = rel['body'].strip()
|
||||
if tbody != '':
|
||||
if tbody[0] != '-' and '\n' not in tbody:
|
||||
item['changes'] = '- ' + tbody
|
||||
else:
|
||||
item['changes'] = tbody
|
||||
|
||||
data.append(item)
|
||||
return ChangeLog(data)
|
||||
|
||||
class ChangeLog:
|
||||
def __init__(self, data):
|
||||
self.raw = data
|
||||
def rpm(self):
|
||||
rel = '%changelog\n'
|
||||
for item in self.raw:
|
||||
rel += '* {} {} <{}> - {}\n'.format(item['time'].strftime('%a %b %d %Y'), item['author']['name'], item['author']['email'], '.'.join(item['version']))
|
||||
if item['changes'] is not None:
|
||||
rel += item['changes'] + '\n'
|
||||
return rel
|
||||
|
||||
available_formats = list(filter(lambda v: v[0] != '_', dir(ChangeLog)))
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print('Usage: {} <format>\nAvailable formats: {}'.format(sys.argv[0], ','.join(available_formats)))
|
||||
else:
|
||||
changelog = get_changelog('QSCTech', 'zjunet')
|
||||
if hasattr(changelog, sys.argv[1]):
|
||||
print(getattr(changelog, sys.argv[1])())
|
||||
else:
|
||||
print('Invalid format {}\nAvailable formats: {}'.format(','.join(available_formats)))
|
||||
@ -1,17 +1,32 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
rm -rf *.deb
|
||||
|
||||
VERSION=$1
|
||||
|
||||
# share
|
||||
mkdir -p ./debian/usr/share/zjunet
|
||||
cp ../../miscellaneous/* ./debian/usr/share/zjunet
|
||||
cp ../../VERSION ./debian/usr/share/zjunet
|
||||
|
||||
# lib
|
||||
mkdir -p ./debian/usr/lib/zjunet
|
||||
cp ../../lib/* ./debian/usr/lib/zjunet
|
||||
cp ../../lib/*.sh ./debian/usr/lib/zjunet
|
||||
|
||||
# bin
|
||||
mkdir -p ./debian/usr/bin
|
||||
echo '/usr/lib/zjunet/zjunet.sh "$@"' >> ./debian/usr/bin/zjunet
|
||||
chmod +x ./debian/usr/bin/zjunet
|
||||
install -m 755 -d ./debian/usr/bin
|
||||
install -m 755 ../../bin/zjunet ./debian/usr/bin/zjunet
|
||||
|
||||
# postinst
|
||||
mkdir -p debian/DEBIAN
|
||||
cat > debian/DEBIAN/postinst <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
/usr/share/zjunet/zjunet-postinst
|
||||
|
||||
EOF
|
||||
chmod 755 debian/DEBIAN/postinst
|
||||
|
||||
# contorl file
|
||||
mkdir -p debian/DEBIAN
|
||||
@ -21,17 +36,18 @@ Version: $VERSION
|
||||
Section: net
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
Depends: xl2tpd (>= 1.3.1), curl
|
||||
Maintainer: Zeno Zeng <zenoofzeng@gmail.com>
|
||||
Description: Command Line Scripts for ZJU
|
||||
Depends: xl2tpd (>= 1.3.7), dnsutils
|
||||
Maintainer: Azuk 443 <me@azuk.top>
|
||||
Description: Command Line Scripts for ZJU Campus Network
|
||||
This script provides a VPN / WLAN / NEXTHOP for ZJUer.
|
||||
EOF
|
||||
|
||||
# dpkg-deb
|
||||
find ./debian -type d | xargs chmod 755
|
||||
dpkg-deb --build debian
|
||||
fakeroot dpkg-deb -Zxz --build debian
|
||||
mv debian.deb zjunet_${VERSION}_all.deb
|
||||
|
||||
# remove debian/
|
||||
rm -rf ./debian
|
||||
rm -f control
|
||||
rm -rf control
|
||||
|
||||
|
||||
@ -1,17 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
rm -rf *.opk
|
||||
|
||||
VERSION=$1
|
||||
|
||||
# share
|
||||
mkdir -p ./debian/usr/share/zjunet
|
||||
cp ../../miscellaneous/* ./debian/usr/share/zjunet
|
||||
cp ../../VERSION ./debian/usr/share/zjunet
|
||||
|
||||
# lib
|
||||
mkdir -p ./debian/usr/lib/zjunet
|
||||
cp ../../lib/* ./debian/usr/lib/zjunet
|
||||
cp ../../lib/*.sh ./debian/usr/lib/zjunet
|
||||
|
||||
# bin
|
||||
mkdir -p ./debian/usr/bin
|
||||
echo '/usr/lib/zjunet/zjunet.sh "$@"' >> ./debian/usr/bin/zjunet
|
||||
chmod +x ./debian/usr/bin/zjunet
|
||||
install -m 755 -d ./debian/usr/bin
|
||||
install -m 755 ../../bin/zjunet ./debian/usr/bin/zjunet
|
||||
|
||||
# contorl file
|
||||
mkdir -p debian/DEBIAN
|
||||
@ -21,15 +26,15 @@ Version: $VERSION
|
||||
Section: net
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
Depends: xl2tpd (>= 1.3.1), curl
|
||||
Maintainer: Zeno Zeng <zenoofzeng@gmail.com>
|
||||
Description: Command Line Scripts for ZJU
|
||||
Depends: xl2tpd (>= 1.3.7), bind-dig
|
||||
Maintainer: Azuk 443 <me@azuk.top>
|
||||
Description: Command Line Scripts for ZJU Campus Network
|
||||
This script provides a VPN / WLAN / NEXTHOP for ZJUer.
|
||||
EOF
|
||||
|
||||
# dpkg-deb
|
||||
find ./debian -type d | xargs chmod 755
|
||||
dpkg-deb -Zgzip --build debian # for opkg
|
||||
fakeroot dpkg-deb -Zgzip --build debian # for opkg
|
||||
mv debian.deb zjunet_${VERSION}_all.opk
|
||||
|
||||
# remove debian/
|
||||
|
||||
45
build/rpm/build.sh
Executable file
45
build/rpm/build.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
rm -rf *.rpm
|
||||
|
||||
VERSION=$1
|
||||
REALVERSION=`echo "$VERSION" | cut -d'-' -f1`
|
||||
RELEASE=`echo "$VERSION" | cut -d'-' -f2`
|
||||
|
||||
mkdir -p rpm/
|
||||
|
||||
# share
|
||||
cp ../../miscellaneous/* rpm/
|
||||
cp ../../VERSION rpm/
|
||||
|
||||
# lib
|
||||
mkdir -p rpm/lib/
|
||||
cp ../../lib/* rpm/lib/
|
||||
|
||||
# bin
|
||||
echo '/usr/lib/zjunet/zjunet.sh "$@"' > rpm/zjunet
|
||||
install -m 755 -d ./debian/usr/bin
|
||||
|
||||
# rpm
|
||||
ARCH="noarch"
|
||||
SEMINAME="zjunet-$REALVERSION"
|
||||
FULLNAME="zjunet-$VERSION"
|
||||
rm -rf ${SEMINAME}.tar.gz
|
||||
find rpm -type d | xargs chmod 755
|
||||
rm -rf $SEMINAME
|
||||
mv rpm $SEMINAME
|
||||
tar zcf ${SEMINAME}.tar.gz $SEMINAME
|
||||
mkdir -p $HOME/rpmbuild/SOURCES
|
||||
cp ${SEMINAME}.tar.gz $HOME/rpmbuild/SOURCES
|
||||
cp build_spec.sh $SEMINAME/
|
||||
cd $SEMINAME
|
||||
./build_spec.sh $VERSION
|
||||
cd ..
|
||||
cp "$SEMINAME/zjunet.spec" ./
|
||||
mkdir -p "$HOME/rpmbuild/SPECS"
|
||||
cp zjunet.spec "$HOME/rpmbuild/SPECS"
|
||||
fakeroot rpmbuild -ba zjunet.spec --target $ARCH
|
||||
rm -rf zjunet.spec ${SEMINAME}.tar.gz $SEMINAME
|
||||
cp $HOME/rpmbuild/RPMS/$ARCH/${FULLNAME}.$ARCH.rpm ./
|
||||
|
||||
63
build/rpm/build_spec.sh
Executable file
63
build/rpm/build_spec.sh
Executable file
@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=$1
|
||||
REALVERSION=`echo "$VERSION" | cut -d'-' -f1`
|
||||
RELEASE=`echo "$VERSION" | cut -d'-' -f2`
|
||||
|
||||
echo "Summary: Command Line Scripts for ZJU " > zjunet.spec
|
||||
echo "Name: zjunet" >> zjunet.spec
|
||||
echo "Version: $REALVERSION" >> zjunet.spec
|
||||
echo "Release: $RELEASE" >> zjunet.spec
|
||||
echo "License: GPL" >> zjunet.spec
|
||||
echo "Group: Applications/Internet" >> zjunet.spec
|
||||
echo "URL: https://github.com/QSCTech/zjunet/" >> zjunet.spec
|
||||
echo "Vendor: Qiu Shi Chao Website of Zhejiang University" >> zjunet.spec
|
||||
echo "Packager: Azuk 443 <me@azuk.top>" >> zjunet.spec
|
||||
echo "Requires: xl2tpd >= 1.3.7, bind-utils" >> zjunet.spec
|
||||
echo "BuildRoot: %{_builddir}/%{name}-root" >> zjunet.spec
|
||||
echo "Source: %{name}-%{version}.tar.gz" >> zjunet.spec
|
||||
echo "BuildArch: noarch" >> zjunet.spec
|
||||
echo "" >> zjunet.spec
|
||||
echo "%description" >> zjunet.spec
|
||||
echo "Command Line Scripts for ZJU " >> zjunet.spec
|
||||
echo "This script provides a VPN / WLAN / NEXTHOP for ZJUer. " >> zjunet.spec
|
||||
echo "" >> zjunet.spec
|
||||
echo "%prep" >> zjunet.spec
|
||||
echo "%setup -q" >> zjunet.spec
|
||||
echo "" >> zjunet.spec
|
||||
echo "%build" >> zjunet.spec
|
||||
echo 'echo $RPM_BUILD' >> zjunet.spec
|
||||
echo "" >> zjunet.spec
|
||||
echo "%install" >> zjunet.spec
|
||||
echo 'rm -rf $RPM_BUILD_ROOT' >> zjunet.spec
|
||||
echo 'mkdir -p $RPM_BUILD_ROOT/usr/bin' >> zjunet.spec
|
||||
echo 'mkdir -p $RPM_BUILD_ROOT/usr/lib/zjunet' >> zjunet.spec
|
||||
echo 'mkdir -p $RPM_BUILD_ROOT/usr/share/zjunet' >> zjunet.spec
|
||||
echo 'install -m 755 zjunet $RPM_BUILD_ROOT/usr/bin/zjunet' >> zjunet.spec
|
||||
echo 'install -m 755 zjunet-postinst $RPM_BUILD_ROOT/usr/share/zjunet/zjunet-postinst' >> zjunet.spec
|
||||
cd lib
|
||||
for f in *.sh; do
|
||||
echo "install -m 755 lib/$f \$RPM_BUILD_ROOT/usr/lib/zjunet/$f" >> ../zjunet.spec
|
||||
done
|
||||
cd ..
|
||||
echo 'install -m 644 VERSION $RPM_BUILD_ROOT/usr/share/zjunet/VERSION' >> zjunet.spec
|
||||
echo "" >> zjunet.spec
|
||||
echo "%files" >> zjunet.spec
|
||||
echo "%defattr(-,root,root)" >> zjunet.spec
|
||||
echo "/usr/bin/zjunet" >> zjunet.spec
|
||||
echo "/usr/share/zjunet/zjunet-postinst" >> zjunet.spec
|
||||
echo "/usr/share/zjunet/VERSION" >> zjunet.spec
|
||||
cd lib
|
||||
for f in *.sh; do
|
||||
echo "/usr/lib/zjunet/$f" >> ../zjunet.spec
|
||||
done
|
||||
cd ..
|
||||
echo "" >> zjunet.spec
|
||||
echo "%clean" >> zjunet.spec
|
||||
echo 'rm -rf $RPM_BUILD_ROOT' >> zjunet.spec
|
||||
echo "" >> zjunet.spec
|
||||
echo "%post" >> zjunet.spec
|
||||
echo "/usr/share/zjunet/zjunet-postinst || true" >> zjunet.spec
|
||||
echo "" >> zjunet.spec
|
||||
|
||||
../../changelog.py rpm >> zjunet.spec
|
||||
25
install.sh
25
install.sh
@ -1,12 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
BASEDIR=$(dirname $0)/lib
|
||||
mkdir -p /usr/local/lib/zjunet
|
||||
cp -rf $BASEDIR/* /usr/local/lib/zjunet
|
||||
mkdir -p /usr/local/bin
|
||||
echo "#!/bin/sh" > /usr/local/bin/zjunet
|
||||
echo '/usr/local/lib/zjunet/zjunet.sh "$@"' >> /usr/local/bin/zjunet
|
||||
chmod +x /usr/local/bin/zjunet
|
||||
if [ -z "$PREFIX" ]; then
|
||||
PREFIX=/usr/local
|
||||
fi
|
||||
|
||||
mkdir -p $DESTDIR$PREFIX/lib/zjunet
|
||||
cp -rf $BASEDIR/* $DESTDIR$PREFIX/lib/zjunet
|
||||
mkdir -p $DESTDIR$PREFIX/bin
|
||||
mkdir -p $DESTDIR$PREFIX/share/zjunet
|
||||
ln -fs ../../share/zjunet/VERSION $DESTDIR$PREFIX/lib/zjunet/VERSION
|
||||
cp -f VERSION $DESTDIR$PREFIX/share/zjunet
|
||||
cat > $DESTDIR$PREFIX/bin/zjunet << EOF
|
||||
#!/bin/sh
|
||||
$PREFIX/lib/zjunet/zjunet.sh "\$@"
|
||||
EOF
|
||||
chmod +x $DESTDIR$PREFIX/bin/zjunet
|
||||
echo "[INFO] Done."
|
||||
echo
|
||||
if [[ -z $DESTDIR ]]; then
|
||||
zjunet usage
|
||||
fi
|
||||
|
||||
1
lib/VERSION
Symbolic link
1
lib/VERSION
Symbolic link
@ -0,0 +1 @@
|
||||
../VERSION
|
||||
@ -28,9 +28,10 @@ zju_test_and_set_up_dns () {
|
||||
}
|
||||
|
||||
# 浙大的DNS不是很稳定,这里列了备用方案
|
||||
# 官方 > 10.12.10.12 > Senorsen (QSC Server) DNS > ALI YUN
|
||||
# 官方 > 10.12.10.12 > Senorsen (QSC Server) DNS > 114 DNS
|
||||
zju_test_and_set_up_dns \
|
||||
$1 \
|
||||
10.10.0.21 10.10.0.22 10.10.0.23 \
|
||||
10.12.10.12 \
|
||||
10.202.68.43 \
|
||||
10.202.68.73 \
|
||||
114.114.114.114
|
||||
|
||||
34
lib/route.sh
34
lib/route.sh
@ -33,7 +33,9 @@ echo "[INFO] Setting up ip route."
|
||||
|
||||
gateway=$(ip route get 10.10.0.21 | grep via | awk '{print $3}')
|
||||
|
||||
devs_count=$(ip addr show | grep 'inet.*ppp' | grep ' 10.5.' | awk '{print $7}' | wc -l)
|
||||
# Recently VPN server 10.5.1.7 has the P-t-P: 172.172.172.2, after some updates.
|
||||
# Mar 2019 Update: A new VPN server 10.0.2.27 has been set up.
|
||||
devs_count=$(ip addr show | grep 'inet.*ppp' | grep ' 10.5.\|172.172.172.\|10.0.2.' | awk '{print $7}' | wc -l)
|
||||
if [ "${devs_count}" -eq "0" ]; then
|
||||
dev=$(ip route get 10.10.0.21 | head -n1 | awk '{print $5}')
|
||||
|
||||
@ -47,6 +49,7 @@ if [ "${devs_count}" -eq "0" ]; then
|
||||
ip_route_del 210.32.160.0/21
|
||||
ip_route_del 210.32.168.0/22
|
||||
ip_route_del 210.32.172.0/23
|
||||
ip_route_del 210.32.174.0/24
|
||||
ip_route_del 210.32.176.0/20
|
||||
ip_route_del 222.205.0.0/17
|
||||
ip_route_del 10.5.1.0/24
|
||||
@ -66,8 +69,6 @@ case "$gateway" in
|
||||
10.189.*)
|
||||
ip route replace 10.50.200.245 via $gateway
|
||||
;;
|
||||
10.171.*)
|
||||
;;
|
||||
*)
|
||||
# 内网静态路由
|
||||
# See also: #18 (thanks Hexcles Ma)
|
||||
@ -78,41 +79,30 @@ case "$gateway" in
|
||||
ip route replace 58.196.224.0/20 via $gateway
|
||||
ip route replace 58.200.100.0/24 via $gateway
|
||||
|
||||
# The public CERNET IP of most ZJU servers, which can be reached directly in the Intranet.
|
||||
# Most of them do have a 10.* IP, but sometimes school DNS just returns the public ones.
|
||||
# The public CERNET IP of most ZJU servers, which can be reached directly in the Intranet through 10.0.0.0/8.
|
||||
# If these servers are DNATed(have 210.32.*.* IP), we can't reach it through our gateway or VPN P-t-P.
|
||||
# However these addresses also belong to Yu Quan Campus, our VPN, etc.,
|
||||
# Which can be reached through our internal gateway.
|
||||
ip route replace 210.32.0.0/20 via $gateway
|
||||
ip route replace 210.32.128.0/19 via $gateway
|
||||
ip route replace 210.32.160.0/21 via $gateway
|
||||
ip route replace 210.32.168.0/22 via $gateway
|
||||
ip route replace 210.32.172.0/23 via $gateway
|
||||
ip route replace 210.32.174.0/24 via $gateway
|
||||
ip route replace 210.32.176.0/20 via $gateway
|
||||
|
||||
# 玉泉和我们 vpn 后的 ip
|
||||
ip route replace 222.205.0.0/17 via $gateway
|
||||
;;
|
||||
esac
|
||||
|
||||
# NEXTHOP
|
||||
devs=$(ip addr show | grep 'inet.*ppp' | grep ' 10.5.' | awk '{print $7}')
|
||||
# Recently VPN server 10.5.1.7 has the P-t-P: 172.172.172.2, after some updates.
|
||||
# Mar 2019 Update: A new VPN server 10.0.2.27 has been set up.
|
||||
devs=$(ip addr show | grep 'inet.*ppp' | grep ' 10.5.\|172.172.172.\|10.0.2.' | awk '{print $7}')
|
||||
cmd="ip route replace default"
|
||||
for dev in $devs; do
|
||||
cmd="${cmd} nexthop dev ${dev}"
|
||||
done
|
||||
|
||||
case "$gateway" in
|
||||
10.189.*)
|
||||
# WLAN
|
||||
zjuwlan_test_ip=10.202.68.44
|
||||
ip route replace $zjuwlan_test_ip via ${gateway}
|
||||
zjuwlan_status=`curl -s $zjuwlan_test_ip | grep net.zju.edu.cn | wc -l`
|
||||
if [ $zjuwlan_status -eq 0 ]
|
||||
then
|
||||
cmd="${cmd} nexthop via ${gateway}"
|
||||
fi
|
||||
ip route del $zjuwlan_test_ip || true
|
||||
;;
|
||||
esac
|
||||
|
||||
$cmd
|
||||
|
||||
ip route
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# user.sh -- User Manager
|
||||
#
|
||||
@ -18,8 +18,6 @@
|
||||
# along with this program. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
# init
|
||||
|
||||
L2TPD_CFG_FILE=/etc/xl2tpd/xl2tpd.conf
|
||||
|
||||
BASEDIR=$(dirname $0)
|
||||
|
||||
16
lib/vpn.sh
16
lib/vpn.sh
@ -34,16 +34,12 @@ flush() {
|
||||
disconnect() {
|
||||
users=$("${BASEDIR}/user.sh" getall)
|
||||
for username in $users; do
|
||||
echo "[INFO] Logout: ${username}"
|
||||
"${BASEDIR}/sudo.sh" "${BASEDIR}/xl2tpd.sh" disconnect $username
|
||||
done
|
||||
"${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh"
|
||||
}
|
||||
|
||||
connect() {
|
||||
disconnect
|
||||
sleep 3
|
||||
|
||||
users=$("${BASEDIR}/user.sh" getall)
|
||||
|
||||
"${BASEDIR}/sudo.sh" "${BASEDIR}/xl2tpd.sh" restart
|
||||
@ -69,16 +65,18 @@ connect() {
|
||||
|
||||
case "$1" in
|
||||
|
||||
-d)
|
||||
d|-d|disconnect)
|
||||
disconnect
|
||||
;;
|
||||
|
||||
disconnect)
|
||||
""|c|-c|connect)
|
||||
disconnect
|
||||
;;
|
||||
|
||||
*)
|
||||
sleep 3
|
||||
connect
|
||||
;;
|
||||
|
||||
*)
|
||||
echo Invalid subcommand \"$1\" for \`zjunet vpn\`. Run \`zjunet usage\` for help.
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
70
lib/wlan.sh
70
lib/wlan.sh
@ -2,10 +2,10 @@
|
||||
|
||||
# wlan.sh -- login/logout for ZJUWLAN
|
||||
#
|
||||
# Requirements: curl
|
||||
#
|
||||
# Copyright (C) 2014 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
# Copyright (C) 2014 Zeno Zeng <zenoofzeng@gmail.com>
|
||||
# Copyright (C) 2017 Wu Fan <wfwf1997@gmail.com>
|
||||
# Copyright (C) 2023 Azuk 443 <azukmm@gmail.com>
|
||||
#
|
||||
# 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
|
||||
@ -21,69 +21,5 @@
|
||||
# along with this program. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
BASEDIR=$(dirname $0)
|
||||
|
||||
USER="${BASEDIR}/user.sh"
|
||||
|
||||
USERNAME=$($USER get)
|
||||
PASSWORD=$($USER getpwd $USERNAME)
|
||||
|
||||
logout() {
|
||||
USERNAME=$1
|
||||
PASSWORD=$2
|
||||
|
||||
echo "Logout: ${USERNAME}"
|
||||
RESPONSE=$(curl "https://net.zju.edu.cn/cgi-bin/srun_portal" -H "Content-Type: application/x-www-form-urlencoded" -d "action=logout" -s)
|
||||
|
||||
case "${RESPONSE}" in
|
||||
*ok*)
|
||||
echo "Logout: success."
|
||||
;;
|
||||
*成功*)
|
||||
echo "Logout: success."
|
||||
;;
|
||||
*)
|
||||
echo "Logout: ${RESPONSE}"
|
||||
exit 1;
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
login() {
|
||||
USERNAME=$1
|
||||
PASSWORD=$2
|
||||
|
||||
logout $USERNAME $PASSWORD
|
||||
|
||||
echo "Login: ${USERNAME}"
|
||||
RESPONSE=$(curl "https://net.zju.edu.cn/cgi-bin/srun_portal" -H "Content-Type: application/x-www-form-urlencoded" -d "action=login&username=${USERNAME}&password=${PASSWORD}&ac_id=3&type=1&is_ldap=1&local_auth=1" -s)
|
||||
|
||||
case "${RESPONSE}" in
|
||||
*help.html*)
|
||||
echo "Login: success."
|
||||
;;
|
||||
*login_ok*)
|
||||
echo "Login: success."
|
||||
;;
|
||||
*)
|
||||
echo "Login: ${RESPONSE}" >&2
|
||||
echo "zjunet WLAN function is deprecated."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
disconnect)
|
||||
logout $USERNAME $PASSWORD
|
||||
;;
|
||||
-d)
|
||||
logout $USERNAME $PASSWORD
|
||||
;;
|
||||
*)
|
||||
login $USERNAME $PASSWORD
|
||||
;;
|
||||
esac
|
||||
|
||||
"${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh"
|
||||
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# RUN AS ROOT! >..< ~~ / by xero ~~~ ararararar ~~~~
|
||||
|
||||
LNS="10.5.1.9"
|
||||
L2TPD_CFG_FILE=/etc/xl2tpd/xl2tpd.conf
|
||||
@ -36,28 +34,25 @@ LOG_FILE=/var/log/zjunet/${USERNAME}
|
||||
|
||||
XL2TPD_CONTROL_FILE=/var/run/xl2tpd/l2tp-control
|
||||
|
||||
xl2tpd_stop() {
|
||||
# for Openwrt / Debian / Ubuntu
|
||||
type systemctl >/dev/null 2>&1 || {
|
||||
/etc/init.d/xl2tpd stop
|
||||
}
|
||||
type systemctl >/dev/null 2>&1
|
||||
HAVE_SYSTEMD=$?
|
||||
|
||||
# for Arch Linux
|
||||
type systemctl >/dev/null 2>&1 && {
|
||||
xl2tpd_stop() {
|
||||
echo "[INFO] Stopping xl2tpd"
|
||||
if [ $HAVE_SYSTEMD -eq 0 ]; then
|
||||
systemctl stop xl2tpd
|
||||
}
|
||||
else
|
||||
/etc/init.d/xl2tpd stop
|
||||
fi
|
||||
}
|
||||
|
||||
xl2tpd_start() {
|
||||
# for Openwrt / Debian / Ubuntu
|
||||
type systemctl >/dev/null 2>&1 || {
|
||||
/etc/init.d/xl2tpd start
|
||||
}
|
||||
|
||||
# for Arch Linux
|
||||
type systemctl >/dev/null 2>&1 && {
|
||||
echo "[INFO] Starting xl2tpd"
|
||||
if [ $HAVE_SYSTEMD -eq 0 ]; then
|
||||
systemctl start xl2tpd
|
||||
}
|
||||
else
|
||||
/etc/init.d/xl2tpd start
|
||||
fi
|
||||
|
||||
# wait until ready
|
||||
for i in $(seq 0 10); do
|
||||
@ -73,6 +68,7 @@ xl2tpd_start() {
|
||||
}
|
||||
|
||||
xl2tpd_trystart() {
|
||||
echo "[INFO] Try to start xl2tpd if not"
|
||||
if [ -e ${XL2TPD_CONTROL_FILE} ] || (type systemctl >/dev/null && systemctl status xl2tpd >/dev/null); then
|
||||
echo "[INFO] xl2tpd ready."
|
||||
else
|
||||
@ -94,6 +90,7 @@ linkname $LAC_NAME
|
||||
logfile $PPP_LOG_FILE
|
||||
name $USERNAME
|
||||
password $PASSWORD
|
||||
mtu 1428
|
||||
EOF
|
||||
chmod 600 $PPP_OPT_FILE
|
||||
|
||||
@ -116,11 +113,17 @@ EOF
|
||||
}
|
||||
|
||||
xl2tpd_connect() {
|
||||
xl2tpd-control connect $1
|
||||
echo "[INFO] try connecting $1"
|
||||
pkill xl2tpd-control > /dev/null
|
||||
xl2tpd-control connect-lac $1 &
|
||||
echo "[INFO] xl2tpd-control done"
|
||||
}
|
||||
|
||||
xl2tpd_disconnect() {
|
||||
xl2tpd-control disconnect $1
|
||||
echo "[INFO] try disconnecting $1"
|
||||
pkill xl2tpd-control > /dev/null
|
||||
xl2tpd-control disconnect-lac $1 &
|
||||
echo "[INFO] xl2tpd-control done"
|
||||
}
|
||||
|
||||
xl2tpd_waituser() {
|
||||
@ -131,22 +134,27 @@ xl2tpd_waituser() {
|
||||
then
|
||||
echo "[INFO] Connection terminated."
|
||||
echo -n > $PPP_LOG_FILE
|
||||
echo "[INFO] Retrying now. (try to kick off, may take some time)"
|
||||
echo "[INFO] Retrying now. "
|
||||
sleep 1
|
||||
xl2tpd_disconnect ${LAC_NAME}
|
||||
sleep 5
|
||||
xl2tpd_connect ${LAC_NAME}
|
||||
echo "[INFO] again"
|
||||
fi
|
||||
echo -n > $PPP_LOG_FILE
|
||||
|
||||
pid="/var/run/ppp-${LAC_NAME}.pid"
|
||||
for pid in "/var/run/ppp-${LAC_NAME}.pid" \
|
||||
"/var/run/pppdppp-${LAC_NAME}.pid" \
|
||||
"/var/run/pppd/ppp-${LAC_NAME}.pid"; do
|
||||
if [ -e $pid ]; then
|
||||
ppp=$(cat $pid | grep ppp)
|
||||
if ip addr show | grep "inet.*${ppp}" > /dev/null; then
|
||||
ip addr show | grep "inet.*${ppp}" | sed 's/^ */[VPN] /'
|
||||
return
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
done
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
# zjunet.sh -- router for zjunet
|
||||
#
|
||||
# Copyright (C) 2014 Zeno Zeng <zenoofzeng@gmail.com>
|
||||
# Copyright (C) 2023 Azuk 443 <azukmm@gmail.com>
|
||||
#
|
||||
# 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
|
||||
@ -19,54 +20,59 @@
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
BASEDIR=$(dirname $0)
|
||||
MISCELLDIR="$BASEDIR/../../share/zjunet"
|
||||
|
||||
case "$1" in
|
||||
route)
|
||||
r|route)
|
||||
"${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh"
|
||||
;;
|
||||
user)
|
||||
u|user)
|
||||
"${BASEDIR}/user.sh" $2
|
||||
;;
|
||||
all)
|
||||
a|all)
|
||||
"${BASEDIR}/wlan.sh" $2
|
||||
"${BASEDIR}/vpn.sh" $2
|
||||
;;
|
||||
wlan)
|
||||
w|wlan)
|
||||
"${BASEDIR}/wlan.sh" $2
|
||||
;;
|
||||
vpn)
|
||||
v|vpn)
|
||||
"${BASEDIR}/vpn.sh" $2
|
||||
;;
|
||||
dns)
|
||||
"${BASEDIR}/dns.sh"
|
||||
d|dns)
|
||||
"${BASEDIR}/dns.sh" $2
|
||||
;;
|
||||
--version)
|
||||
echo "zjunet version: zjunet-0.2.1"
|
||||
-v|version|--version)
|
||||
version_full=`cat "${MISCELLDIR}/VERSION"`
|
||||
version=$(echo $version_full | sed 's/-.*//')
|
||||
echo "zjunet version: $version (${version_full})"
|
||||
;;
|
||||
*)
|
||||
cat <<EOF
|
||||
zjunet: CLI Tool (VPN/WLAN/DNS) for Zjuer
|
||||
zjunet: CLI tool (VPN/WLAN/DNS) for network connection in ZJU
|
||||
|
||||
Usage: zjunet [ACTION]
|
||||
|
||||
Actions:
|
||||
user
|
||||
user, u
|
||||
add Add a user
|
||||
list List all enabled users
|
||||
edit Edit a (enabled) user
|
||||
Note: to delete/disable a user, edit /etc/xl2tpd/xl2tpd.conf yourself
|
||||
all
|
||||
connect(-c) Connect VPN & ZJUWLAN, and combine them using nexthop
|
||||
disconnect(-d) Disconnect VPN & ZJUWLAN
|
||||
vpn
|
||||
connect(-c) Connect VPN and set up ip route
|
||||
disconnect(-d) Disconnect VPN and reset ip route
|
||||
wlan
|
||||
connect(-c) Login ZJUWLAN via curl
|
||||
disconnect(-d) Logout ZJUWLAN via curl
|
||||
route Set up ip route
|
||||
dns Test and set up DNS Server
|
||||
--version Show Version
|
||||
* Note: to delete/disable a user, edit /etc/xl2tpd/xl2tpd.conf
|
||||
all, a
|
||||
connect, -c Connect VPN & ZJUWLAN, and combine them using nexthop
|
||||
disconnect, -d Disconnect VPN & ZJUWLAN
|
||||
vpn, v
|
||||
connect, -c Connect VPN and set up ip route
|
||||
disconnect, -d Disconnect VPN and reset ip route
|
||||
route, r Set up static route
|
||||
dns [ip], d [ip] Test and set up DNS Server (default: 10.10.0.21)
|
||||
version, -v Display program version
|
||||
|
||||
Example:
|
||||
zjunet user add Add a new user
|
||||
zjunet vpn -c Connect VPN
|
||||
zjunet vpn -d Disconnect VPN
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
||||
16
miscellaneous/zjunet-postinst
Executable file
16
miscellaneous/zjunet-postinst
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
cat <<BANNER
|
||||
----------------------------------------------------------------------
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License Version 3 for more details.
|
||||
|
||||
You can ask questions, file a bug or make PRs here:
|
||||
* https://github.com/QSCTech/zjunet
|
||||
|
||||
----------------------------------------------------------------------
|
||||
BANNER
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rIv /usr/local/lib/zjunet
|
||||
rm -iv /usr/local/bin/zjunet
|
||||
PREFIX=/usr/local
|
||||
|
||||
rm -rIv $PREFIX/lib/zjunet
|
||||
rm -iv $PREFIX/bin/zjunet
|
||||
rm -riv $PREFIX/share/zjunet
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user