@@ -96,9 +96,17 @@ def login
96
96
97
97
fail_with ( Failure ::TimeoutExpired , "#{ peer } - Connection timed out during login" ) unless res
98
98
99
- local_session_cookie = res . get_cookies . scan ( /(_gitlab_session=[a- z0-9]+)/ ) . flatten [ 0 ] || ''
99
+ local_session_cookie = res . get_cookies . scan ( /(_gitlab_session=[A-Za- z0-9%- ]+)/ ) . flatten [ 0 ]
100
100
auth_token = res . body . scan ( /<input name="authenticity_token" type="hidden" value="(.*?)"/ ) . flatten [ 0 ]
101
101
102
+ if res . body . include? 'user[email]'
103
+ @gitlab_version = 5
104
+ user_field = 'user[email]'
105
+ else
106
+ @gitlab_version = 7
107
+ user_field = 'user[login]'
108
+ end
109
+
102
110
# Perform the actual login and get the newly assigned session cookie
103
111
res = send_request_cgi (
104
112
'method' => 'POST' ,
@@ -108,26 +116,30 @@ def login
108
116
{
109
117
'utf8' => "\xE2 \x9C \x93 " ,
110
118
'authenticity_token' => auth_token ,
111
- 'user[login]' => username ,
119
+ " #{ user_field } " => username ,
112
120
'user[password]' => password ,
113
121
'user[remember_me]' => 0
114
122
}
115
123
)
116
124
117
125
fail_with ( Failure ::NoAccess , "#{ peer } - Login failed" ) unless res
118
126
119
- @session_cookie = res . get_cookies . scan ( /(_gitlab_session=[a- z0-9]+)/ ) . flatten [ 0 ]
127
+ @session_cookie = res . get_cookies . scan ( /(_gitlab_session=[A-Za- z0-9%- ]+)/ ) . flatten [ 0 ]
120
128
end
121
129
122
130
def add_key ( cmd )
123
- add_key_base = normalize_uri ( datastore [ 'TARGETURI' ] , 'profile' , 'keys' )
131
+ if @gitlab_version == 5
132
+ @key_base = normalize_uri ( datastore [ 'TARGETURI' ] , 'keys' )
133
+ else
134
+ @key_base = normalize_uri ( datastore [ 'TARGETURI' ] , 'profile' , 'keys' )
135
+ end
124
136
125
137
# Perform an initial request to get an authenticity_token so the actual
126
138
# key addition can be done successfully.
127
139
res = send_request_cgi (
128
140
'method' => 'GET' ,
129
141
'cookie' => "request_method=GET; #{ @session_cookie } " ,
130
- 'uri' => normalize_uri ( add_key_base , 'new' )
142
+ 'uri' => normalize_uri ( @key_base , 'new' )
131
143
)
132
144
133
145
fail_with ( Failure ::TimeoutExpired , "#{ peer } - Connection timed out during request" ) unless res
@@ -149,7 +161,7 @@ def add_key(cmd)
149
161
res = send_request_cgi (
150
162
'method' => 'POST' ,
151
163
'cookie' => "request_method=GET; #{ @session_cookie } " ,
152
- 'uri' => add_key_base ,
164
+ 'uri' => @key_base ,
153
165
'vars_post' =>
154
166
{
155
167
'utf8' => "\xE2 \x9C \x93 " ,
@@ -168,12 +180,10 @@ def add_key(cmd)
168
180
end
169
181
170
182
def delete_key ( key_id )
171
- key_base = normalize_uri ( datastore [ 'TARGETURI' ] , 'profile' , 'keys' )
172
-
173
183
res = send_request_cgi (
174
184
'method' => 'GET' ,
175
185
'cookie' => "request_method=GET; #{ @session_cookie } " ,
176
- 'uri' => key_base
186
+ 'uri' => @ key_base
177
187
)
178
188
179
189
fail_with ( Failure ::TimeoutExpired , "#{ peer } - Connection timed out during request" ) unless res
@@ -184,7 +194,7 @@ def delete_key(key_id)
184
194
res = send_request_cgi (
185
195
'method' => 'POST' ,
186
196
'cookie' => "#{ @session_cookie } " ,
187
- 'uri' => normalize_uri ( "#{ key_base } " , "#{ key_id } " ) ,
197
+ 'uri' => normalize_uri ( "#{ @ key_base} " , "#{ key_id } " ) ,
188
198
'vars_post' =>
189
199
{
190
200
'_method' => 'delete' ,
0 commit comments