diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-03-22 14:26:54 +0300 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-03-22 14:26:54 +0300 |
commit | ff01ac4df1e88950bcdec82c75c90fa084044ac5 (patch) | |
tree | 361fcb6d0eb1a6b81af455f2028a1f2b7c75de95 /plugins/SitesManager | |
parent | 103c1f33a13babcbce01b51f2e9e93e3568209ea (diff) |
Fixes #43
- modify websites admin UI, API to add a column Exclude IPs
- IPs contain wildcards, unlimited IPs per website
- below the website table, added a "Global IP exclude" list. Ips there are excluded from all websites automatically.
- IPs are stored in the tracker cache file for fast access at Tracking time.
- added new field in website table "excluded_ips"
- refactored the ajax loading/error display to allow multiple loading/error div per page
Diffstat (limited to 'plugins/SitesManager')
-rw-r--r-- | plugins/SitesManager/API.php | 103 | ||||
-rw-r--r-- | plugins/SitesManager/Controller.php | 4 | ||||
-rw-r--r-- | plugins/SitesManager/SitesManager.php | 45 | ||||
-rw-r--r-- | plugins/SitesManager/templates/DisplayJavascriptCode.tpl | 2 | ||||
-rw-r--r-- | plugins/SitesManager/templates/SitesManager.js | 64 | ||||
-rw-r--r-- | plugins/SitesManager/templates/SitesManager.tpl | 47 | ||||
-rw-r--r-- | plugins/SitesManager/tests/SitesManager.test.php | 54 |
7 files changed, 265 insertions, 54 deletions
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index 157abada8b..3274f5673d 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -17,6 +17,10 @@ class Piwik_SitesManager_API { static private $instance = null; + + /** + * @return Piwik_SitesManager_API + */ static public function getInstance() { if (self::$instance == null) @@ -27,6 +31,8 @@ class Piwik_SitesManager_API return self::$instance; } + const OPTION_EXCLUDED_IPS_GLOBAL = 'SitesManager_ExcludedIpsGlobal'; + /** * Returns the javascript tag for the given idSite. * This tag must be included on every page to be tracked by Piwik @@ -206,19 +212,19 @@ class Piwik_SitesManager_API } /** - * Add a website in the database. + * Add a website. + * Requires Super User access. * * The website is defined by a name and an array of URLs. - * The name must not be empty. - * The URLs array must contain at least one URL called the 'main_url' ; - * if several URLs are provided in the array, they will be recorded as Alias URLs for - * this website. - * - * Requires Super User access. + * @param string Site name + * @param array|string The URLs array must contain at least one URL called the 'main_url' ; + * if several URLs are provided in the array, they will be recorded + * as Alias URLs for this website. + * @param string Comma separated list of IPs to exclude from the reports (allows wildcards) * * @return int the website ID created */ - public function addSite( $siteName, $urls ) + public function addSite( $siteName, $urls, $excludedIps = null ) { Piwik::checkUserIsSuperUser(); @@ -232,11 +238,12 @@ class Piwik_SitesManager_API $url = $urls[0]; $urls = array_slice($urls, 1); - $db->insert(Piwik::prefixTable("site"), array( - 'name' => $siteName, - 'main_url' => $url, - ) - ); + $bind = array( 'name' => $siteName, + 'main_url' => $url, + ); + + $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps); + $db->insert(Piwik::prefixTable("site"), $bind); $idSite = $db->lastInsertId(); @@ -306,6 +313,27 @@ class Piwik_SitesManager_API } /** + * Checks that the submitted IPs (comma separated list) are valid + * Returns the cleaned up IPs + * @param $excludedIps + * + * @return array of IPs + */ + private function checkAndReturnExcludedIps($excludedIps) + { + $ips = explode(',', $excludedIps); + $ips = array_filter($ips, 'trim'); + foreach($ips as $ip) + { + if(!$this->isValidIp($ip)) + { + throw new Exception('The IP to exclude "'.$ip.'" does not have a valid IP format (eg. 1.2.3.4 or 1.2.3.*).'); + } + } + $ips = implode(',', $ips); + return $ips; + } + /** * Add a list of alias Urls to the given idSite * * If some URLs given in parameter are already recorded as alias URLs for this website, @@ -329,6 +357,33 @@ class Piwik_SitesManager_API } /** + * Sets IPs to be excluded from all websites. IPs can contain wildcards. + * Will also apply to websites created in the future. + * + * @param string Comma separated list of IPs to exclude from being tracked (allows wildcards) + * @return bool + */ + public function setGlobalExcludedIps($excludedIps) + { + Piwik::checkUserIsSuperUser(); + $excludedIps = $this->checkAndReturnExcludedIps($excludedIps); + Piwik_SetOption(self::OPTION_EXCLUDED_IPS_GLOBAL, $excludedIps); + Piwik_Common::deleteAllCache(); + return true; + } + + /** + * Returns the list of IPs that are excluded from all websites + * + * @return string Comma separated list of IPs + */ + public function getExcludedIpsGlobal() + { + Piwik::checkUserIsSuperUser(); + return Piwik_GetOption(self::OPTION_EXCLUDED_IPS_GLOBAL); + } + + /** * Update an existing website. * If only one URL is specified then only the main url will be updated. * If several URLs are specified, both the main URL and the alias URLs will be updated. @@ -336,12 +391,13 @@ class Piwik_SitesManager_API * @param int website ID defining the website to edit * @param string website name * @param string|array the website URLs + * @param string Comma separated list of IPs to exclude from being tracked (allows wildcards) * * @exception if any of the parameter is not correct * * @return bool true on success */ - public function updateSite( $idSite, $siteName, $urls = null) + public function updateSite( $idSite, $siteName, $urls = null, $excludedIps = null) { Piwik::checkUserHasAdminAccess($idSite); @@ -359,9 +415,8 @@ class Piwik_SitesManager_API $bind['main_url'] = $url; } - + $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps); $bind['name'] = $siteName; - $db = Zend_Registry::get('db'); $db->update(Piwik::prefixTable("site"), $bind, @@ -434,6 +489,22 @@ class Piwik_SitesManager_API } /** + * Tests if the IP is a valid IP, allowing wildcards, except in the first octet. + * Wildcards can only be used from right to left, ie. 1.1.*.* is allowed, but 1.1.*.1 is not. + * + * @param $ip + * @return bool + */ + private function isValidIp( $ip ) + { + return preg_match('~^(\d+)\.(\d+)\.(\d+)\.(\d+)$~', $ip, $matches) !== 0 + || preg_match('~^(\d+)\.(\d+)\.(\d+)\.\*$~', $ip, $matches) !== 0 + || preg_match('~^(\d+)\.(\d+)\.\*.\*$~', $ip, $matches) !== 0 + || preg_match('~^(\d+)\.\*\.\*\.\*$~', $ip, $matches) !== 0 + ; + } + + /** * Check that the website name has a correct format. * * @exception if the website name is empty diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index bd349b16dc..2647008093 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -23,9 +23,13 @@ class Piwik_SitesManager_Controller extends Piwik_Controller foreach($sites as &$site) { $site['alias_urls'] = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($site['idsite']); + $site['excluded_ips'] = str_replace(',','<br/>', $site['excluded_ips']); } $view->adminSites = $sites; + $view->currentIpAddress = Piwik_Common::getIpString(); $this->setGeneralVariablesView($view); + $excludedIpsGlobal = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal(); + $view->globalExcludedIps = str_replace(',',"\n", $excludedIpsGlobal); $view->menu = Piwik_GetAdminMenu(); echo $view->render(); } diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index 10f4d05a08..01f4b703de 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -33,7 +33,7 @@ class Piwik_SitesManager extends Piwik_Plugin return array( 'template_css_import' => 'css', 'AdminMenu.add' => 'addMenu', - 'Common.fetchWebsiteAttributes' => 'recordWebsiteHostsInCache', + 'Common.fetchWebsiteAttributes' => 'recordWebsiteDataInCache', ); } @@ -42,12 +42,47 @@ class Piwik_SitesManager extends Piwik_Plugin echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"themes/default/styles.css\" />\n"; } - function recordWebsiteHostsInCache($notification) + function recordWebsiteDataInCache($notification) { - $idsite = $notification->getNotificationInfo(); + $idSite = $notification->getNotificationInfo(); // add the 'hosts' entry in the website array $array =& $notification->getNotificationObject(); - $urls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idsite); + $array['hosts'] = $this->getTrackerHosts($idSite); + $array['excluded_ips'] = $this->getTrackerExcludedIps($idSite); + } + + private function getTrackerExcludedIps($idSite) + { + $website = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); + $excludedIps = $website['excluded_ips']; + $globalExcludedIps = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal(); + + $excludedIps .= ',' . $globalExcludedIps; + + $ipRanges = array(); + foreach(explode(',', $excludedIps) as $ip) + { + $ipMin = $ipMax = $ip; + if(substr_count($ip, '*') > 0) + { + $ipMin = str_replace('*', '0', $ip); + $ipMax = str_replace('*', '255', $ip); + } + $ipRange = array( ip2long($ipMin), ip2long($ipMax)); + + // we can still get invalid IPs at this stage (eg. ip2long(555.1.1.1) would return false) + if($ipRange[0] === false || $ipRange[1] === false) + { + continue; + } + $ipRanges[] = $ipRange; + } + return $ipRanges; + } + + private function getTrackerHosts($idSite) + { + $urls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idSite); $hosts = array(); foreach($urls as $url) { @@ -57,7 +92,7 @@ class Piwik_SitesManager extends Piwik_Plugin $hosts[] = $url['host']; } } - $array['hosts'] = $hosts; + return $hosts; } function addMenu() diff --git a/plugins/SitesManager/templates/DisplayJavascriptCode.tpl b/plugins/SitesManager/templates/DisplayJavascriptCode.tpl index 54332e93b8..571caff533 100644 --- a/plugins/SitesManager/templates/DisplayJavascriptCode.tpl +++ b/plugins/SitesManager/templates/DisplayJavascriptCode.tpl @@ -13,7 +13,7 @@ code { border-width:1px 1px 1px 5px; direction:ltr; display:block; - font-size:80%; + font-size:90%; margin:2px 2px 20px; padding:4px; text-align:left; diff --git a/plugins/SitesManager/templates/SitesManager.js b/plugins/SitesManager/templates/SitesManager.js index 58b424abff..1c06c8c4ac 100644 --- a/plugins/SitesManager/templates/SitesManager.js +++ b/plugins/SitesManager/templates/SitesManager.js @@ -1,8 +1,7 @@ function getDeleteSiteAJAX( idSite ) { var ajaxRequest = piwikHelper.getStandardAjaxConf(); - piwikHelper.toggleAjaxLoading(); - + var parameters = {}; parameters.module = 'API'; parameters.format = 'json'; @@ -18,12 +17,13 @@ function getDeleteSiteAJAX( idSite ) function getAddSiteAJAX( row ) { var ajaxRequest = piwikHelper.getStandardAjaxConf(); - piwikHelper.toggleAjaxLoading(); var parameters = {}; var siteName = $(row).find('input#siteadd_name').val(); var urls = $(row).find('textarea#siteadd_urls').val(); - var urls = urls.trim().split("\n"); + var urls = getApiFormatUrls(urls); + var excludedIps = $(row).find('textarea#siteadd_excludedIps').val(); + excludedIps = getApiFormatExcludedIps(excludedIps); var request = ''; request += '&module=API'; @@ -31,6 +31,7 @@ function getAddSiteAJAX( row ) request += '&method=SitesManager.addSite'; siteName = encodeURIComponent(siteName); request += '&siteName='+siteName; + request += '&excludedIps='+excludedIps; $.each(urls, function (key,value){ request+= '&urls[]='+escape(value);} ); request += '&token_auth=' + piwik.token_auth; @@ -39,14 +40,25 @@ function getAddSiteAJAX( row ) return ajaxRequest; } +function getApiFormatUrls(urls) +{ + return urls.trim().split("\n"); +} +function getApiFormatExcludedIps(excludedIps) +{ + return excludedIps.trim().split("\n").join(','); +} + function getUpdateSiteAJAX( row ) { var ajaxRequest = piwikHelper.getStandardAjaxConf(); - piwikHelper.toggleAjaxLoading(); var siteName = $(row).find('input#siteName').val(); var idSite = $(row).children('#idSite').html(); - var urls = $(row).find('textarea#urls').val().trim().split("\n"); + var urls = $(row).find('textarea#urls').val(); + urls = getApiFormatUrls(urls); + var excludedIps = $(row).find('textarea#excludedIps').val(); + excludedIps = getApiFormatExcludedIps(excludedIps); var request = ''; request += '&module=API'; @@ -55,6 +67,7 @@ function getUpdateSiteAJAX( row ) siteName = encodeURIComponent(siteName); request += '&siteName='+siteName; request += '&idSite='+idSite; + request += '&excludedIps='+excludedIps; $.each(urls, function (key,value){ if(value.length>1) request+= '&urls[]='+value;} ); request += '&token_auth=' + piwik.token_auth; @@ -63,9 +76,24 @@ function getUpdateSiteAJAX( row ) return ajaxRequest; } +function getSetGlobalExcludedIpsAJAX() +{ + var ajaxRequest = piwikHelper.getStandardAjaxConf('ajaxLoadingExcludedIps', 'ajaxErrorExcludedIps'); + var excludedIps = $('textarea#globalExcludedIps').val(); + excludedIps = getApiFormatExcludedIps(excludedIps); + var request = ''; + request += '&module=API'; + request += '&format=json'; + request += '&method=SitesManager.setGlobalExcludedIps'; + request += '&excludedIps='+excludedIps; + request += '&token_auth=' + piwik.token_auth; + ajaxRequest.data = request; + return ajaxRequest; +} + $(document).ready( function() { $('.addRowSite').click( function() { - piwikHelper.ajaxHideError(); + piwikHelper.hideAjaxError(); $(this).toggle(); var numberOfRows = $('table#editSites')[0].rows.length; @@ -74,7 +102,8 @@ $(document).ready( function() { $(' <tr id="'+newRowId+'">\ <td> </td>\ <td><input id="siteadd_name" value="Name" size="25" /></td>\ - <td><textarea cols="30" rows="3" id="siteadd_urls">http://siteUrl.com/\nhttp://siteUrl2.com/</textarea></td>\ + <td><textarea cols="30" rows="3" id="siteadd_urls">http://siteUrl.com/\nhttp://siteUrl2.com/</textarea><br />'+aliasUrlsHelp+'</td>\ + <td><textarea cols="30" rows="3" id="siteadd_excludedIps"></textarea><br />'+excludedIpHelp+'</td>\ <td><img src="plugins/UsersManager/images/ok.png" class="addsite" href="#" /></td>\ <td><img src="plugins/UsersManager/images/remove.png" class="cancel" /></td>\ </tr>') @@ -82,13 +111,13 @@ $(document).ready( function() { ; $('#'+newRowId).keypress( submitSiteOnEnter ); $('.addsite').click( function(){ $.ajax( getAddSiteAJAX($('tr#'+newRowId)) ); } ); - $('.cancel').click(function() { piwikHelper.ajaxHideError(); $(this).parents('tr').remove(); $('.addRowSite').toggle(); }); - + $('.cancel').click(function() { piwikHelper.hideAjaxError(); $(this).parents('tr').remove(); $('.addRowSite').toggle(); }); + return false; } ); // when click on deleteuser, the we ask for confirmation and then delete the user $('.deleteSite').click( function() { - piwikHelper.ajaxHideError(); + piwikHelper.hideAjaxError(); var idRow = $(this).attr('id'); var nameToDelete = $(this).parent().parent().find('input#siteName').val() || $(this).parent().parent().find('td#siteName').html(); var idsiteToDelete = $(this).parent().parent().find('#idSite').html(); @@ -101,7 +130,7 @@ $(document).ready( function() { var alreadyEdited = new Array; $('.editSite') .click( function() { - piwikHelper.ajaxHideError(); + piwikHelper.hideAjaxError(); var idRow = $(this).attr('id'); if(alreadyEdited[idRow]==1) return; alreadyEdited[idRow] = 1; @@ -121,6 +150,13 @@ $(document).ready( function() { if(idName == 'urls') { var contentAfter = '<textarea cols="30" rows="3" id="urls">'+contentBefore.replace(/<br *\/? *>/gi,"\n")+'</textarea>'; + contentAfter += '<br />'+aliasUrlsHelp; + $(n).html(contentAfter); + } + if(idName == 'excludedIps') + { + var contentAfter = '<textarea cols="30" rows="3" id="excludedIps">'+contentBefore.replace(/<br *\/? *>/gi,"\n")+'</textarea>'; + contentAfter += '<br />'+excludedIpHelp; $(n).html(contentAfter); } } @@ -134,6 +170,10 @@ $(document).ready( function() { } ); + $('#globalExcludedIpsSubmit').click( function() { + $.ajax( getSetGlobalExcludedIpsAJAX() ); + }); + $('td.editableSite').click( function(){ $(this).parent().find('.editSite').click(); } ); }); diff --git a/plugins/SitesManager/templates/SitesManager.tpl b/plugins/SitesManager/templates/SitesManager.tpl index d21ac253be..3331aacd63 100644 --- a/plugins/SitesManager/templates/SitesManager.tpl +++ b/plugins/SitesManager/templates/SitesManager.tpl @@ -4,7 +4,14 @@ {loadJavascriptTranslations plugins='SitesManager'} {include file="CoreAdminHome/templates/menu.tpl"} +<script type="text/javascript"> +{capture assign=excludedIpHelpPlain}{'SitesManager_HelpExcludedIps'|translate:"1.2.3.*":"1.2.*.*"}<br/><br/> {'SitesManager_YourCurrentIpAddressIs'|translate:"<i>$currentIpAddress</i>"}{/capture} +{assign var=excludedIpHelp value=$excludedIpHelpPlain|inlineHelp} +var excludedIpHelp = '{$excludedIpHelp|escape:javascript}'; +var aliasUrlsHelp = '{'SitesManager_AliasUrlHelp'|translate|inlineHelp|escape:javascript}'; +</script> <script type="text/javascript" src="plugins/SitesManager/templates/SitesManager.js"></script> + {literal} <style> .addRowSite:hover, .editableSite:hover, .addsite:hover, .cancel:hover, .deleteSite:hover, .editSite:hover, .updateSite:hover{ @@ -24,11 +31,15 @@ } </style> {/literal} -<h2>{'SitesManager_WebsitesManagement'|translate}</h2> -<p>{'SitesManager_MainDescription'|translate}</p> -<div id="ajaxError" style="display:none"></div> -<div id="ajaxLoading" style="display:none"><div id="loadingPiwik"><img src="themes/default/images/loading-blue.gif" alt="" /> {'General_LoadingData'|translate} </div></div> +<h2>{'SitesManager_WebsitesManagement'|translate}</h2> +<p>{'SitesManager_MainDescription'|translate} +{if $isSuperUser} +<br/>{'SitesManager_SuperUserCanExcludeIpsOnAllWebsites'|translate:"<a href='#globalIpExclusion'>":"</a>"}. +{/if} +</p> +{ajaxErrorDiv} +{ajaxLoadingDiv} {if $adminSites|@count == 0} {'SitesManager_NoWebsites'|translate} @@ -39,6 +50,7 @@ <th>{'SitesManager_Id'|translate}</th> <th>{'SitesManager_Name'|translate}</th> <th>{'SitesManager_Urls'|translate}</th> + <th>{'SitesManager_ExcludedIps'|translate}</th> <th> </th> <th> </th> <th> {'SitesManager_JsTrackingTag'|translate} </th> @@ -50,23 +62,30 @@ <td id="idSite">{$site.idsite}</td> <td id="siteName" class="editableSite">{$site.name}</td> <td id="urls" class="editableSite">{foreach from=$site.alias_urls item=url}{$url}<br />{/foreach}</td> - <td><img src='plugins/UsersManager/images/edit.png' class="editSite" id="row{$i}" href='#' alt="" /></td> - <td><img src='plugins/UsersManager/images/remove.png' class="deleteSite" id="row{$i}" value="{'General_Delete'|translate}" alt="" /></td> + <td id="excludedIps" class="editableSite">{foreach from=$site.excluded_ips item=ip}{$ip}<br />{/foreach}</td> + <td><img src='plugins/UsersManager/images/edit.png' class="editSite" id="row{$i}" href='#' title="{'General_Edit'|translate}" /></td> + <td><img src='plugins/UsersManager/images/remove.png' class="deleteSite" id="row{$i}" title="{'General_Delete'|translate}" value="{'General_Delete'|translate}" /></td> <td><a href='{url action=displayJavascriptCode idsite=$site.idsite}'>{'SitesManager_ShowTrackingTag'|translate}</a></td> </tr> {/foreach} - </tbody> </table> {if $isSuperUser} - <div class="addRowSite"><a href="#"><img src='plugins/UsersManager/images/add.png' alt="" /> {'SitesManager_AddSite'|translate}</a></div> + <div class="addRowSite"><a href=""><img src='plugins/UsersManager/images/add.png' alt="" /> {'SitesManager_AddSite'|translate}</a></div> {/if} - <div class="ui-widget"> - <div class="ui-state-highlight ui-corner-all" style="margin-top:20px; padding:0 .7em; width:400px"> - <p style="font-size:62.5%;"><span class="ui-icon ui-icon-info" style="float:left;margin-right:.3em;"></span> - {'SitesManager_AliasUrlHelp'|translate}</p> - </div> - </div> {/if} +{if $isSuperUser} + <a name='globalIpExclusion'></a><h2>{'SitesManager_GlobalListExcludedIps'|translate}</h2> + <p>{'SitesManager_ListOfIpsToBeExcludedOnAllWebsites'|translate} </p> + {ajaxErrorDiv id=ajaxErrorExcludedIps} + {ajaxLoadingDiv id=ajaxLoadingExcludedIps} + <textarea cols="30" rows="3" id="globalExcludedIps">{$globalExcludedIps} + </textarea><br/> + {$excludedIpHelp} + <input type="hidden" name="token_auth" value="{$token_auth}" /> + <p><input type="submit" class="submit" id='globalExcludedIpsSubmit' value="{'General_Save'|translate}" /></p> +{/if} + +<br /><br /><br /><br /> {include file="CoreAdminHome/templates/footer.tpl"} diff --git a/plugins/SitesManager/tests/SitesManager.test.php b/plugins/SitesManager/tests/SitesManager.test.php index 67eecdec5e..eb090a5c0c 100644 --- a/plugins/SitesManager/tests/SitesManager.test.php +++ b/plugins/SitesManager/tests/SitesManager.test.php @@ -105,6 +105,48 @@ class Test_Piwik_SitesManager extends Test_Database } /** + * Test with valid IPs + */ + public function test_addSite_excludedIps_valid() + { + $ips = '1.2.3.4,1.1.1.*,1.2.*.*,1.*.*.*'; + $idsite = Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/", $ips); + $siteInfo = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite); + $this->assertEqual($siteInfo['excluded_ips'], $ips); + } + + /** + * Test with invalid IPs + */ + public function test_addSite_excludedIps_notValid() + { + $invalidIps = array( + '35817587341', + 'ieagieha', + '1.2.3', + '*.1.1.1', + '*.*.1.1', + '*.*.*.1', + '*.*.*.*', + '1.1.1.1.1', + ); + foreach($invalidIps as $ip) + { + $raised = false; + try { + $idsite = Piwik_SitesManager_API::getInstance()->addSite("name","http://piwik.net/", $ip); + } catch(Exception $e) { + $raised = true; + } + if(!$raised) + { + $this->fail('was expecting invalid IP exception to raise'); + } + } + $this->pass(); + } + + /** * one url -> one main_url and nothing inserted as alias urls */ public function test_addSite_oneUrl() @@ -440,8 +482,8 @@ class Test_Piwik_SitesManager extends Test_Database $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org")); $resultWanted = array( - 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net"), - 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org"), + 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => ""), + 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => ""), ); FakeAccess::setIdSitesAdmin (array(1,3)); @@ -476,8 +518,8 @@ class Test_Piwik_SitesManager extends Test_Database $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org")); $resultWanted = array( - 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net"), - 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org"), + 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => ""), + 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => ""), ); FakeAccess::setIdSitesView (array(1,3)); @@ -512,8 +554,8 @@ class Test_Piwik_SitesManager extends Test_Database $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3",array("http://piwik.org")); $resultWanted = array( - 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net"), - 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org"), + 0 => array("idsite" => 1, "name" => "site1", "main_url" =>"http://piwik.net", "excluded_ips" => ""), + 1 => array("idsite" => 3, "name" => "site3", "main_url" =>"http://piwik.org", "excluded_ips" => ""), ); FakeAccess::setIdSitesView (array(1,3)); |