This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
202 lines (188 loc) · 7.77 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>复旦校园网自动连接工具</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<div class="container" ng-app="fdApp" ng-controller="main">
<div class="row">
<div class="col-xs-8 col-xs-offset-2" ng-show="mainShow">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
基本信息
</h3>
</div>
<div class="panel-body">
<h3><strong>学号:</strong>{{stuId}}</h3>
<h3><strong>自动重连时间</strong>:{{updateMinute}}分钟</h3>
<h3><strong>当前网络状态:</strong>{{connectStatus}}</h3>
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
还有这种操作
</h3>
</div>
<div class="panel-body">
<button class="btn btn-default" ng-click="connect()">重新连接</button>
<button class="btn btn-default" ng-click="checkConnect()">检测连接</button>
<button class="btn btn-default" ng-click="editConfig()">修改配置</button>
</div>
</div>
</div>
<div class="col-xs-8 col-xs-offset-2" ng-show="!mainShow">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
配置修改
</h3>
</div>
<div class="panel-body">
<div class="form-horizontal">
<div class="form-group">
<label for="stuId" class="col-xs-3 control-label">学号</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="stuId" placeholder="学号" ng-model="stuId">
</div>
</div>
<div class="form-group">
<label for="stuPasswd" class="col-xs-3 control-label">密码</label>
<div class="col-xs-9">
<input type="password" class="form-control" id="stuPasswd" placeholder="密码" ng-model="stuPasswd">
</div>
</div>
<div class="form-group">
<label for="updateMinute" class="col-xs-3 control-label">重连时长(分钟)</label>
<div class="col-xs-9">
<input type="number" class="form-control" id="updateMinute" placeholder="重连时长(分钟)" ng-model="updateMinute">
</div>
</div>
<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
<label>
<input type="checkbox" ng-model="hide">启动时窗口缩小至托盘
</label>
</div>
</div>
<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
<button class="btn btn-primary" ng-click="saveConfig()">保存</button>
<button class="btn btn-default" ng-click="cancelEditConfig()">取消</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="js/angular.min.js"></script>
<script>
const http = require('http');
const querystring = require('querystring');
const fs = require('fs');
const path = require('path');
const request = require('request');
const remote = require('electron').remote;
let configName = "config.json";
let app = angular.module('fdApp', []);
app.controller('main', function($scope) {
let timeHandle = null;
init();
function init() {
$scope.mainShow = true;
loadConfig();
if ($scope.hide) {
remote.getCurrentWindow().hide();
}
connectWeb();
timeHandle = setInterval(connectWeb, $scope.updateMinute * 60 * 1000);
testConnect();
$scope.editConfig = function () {
$scope.mainShow = false;
$scope.$apply();
};
$scope.checkConnect = testConnect;
$scope.connect = connectWeb;
$scope.cancelEditConfig = function () {
$scope.mainShow = true;
$scope.$apply();
};
$scope.saveConfig = function () {
let data = JSON.stringify({
stuId: $scope.stuId,
stuPasswd: $scope.stuPasswd,
updateMinute: $scope.updateMinute,
hide: $scope.hide
});
const configPath = path.join(__dirname, configName);
fs.writeFileSync(configPath, data);
$scope.mainShow = true;
$scope.$apply();
connectWeb();
clearInterval(timeHandle);
timeHandle = setInterval(connectWeb, $scope.updateMinute * 60 * 1000);
}
}
function loadConfig() {
const configPath = path.join(__dirname, configName);
let config = JSON.parse(fs.readFileSync(configPath));
$scope.stuId = config.stuId;
$scope.stuPasswd = config.stuPasswd;
$scope.updateMinute = config.updateMinute;
$scope.hide = config.hide;
}
function connectWeb() {
var data = querystring.stringify({
action: "login",
username: $scope.stuId,
password: $scope.stuPasswd,
ac_id: 1,
ajax: 1
});
var options = {
host: '10.108.255.249',
path:'/include/auth_action.php',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log("body: " + chunk);
});
res.on('end',function(chunk){
console.log("body: " + chunk);
})
});
req.write(data);
req.end();
// let urlPath = 'http://10.108.255.249/include/auth_action.php?action=login&username=' + $scope.stuId +
// '&password=' + $scope.stuPasswd +
// '&ac_id=1&user_ip=10.141.248.186&ajax=1';
// console.log(urlPath);
// http.get(urlPath, function (res) {
// console.log("statusCode: ", res.statusCode);
// })
}
function testConnect() {
request('https://www.baidu.com', function (error, response, body) {
if (error) {
$scope.connectStatus = '未连接';
} else {
$scope.connectStatus = '已连接';
}
$scope.$apply();
})
}
});
</script>
</html>