-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.aardio
392 lines (347 loc) · 11.1 KB
/
main.aardio
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import win.ui;
import win.ui.menu;
/*DSG{{*/
mainForm = win.form(text="Unofficial_Z_Access";right=757;bottom=467)
mainForm.add(
BTgo={cls="button";text="GO";left=684;top=2;right=757;bottom=23;dr=1;dt=1;z=3};
EDurl={cls="edit";text="https://bu2021.xyz/";left=1;top=0;right=681;bottom=24;aw=1;dl=1;dr=1;dt=1;edge=1;z=2};
mainWeb={cls="custom";text="自定义控件";left=0;top=28;right=753;bottom=467;db=1;dl=1;dr=1;dt=1;z=1}
)
/*}}*/
var HostResolverLine="";
var QUICLine="";
var HostLine="";
var CMDLine="";
//var CMDLine='--proxy-server=127.0.0.1:2500';
import wsock.tcp.simpleHttpServer;
var webbase=wsock.tcp.simpleHttpServer.startUrl()
//var url="https://zh.z-library.se/";
var url="/web/index.html";
if(_ARGV["c"])
{
import fsys.file;
var cfg;
if(_ARGV["c"]!="")
cfg=fsys.file(_ARGV["c"]);
else
cfg=fsys.file("CMDconfig.txt");
if(!fsys.file.is(cfg))
{
win.msgboxErr("No Config File! ","ERROR!");
return;
}
CMDLine=cfg.read();
cfg.close();
}
if(true)
{
HostResolverLine="";
QUICLine="";
import fsys.file;
var cfg;
if(_ARGV["d"]!=""&&_ARGV["d"]!=null)
cfg=fsys.file(_ARGV["d"]);
else
cfg=fsys.file("DOMAINconfig.txt");
if(!fsys.file.is(cfg))
{
win.msgboxErr("No Config File! ","ERROR!");
return;
}
while(1)
{
var IP=cfg.read();
var d=IP;
while(1)
{
d=cfg.read();
if(d=="") break 1;
else if(!d) break 2;
if(string.unpack(d,1,1)==string.unpack("^"))
{
d=string.slice(d,2,-1,true);
HostLine=HostLine+"MAP "+d+" "+IP+",";
}
else if(string.unpack(d,1,1)==string.unpack("-"))
{
d=string.slice(d,2,-1,true);
HostResolverLine=HostResolverLine+"MAP "+d+" "+IP+":443,";
}
else
{
HostResolverLine=HostResolverLine+"MAP "+d+" "+IP+":443,";
QUICLine=QUICLine+d+":443,";
}
}
}
cfg.close();
if(HostResolverLine!="") HostResolverLine=string.slice(HostResolverLine,1,-2,true);
if(QUICLine!="") QUICLine=string.slice(QUICLine,1,-2,true);
if(HostLine!="") HostLine=string.slice(HostLine,1,-2,true);
CMDLine="";
if(HostResolverLine!="") CMDLine=CMDLine+'--host-resolver-rules="'+HostResolverLine+'" ';
if(QUICLine!="") CMDLine=CMDLine+'-origin-to-force-quic-on='+QUICLine+' ';
if(HostLine!="") CMDLine=CMDLine+'--host-rules="'+HostLine+'" --ignore-certificate-errors ';
if(CMDLine!="") CMDLine=string.slice(CMDLine,1,-2,true);
}
if(_ARGV["p"]||_STUDIO_INVOKED)
{
import fsys.file;
import web.json;
var fcfg=fsys.file("config.json")
if(!fsys.file.is(fcfg))
{
win.msgboxErr("No Config File! ","ERROR!");
return;
}
var cfg=fcfg.read(-1)
//win.msgbox(cfg)
fcfg.close()
cfg=web.json.parse(cfg)
//win.msgbox(cfg)
var VarietesofCode=/**class TrieNode {
constructor(value){
this.value = value;
this.num=1;
this.deep=0;
this.son=[];
this.isEnd=false;
}
findNode(value){
for(let i=0;i<this.son.length;i++){
const node=this.son[i]
if(node.value == value){
return node;
}
}
return null;
}
}
class Trie {
constructor(){
this.root=new TrieNode(null);
this.size=1;
}
insert(str){
let node=this.root;
for(let c of str){
let snode = node.findNode(c);
if(snode==null){
snode=new TrieNode(c)
snode.deep=node.deep+1;
node.son.push(snode);
}else{
snode.num++;
}
node=snode;
}
if (!node.isEnd) {
this.size++;
node.isEnd = true;
}
}
has(str){
let node=this.root;
for(let c of str){
const snode=node.findNode(c)
if(snode){
node=snode;
}else{
return false;
}
}
return node.isEnd;
}
}
let tr=null;
function BuildAutomatom(arr) {
tr=new Trie()
arr.forEach(function (item) {
tr.insert(item)
})
root=tr.root;
root.fail=null;
const queue=[root]
let i=0;
while(i<queue.length){
const temp=queue[i];
for(let j=0;j<temp.son.length;j++){
const node=temp.son[j]
if(temp===root){
node.fail=root;
}else{
node.fail=temp.fail.findNode(node.value)||root;
}
queue.push(node);
}
i++
}
}
function MatchAutomatom(str) {
let node=tr.root;
const data=[];
for(let i=0;i<str.length;i++){
let cnode=node.findNode(str[i])
while(!cnode&&node!==tr.root){
node=node.fail;
cnode=node.findNode(str[i])
}
if(cnode){
node=cnode;
}
if(node.isEnd){
data.push({
start:i+1-node.deep,
len:node.deep,
str:str.substr(i+1-node.deep,node.deep),
num:node.num,
})
}
}
return data;
}
**/
fcfg=fsys.file("proxy.pac","w")
fcfg.write(VarietesofCode)
fcfg.write('let domains=[];\n')
for domain in cfg["domains"]
{
fcfg.write('domains.push("')
fcfg.write(domain)
fcfg.write('");\n')
}
fcfg.write('BuildAutomatom(domains);\n')
VarietesofCode=/**function FindProxyForURL(url, host) {
if(MatchAutomatom(host).length)
return "PROXY 127.0.0.1:**/
fcfg.write(VarietesofCode);
fcfg.write(tostring(cfg["listen_PORT"]));
VarietesofCode=/**";
else
return "DIRECT";
}
**/
fcfg.write(VarietesofCode)
fcfg.close()
var pacpath=webbase+"/proxy.pac"
//url="https://freezhihu.org"
//url="https://cn.bing.com"
//win.msgbox(pacpath)
//CMDLine=CMDLine+' --proxy-pac-url="file:\\\\\\d:\\apps\\unofficial_z_access\\proxy.pac"';
CMDLine=CMDLine+" --proxy-pac-url="+pacpath;
//CMDLine=CMDLine+" --proxy-server=127.0.0.1:2500";
import process.python;
import process.python.pip;
process.python.pip.require("requests==2.32.3")
process.python.pip.require("ahocorasick-python==0.0.9")
process.python.pip.require("dnspython==2.3.0")
process.python.execfile("/py/server.py")
console.close()
}
import web.view.7;
if(string.len(CMDLine)>=8192) win.msgbox("Too long CMDLine, and this may cause Error. ","Warning");
var view=web.view(mainForm.mainWeb,0,CMDLine);
view.go(webbase+"/web/index.html");
//win.msgbox(webbase)
mainForm.show();
import fsys.file
wrt=fsys.file("CMDline.txt","w")
wrt.write(CMDLine)
wrt.close()
var AndroidLine=CMDLine;
var ReplaceTable={
['"'] = "\"+'"'
};
AndroidLine=string.replace(AndroidLine,".|:",ReplaceTable);
AndroidLine='echo "_'+" "+AndroidLine+'" > chrome-command-line';
wrt=fsys.file("AndroidECHO.txt","w")
wrt.write(AndroidLine)
wrt.close()
if(_ARGV["o"])
{
url=webbase+"/CMDline.txt";
}
else if(_ARGV["a"])
{
url=webbase+"/AndroidECHO.txt";
}
else if(_ARGV["g"]) url=_ARGV["g"];
else if(_ARGV["h"])
{
url=webbase+"/help.html";
}
view.go(webbase+url);
mainForm.BTgo.oncommand = function(id,event){
if(mainForm.EDurl.text=="index") mainForm.EDurl.text=webbase+"/web/index.html"
if(mainForm.EDurl.text=="proxypac") mainForm.EDurl.text=webbase+"/proxy.pac"
if(mainForm.EDurl.text=="cmdline") mainForm.EDurl.text=webbase+"/CMDline.txt"
if(mainForm.EDurl.text=="androidecho") mainForm.EDurl.text=webbase+"/AndroidECHO.txt"
view.go(mainForm.EDurl.text)
}
mainForm.EDurl.oncommand = function(id,event){
}
return win.loopMessage();
/* You may need:
// from: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/network_session_configurator/common/network_switch_list.h
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file deliberately has no header guard, as it's inlined in a number of
// files.
// no-include-guard-because-multiply-included
// Disables the QUIC protocol.
NETWORK_SWITCH(kDisableQuic, "disable-quic")
// Disables the HTTP/2 protocol.
NETWORK_SWITCH(kDisableHttp2, "disable-http2")
// Enables Alternate-Protocol when the port is user controlled (> 1024).
NETWORK_SWITCH(kEnableUserAlternateProtocolPorts,
"enable-user-controlled-alternate-protocol-ports")
// Enables the QUIC protocol. This is a temporary testing flag.
NETWORK_SWITCH(kEnableQuic, "enable-quic")
// Ignores certificate-related errors.
NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors")
// Specifies a comma separated list of host-port pairs to force use of QUIC on.
NETWORK_SWITCH(kOriginToForceQuicOn, "origin-to-force-quic-on")
// Disables known-root checks for outgoing WebTransport connections.
NETWORK_SWITCH(kWebTransportDeveloperMode, "webtransport-developer-mode")
// Specifies a comma separated list of QUIC connection options to send to
// the server.
NETWORK_SWITCH(kQuicConnectionOptions, "quic-connection-options")
// Specifies a comma separated list of QUIC client connection options.
NETWORK_SWITCH(kQuicClientConnectionOptions, "quic-client-connection-options")
// Specifies the maximum length for a QUIC packet.
NETWORK_SWITCH(kQuicMaxPacketLength, "quic-max-packet-length")
// Specifies the version of QUIC to use.
NETWORK_SWITCH(kQuicVersion, "quic-version")
// Allows for forcing socket connections to http/https to use fixed ports.
NETWORK_SWITCH(kTestingFixedHttpPort, "testing-fixed-http-port")
NETWORK_SWITCH(kTestingFixedHttpsPort, "testing-fixed-https-port")
// Comma-separated list of rules that control how hostnames are mapped.
//
// For example:
// "MAP * 127.0.0.1" --> Forces all hostnames to be mapped to 127.0.0.1
// "MAP *.google.com proxy" --> Forces all google.com subdomains to be
// resolved to "proxy".
// "MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback.
// Will also force the port of the resulting
// socket address to be 77.
// "MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz",
// except for "www.google.com".
//
// These mappings apply to the endpoint host in a net::URLRequest (the TCP
// connect and host resolver in a direct connection, and the CONNECT in an http
// proxy connection, and the endpoint host in a SOCKS proxy connection).
//
// TODO(mmenke): Can we just remove this? host-resolver-rules is more generally
// useful.
NETWORK_SWITCH(kHostRules, "host-rules")
// Enable "greasing" HTTP/2 frame types, that is, sending frames of reserved
// types. See https://tools.ietf.org/html/draft-bishop-httpbis-grease-00 for
// more detail.
NETWORK_SWITCH(kHttp2GreaseFrameType, "http2-grease-frame-type")
// If request has no body, close the stream not by setting END_STREAM flag on
// the HEADERS frame, but by sending an empty DATA frame with END_STREAM
// afterwards. Only affects HTTP/2 request streams, not proxy or bidirectional
// streams.
NETWORK_SWITCH(kHttp2EndStreamWithDataFrame, "http2-end-stream-with-data-frame")
*/