1
1
<?php
2
2
/**
3
- * SigTool v1 .0.3 (last modified: 2021.07.21 ).
3
+ * SigTool v2 .0.0 (last modified: 2021.07.22 ).
4
4
*
5
5
* Generates signatures for phpMussel using main.cvd and daily.cvd from ClamAV.
6
6
*
@@ -18,12 +18,12 @@ class SigTool extends \Maikuolan\Common\YAML
18
18
/**
19
19
* @var string Script version.
20
20
*/
21
- public $ Ver = '1 .0.3 ' ;
21
+ public $ Ver = '2 .0.0 ' ;
22
22
23
23
/**
24
24
* @var string Last modified date.
25
25
*/
26
- public $ Modified = '2021.07.21 ' ;
26
+ public $ Modified = '2021.07.22 ' ;
27
27
28
28
/**
29
29
* @var string Script user agent.
@@ -86,44 +86,6 @@ public function setRaw(string $Raw)
86
86
$ this ->Raw = $ Raw ;
87
87
}
88
88
89
- /**
90
- * Use cURL to fetch files.
91
- *
92
- * @param string $URI The resource to fetch.
93
- * @param int $Timeout An optional timeout.
94
- * @return string The cURL response (the fetched resource).
95
- */
96
- public function fetch ($ URI , $ Timeout = 600 )
97
- {
98
- /** Initialise the cURL session. */
99
- $ Request = curl_init ($ URI );
100
-
101
- $ LCURI = strtolower ($ URI );
102
- $ SSL = (substr ($ LCURI , 0 , 6 ) === 'https: ' );
103
-
104
- curl_setopt ($ Request , CURLOPT_FRESH_CONNECT , true );
105
- curl_setopt ($ Request , CURLOPT_HEADER , false );
106
- curl_setopt ($ Request , CURLOPT_POST , false );
107
- if ($ SSL ) {
108
- curl_setopt ($ Request , CURLOPT_PROTOCOLS , CURLPROTO_HTTPS );
109
- curl_setopt ($ Request , CURLOPT_SSL_VERIFYPEER , false );
110
- }
111
- curl_setopt ($ Request , CURLOPT_FOLLOWLOCATION , true );
112
- curl_setopt ($ Request , CURLOPT_MAXREDIRS , 1 );
113
- curl_setopt ($ Request , CURLOPT_RETURNTRANSFER , true );
114
- curl_setopt ($ Request , CURLOPT_TIMEOUT , $ Timeout );
115
- curl_setopt ($ Request , CURLOPT_USERAGENT , $ this ->UA );
116
-
117
- /** Execute and get the response. */
118
- $ Response = curl_exec ($ Request );
119
-
120
- /** Close the cURL session. */
121
- curl_close ($ Request );
122
-
123
- /** Return the results of the request. */
124
- return $ Response ;
125
- }
126
-
127
89
/**
128
90
* Apply shorthand to signature names and remove any unwanted lines.
129
91
*
@@ -325,36 +287,28 @@ private function formatSize($Size)
325
287
" Arguments (all are OFF by default; include to turn ON): \n" .
326
288
" - No arguments: Display this help information. \n" .
327
289
" - x: Extract signature files from \"daily.cvd \" and \"main.cvd \". \n" .
328
- " - p: Process signature files for use with phpMussel. \n" .
329
- " - m: Download main.cvd before processing (deprecated). \n" .
330
- " - d: Download daily.cvd before processing (deprecated). \n" .
331
- " - u: Update SigTool (redownloads SigTool's files and dies; \n" .
332
- " doesn't perform any checks). \n\n"
290
+ " - p: Process signature files for use with phpMussel. \n\n"
333
291
),
334
292
'Accessing ' => ' Accessing %s ... ' ,
335
293
'Decompressing ' => ' Decompressing %s ... ' ,
336
294
'Deleting ' => ' Deleting %s ... ' ,
337
295
'Done ' => " Done! " ,
338
- 'Downloading ' => ' Downloading %s ... ' ,
339
296
'Extracting_to_Cvd ' => ' Extracting contents from %s to Cvd object ... ' ,
340
297
'Failed ' => " Failed! " ,
341
298
'Processing ' => ' Processing ... ' ,
342
- 'Sorting ' => ' Sorting %s ... ' ,
343
299
'Writing ' => ' Writing %s ... ' ,
344
- '_Error0 ' => ' Error at line "%d"! SigTool terminated. ' ,
345
- '_Error1 ' => ' Writing to "%2$s" failed at line "%1$d"! SigTool terminated. ' ,
346
- '_Error2 ' => ' Reading from "%2$s" failed at line "%1$d"! SigTool terminated. ' ,
347
- '_Error3 ' => ' Fetching "%2$s" from the upstream failed at line "%1$d"! SigTool terminated. ' ,
348
- '_Error4 ' => ' Fetching "%2$s" blocked by upstream firewall at line "%1$d"! SigTool terminated. ' ,
349
- '_Error5 ' => ' Reading "%2$s" failed at line "%1$d"! "%2$s" could be corrupted! SigTool terminated. '
300
+ '_Error_Corrupted ' => ' Reading "%2$s" failed at line "%1$d"! "%2$s" could be corrupted! SigTool terminated. ' ,
301
+ '_Error_Other ' => ' Error at line "%d"! SigTool terminated. ' ,
302
+ '_Error_Reading ' => ' Reading from "%2$s" failed at line "%1$d"! SigTool terminated. ' ,
303
+ '_Error_Writing ' => ' Writing to "%2$s" failed at line "%1$d"! SigTool terminated. '
350
304
];
351
305
352
306
/**
353
307
* Terminate with debug information.
354
308
*/
355
- $ Terminate = function ($ Err = '_Error0 ' , $ Msg = '' ) use (&$ SigTool , &$ L10N ) {
309
+ $ Terminate = function ($ Err = '_Error_Other ' , $ Msg = '' ) use (&$ SigTool , &$ L10N ) {
356
310
$ Debug = debug_backtrace (DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS , 1 )[0 ];
357
- $ SigTool ->outputMessage (sprintf ($ L10N [$ Err ] ?? $ L10N ['_Error0 ' ], $ Debug ['line ' ], $ Msg ), true );
311
+ $ SigTool ->outputMessage (sprintf ($ L10N [$ Err ] ?? $ L10N ['_Error_Other ' ], $ Debug ['line ' ], $ Msg ), true );
358
312
echo "\n\n" ;
359
313
die;
360
314
};
@@ -373,94 +327,23 @@ private function formatSize($Size)
373
327
date_default_timezone_set ('Europe/Zurich ' );
374
328
375
329
/**
376
- * Updating SigTool.
377
- */
378
- if (strpos ($ RunMode , 'u ' ) !== false ) {
379
- foreach (['SigTool.php ' , 'YAML.php ' , 'Cvd.php ' ] as $ File ) {
380
- $ SigTool ->outputMessage (sprintf ($ L10N ['Downloading ' ], $ File ), true );
381
- try {
382
- $ Data = $ SigTool ->fetch ('https://raw.githubusercontent.com/phpMussel/SigTool/master/ ' . $ File );
383
- } catch (\Exception $ e ) {
384
- $ Terminate ('_Error3 ' , $ File );
385
- }
386
- $ SigTool ->outputMessage (sprintf ($ L10N ['Downloading ' ], $ File ) . $ L10N ['Done ' ]);
387
- $ SigTool ->outputMessage (sprintf ($ L10N ['Writing ' ], $ File ), true );
388
- if (!file_put_contents ($ SigTool ->fixPath (__DIR__ . '/ ' . $ File ), $ Data )) {
389
- $ Terminate ('_Error1 ' , $ File );
390
- }
391
- $ SigTool ->outputMessage (sprintf ($ L10N ['Writing ' ], $ File ) . $ L10N ['Done ' ]);
392
- }
393
- die;
394
- }
395
-
396
- /**
397
- * @deprecated
398
- * Phase 1: Download main.cvd.
399
- */
400
- if (strpos ($ RunMode , 'm ' ) !== false ) {
401
- echo sprintf ($ L10N ['Downloading ' ], 'main.cvd ' );
402
- try {
403
- $ Data = $ SigTool ->fetch ('http://database.clamav.net/main.cvd ' );
404
- } catch (\Exception $ e ) {
405
- $ Terminate ('_Error3 ' , 'main.cvd ' );
406
- }
407
- if ($ Data === '' ) {
408
- $ Terminate ('_Error3 ' , 'main.cvd ' );
409
- }
410
- if ($ Data === 'error code: 1020 ' ) {
411
- $ Terminate ('_Error4 ' , 'main.cvd ' );
412
- }
413
- echo $ L10N ['Done ' ] . sprintf ($ L10N ['Writing ' ], 'main.cvd ' );
414
- if (!file_put_contents ($ SigTool ->fixPath (__DIR__ . '/main.cvd ' ), $ Data )) {
415
- $ Terminate ('_Error1 ' , 'main.cvd ' );
416
- }
417
- echo $ L10N ['Done ' ];
418
- unset($ Data );
419
- }
420
-
421
- /**
422
- * @deprecated
423
- * Phase 2: Download daily.cvd.
424
- */
425
- if (strpos ($ RunMode , 'd ' ) !== false ) {
426
- echo sprintf ($ L10N ['Downloading ' ], 'daily.cvd ' );
427
- try {
428
- $ Data = $ SigTool ->fetch ('http://database.clamav.net/daily.cvd ' );
429
- } catch (\Exception $ e ) {
430
- $ Terminate ('_Error3 ' , 'daily.cvd ' );
431
- }
432
- if ($ Data === '' ) {
433
- $ Terminate ('_Error3 ' , 'daily.cvd ' );
434
- }
435
- if ($ Data === 'error code: 1020 ' ) {
436
- $ Terminate ('_Error4 ' , 'daily.cvd ' );
437
- }
438
- echo $ L10N ['Done ' ] . sprintf ($ L10N ['Writing ' ], 'daily.cvd ' );
439
- if (!file_put_contents ($ SigTool ->fixPath (__DIR__ . '/daily.cvd ' ), $ Data )) {
440
- $ Terminate ('_Error1 ' , 'daily.cvd ' );
441
- }
442
- echo $ L10N ['Done ' ];
443
- unset($ Data );
444
- }
445
-
446
- /**
447
- * Phase 3: Extract ClamAV signature files from "daily.cvd" and "main.cvd" packages.
330
+ * Extract ClamAV signature files from "daily.cvd" and "main.cvd" packages.
448
331
*/
449
332
if (strpos ($ RunMode , 'x ' ) !== false ) {
450
333
foreach (['daily.cvd ' , 'main.cvd ' ] as $ Set ) {
451
334
$ File = $ SigTool ->fixPath (__DIR__ . '/ ' . $ Set );
452
335
453
336
/** Terminate if the file is missing or unreadable. */
454
337
if (!file_exists ($ File ) || !is_readable ($ File )) {
455
- $ Terminate ('_Error2 ' , $ Set );
338
+ $ Terminate ('_Error_Reading ' , $ Set );
456
339
}
457
340
458
341
$ SigTool ->outputMessage (sprintf ($ L10N ['Decompressing ' ], $ Set ), true );
459
342
$ Files = new Cvd ($ File );
460
343
$ SigTool ->outputMessage (sprintf ($ L10N ['Decompressing ' ], $ Set ) . $ L10N ['Done ' ]);
461
344
$ SigTool ->outputMessage (sprintf ($ L10N ['Extracting_to_Cvd ' ], $ Set ), true );
462
345
if ($ Files ->ErrorState !== 0 ) {
463
- $ Terminate ('_Error5 ' , $ File );
346
+ $ Terminate ('_Error_Corrupted ' , $ File );
464
347
}
465
348
$ SigTool ->outputMessage (sprintf ($ L10N ['Extracting_to_Cvd ' ], $ Set ) . $ L10N ['Done ' ]);
466
349
while (true ) {
@@ -470,7 +353,7 @@ private function formatSize($Size)
470
353
$ SigTool ->outputMessage (sprintf ($ L10N ['Writing ' ], $ Name ), true );
471
354
$ Handle = fopen ($ SigTool ->fixPath (__DIR__ . '/ ' . $ Name ), 'wb ' );
472
355
if (!is_resource ($ Handle )) {
473
- $ Terminate ('_Error1 ' , $ Name );
356
+ $ Terminate ('_Error_Writing ' , $ Name );
474
357
}
475
358
fwrite ($ Handle , $ Data );
476
359
fclose ($ Handle );
@@ -487,7 +370,7 @@ private function formatSize($Size)
487
370
}
488
371
489
372
/**
490
- * Phase 4: Process signature files for use with phpMussel.
373
+ * Process signature files for use with phpMussel.
491
374
*/
492
375
if (strpos ($ RunMode , 'p ' ) !== false ) {
493
376
/** Check if signatures.dat exists; If so, we'll read it for updating. */
@@ -605,13 +488,13 @@ private function formatSize($Size)
605
488
606
489
/** Write to file. */
607
490
if (!is_resource ($ Handle = fopen ($ SigTool ->fixPath (__DIR__ . '/ ' . $ Set [4 ]), 'wb ' ))) {
608
- $ Terminate ('_Error1 ' , $ Set [4 ] . '.gz ' );
491
+ $ Terminate ('_Error_Writing ' , $ Set [4 ] . '.gz ' );
609
492
}
610
493
fwrite ($ Handle , $ FileData );
611
494
fclose ($ Handle );
612
495
if ($ Set [5 ]) {
613
496
if (!is_resource ($ Handle = gzopen ($ SigTool ->fixPath (__DIR__ . '/ ' . $ Set [4 ] . '.gz ' ), 'wb ' ))) {
614
- $ Terminate ('_Error1 ' , $ Set [4 ] . '.gz ' );
497
+ $ Terminate ('_Error_Writing ' , $ Set [4 ] . '.gz ' );
615
498
}
616
499
gzwrite ($ Handle , $ FileData );
617
500
gzclose ($ Handle );
0 commit comments