10 files changed +62
-26
lines changed Original file line number Diff line number Diff line change
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 );
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -542,8 +542,12 @@ public function isDialogFormPost() {
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 () {
Original file line number Diff line number Diff line change @@ -322,6 +322,7 @@ private function getDetailsForDataType($data_type) {
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 ' :
Original file line number Diff line number Diff line change @@ -76,8 +76,7 @@ public function handleRequest(AphrontRequest $request) {
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,11 +719,11 @@ private function isValidGitShallowCloneResponse($stdout, $stderr) {
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
}
Original file line number Diff line number Diff line change @@ -56,15 +56,6 @@ public function getRemoteAddress() {
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,7 +1069,7 @@ private function newPushEvent() {
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
}
Original file line number Diff line number Diff line change @@ -42,12 +42,9 @@ public function render() {
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,7 +73,7 @@ public function render() {
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 (),
Original file line number Diff line number Diff line change @@ -41,13 +41,13 @@ public function render() {
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
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ protected function getConfiguration() {
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 ' ,
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ protected function getConfiguration() {
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? ' ,
0 commit comments