@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use large text columns to store IP addresses

Summary: Fixes T10259. There was no real reason to do this `ip2long()` stuff in the first place -- it's very slightly smaller, but won't work with ipv6 and the savings are miniscule.

Test Plan:
- Ran migration.
- Viewed logs in web UI.
- Pulled and pushed.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10259

Differential Revision: https://secure.phabricator.com/D15165

+62 -26
+5
resources/sql/autopatches/20160202.ipv6.1.sql
··· 1 + ALTER TABLE {$NAMESPACE}_repository.repository_pullevent 2 + CHANGE remoteAddress remoteAddress VARBINARY(64); 3 + 4 + ALTER TABLE {$NAMESPACE}_repository.repository_pushevent 5 + CHANGE remoteAddress remoteAddress VARBINARY(64);
+39
resources/sql/autopatches/20160202.ipv6.2.php
··· 1 + <?php 2 + 3 + $pull = new PhabricatorRepositoryPullEvent(); 4 + $push = new PhabricatorRepositoryPushEvent(); 5 + 6 + $conn_w = $pull->establishConnection('w'); 7 + 8 + $log_types = array($pull, $push); 9 + foreach ($log_types as $log) { 10 + foreach (new LiskMigrationIterator($log) as $row) { 11 + $addr = $row->getRemoteAddress(); 12 + 13 + $addr = (string)$addr; 14 + if (!strlen($addr)) { 15 + continue; 16 + } 17 + 18 + if (!ctype_digit($addr)) { 19 + continue; 20 + } 21 + 22 + if (!(int)$addr) { 23 + continue; 24 + } 25 + 26 + $ip = long2ip($addr); 27 + if (!is_string($ip) || !strlen($ip)) { 28 + continue; 29 + } 30 + 31 + $id = $row->getID(); 32 + queryfx( 33 + $conn_w, 34 + 'UPDATE %T SET remoteAddress = %s WHERE id = %d', 35 + $log->getTableName(), 36 + $ip, 37 + $id); 38 + } 39 + }
+6 -2
src/aphront/AphrontRequest.php
··· 542 542 return $this->isFormPost() && $this->getStr('__dialog__'); 543 543 } 544 544 545 - public function getRemoteAddr() { 546 - return $_SERVER['REMOTE_ADDR']; 545 + public function getRemoteAddress() { 546 + $address = $_SERVER['REMOTE_ADDR']; 547 + if (!strlen($address)) { 548 + return null; 549 + } 550 + return substr($address, 0, 64); 547 551 } 548 552 549 553 public function isHTTPS() {
+1
src/applications/config/schema/PhabricatorConfigSchemaSpec.php
··· 322 322 case 'phid': 323 323 case 'policy'; 324 324 case 'hashpath64': 325 + case 'ipaddress': 325 326 $column_type = 'varbinary(64)'; 326 327 break; 327 328 case 'bytes64':
+3 -4
src/applications/diffusion/controller/DiffusionServeController.php
··· 76 76 } 77 77 78 78 try { 79 - $remote_addr = $request->getRemoteAddr(); 80 - $remote_addr = ip2long($remote_addr); 79 + $remote_addr = $request->getRemoteAddress(); 81 80 82 81 $pull_event = id(new PhabricatorRepositoryPullEvent()) 83 82 ->setEpoch(PhabricatorTime::getNow()) ··· 720 719 } 721 720 722 721 private function getCommonEnvironment(PhabricatorUser $viewer) { 723 - $remote_addr = $this->getRequest()->getRemoteAddr(); 722 + $remote_address = $this->getRequest()->getRemoteAddress(); 724 723 725 724 return array( 726 725 DiffusionCommitHookEngine::ENV_USER => $viewer->getUsername(), 727 - DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS => $remote_addr, 726 + DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS => $remote_address, 728 727 DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL => 'http', 729 728 ); 730 729 }
+1 -10
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 56 56 return $this->remoteAddress; 57 57 } 58 58 59 - private function getRemoteAddressForLog() { 60 - // If whatever we have here isn't a valid IPv4 address, just store `null`. 61 - // Older versions of PHP return `-1` on failure instead of `false`. 62 - $remote_address = $this->getRemoteAddress(); 63 - $remote_address = max(0, ip2long($remote_address)); 64 - $remote_address = nonempty($remote_address, null); 65 - return $remote_address; 66 - } 67 - 68 59 public function setSubversionTransactionInfo($transaction, $repository) { 69 60 $this->subversionTransaction = $transaction; 70 61 $this->subversionRepository = $repository; ··· 1078 1069 $viewer = $this->getViewer(); 1079 1070 return PhabricatorRepositoryPushEvent::initializeNewEvent($viewer) 1080 1071 ->setRepositoryPHID($this->getRepository()->getPHID()) 1081 - ->setRemoteAddress($this->getRemoteAddressForLog()) 1072 + ->setRemoteAddress($this->getRemoteAddress()) 1082 1073 ->setRemoteProtocol($this->getRemoteProtocol()) 1083 1074 ->setEpoch(time()); 1084 1075 }
+3 -6
src/applications/diffusion/view/DiffusionPushLogListView.php
··· 42 42 $repository = $log->getRepository(); 43 43 44 44 // Reveal this if it's valid and the user can edit the repository. 45 - $remote_addr = '-'; 45 + $remote_address = '-'; 46 46 if (isset($editable_repos[$log->getRepositoryPHID()])) { 47 - $remote_long = $log->getPushEvent()->getRemoteAddress(); 48 - if ($remote_long) { 49 - $remote_addr = long2ip($remote_long); 50 - } 47 + $remote_address = $log->getPushEvent()->getRemoteAddress(); 51 48 } 52 49 53 50 $event_id = $log->getPushEvent()->getID(); ··· 76 73 ), 77 74 $repository->getDisplayName()), 78 75 $handles[$log->getPusherPHID()]->renderLink(), 79 - $remote_addr, 76 + $remote_address, 80 77 $log->getPushEvent()->getRemoteProtocol(), 81 78 $log->getRefType(), 82 79 $log->getRefName(),
+2 -2
src/applications/people/view/PhabricatorUserLogView.php
··· 41 41 $ip = phutil_tag( 42 42 'a', 43 43 array( 44 - 'href' => $base_uri.'?ip='.$log->getRemoteAddr().'#R', 44 + 'href' => $base_uri.'?ip='.$ip.'#R', 45 45 ), 46 46 $ip); 47 47 $session = phutil_tag( 48 48 'a', 49 49 array( 50 - 'href' => $base_uri.'?sessions='.$log->getSession().'#R', 50 + 'href' => $base_uri.'?sessions='.$ip.'#R', 51 51 ), 52 52 $session); 53 53 }
+1 -1
src/applications/repository/storage/PhabricatorRepositoryPullEvent.php
··· 30 30 self::CONFIG_COLUMN_SCHEMA => array( 31 31 'repositoryPHID' => 'phid?', 32 32 'pullerPHID' => 'phid?', 33 - 'remoteAddress' => 'uint32?', 33 + 'remoteAddress' => 'ipaddress?', 34 34 'remoteProtocol' => 'text32?', 35 35 'resultType' => 'text32', 36 36 'resultCode' => 'uint32',
+1 -1
src/applications/repository/storage/PhabricatorRepositoryPushEvent.php
··· 29 29 self::CONFIG_AUX_PHID => true, 30 30 self::CONFIG_TIMESTAMPS => false, 31 31 self::CONFIG_COLUMN_SCHEMA => array( 32 - 'remoteAddress' => 'uint32?', 32 + 'remoteAddress' => 'ipaddress?', 33 33 'remoteProtocol' => 'text32?', 34 34 'rejectCode' => 'uint32', 35 35 'rejectDetails' => 'text64?',