4
4
use function Swoole \Timer ;
5
5
declare (ticks=1 )
6
6
date_default_timezone_set ('Asia/Shanghai ' );
7
- set_time_limit (0 );
8
- ini_set ('memory_limit ' , '-1 ' );
9
7
require './config.php ' ;
10
8
const PHPOBAVERSION = '1.3.0 ' ;
11
9
const VERSION = '1.10.4 ' ;
12
10
global $ DOWNLOAD_DIR ;
13
11
$ DOWNLOAD_DIR = $ config ['file ' ]['cache_dir ' ];
14
12
const USERAGENT = 'openbmclapi-cluster/ ' . VERSION . ' ' . 'PHP-OpenBmclApi/ ' .PHPOBAVERSION ;
15
- const OPENBMCLAPIURL = 'openbmclapi.bangbang93.com ' ;
13
+ const OPENBMCLAPIURL = 'openbmclapi.staging. bangbang93.com ' ;
16
14
$ list = glob ('inc/*.php ' );
17
15
foreach ($ list as $ file ) {
18
16
require $ file ;
@@ -55,7 +53,49 @@ function registerSigintHandler() {
55
53
});
56
54
registerSigintHandler ();
57
55
mlog ("Timer start on ID {$ tokentimerid }" ,1 );
58
-
56
+ //建立socketio连接主控
57
+ $ socketio = new socketio (OPENBMCLAPIURL ,$ tokendata ['token ' ],$ config ['advanced ' ]['keepalive ' ]);
58
+ mlog ("正在连接主控 " );
59
+ Coroutine::create (function () use ($ socketio ){
60
+ $ socketio ->connect ();
61
+ });
62
+ Coroutine::sleep (1 );
63
+ //获取证书
64
+ $ socketio ->ack ("request-cert " );
65
+ Coroutine::sleep (1 );
66
+ $ allcert = $ socketio ->Getcert ();
67
+ //写入证书并且是否损坏
68
+ if (!file_exists ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' ) && !file_exists ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' )) {
69
+ mlog ("正在获取证书 " );
70
+ if (!file_exists ("./cert " )) {
71
+ mkdir ("./cert " ,0777 ,true );
72
+ }
73
+ mlog ("已获取证书,到期时间 {$ allcert ['0 ' ]['1 ' ]['expires ' ]}" );
74
+ $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' , 'w ' );
75
+ $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['cert ' ]);
76
+ fclose ($ cert );
77
+ $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' , 'w ' );
78
+ $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['key ' ]);
79
+ fclose ($ cert );
80
+ }
81
+ $ crt = file_get_contents ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' );
82
+ if ($ crt !== $ allcert ['0 ' ]['1 ' ]['cert ' ]) {
83
+ mlog ("证书损坏/过期 " );
84
+ mlog ("已获取新的证书,到期时间 {$ allcert ['0 ' ]['1 ' ]['expires ' ]}" );
85
+ $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' , 'w ' );
86
+ $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['cert ' ]);
87
+ fclose ($ cert );
88
+ $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' , 'w ' );
89
+ $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['key ' ]);
90
+ fclose ($ cert );
91
+ }
92
+ //启动http服务器
93
+ global $ httpserver ;
94
+ $ httpserver = new fileserver ($ config ['cluster ' ]['host ' ],$ config ['cluster ' ]['port ' ],$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' ,$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' ,$ config ['cluster ' ]['CLUSTER_SECRET ' ]);
95
+ Coroutine::create (function () use ($ config ,$ httpserver ){
96
+ $ httpserver ->startserver ();
97
+ });
98
+
59
99
//下载文件列表
60
100
$ cluster = new cluster ($ tokendata ['token ' ],VERSION );
61
101
$ files = $ cluster ->getFileList ();
@@ -69,6 +109,7 @@ function registerSigintHandler() {
69
109
elseif ($ config ['file ' ]['check ' ] == "exists " ){
70
110
$ Missfile = $ FilesCheck ->FilesCheckerexists ();
71
111
}
112
+ //循环到没有Missfile这个变量
72
113
if (is_array ($ Missfile )){
73
114
mlog ("缺失/损坏 " .count ($ Missfile )."个文件 " );
74
115
while (is_array ($ Missfile )){
@@ -100,44 +141,7 @@ function registerSigintHandler() {
100
141
}
101
142
global $ shouldExit ;
102
143
if (!is_array ($ Missfile ) && !$ shouldExit ){//判断Missfile是否为空和是否是主动退出
103
- $ socketio = new socketio (OPENBMCLAPIURL ,$ tokendata ['token ' ],$ config ['advanced ' ]['keepalive ' ]);
104
- mlog ("正在连接主控 " );
105
- Coroutine::create (function () use ($ socketio ){
106
- $ socketio ->connect ();
107
- });
108
- Coroutine::sleep (1 );
109
- $ socketio ->ack ("request-cert " );
110
- Coroutine::sleep (1 );
111
- $ allcert = $ socketio ->Getcert ();
112
- if (!file_exists ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' ) && !file_exists ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' )) {
113
- mlog ("正在获取证书 " );
114
- if (!file_exists ("./cert " )) {
115
- mkdir ("./cert " ,0777 ,true );
116
- }
117
- mlog ("已获取证书,到期时间 {$ allcert ['0 ' ]['1 ' ]['expires ' ]}" );
118
- $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' , 'w ' );
119
- $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['cert ' ]);
120
- fclose ($ cert );
121
- $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' , 'w ' );
122
- $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['key ' ]);
123
- fclose ($ cert );
124
- }
125
- $ crt = file_get_contents ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' );
126
- if ($ crt !== $ allcert ['0 ' ]['1 ' ]['cert ' ]) {
127
- mlog ("证书损坏/过期 " );
128
- mlog ("已获取新的证书,到期时间 {$ allcert ['0 ' ]['1 ' ]['expires ' ]}" );
129
- $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' , 'w ' );
130
- $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['cert ' ]);
131
- fclose ($ cert );
132
- $ cert = fopen ('./cert/ ' .$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' , 'w ' );
133
- $ Writtencert = fwrite ($ cert , $ allcert ['0 ' ]['1 ' ]['key ' ]);
134
- fclose ($ cert );
135
- }
136
- global $ httpserver ;
137
- $ httpserver = new fileserver ($ config ['cluster ' ]['host ' ],$ config ['cluster ' ]['port ' ],$ config ['cluster ' ]['CLUSTER_ID ' ].'.crt ' ,$ config ['cluster ' ]['CLUSTER_ID ' ].'.key ' ,$ config ['cluster ' ]['CLUSTER_SECRET ' ]);
138
- Coroutine::create (function () use ($ config ,$ httpserver ){
139
- $ httpserver ->startserver ();
140
- });
144
+ //enable节点
141
145
$ socketio ->enable ($ config ['cluster ' ]['public_host ' ],$ config ['cluster ' ]['public_port ' ],$ config ['cluster ' ]['byoc ' ]);
142
146
}
143
147
});
0 commit comments