camp_html_display_error(getGS('Invalid security token!')); exit; } read_user_common_parameters(); // $uType, $userOffs, $ItemsPerPage, search parameters $uType = 'Subscribers'; compute_user_rights($g_user, $canManage, $canDelete); if (!$canManage) { camp_html_display_error(getGS('You do not have the right to change user account information.')); exit; } $userId = Input::Get('User', 'int', 0); $editUser = new User($userId); if ($editUser->getUserName() == '') { camp_html_display_error(getGS('No such user account.')); exit; } $startIP = Input::Get('StartIP', 'string', ''); $ipAccess = new IPAccess($userId, $startIP); $startIPstring = $ipAccess->getStartIPstring(); $addresses = $ipAccess->getAddresses(); if (!$ipAccess->delete()) { camp_html_goto_page("/$ADMIN/users/edit.php?uType=Subscribers&User=$userId"); } camp_html_add_msg(getGS("The IP address group $1 has been deleted.", "$startIPstring:$addresses"), "ok"); camp_html_goto_page("/$ADMIN/users/edit.php?uType=Subscribers&User=$userId"); ?>
public static function GetUsersHavingIP($p_ipAddress) { global $g_ado_db; $ipObj = new IPAccess(); $intIPAddress = $ipObj->__array2int($ipObj->__string2array($p_ipAddress)); $queryStr = "SELECT DISTINCT(IdUser) FROM SubsByIP WHERE StartIP <= $intIPAddress " . "AND $intIPAddress <= (StartIP + Addresses - 1)"; $rows = $g_ado_db->GetAll($queryStr); $users = array(); foreach ($rows as $row) { $users[] = new User($row['IdUser']); } return $users; }
private function readUser() { $userId = CampRequest::GetVar('LoginUserId'); if (!is_null($userId)) { $user = new User($userId); if ($user->exists() && $user->getKeyId() == CampRequest::GetVar('LoginUserKey')) { $this->m_user = new MetaUser($userId); $this->m_preview = CampRequest::GetVar('preview') == 'on' && $this->m_user->is_admin; } } else { $ipUsers = IPAccess::GetUsersHavingIP($_SERVER['REMOTE_ADDR']); if (count($ipUsers) > 0) { $this->m_user = new MetaUser($ipUsers[0]->getUserId()); $this->m_preview = CampRequest::GetVar('preview') == 'on' && $this->m_user->is_admin; } } }
public static function GetUsersHavingIP($p_ipAddress) { global $g_ado_db; $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheKey = $cacheService->getCacheKey(array('GetUsersHavingIP', $p_ipAddress), 'users'); if ($cacheService->contains($cacheKey)) { $users = $cacheService->fetch($cacheKey); } else { $ipObj = new IPAccess(); $intIPAddress = $ipObj->__array2int($ipObj->__string2array($p_ipAddress)); $queryStr = "SELECT DISTINCT(IdUser) FROM SubsByIP WHERE StartIP <= {$intIPAddress} " . "AND {$intIPAddress} <= (StartIP + Addresses - 1)"; $rows = (array) $g_ado_db->GetAll($queryStr); if (empty($rows)) { $cacheService->save($cacheKey, array()); return array(); } $users = array(); foreach ($rows as $row) { $users[] = $GLOBALS['controller']->getHelper('service')->getService('user')->find($row['IdUser']); } $cacheService->save($cacheKey, $users); } return $users; }
<td align="left" style="padding-left: 3px; padding-top: 5px; padding-bottom: 5px; "> <?php putGS('User IP access list management'); ?> </td> <td align="right" nowrap> <a href="javascript: void(0);" onclick="ToggleRowVisibility('add_ip_row_id');"><img src="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"]; ?>/add.png" id="my_icon" border="0" align="center"></a> <a href="javascript: void(0);" onclick="ToggleRowVisibility('add_ip_row_id');"> <?php putGS("Add new"); ?> </a> </td> </tr> </table> </td> </tr> <?php $ipAccessList = IPAccess::GetUserIPAccessList($editUser->getUserId()); if (sizeof($ipAccessList) > 0) { $color= 0; ?> <tr class="table_list_header"> <td align="left" valign="top" style="padding-left: 3px; padding-top: 3px; padding-bottom: 3px; "><B><?php putGS("Start IP"); ?></b></td> <td align="left" valign="top" style="padding-left: 3px;"><b><?php putGS("Number of addresses"); ?></b></td> <td align="left" valign="top" width="1%" style="padding-left: 3px;"><b><?php putGS("Delete"); ?></b></td> </tr> <?php foreach ($ipAccessList as $i=>$ipAccess) { $startIP = $ipAccess->getStartIPstring(); $addresses = $ipAccess->getAddresses(); ?> <tr style="padding-left: 3px;" <?php if ($color) { $color=0; ?>class="list_row_even"<?php } else { $color=1; ?>class="list_row_odd"<?php } ?>> <td style="padding-left: 3px; padding-top: 3px; padding-bottom: 3px; "><?php echo $startIP; ?></td> <td style="padding-left: 3px;"><?php p(htmlspecialchars($addresses)); ?></td>
} $g_backLink = "/{$ADMIN}/users/edit.php?uType=Subscribers&User={$g_userId}"; $g_cStartIP1 = Input::Get('cStartIP1', 'int', -1); $g_cStartIP2 = Input::Get('cStartIP2', 'int', -1); $g_cStartIP3 = Input::Get('cStartIP3', 'int', -1); $g_cStartIP4 = Input::Get('cStartIP4', 'int', -1); $g_cAddresses = Input::Get('cAddresses', 'int', 0); // check if input was correct if ($g_cStartIP1 == -1 || $g_cStartIP2 == -1 || $g_cStartIP3 == -1 || $g_cStartIP4 == -1) { camp_html_display_error($translator->trans('You must fill in the $1 field.', array('$1' => 'Start IP')), $g_backLink); exit; } if ($g_cAddresses == 0) { $g_errorMsg = $translator->trans('You must fill in the $1 field.', array('$1' => 'Number of addresses')); camp_html_display_error($g_errorMsg, $g_backLink); exit; } // check if the IP address group exists already $ipAddressArray = array($g_cStartIP1, $g_cStartIP2, $g_cStartIP3, $g_cStartIP4); $ipAccess = new IPAccess($g_userId, $ipAddressArray, $g_cAddresses); if ($ipAccess->exists()) { $g_errorMsg = $translator->trans('The IP address group $1:$2 conflicts with another existing group.', array('$1' => $ipAccess->getStartIPstring(), '$2' => $g_cAddresses), 'users'); camp_html_display_error($g_errorMsg, $g_backLink); exit; } if (!$ipAccess->create($g_userId, $ipAddressArray, $g_cAddresses)) { camp_html_display_error($translator->trans('There was an error creating the IP address group.', array('$1' => "{$g_startIPStr}:{$g_cAddresses}"), 'users'), $g_backLink); exit; } camp_html_add_msg($translator->trans("The IP Group \$1 has been created.", array('$1' => $ipAccess->getStartIPstring() . ":{$g_cAddresses}"), 'users'), "ok"); camp_html_goto_page($g_backLink);
private function readUser() { $this->m_preview = false; $container = \Zend_Registry::get('container'); $userService = $container->getService('user'); $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $user = $userService->find($auth->getIdentity()); if (!empty($user)) { $this->m_user = new MetaUser($user); $this->m_preview = CampRequest::GetVar('preview') === 'on' && $this->m_user->isAdmin(); if (!$this->m_preview && CampRequest::GetVar('preview') === 'on' && $container->getService('blog')->isBlogger($user)) { $lang = \Language::GetLanguageIdByCode(CampRequest::GetVar('language')); $article = new \Article($lang, CampRequest::GetVar('articleNo')); $this->m_preview = $container->getService('blog')->isUsersArticle($article, $user); } } } elseif (!empty($_SERVER['REMOTE_ADDR'])) { // empty in cli $ipUsers = IPAccess::GetUsersHavingIP($_SERVER['REMOTE_ADDR']); if (!empty($ipUsers)) { $user = $userService->find($ipUsers[0]->getUserId()); $this->m_user = new MetaUser($user); } } }
public static function GetUsersHavingIP($p_ipAddress) { global $g_ado_db; $ipObj = new IPAccess(); $intIPAddress = $ipObj->__array2int($ipObj->__string2array($p_ipAddress)); $queryStr = "SELECT DISTINCT(IdUser) FROM SubsByIP WHERE StartIP <= {$intIPAddress} " . "AND {$intIPAddress} <= (StartIP + Addresses - 1)"; $rows = (array) $g_ado_db->GetAll($queryStr); if (empty($rows)) { return array(); } $users = array(); foreach ($rows as $row) { $users[] = $GLOBALS['controller']->getHelper('service')->getService('user')->find($row['IdUser']); } return $users; }