Page MenuHomePhabricator

D15165.id36614.diff
No OneTemporary

D15165.id36614.diff

diff --git a/resources/sql/autopatches/20160202.ipv6.1.sql b/resources/sql/autopatches/20160202.ipv6.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160202.ipv6.1.sql
@@ -0,0 +1,5 @@
+ALTER TABLE {$NAMESPACE}_repository.repository_pullevent
+ CHANGE remoteAddress remoteAddress VARBINARY(64);
+
+ALTER TABLE {$NAMESPACE}_repository.repository_pushevent
+ CHANGE remoteAddress remoteAddress VARBINARY(64);
diff --git a/resources/sql/autopatches/20160202.ipv6.2.php b/resources/sql/autopatches/20160202.ipv6.2.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160202.ipv6.2.php
@@ -0,0 +1,39 @@
+<?php
+
+$pull = new PhabricatorRepositoryPullEvent();
+$push = new PhabricatorRepositoryPushEvent();
+
+$conn_w = $pull->establishConnection('w');
+
+$log_types = array($pull, $push);
+foreach ($log_types as $log) {
+ foreach (new LiskMigrationIterator($log) as $row) {
+ $addr = $row->getRemoteAddress();
+
+ $addr = (string)$addr;
+ if (!strlen($addr)) {
+ continue;
+ }
+
+ if (!ctype_digit($addr)) {
+ continue;
+ }
+
+ if (!(int)$addr) {
+ continue;
+ }
+
+ $ip = long2ip($addr);
+ if (!is_string($ip) || !strlen($ip)) {
+ continue;
+ }
+
+ $id = $row->getID();
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET remoteAddress = %s WHERE id = %d',
+ $log->getTableName(),
+ $ip,
+ $id);
+ }
+}
diff --git a/src/aphront/AphrontRequest.php b/src/aphront/AphrontRequest.php
--- a/src/aphront/AphrontRequest.php
+++ b/src/aphront/AphrontRequest.php
@@ -542,8 +542,12 @@
return $this->isFormPost() && $this->getStr('__dialog__');
}
- public function getRemoteAddr() {
- return $_SERVER['REMOTE_ADDR'];
+ public function getRemoteAddress() {
+ $address = $_SERVER['REMOTE_ADDR'];
+ if (!strlen($address)) {
+ return null;
+ }
+ return substr($address, 0, 64);
}
public function isHTTPS() {
diff --git a/src/applications/config/schema/PhabricatorConfigSchemaSpec.php b/src/applications/config/schema/PhabricatorConfigSchemaSpec.php
--- a/src/applications/config/schema/PhabricatorConfigSchemaSpec.php
+++ b/src/applications/config/schema/PhabricatorConfigSchemaSpec.php
@@ -322,6 +322,7 @@
case 'phid':
case 'policy';
case 'hashpath64':
+ case 'ipaddress':
$column_type = 'varbinary(64)';
break;
case 'bytes64':
diff --git a/src/applications/diffusion/controller/DiffusionServeController.php b/src/applications/diffusion/controller/DiffusionServeController.php
--- a/src/applications/diffusion/controller/DiffusionServeController.php
+++ b/src/applications/diffusion/controller/DiffusionServeController.php
@@ -76,8 +76,7 @@
}
try {
- $remote_addr = $request->getRemoteAddr();
- $remote_addr = ip2long($remote_addr);
+ $remote_addr = $request->getRemoteAddress();
$pull_event = id(new PhabricatorRepositoryPullEvent())
->setEpoch(PhabricatorTime::getNow())
@@ -720,11 +719,11 @@
}
private function getCommonEnvironment(PhabricatorUser $viewer) {
- $remote_addr = $this->getRequest()->getRemoteAddr();
+ $remote_address = $this->getRequest()->getRemoteAddress();
return array(
DiffusionCommitHookEngine::ENV_USER => $viewer->getUsername(),
- DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS => $remote_addr,
+ DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS => $remote_address,
DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL => 'http',
);
}
diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
--- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
+++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php
@@ -56,15 +56,6 @@
return $this->remoteAddress;
}
- private function getRemoteAddressForLog() {
- // If whatever we have here isn't a valid IPv4 address, just store `null`.
- // Older versions of PHP return `-1` on failure instead of `false`.
- $remote_address = $this->getRemoteAddress();
- $remote_address = max(0, ip2long($remote_address));
- $remote_address = nonempty($remote_address, null);
- return $remote_address;
- }
-
public function setSubversionTransactionInfo($transaction, $repository) {
$this->subversionTransaction = $transaction;
$this->subversionRepository = $repository;
@@ -1078,7 +1069,7 @@
$viewer = $this->getViewer();
return PhabricatorRepositoryPushEvent::initializeNewEvent($viewer)
->setRepositoryPHID($this->getRepository()->getPHID())
- ->setRemoteAddress($this->getRemoteAddressForLog())
+ ->setRemoteAddress($this->getRemoteAddress())
->setRemoteProtocol($this->getRemoteProtocol())
->setEpoch(time());
}
diff --git a/src/applications/diffusion/view/DiffusionPushLogListView.php b/src/applications/diffusion/view/DiffusionPushLogListView.php
--- a/src/applications/diffusion/view/DiffusionPushLogListView.php
+++ b/src/applications/diffusion/view/DiffusionPushLogListView.php
@@ -42,12 +42,9 @@
$repository = $log->getRepository();
// Reveal this if it's valid and the user can edit the repository.
- $remote_addr = '-';
+ $remote_address = '-';
if (isset($editable_repos[$log->getRepositoryPHID()])) {
- $remote_long = $log->getPushEvent()->getRemoteAddress();
- if ($remote_long) {
- $remote_addr = long2ip($remote_long);
- }
+ $remote_address = $log->getPushEvent()->getRemoteAddress();
}
$event_id = $log->getPushEvent()->getID();
@@ -76,7 +73,7 @@
),
$repository->getDisplayName()),
$handles[$log->getPusherPHID()]->renderLink(),
- $remote_addr,
+ $remote_address,
$log->getPushEvent()->getRemoteProtocol(),
$log->getRefType(),
$log->getRefName(),
diff --git a/src/applications/people/view/PhabricatorUserLogView.php b/src/applications/people/view/PhabricatorUserLogView.php
--- a/src/applications/people/view/PhabricatorUserLogView.php
+++ b/src/applications/people/view/PhabricatorUserLogView.php
@@ -41,13 +41,13 @@
$ip = phutil_tag(
'a',
array(
- 'href' => $base_uri.'?ip='.$log->getRemoteAddr().'#R',
+ 'href' => $base_uri.'?ip='.$ip.'#R',
),
$ip);
$session = phutil_tag(
'a',
array(
- 'href' => $base_uri.'?sessions='.$log->getSession().'#R',
+ 'href' => $base_uri.'?sessions='.$ip.'#R',
),
$session);
}
diff --git a/src/applications/repository/storage/PhabricatorRepositoryPullEvent.php b/src/applications/repository/storage/PhabricatorRepositoryPullEvent.php
--- a/src/applications/repository/storage/PhabricatorRepositoryPullEvent.php
+++ b/src/applications/repository/storage/PhabricatorRepositoryPullEvent.php
@@ -30,7 +30,7 @@
self::CONFIG_COLUMN_SCHEMA => array(
'repositoryPHID' => 'phid?',
'pullerPHID' => 'phid?',
- 'remoteAddress' => 'uint32?',
+ 'remoteAddress' => 'ipaddress?',
'remoteProtocol' => 'text32?',
'resultType' => 'text32',
'resultCode' => 'uint32',
diff --git a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php
--- a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php
+++ b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php
@@ -29,7 +29,7 @@
self::CONFIG_AUX_PHID => true,
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_COLUMN_SCHEMA => array(
- 'remoteAddress' => 'uint32?',
+ 'remoteAddress' => 'ipaddress?',
'remoteProtocol' => 'text32?',
'rejectCode' => 'uint32',
'rejectDetails' => 'text64?',

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 17, 2:33 AM (5 d, 4 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7390206
Default Alt Text
D15165.id36614.diff (7 KB)

Event Timeline