Skip to content

Commit a2346a8

Browse files
committed
Add source and status fields
1 parent aa0e15b commit a2346a8

File tree

6 files changed

+46
-16
lines changed

6 files changed

+46
-16
lines changed

lib/CountryRange.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
class CountryRange extends Range {
66
var string $iso;
77

8-
function __construct(string $iso, int $start, int $end, int $merges = 0){
9-
parent::__construct($start, $end, $merges);
8+
function __construct(string $iso, int $start, int $end, int $merges, int $source, int $status){
9+
parent::__construct($start, $end, $merges, $source, $status);
1010
$this->iso = $iso;
1111
}
1212

lib/CountryRangeDB.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ class CountryRangeDB extends RangeDB {
66
protected function addLine(string $line){
77
$parts = preg_split('/[,\s]/', trim($line));
88

9-
list($iso, $start, $end, $merges) = $parts;
9+
list($iso, $start, $end, $merges, $source, $status) = $parts;
1010

11-
$r = new CountryRange($iso, (int)$start, (int)$end, (int)$merges);
11+
$r = new CountryRange($iso, (int)$start, (int)$end, (int)$merges, (int)$source, (int)$status);
1212

1313
$this->addRecord($r);
1414
}
1515

1616
function copyFrom(RangeDB $db){
1717
foreach($db->ranges as $Range){
18-
$r = new CountryRange($db->name, $Range->start, $Range->end, $Range->merges);
18+
$r = new CountryRange($db->name, $Range->start, $Range->end, $Range->merges, $Range->source, $Range->status);
1919
$this->addRecord($r);
2020
}
2121
}

lib/ProcessDelegated.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ public function run(): CountryRangeDB {
3434
$ipStart = ip2long($parts[3]);
3535
$ipCount = (int)$parts[4];
3636
$ipEnd = $ipStart + $ipCount - 1;
37-
// $data[] = "$country,$ipStart,$ipEnd";
38-
// $data[] = new CountryRange($country, $ipStart, $ipEnd);
39-
$data->addRecord(new CountryRange($country, $ipStart, $ipEnd));
37+
38+
$s = $parts[6];
39+
if($s == 'assigned')
40+
$status = Range::STATUS_ASSIGNED;
41+
elseif($s == 'allocated')
42+
$status = Range::STATUS_ALLOCATED;
43+
else
44+
$status = 0;
45+
46+
$data->addRecord(new CountryRange($country, $ipStart, $ipEnd, 0, Range::SOURCE_STATS, $status));
4047
}
4148
proc_close($r);
4249

lib/ProcessWhois.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,20 @@ function save_state($record){
112112
if(!($c = country_rule($country)))
113113
return;
114114

115-
// $this->data[] = "$c,$ip_start_long,$ip_end_long";
116-
// $this->data[] = new CountryRange($c, $ip_start_long, $ip_end_long);
117-
$this->data->addRecord(new CountryRange($c, $ip_start_long, $ip_end_long));
115+
$status = 0;
116+
if(isset($record['status'])){
117+
$s = strtoupper($record['status']);
118+
if($s == 'REASSIGNED')
119+
$status = Range::STATUS_REASSIGNED;
120+
elseif($s == 'REALLOCATED')
121+
$status = Range::STATUS_REALLOCATED;
122+
elseif(preg_match("/ASSIGNED/", $s))
123+
$status = Range::STATUS_ASSIGNED;
124+
elseif(preg_match("/ALLOCATED/", $s))
125+
$status = Range::STATUS_ALLOCATED;
126+
}
127+
128+
$this->data->addRecord(new CountryRange($c, $ip_start_long, $ip_end_long, 0, Range::SOURCE_INETNUM, $status));
118129

119130
return true;
120131
}

lib/Range.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,32 @@
33
declare(strict_types = 1);
44

55
class Range {
6+
const STATUS_ALLOCATED = 1;
7+
const STATUS_ASSIGNED = 2;
8+
const STATUS_REALLOCATED = 3;
9+
const STATUS_REASSIGNED = 4;
10+
11+
const SOURCE_INETNUM = 1;
12+
const SOURCE_STATS = 2;
13+
614
var int $start;
715
var int $end;
816
var int $interval;
9-
var int $merges = 0;
17+
var int $merges;
18+
var int $status;
19+
var int $source;
1020

11-
function __construct(int $start, int $end, int $merges = 0) {
21+
function __construct(int $start, int $end, int $merges, int $source, int $status) {
1222
$this->start = $start;
1323
$this->end = $end;
1424
$this->merges = $merges;
25+
$this->source = $source;
26+
$this->status = $status;
1527
$this->interval = $this->end - $this->start;
1628
}
1729

1830
function __toString() {
19-
return "$this->start,$this->end,$this->merges";
31+
return "$this->start,$this->end,$this->merges,$this->source,$this->status";
2032
}
2133

2234
function isWithin(Range $r) {

lib/RangeDB.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ function __toString() {
1919

2020
protected function addLine(string $line){
2121
$parts = preg_split('/[,\s]/', trim($line));
22-
list($start, $end, $merges) = $parts;
22+
list($start, $end, $merges, $source, $status) = $parts;
2323

24-
$r = new Range((int)$start, (int)$end, (int)$merges);
24+
$r = new Range((int)$start, (int)$end, (int)$merges, (int)$source, (int)$status);
2525

2626
$this->addRecord($r);
2727
}

0 commit comments

Comments
 (0)