Collection.php
1.68 KB
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
<?php
namespace app\components;
use Yii;
use yii\base\Component;
class Collection extends Component
{
public static function getHostsByCsv($csvFile, $separator = ";", $seporatorHosts = '|', $pos = 1, $unique = true)
{
$date = '';
$hosts = [];
$row = 1;
if (($handle = fopen($csvFile, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, $separator)) !== FALSE) {
if ($row > 1) {
$hostsString = $data[$pos] ?? '';
if ($hostsString) {
//$arr = array_map('trim', explode($seporatorHosts, $hostsString));
//$hosts = array_merge($hosts, $arr);
$hosts[] = str_replace('*.', '', $hostsString);
}
} else {
$date = $data[0];
}
$row++;
}
fclose($handle);
}
if ($unique && $hosts) {
$hosts = array_unique($hosts);
}
return ['csv_date' => str_replace('Updated: ', '', $date), 'data' => $hosts];
}
public static function getRawData($url, $domain)
{
$post = [
'a' => 'act',
'ip' => $domain,
];
$ch = curl_init('https://2ip.ua/ru/services/information-service/domain-information');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$errorNum = curl_errno($ch);
$errorMsg = curl_error($ch);
curl_close($ch);
return ['data' => $response, 'errorno' => $errorNum, 'errormessage' => $errorMsg];
}
}