Skip to content

Commit

Permalink
feat: ipgw
Browse files Browse the repository at this point in the history
  • Loading branch information
unbyte committed Mar 11, 2021
0 parents commit 28c03c4
Show file tree
Hide file tree
Showing 35 changed files with 2,293 additions and 0 deletions.
Binary file added .doc/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: release
on:
push:
tags:
- 'v*.*.*'

jobs:
release:
name: publish releases
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Golang
uses: actions/setup-go@v2
with:
go-version: '^1.16.0'
- name: Build and Release
run: make release
- name: Upload to release
uses: softprops/action-gh-release@v1
with:
files: release/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
build/
release/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 unbyte <i@shangyes.net>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
69 changes: 69 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
NAME=ipgw
REPO=neucn/ipgw
MAIN_ENTRY=cmd/ipgw/main.go
VERSION=$(shell git describe --tags || echo "unknown")
BUILD=$(shell date +%FT%T%z)
BUILD_DIR=build
RELEASE_DIR=release
GO_BUILD=CGO_ENABLED=0 go build -trimpath -ldflags '-w -s -X "github.com/neucn/ipgw.Version=${VERSION}" \
-X "github.com/neucn/ipgw.Build=${BUILD}" -X "github.com/neucn/ipgw.Repo=${REPO}"'

.PHONY: clean

PLATFORM_LIST = \
darwin-amd64 \
darwin-arm64 \
linux-386 \
linux-amd64 \
linux-arm \
linux-mips64 \
linux-mips64le \
freebsd-386 \
freebsd-amd64 \
windows-386 \
windows-amd64 \
windows-arm

all: clean $(PLATFORM_LIST)

darwin-amd64:
GOARCH=amd64 GOOS=darwin $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

darwin-arm64:
GOARCH=arm64 GOOS=darwin $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

linux-386:
GOARCH=386 GOOS=linux $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

linux-amd64:
GOARCH=amd64 GOOS=linux $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

linux-arm:
GOARCH=arm64 GOOS=linux $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

linux-mips64:
GOARCH=mips64 GOOS=linux $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

linux-mips64le:
GOARCH=mips64le GOOS=linux $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

freebsd-386:
GOARCH=386 GOOS=freebsd $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

freebsd-amd64:
GOARCH=amd64 GOOS=freebsd $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME) ${MAIN_ENTRY}

windows-386:
GOARCH=386 GOOS=windows $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME).exe ${MAIN_ENTRY}

windows-amd64:
GOARCH=amd64 GOOS=windows $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME).exe ${MAIN_ENTRY}

windows-arm:
GOARCH=arm GOOS=windows $(GO_BUILD) -o $(BUILD_DIR)/$@/$(NAME).exe ${MAIN_ENTRY}

release: all
bash scripts/release.sh $(NAME) $(BUILD_DIR) $(RELEASE_DIR)

