Passed
Pull Request — master (#13)
by
unknown
02:04
created
index.php 3 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -277,25 +277,25 @@  discard block
 block discarded – undo
277 277
 
278 278
         system_log($renew_log ?: sprintf("在%s这个时刻,并没有需要续期的域名,写这条日志是为了证明我确实执行了。今次取得的域名信息如是:\n%s", date('Y-m-d H:i:s'), var_export($domains, true)));
279 279
         if ($this->notRenewed || $this->renewed) {
280
-		if (static::$config['telegram']['enable'] == 'true') {
281
-			$this->sendTelegram(
282
-		[
283
-	                    $this->renewed ? '续期成功:' . $this->renewed . '<br>' : '',
284
-	                    $this->notRenewed ? '续期出错:' . $this->notRenewed . '<br>' : '',
285
-	                    $this->domainsInfo ?: '啊咧~没看到其它域名呢。'
286
-	                ]
287
-			);
288
-		} else {
289
-				$this->sendEmail(
290
-	                '主人,我刚刚帮你续期域名啦~',
291
-	                [
292
-	                    $this->renewed ? '续期成功:' . $this->renewed . '<br>' : '',
293
-	                    $this->notRenewed ? '续期出错:' . $this->notRenewed . '<br>' : '',
294
-	                    $this->domainsInfo ?: '啊咧~没看到其它域名呢。'
295
-	                ]
296
-	            );
297
-		}		
298
-	}
280
+        if (static::$config['telegram']['enable'] == 'true') {
281
+            $this->sendTelegram(
282
+        [
283
+                        $this->renewed ? '续期成功:' . $this->renewed . '<br>' : '',
284
+                        $this->notRenewed ? '续期出错:' . $this->notRenewed . '<br>' : '',
285
+                        $this->domainsInfo ?: '啊咧~没看到其它域名呢。'
286
+                    ]
287
+            );
288
+        } else {
289
+                $this->sendEmail(
290
+                    '主人,我刚刚帮你续期域名啦~',
291
+                    [
292
+                        $this->renewed ? '续期成功:' . $this->renewed . '<br>' : '',
293
+                        $this->notRenewed ? '续期出错:' . $this->notRenewed . '<br>' : '',
294
+                        $this->domainsInfo ?: '啊咧~没看到其它域名呢。'
295
+                    ]
296
+                );
297
+        }		
298
+    }
299 299
 
300 300
         $curl->close();
301 301
 
@@ -394,17 +394,17 @@  discard block
 block discarded – undo
394 394
 } catch (LlfException $e) {
395 395
     system_log($e->getMessage());
396 396
 if (static::$config['telegram']['enable'] == 'true') {
397
-	FREENOM::instance()->sendTelegram(
398
-		[$e->getMessage(),$e->getFile(),$e->getLine(),$e->getMessage()]
399
-	);
397
+    FREENOM::instance()->sendTelegram(
398
+        [$e->getMessage(),$e->getFile(),$e->getLine(),$e->getMessage()]
399
+    );
400 400
 } else {
401
-	    FREENOM::instance()->sendEmail(
402
-	        '主人,' . $e->getMessage(),
403
-	        sprintf('具体是在%s文件的%d行,抛出了一个异常。异常的内容是%s,快去看看吧。', $e->getFile(), $e->getLine(), $e->getMessage()),
404
-	        '',
405
-	        'llfexception'
406
-	    );
407
-	}
401
+        FREENOM::instance()->sendEmail(
402
+            '主人,' . $e->getMessage(),
403
+            sprintf('具体是在%s文件的%d行,抛出了一个异常。异常的内容是%s,快去看看吧。', $e->getFile(), $e->getLine(), $e->getMessage()),
404
+            '',
405
+            'llfexception'
406
+        );
407
+    }
408 408
 } catch (\Exception $e) {
409 409
     system_log(sprintf('#%d - %s', $e->getCode(), $e->getMessage()));
410 410
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             chmod($logFile, 0666);
77 77
         }
78 78
 
