Git Product home page Git Product logo

tunet-c's Introduction

tunet-c

C cli and library for Tsinghua University network authentication.

Support auth4, auth6 and net, including wired and wireless Tsinghua-5G, Tsinghua and Tsinghua-IPv4.

You can use it as a command line tool or integrate the lib into any application.

Installation on OpenWrt is also available!

Usage

# Create a config file
vi ~/.tunet_config
# Fill in your username and password on each line

# Set proper permissions
chmod 600 ~/.tunet_config

# Use it!
tunet -m auth4 -c ~/.tunet_config -r

# or
tunet -m auth4 -u yingr16 -p iampassword -r

Notes

Entering your password in command line is extremely inappropriate.

Please use a config file and make sure you are the only one who can access it.

Arguments

        -u       Tsinghua username
        -p       Tsinghua password (wrap it in single quotes if it contains special characters)
                    Caution: enter password in cli is not recommended
                    Please use config file instead
        -r       Logout first before logging in; useful when network left inactive for too long
        -m       Network choice: [net auth auth4 auth6]
        -c       Credential config file path
                    Username should be in the first line and password in the second
        -h       Usage help

Installation

OpenWrt

Prebuilt Binary

For OpenWrt users, you can download prebuilt binary from releases.

There is no prebuilt binary for newer versions. The following guide only serves as a reference for installation. You need to compile the binary by yourself.

Upload them to your router and use opkg to install packages.

For example, if you are using a mipsel_24kc router and packages are uploaded to /tmp, run:

opkg install /tmp/libtidy_5.7.28-1_mipsel_24kc.ipk
opkg install /tmp/libtunet_4.0.0-1_mipsel_24kc.ipk
opkg install /tmp/tunet_4.0.0-1_mipsel_24kc.ipk

You could add an init script to run tunet on boot.

vi /etc/init.d/tunet

With the following content:

#!/bin/sh /etc/rc.common
# /etc/init.d/tunet

START=99
DELAY=10

start() {
        tunet -m auth4 -c /root/.tunet_config -r
}

boot() {
        [ $DELAY -gt 0 ] && sleep $DELAY
        start
}
chmod +x /etc/init.d/tunet
/etc/init.d/tunet enable

You can also add a cron job to run /etc/init.d/tunet start periodically in case the network somehow become logged out after inactivity.

Build From Source

Currently, tunet is tested on ramips/mt7620 and should work consistently for all targets.

Other platforms will be added gradually and you can always file an issue to request pre-compiled binary for these platforms.

Here are details for those who want to build the binary by themselves
  1. Get ready by following Install buildsystem and install prerequisites.

  2. Download OpenWrt SDK for your platform. Follow Using the SDK.

  3. For example, for mt7620 and OpenWrt 19.07.0, download and unzip openwrt-sdk-19.07.0-ramips-mt7620_gcc-7.5.0_musl.Linux-x86_64.tar.xz:

    tar xvf openwrt-sdk-19.07.0-ramips-mt7620_gcc-7.5.0_musl.Linux-x86_64.tar.xz
  4. Add tunet into SDK feeds feeds.conf.default:

    cd openwrt-sdk-19.07.0-ramips-mt7620_gcc-7.5.0_musl.Linux-x86_64

    Edit the file feeds.conf.default. Add the following line:

    src-git tunet https://github.com/robertying/tunet-c.git
    
  5. Use ./scripts/feeds update -a command to obtain and update package definitions.

  6. After the definitions have been updated, run ./scripts/feeds install libtidy tunet to prepare the package and its dependencies.

  7. Run make menuconfig and go to Global Build Settings to exclude the following:

    [ ] Select all target specific packages by default
    [ ] Select all kernel module packages by default
    [ ] Select all userspace packages by default
    
  8. Exit and go to Network, select tunet by pressing m and all the dependencies will be selected automatically.

  9. Save the configuration and exit the menu.

  10. Run make package/tunet/compile -j5

  11. After the compilation is finished, the generated .ipk files are placed in the bin/packages/$ARCH/tunet/ of the directory you extracted the SDK into.

Linux & macOS

Now you can only build tunet from source for general Linux distributions or macOS.

You need prerequisites like openssl, curl and tidy-html5 so that libcrypto, libcurl and libtidy exist in system PATH.

For example, macOS users should do:

brew install openssl curl tidy-html5
export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/opt/curl/lib -L/usr/local/opt/tidy-html5/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include -I/usr/local/opt/curl/include -I/usr/local/opt/tidy-html5/include"

And Linux (Ubuntu) users should do:

sudo apt update
sudo apt install libssl-dev libcurl4-openssl-dev libtidy-dev

Then build and install:

git clone --recursive https://github.com/robertying/tunet-c.git
cd tunet-c
./autogen.sh
./configure --prefix=/usr/local/
make
sudo make install

By default, the binary tunet is installed in $prefix/bin. Change --prefix=/usr/local/ to other directories if you want.

A shared library libtunet in $prefix/lib and a header file tunet.h in $prefix/include are provided as well if you want to integrate it yourself.

Android

See CampusNet-Android for details about NDK integration.

Contributing

Please file an issue if you encounter any problem or want new features.

Pull requests are mostly welcomed but will be considered carefully.

tunet-c's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tunet-c's Issues

路由器运行时返回ip地址错误

编译在openwrt上运行,返回以下错误:
E2833: Your IP address is not in the dhcp table. Maybe you need to renew the IP address.
请问如何解决,麻烦大佬有时间看一下~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.