clean:
rm -rf $(BUILD_DIR)/*
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<p align="center">
<img src="https://github.com/neucn/ipgw/raw/master/.doc/logo.png?raw=true" width="200" alt="ipgw"/>
</p>

<h2 align="center">IPGW</h2>
<h3 align="center">东北大学非官方跨平台校园网关客户端</h3>
<p align="center">
<img src="https://img.shields.io/github/v/release/neucn/ipgw" alt="">
<img src="https://img.shields.io/github/issues/neucn/ipgw?color=rgb%2877%20199%20166%29" alt="">
<img src="https://img.shields.io/github/license/neucn/ipgw" alt="">
</p>

<p align="center"><a href="#安装">安装</a> | <a href="#快速开始">快速开始</a> | <a href="https://github.com/neucn/ipgw/issues/new">反馈</a></p>


# 安装

## Windows
在 Powershell 中执行以下命令安装
```powershell
iwr https://raw.githubusercontent.com/neucn/ipgw/master/install.ps1 -useb | iex
```

## Linux/FreeBSD/OSX
在 shell 中执行以下命令安装
```shell
curl -fsSL https://raw.githubusercontent.com/neucn/ipgw/master/install.sh | sh
```

## Others

其他系统的同学请 clone 到本地后自行编译

# 快速开始

> 须知:本项目的最初目的仅在于满足作者本人的日常使用,因此工具的输出文本中同时存在中英文。
>
> 欢迎有兴趣的同学提起 [Pull Request](https://github.com/neucn/ipgw/pulls) 将输出文本统一为中文 😀

保存 ipgw 账号 (密码将被加密存储)

```shell
ipgw config account add -u "学号" -p "密码" --default
```

使用默认账号快速登录,需要先保存至少一个 ipgw 账号在本地

```shell
ipgw
```

快速登出

```shell
ipgw logout
```

查看校园网信息,如套餐详情、使用记录、扣费记录等

```shell
ipgw info -a
```

检测校园网连接状况

```shell
ipgw test
```

更新工具

```shell
ipgw update
```

更多命令及其可配置项请使用 `ipgw help``ipgw help [command name]` 查看

13 changes: 13 additions & 0 deletions cmd/ipgw/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"github.com/neucn/ipgw/pkg/cmd"
"github.com/neucn/ipgw/pkg/console"
"os"
)

func main() {
if err := cmd.App.Run(os.Args); err != nil {
console.FatalL(err.Error())
}
}
7 changes: 7 additions & 0 deletions env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ipgw

var (
Version string
Build string
Repo string
)
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/neucn/ipgw

go 1.16

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/forgoer/openssl v0.0.0-20201023062029-c3112b0c8700 // indirect
github.com/neucn/neugo v0.3.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
42 changes: 42 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/forgoer/openssl v0.0.0-20201023062029-c3112b0c8700 h1:Owfo75EDatkNLuC1TE7UK2PUB4QUC9e6xIYu0afa8wQ=
github.com/forgoer/openssl v0.0.0-20201023062029-c3112b0c8700/go.mod h1:NMVFOzYeLVR7UiGTxsa+A21nrERTZ3Rv2JHDPcJpDyI=
github.com/neucn/neugo v0.2.0 h1:aOzLQWJ9FZmTpciKedaHIuA3w05IjJ3yPpemWTFKYCM=
github.com/neucn/neugo v0.2.0/go.mod h1:sKga4X9FF5N5ApwXxv+7RyqXZPDiBztj27PJX5r4wa8=
github.com/neucn/neugo v0.3.0 h1:JwNAYgXA3GxJ01iGggps+yqJPqyAOp91PjnO/fQLRMg=
github.com/neucn/neugo v0.3.0/go.mod h1:sKga4X9FF5N5ApwXxv+7RyqXZPDiBztj27PJX5r4wa8=
github.com/neucn/neugo v0.3.1 h1:HhaHoLkGghZd+uaYexBnFZOXYEaFpZzKqw8RwUklioE=
github.com/neucn/neugo v0.3.1/go.mod h1:58gIwIAZVecSpRPcDgEsMR3uwu77V7ryywDnv/OgYDI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
46 changes: 46 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env pwsh
# edited from deno_install

$ErrorActionPreference = 'Stop'

$BinDir = "$Home\.neucn\bin"

$DownloadedZip = "$env:Temp\ipgw.zip"
$TargetPath = "$BinDir\ipgw.exe"
$Target = if ([System.Environment]::Is64BitOperatingSystem) {
"windows-amd64"
} else {
"windows-386"
}

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$DownloadURL = "https://github.com/neucn/ipgw/releases/latest/download/ipgw-${Target}.zip"

if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}

Invoke-WebRequest $DownloadURL -OutFile $DownloadedZip -UseBasicParsing

if (Get-Command Expand-Archive -ErrorAction SilentlyContinue) {
Expand-Archive $DownloadedZip -Destination $BinDir -Force
} else {
if (Test-Path $TargetPath) {
Remove-Item $TargetPath
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory($DownloadedZip, $BinDir)
}

Remove-Item $DownloadedZip

$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
$Env:Path += ";$BinDir"
}

Write-Output "ipgw was installed successfully to $TargetPath"
Write-Output "Run 'ipgw --help' to get started"
51 changes: 51 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# edited from deno_install
set -e

if ! command -v unzip >/dev/null; then
echo "Error: unzip is required to install ipgw." 1>&2
exit 1
fi

if [ "$OS" = "Windows_NT" ]; then
target="windows-amd64"
else
case $(uname -sm) in
"Darwin x86_64") target="darwin-amd64" ;;
"Darwin arm64") target="darwin-arm64" ;;
"FreeBSD x86_64") target="freebsd-amd64" ;;
"FreeBSD i386") target="freebsd-386" ;;
"Linux x86_64") target="linux-amd64" ;;
"Linux arm") target="linux-arm" ;;
"Linux i386") target="linux-386" ;;
"Linux mips64") target="linux-mips64" ;;
"Linux mips64le") target="linux-mips64le" ;;
esac
fi

download_url="https://github.com/neucn/ipgw/releases/latest/download/ipgw-${target}.zip"

bin_dir="$HOME/neucn/bin"
target_path="$bin_dir/ipgw"

if [ ! -d "$bin_dir" ]; then
mkdir -p "$bin_dir"
fi

curl --fail --location --progress-bar --output "$target_path.zip" "$download_url"
unzip -d "$bin_dir" -o "$target_path.zip"
chmod +x "$target_path"
rm "$target_path.zip"

echo "ipgw was installed successfully to $target_path"
if command -v ipgw >/dev/null; then
echo "Run 'ipgw --help' to get started"
else
case $SHELL in
/bin/zsh) shell_profile=".zshrc" ;;
*) shell_profile=".bash_profile" ;;
esac
echo "Manually add the directory to your \$HOME/$shell_profile (or similar)"
echo " export PATH=\"\$HOME/neucn/bin:\$PATH\""
echo "Run '$target_path --help' to get started"
fi
Loading

0 comments on commit 28c03c4

Please sign in to comment.