- Specs
List of SSIDs of the campus Wi-Fi.
These networks will be marked as "On Campus", i.e. auto-login (if enabled) will be performed on these networks.
ssids:
- Tsinghua
- Tsinghua-5G
Whether to use decimal units for bytes. Default: false
.
- If set to
true
, 1 KB = 1000 B. - If set to
false
, 1 KB = 1024 B.
decimal_units: true
Definitions of network-related actions. Each action consists of a variable pool, a HTTP session, a JavaScript environment, as well as a list of action entries.
actions:
<action name>:
- <entry 1>
- <entry 2>
# ...
Each entry can have the following optional stages:
- HTTP Request
- XPath Selectors (require HTTP Request)
- JavaScript
Action entries can read/write variables from/to the variable pool. Before the first entry, action inputs are put into the pool. After the last entry, action outputs are extracted from the pool:
Method of the HTTP request. Default: GET
.
method: POST
URL of the HTTP requests. If not specified, the HTTP request stage will be skipped.
{var_name}
will be replaced with the value of var_name
if it can be found in
the variable poll.
url: https://net.tsinghua.edu.cn/users/{username}
Parameters of the HTTP request. For GET requests, they will be added to the
HTTP query strings. For other requests, They will be x-www-form-urlencoded
and
go to the HTTP body. For other form encodings, please set headers and body
manually.
{var_name}
in keys and values will be replaced with the value of var_name
if
it can be found in the variable poll.
params:
action: login
username: "{username}"
password: "{password_md5}"
ac_id: "1"
Headers of the HTTP request. Corresponding headers will be overridden.
{var_name}
in keys and values will be replaced with the value of var_name
if
it can be found in the variable poll.
headers:
Content-Type: application/json
User-Agent: "{user_agent}"
Body of the HTTP request. If set, will override the body set by params
.
{var_name}
will be replaced with the value of var_name
if it can be found in
the variable poll.
headers:
Content-Type: application/json
User-Agent: "{user_agent}"
Parse the HTTP response as HTML, select variables into the variable pool using XPaths.
- If the key is
var_name
, the trimmed text of the first match will be assigned tovar_name
. - If the key is
var_name[]
, an array of trimmed texts of all the matches will be assigned tovar_name
.
vars:
balance: (//td[@class="maintd"])[34]
usage: (//td[@class="maintd"])[26]
ips[]: //tr[position()>=2]/td[2]
Whether to change the status to offcampus
if the HTTP request fails. Default:
false
.
Most campus networks don't have a reliable way to check whether the device is off-campus. This option provides a way to do that.
offcampus_if_failed: true
The JavaScript to run after a request. Notice that to support iOS 9, only ES5 syntax should be used. The following variables can be accessed in the scripts:
url: String
: Full URL of the (possibly redirected) request.resp: String
: Body of the HTTP response.vars: {String: Any}
: Variable pool (onlyString
&Int
can go to placeholders).
Notice that you can also use variables defined in the previous action entries.
For conveniences, the following hash functions are pre-defined in the JavaScript environment:
function md5(String): String
function sha1(String): String
You can also throw strings to indicate errors. Supported errors are:
offcampus
: Set the status tooffcampus
.offline
: Set the status tooffline
.unauthorized
: Incorrect username or password.arrears
: The account is in arrears.unknown: <description>
: Other errors with custom descriptions.
The following errors are mostly used internally, but you can throw them anyway:
network_error
: Network error.invalid_configuration
: Invalid configuration file.internal_error
: Internal error.
script: |
var matches = /index_(\d+)/.exec(resp);
if (!matches) {
throw 'unknown: ' + resp;
}
vars.ac_id = matches[1];ine_username = info[0];
Default inputs:
username: String
: Username of the account.password: String
: Password of the account.
- Extra inputs: None.
- Expected outputs: None.
- Extra inputs: None.
- Expected outputs:
status: String
:online
,offline
oroffcampus
.online_username: String
(optional): The current online username ifstatus
isonline
.
- Extra inputs: None.
- Expected outputs: None.
- Extra inputs: None.
- Expected outputs:
name: String
(optional): Real name of the account owner.balance: Double
(optional): Balance of the account.data_balance: Int
(optional): Data balance of the account in bytes.usage: Int
(optional): Usage of the account in bytes.free_usage: Int
(optional): Free usage of the account in bytes.max_usage: Int
(optional): Max usage of the account in bytes.sessions: [Session]
(optional): Current online sessions.ip: String
: Session IP.id: String
(optional): Session ID.start_time: Date
(optional): Start time of the session.usage: Int
(optional): Usage of the session in bytes.mac: String
(optional): MAC address of the session.device: String
(optional): Device name of the session.
- Extra inputs:
year: Int
: Current year.month: Int
: Current month (1-12).day: Int
: Current day (1-31).
- Expected outputs:
usage_sums: [Int]
: Cumulative sums of the usage this month in bytes.
- Extra inputs:
ip: String
: IP address to login.
- Expected outputs: None.
- Extra inputs:
ip: String
: Session IP.id: String
: Session ID (empty if not existed).
- Expected outputs: None.