Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useragent Support #18

Merged
merged 2 commits into from
Mar 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public function appendPreferences($context)
// Append help
$group->appendChild(new XMLElement('p', __('Any user that has an IP listed above will be granted access. This eliminates the need to allow a user backend access. Separate each with a space.'), array('class' => 'help')));


// Useragent White list
$label = Widget::Label(__('Useragent Whitelist'));
$useragent = implode("\r\n",json_decode(Symphony::Configuration()->get('useragent_whitelist', 'maintenance_mode')));
$label->appendChild(Widget::Textarea('settings[maintenance_mode][useragent_whitelist]', 5, 50, $useragent));
$group->appendChild($label);

// Append help
$group->appendChild(new XMLElement('p', __('Any useragent that listed above will be granted access. This eliminates the need to allow a user backend access, useful when third party services need to access your site prior to launch. Insert in json array format eg ["useragent1","useragent2"].'), array('class' => 'help')));


// Append new preference group
$context['wrapper']->appendChild($group);
}
Expand All @@ -96,6 +107,11 @@ public function appendPreferences($context)
*/
public function __SavePreferences($context)
{
if ($context['settings']['maintenance_mode']['useragent_whitelist']){
// Convert to a json encoded array
$context['settings']['maintenance_mode']['useragent_whitelist'] = json_encode(explode("\r\n",$context['settings']['maintenance_mode']['useragent_whitelist']));
}

if (!is_array($context['settings'])) {

// Disable maintenance mode by default
Expand Down Expand Up @@ -202,6 +218,18 @@ public function __checkForMaintenanceMode($context)
}
}

// Check if useragent is allowed
$useragent = Symphony::Configuration()->get('useragent_whitelist', 'maintenance_mode');
if (strlen(trim($useragent)) > 0) {

$useragent = json_decode($useragent);

if (in_array($_SERVER['HTTP_USER_AGENT'], $useragent)) {

return;
}
}

// Find custom maintenance page
$row = PageManager::fetchPageByType('maintenance');

Expand Down
3 changes: 3 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
</author>
</authors>
<releases>
<release version="1.9" date="2015-03-17" min="2.4" max="2.6.x">
- Add Useragent Whitelist support
</release>
<release version="1.8.3" date="2015-03-11" min="2.4" max="2.6.x">
- Mark compatibility with Symphony 2.6+
</release>
Expand Down