79
-        fwrite($handle, $mark . ' - ' . date('Y-m-d H:i:s') . ' --> ' . (IS_CLI ? 'CLI' : 'URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL . 'REMOTE_ADDR: ' . $_SERVER['REMOTE_ADDR'] . PHP_EOL . 'SERVER_ADDR: ' . $_SERVER['SERVER_ADDR']) . PHP_EOL . (is_string($logContent) ? $logContent : var_export($logContent, true)) . PHP_EOL); // CLI模式下,$_SERVER中几乎无可用值
79
+        fwrite($handle, $mark . ' - ' . date('Y-m-d H:i:s') . ' --> ' . (IS_CLI ? 'CLI' : 'URI: ' . $_SERVER[ 'REQUEST_URI' ] . PHP_EOL . 'REMOTE_ADDR: ' . $_SERVER[ 'REMOTE_ADDR' ] . PHP_EOL . 'SERVER_ADDR: ' . $_SERVER[ 'SERVER_ADDR' ]) . PHP_EOL . (is_string($logContent) ? $logContent : var_export($logContent, true)) . PHP_EOL); // CLI模式下,$_SERVER中几乎无可用值
80 80
 
81 81
         fclose($handle);
82 82
     } catch (\Exception $e) {
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     public function autoLogin()
171 171
     {
172 172
         $curl = new Curl();
173
-        $curl->setUserAgent(static::$config['userInfo']['userAgent']);
173
+        $curl->setUserAgent(static::$config[ 'userInfo' ][ 'userAgent' ]);
174 174
         $curl->setReferrer('https://my.freenom.com/clientarea.php');
175 175
         $curl->setHeaders([
176 176
             'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
@@ -178,21 +178,21 @@  discard block
 block discarded – undo
178 178
         ]);
179 179
         $curl->setTimeout(static::$timeOut);
180 180
         $curl->post(static::LOGIN_URL, [
181
-            'username' => static::$config['userInfo']['username'],
182
-            'password' => static::$config['userInfo']['password']
181
+            'username' => static::$config[ 'userInfo' ][ 'username' ],
182
+            'password' => static::$config[ 'userInfo' ][ 'password' ]
183 183
         ]);
184 184
 
185 185
         if ($curl->error) {
186
-            throw new LlfException(6001, [$curl->errorCode, $curl->errorMessage]);
186
+            throw new LlfException(6001, [ $curl->errorCode, $curl->errorMessage ]);
187 187
         }
188 188
 
189 189
         $curl->close();
190 190
 
191
-        if (!isset($curl->responseCookies['WHMCSZH5eHTGhfvzP'])) { // freenom有几率出现未成功登录也写此cookie的情况,所以此处不能完全断定是否登录成功,这是freenom的锅。若未成功登录,会在后面匹配域名信息的时候抛出异常。
191
+        if (!isset($curl->responseCookies[ 'WHMCSZH5eHTGhfvzP' ])) { // freenom有几率出现未成功登录也写此cookie的情况,所以此处不能完全断定是否登录成功,这是freenom的锅。若未成功登录,会在后面匹配域名信息的时候抛出异常。
192 192
             throw new LlfException(6002);
193 193
         }
194 194
 
195
-        static::$authCookie = $curl->responseCookies['WHMCSZH5eHTGhfvzP'];
195
+        static::$authCookie = $curl->responseCookies[ 'WHMCSZH5eHTGhfvzP' ];
196 196
 
197 197
         return $curl->responseCookies;
198 198
     }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     public function renewDomains()
207 207
     {
208 208
         $curl = new Curl();
209
-        $curl->setUserAgent(static::$config['userInfo']['userAgent']);
209
+        $curl->setUserAgent(static::$config[ 'userInfo' ][ 'userAgent' ]);
210 210
         $curl->setTimeout(static::$timeOut);
211 211
         $curl->setCookies([ // 验证登录状态
212 212
             'WHMCSZH5eHTGhfvzP' => static::$authCookie
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
         ]);
227 227
 
228 228
         if ($curl->error) {
229
-            throw new LlfException(6003, [$curl->errorCode, $curl->errorMessage]);
229
+            throw new LlfException(6003, [ $curl->errorCode, $curl->errorMessage ]);
230 230
         }
231 231
 
232 232
         // 取得token
233 233
         if (!preg_match(self::$tokenRegex, $curl->response, $token)) {
234 234
             throw new LlfException(6004);
235 235
         }
236
-        $token = $token[1];
236
+        $token = $token[ 1 ];
237 237
 
238 238
         // 取得域名数据
239 239
         if (!preg_match_all(self::$domainInfoRegex, $curl->response, $domains, PREG_SET_ORDER)) { // PREG_SET_ORDER结果排序为$matches[0]包含第一次匹配得到的所有匹配(包含子组), $matches[1]是包含第二次匹配到的所有匹配(包含子组)的数组,以此类推。
@@ -245,39 +245,39 @@  discard block
 block discarded – undo
245 245
          */
246 246
         $renew_log = '';
247 247
         foreach ($domains as $domain) {
248
-            if (intval($domain[4]) <= 14) { // 免费域名只允许在到期前14天内续期
249
-                $curl->setReferrer('https://my.freenom.com/domains.php?a=renewdomain&domain=' . $domain[5]);
248
+            if (intval($domain[ 4 ]) <= 14) { // 免费域名只允许在到期前14天内续期
249
+                $curl->setReferrer('https://my.freenom.com/domains.php?a=renewdomain&domain=' . $domain[ 5 ]);
250 250
                 $curl->setHeader('Content-Type', 'application/x-www-form-urlencoded');
251 251
                 $curl->post(static::RENEW_DOMAIN_URL, [
252 252
                     'token' => $token,
253
-                    'renewalid' => $domain[5], // 域名id
254
-                    'renewalperiod[' . $domain[5] . ']' => '12M', // 续期一年
253
+                    'renewalid' => $domain[ 5 ], // 域名id
254
+                    'renewalperiod[' . $domain[ 5 ] . ']' => '12M', // 续期一年
255 255
                     'paymentmethod' => 'credit', // 支付方式 - 信用卡
256 256
                 ]);
257 257
 
258 258
                 if ($curl->error) {
259
-                    throw new LlfException(6006, [$domain[1], $curl->errorCode, $curl->errorMessage]);
259
+                    throw new LlfException(6006, [ $domain[ 1 ], $curl->errorCode, $curl->errorMessage ]);
260 260
                 }
261 261
 
262 262
                 sleep(1); // 防止操作过于频繁
263 263
 
264 264
                 if (stripos($curl->rawResponse, 'Order Confirmation') === false) { // 续期失败
265
-                    $renew_log .= $domain[1] . '续期失败' . "\n";
266
-                    $this->notRenewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[1], $domain[1]);
265
+                    $renew_log .= $domain[ 1 ] . '续期失败' . "\n";
266
+                    $this->notRenewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[ 1 ], $domain[ 1 ]);
267 267
                 } else {
268
-                    $renew_log .= $domain[1] . '续期成功' . "\n";
269
-                    $this->renewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[1], $domain[1]);
268
+                    $renew_log .= $domain[ 1 ] . '续期成功' . "\n";
269
+                    $this->renewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[ 1 ], $domain[ 1 ]);
270 270
                     continue;
271 271
                 }
272 272
             }
273 273
 
274
-            $this->domainsInfo .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>' . '还有<span style="font-weight: bold; font-size: 16px;">%d</span>天到期,', $domain[1], $domain[1], intval($domain[4]));
275
-            $this->sendTelegram($domain[1].' left '.$domain[4]);
274
+            $this->domainsInfo .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>' . '还有<span style="font-weight: bold; font-size: 16px;">%d</span>天到期,', $domain[ 1 ], $domain[ 1 ], intval($domain[ 4 ]));
275
+            $this->sendTelegram($domain[ 1 ] . ' left ' . $domain[ 4 ]);
276 276
         }
277 277
 
278 278
         system_log($renew_log ?: sprintf("在%s这个时刻,并没有需要续期的域名,写这条日志是为了证明我确实执行了。今次取得的域名信息如是:\n%s", date('Y-m-d H:i:s'), var_export($domains, true)));
279 279
         if ($this->notRenewed || $this->renewed) {
280
-		if (static::$config['telegram']['enable'] == 'true') {
280
+		if (static::$config[ 'telegram' ][ 'enable' ] == 'true') {
281 281
 			$this->sendTelegram(
282 282
 		[
283 283
 	                    $this->renewed ? '续期成功:' . $this->renewed . '<br>' : '',
@@ -315,21 +315,21 @@  discard block
 block discarded – undo
315 315
         $mail = new PHPMailer(true);
316 316
 
317 317
         // 邮件服务配置
318
-        $mail->SMTPDebug = static::$config['mail']['debug']; // debug,正式环境应关闭 0:关闭 1:客户端信息 2:客户端和服务端信息
318
+        $mail->SMTPDebug = static::$config[ 'mail' ][ 'debug' ]; // debug,正式环境应关闭 0:关闭 1:客户端信息 2:客户端和服务端信息
319 319
         $mail->isSMTP(); // 告诉PHPMailer使用SMTP
320 320
         $mail->Host = 'smtp.gmail.com'; // SMTP服务器
321 321
         $mail->SMTPAuth = true; // 启用SMTP身份验证
322
-        $mail->Username = static::$config['mail']['username']; // 账号
323
-        $mail->Password = static::$config['mail']['password']; // 密码
322
+        $mail->Username = static::$config[ 'mail' ][ 'username' ]; // 账号
323
+        $mail->Password = static::$config[ 'mail' ][ 'password' ]; // 密码
324 324
         $mail->SMTPSecure = 'tls'; // 将加密系统设置为使用 - ssl(不建议使用)或tls
325 325
         $mail->Port = 587; // 设置SMTP端口号 - tsl使用587端口,ssl使用465端口
326 326
 
327 327
         $mail->CharSet = 'UTF-8'; // 防止中文邮件乱码
328 328
         $mail->setLanguage('zh_cn', VENDOR_PATH . '/phpmailer/phpmailer/language/'); // 设置语言
329 329
 
330
-        $mail->setFrom(static::$config['mail']['from'], 'im robot'); // 发件人
331
-        $mail->addAddress($to ?: static::$config['mail']['to'], '罗叔叔'); // 添加收件人,参数2选填
332
-        $mail->addReplyTo(static::$config['mail']['replyTo'], '罗飞飞'); // 备用回复地址,收到的回复的邮件将被发到此地址
330
+        $mail->setFrom(static::$config[ 'mail' ][ 'from' ], 'im robot'); // 发件人
331
+        $mail->addAddress($to ?: static::$config[ 'mail' ][ 'to' ], '罗叔叔'); // 添加收件人,参数2选填
332
+        $mail->addReplyTo(static::$config[ 'mail' ][ 'replyTo' ], '罗飞飞'); // 备用回复地址,收到的回复的邮件将被发到此地址
333 333
 
334 334
         /**
335 335
          * 抄送和密送都是添加收件人,抄送方式下,被抄送者知道除被密送者外的所有的收件人,密送方式下,
@@ -370,13 +370,13 @@  discard block
 block discarded – undo
370 370
     
371 371
     public function sendTelegram($text)
372 372
     {
373
-            $token = static::$config['telegram']['token'];
374
-            $chatid = static::$config['telegram']['chatid'];
373
+            $token = static::$config[ 'telegram' ][ 'token' ];
374
+            $chatid = static::$config[ 'telegram' ][ 'chatid' ];
375 375
             $curl = new Curl();
376 376
             if (!is_string($text)) {
377
-                    $text=var_export($text,true);
377
+                    $text = var_export($text, true);
378 378
             }
379
-            $curl->get('https://api.telegram.org/bot'.$token.'/sendMessage?chat_id='.$chatid.'&text='.$text);
379
+            $curl->get('https://api.telegram.org/bot' . $token . '/sendMessage?chat_id=' . $chatid . '&text=' . $text);
380 380
             $curl->close();
381 381
     }
382 382
 }
@@ -393,9 +393,9 @@  discard block
 block discarded – undo
393 393
     FREENOM::instance()->renewDomains();
394 394
 } catch (LlfException $e) {
395 395
     system_log($e->getMessage());
396
-if (static::$config['telegram']['enable'] == 'true') {
396
+if (static::$config[ 'telegram' ][ 'enable' ] == 'true') {
397 397
 	FREENOM::instance()->sendTelegram(
398
-		[$e->getMessage(),$e->getFile(),$e->getLine(),$e->getMessage()]
398
+		[ $e->getMessage(), $e->getFile(), $e->getLine(), $e->getMessage() ]
399 399
 	);
400 400
 } else {
401 401
 	    FREENOM::instance()->sendEmail(
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -365,7 +365,9 @@
 block discarded – undo
365 365
         }
366 366
         $mail->msgHTML($message, __DIR__ . '/mail');
367 367
 
368
-        if (!$mail->send()) throw new \Exception($mail->ErrorInfo);
368
+        if (!$mail->send()) {
369
+            throw new \Exception($mail->ErrorInfo);
370
+        }
369 371
     }
370 372
     
371 373
     public function sendTelegram($text)
Please login to merge, or discard this patch.