Skip to content

Commit

Permalink
Merge pull request #18 from jonmifsud/useragent
Browse files Browse the repository at this point in the history
Useragent Support
  • Loading branch information
nitriques committed Mar 18, 2015
2 parents 3562947 + 71fb57a commit 93c4b94
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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

0 comments on commit 93c4b94

Please sign in to comment.