Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
5a72e9aa
Commit
5a72e9aa
authored
15 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
HTTP Basic Authentication support for HTTP Fetcher.
parent
899b5f1f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
feeds_ui/feeds_ui.admin.inc
+1
-0
1 addition, 0 deletions
feeds_ui/feeds_ui.admin.inc
feeds_ui/feeds_ui.js
+21
-0
21 additions, 0 deletions
feeds_ui/feeds_ui.js
plugins/FeedsHTTPFetcher.inc
+98
-2
98 additions, 2 deletions
plugins/FeedsHTTPFetcher.inc
with
120 additions
and
2 deletions
feeds_ui/feeds_ui.admin.inc
+
1
−
0
View file @
5a72e9aa
...
...
@@ -303,6 +303,7 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') {
$active_container
[
'body'
]
=
drupal_get_form
(
'feeds_ui_plugin_form'
,
$importer
,
$active
);
break
;
case
'settings'
:
drupal_add_js
(
drupal_get_path
(
'module'
,
'feeds_ui'
)
.
'/feeds_ui.js'
);
if
(
empty
(
$plugin_key
))
{
$active_container
[
'title'
]
=
t
(
'Basic settings'
);
$active_container
[
'body'
]
=
feeds_get_config_form
(
$importer
);
...
...
This diff is collapsed.
Click to expand it.
feeds_ui/feeds_ui.js
+
21
−
0
View file @
5a72e9aa
...
...
@@ -87,4 +87,25 @@ Drupal.behaviors.feeds = function() {
$
(
'
#
'
+
$
(
this
).
attr
(
'
id
'
)).
attr
(
'
checked
'
,
1
);
$
(
'
input.form-submit.feeds-ui-hidden-submit
'
).
click
();
});
// Show basic auth u/pw conditionally.
// @todo Generalize dependencies between form elements.
if
(
$
(
'
#edit-basic-auth-2
'
).
attr
(
'
checked
'
))
{
$
(
'
#edit-basic-auth-user-wrapper
'
).
show
();
$
(
'
#edit-basic-auth-password-wrapper
'
).
show
();
}
else
{
$
(
'
#edit-basic-auth-user-wrapper
'
).
hide
();
$
(
'
#edit-basic-auth-password-wrapper
'
).
hide
();
}
$
(
'
#edit-basic-auth-2
'
).
click
(
function
()
{
if
(
$
(
this
).
attr
(
'
checked
'
))
{
$
(
'
#edit-basic-auth-user-wrapper
'
).
show
(
100
);
$
(
'
#edit-basic-auth-password-wrapper
'
).
show
(
100
);
}
});
$
(
'
#edit-basic-auth-0,#edit-basic-auth-1
'
).
click
(
function
()
{
$
(
'
#edit-basic-auth-user-wrapper
'
).
hide
(
100
);
$
(
'
#edit-basic-auth-password-wrapper
'
).
hide
(
100
);
});
};
This diff is collapsed.
Click to expand it.
plugins/FeedsHTTPFetcher.inc
+
98
−
2
View file @
5a72e9aa
...
...
@@ -6,6 +6,10 @@
* Home of the FeedsHTTPFetcher and related classes.
*/
define
(
'FEEDS_HTTP_NO_BASIC_AUTH'
,
0
);
define
(
'FEEDS_HTTP_BASIC_AUTH_PER_SOURCE'
,
1
);
define
(
'FEEDS_HTTP_BASIC_AUTH_PER_IMPORTER'
,
2
);
/**
* Definition of the import batch object created on the fetching stage by
* FeedsHTTPFetcher.
...
...
@@ -59,7 +63,9 @@ class FeedsHTTPFetcher extends FeedsFetcher {
*/
public
function
fetch
(
FeedsSource
$source
)
{
$source_config
=
$source
->
getConfigFor
(
$this
);
return
new
FeedsHTTPBatch
(
$source_config
[
'source'
]);
$url
=
$source_config
[
'source'
];
$url
=
$this
->
basicAuth
(
$url
,
isset
(
$source_config
[
'basic_auth'
])
?
$source_config
[
'basic_auth'
]
:
array
());
return
new
FeedsHTTPBatch
(
$url
);
}
/**
...
...
@@ -85,6 +91,16 @@ class FeedsHTTPFetcher extends FeedsFetcher {
'#maxlength'
=>
NULL
,
'#required'
=>
TRUE
,
);
if
(
isset
(
$this
->
config
[
'basic_auth'
])
&&
$this
->
config
[
'basic_auth'
]
==
FEEDS_HTTP_BASIC_AUTH_PER_SOURCE
)
{
$form
[
'basic_auth'
]
=
array
(
'#type'
=>
'fieldset'
,
'#collapsible'
=>
TRUE
,
'#collapsed'
=>
empty
(
$source_config
[
'basic_auth'
][
'basic_auth_user'
]),
'#title'
=>
t
(
'Authentication'
),
'#description'
=>
t
(
'Enter user name and password for authentication. Leave empty if no authentication is required.'
),
);
$form
[
'basic_auth'
]
+=
$this
->
basicAuthForm
(
isset
(
$source_config
[
'basic_auth'
])
?
$source_config
[
'basic_auth'
]
:
array
());
}
return
$form
;
}
...
...
@@ -92,7 +108,87 @@ class FeedsHTTPFetcher extends FeedsFetcher {
* Override parent::configDefaults().
*/
public
function
configDefaults
()
{
return
array
(
'auto_detect_feeds'
=>
FALSE
);
return
array
(
'basic_auth'
=>
FEEDS_HTTP_NO_BASIC_AUTH
,
'basic_auth_user'
=>
''
,
'basic_auth_password'
=>
''
,
);
}
/**
* Override parent::configForm();
*/
public
function
configForm
()
{
$form
=
array
();
$form
[
'basic_auth'
]
=
array
(
'#type'
=>
'fieldset'
,
'#title'
=>
t
(
'HTTP Basic Authentication'
),
);
$form
[
'basic_auth'
][
'basic_auth'
]
=
array
(
'#type'
=>
'radios'
,
'#options'
=>
array
(
FEEDS_HTTP_NO_BASIC_AUTH
=>
t
(
'No authentication'
),
FEEDS_HTTP_BASIC_AUTH_PER_SOURCE
=>
t
(
'Specify credentials when creating a feed.'
),
FEEDS_HTTP_BASIC_AUTH_PER_IMPORTER
=>
t
(
'One set of credentials for all feeds.'
),
),
'#default_value'
=>
$this
->
config
[
'basic_auth'
],
);
$form
[
'basic_auth'
]
+=
$this
->
basicAuthForm
(
$this
->
config
);
return
$form
;
}
/**
* Validate config form.
*/
public
function
configFormValidate
(
&
$values
)
{
// Don't accidentally wipe out password.
if
(
empty
(
$values
[
'basic_auth_password'
]))
{
$values
[
'basic_auth_password'
]
=
$this
->
config
[
'basic_auth_password'
];
}
if
(
$values
[
'basic_auth'
]
!=
FEEDS_HTTP_BASIC_AUTH_PER_IMPORTER
)
{
$values
[
'basic_auth_user'
]
=
''
;
$values
[
'basic_auth_password'
]
=
''
;
}
}
/**
* Basic auth form.
*/
protected
function
basicAuthForm
(
$config
)
{
$form
=
array
();
$form
[
'basic_auth_user'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Username'
),
'#default_value'
=>
empty
(
$config
[
'basic_auth_user'
])
?
''
:
$config
[
'basic_auth_user'
],
);
$form
[
'basic_auth_password'
]
=
array
(
'#type'
=>
'password'
,
'#title'
=>
t
(
'Password'
),
);
return
$form
;
}
/**
* Encode basic authentication credentials in URL depending on configuration.
*/
protected
function
basicAuth
(
$url
,
$source_config
=
array
())
{
if
(
$this
->
config
[
'basic_auth'
]
==
FEEDS_HTTP_BASIC_AUTH_PER_SOURCE
)
{
if
(
!
empty
(
$source_config
[
'basic_auth_user'
])
&&
!
empty
(
$source_config
[
'basic_auth_password'
]))
{
return
$this
->
basicAuthEncodeCredentials
(
$url
,
$source_config
[
'basic_auth_user'
],
$source_config
[
'basic_auth_password'
]);
}
}
elseif
(
$this
->
config
[
'basic_auth'
]
==
FEEDS_HTTP_BASIC_AUTH_PER_IMPORTER
)
{
return
$this
->
basicAuthEncodeCredentials
(
$url
,
$this
->
config
[
'basic_auth_user'
],
$this
->
config
[
'basic_auth_password'
]);
}
return
$url
;
}
/**
* Encode basic authentication credentials into URL.
*/
protected
function
basicAuthEncodeCredentials
(
$url
,
$user
,
$password
)
{
$parsed
=
parse_url
(
$url
);
return
str_replace
(
"
{
$parsed
[
'scheme'
]
}
://"
,
"
{
$parsed
[
'scheme'
]
}
://
$user
:
$password
@"
,
$url
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment