Cheetah
ChWsbAdminIpBlockList.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChTemplFormView');
9 
11 {
12  var $_oDb;
14 
18  function __construct($sActionUrl = '')
19  {
20  $this->_oDb = $GLOBALS['MySQL'];
21  $this->_sActionUrl = !empty($sActionUrl) ? $sActionUrl : ch_html_attribute($_SERVER['PHP_SELF']) . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
22  }
23 
24  function GenStoredMemIPs()
25  {
26  $sCntSQL = "SELECT COUNT(*) FROM `sys_ip_members_visits`";
28  $iTotalNum = db_value( $sCntSQL );
29  if(!$iTotalNum)
30  return MsgBox(_t('_Empty'));
31 
32  $iPerPage = (int)$_GET['per_page'];
33  if( !$iPerPage )
34  $iPerPage = 10;
35  $iCurPage = (int)$_GET['page'];
36  if( $iCurPage < 1 )
37  $iCurPage = 1;
38  $sLimitFrom = ( $iCurPage - 1 ) * $iPerPage;
39  $sqlLimit = "LIMIT {$sLimitFrom}, {$iPerPage}";
41 
42  $sSQL = "SELECT *, UNIX_TIMESTAMP(`DateTime`) AS `DateTimeTS` FROM `sys_ip_members_visits` ORDER BY `DateTime` DESC {$sqlLimit}";
43  $rIPList = db_res( $sSQL );
44 
45  $aTmplVarsItems = array();
46  while( $aIPList = $rIPList ->fetch() ) {
47  $iID = (int)$aIPList['ID'];
48  $sFrom = long2ip($aIPList['From']);
49  $sLastDT = getLocaleDate($aIPList['DateTimeTS'], CH_WSB_LOCALE_DATE);
50  $sMember = $aIPList['MemberID'] ? '<a href="' . getProfileLink($aIPList['MemberID']) . '">' . getNickname($aIPList['MemberID']) . '</a>' : '';
51 
52  $aTmplVarsItems[] = array(
53  'from' => $sFrom,
54  'ch_if:show_profile_link' => array(
55  'condition' => !empty($aIPList['MemberID']),
56  'content' => array(
57  'href' => getProfileLink($aIPList['MemberID']),
58  'caption' => getNickname($aIPList['MemberID'])
59  )
60  ),
61  'date' => $sLastDT
62  );
63  }
64 
65  $oPaginate = new ChWsbPaginate(array(
66  'page_url' => $GLOBALS['site']['url_admin'] . 'ip_blacklist.php?mode=list&page={page}&per_page={per_page}',
67  'count' => $iTotalNum,
68  'per_page' => $iPerPage,
69  'page' => $iCurPage,
70  ));
71 
72  return $GLOBALS['oAdmTemplate']-> parseHtmlByName('ip_blacklist_list_ips.html', array(
73  'ch_repeat:items' => $aTmplVarsItems,
74  'paginate' => $oPaginate -> getPaginate()
75  ));
76  }
77 
79  {
80  $sSQL = "SELECT *, FROM_UNIXTIME(`LastDT`) AS `LastDT_U` FROM `sys_ip_list` ORDER BY `From` ASC";
81  $rIPList = db_res( $sSQL );
82 
83  $aTmplVarsItems = array();
84  while( $aIPList = $rIPList ->fetch() ) {
85  $iID = (int)$aIPList['ID'];
86  $sFrom = long2ip($aIPList['From']);
87  $sTo = ($aIPList['To'] == 0) ? '' : long2ip($aIPList['To']);
88  $sType = process_html_output($aIPList['Type']);
89  $sLastDT_Formatted = getLocaleDate($aIPList['LastDT'], CH_WSB_LOCALE_DATE);
90  $sLastDT = preg_replace('/([\d]{2}):([\d]{2}):([\d]{2})/', '$1:$2', $aIPList['LastDT_U']);
91  $sDesc = process_html_output($aIPList['Desc']);
92  $sDescAttr = ch_html_attribute(ch_js_string($aIPList['Desc'], CH_ESCAPE_STR_APOS));
93 
94  $aTmplVarsItems[] = array(
95  'id' => $iID,
96  'from' => $sFrom,
97  'to' => $sTo,
98  'type' => $sType,
99  'date' => $sLastDT,
100  'date_uf' => $sLastDT_Formatted,
101  'description' => $sDesc,
102  'description_attr' => $sDescAttr,
103  'delete_action_url' => ch_append_url_params($this->_sActionUrl, array('action' => 'apply_delete', 'id' => $iID)),
104  );
105  }
106 
107  if(empty($aTmplVarsItems))
108  return MsgBox(_t('_Empty'));
109 
110  return $GLOBALS['oAdmTemplate']-> parseHtmlByName('ip_blacklist_list_filters.html', array(
111  'ch_repeat:items' => $aTmplVarsItems
112  ));
113  }
114 
115  function getManagingForm()
116  {
117  $sApplyChangesC = _t('_sys_admin_apply');
118  $sFromC = _t('_From');
119  $sToC = _t('_To');
120  $sSampleC = _t('_adm_ipbl_sample');
121  $sTypeC = _t('_adm_ipbl_IP_Role');
122  $sDescriptionC = _t('_Description');
123  $sDatatimeC = _t('_adm_ipbl_Date_of_finish');
124  $sErrorC = _t('_Error Occured');
125 
126  $aForm = array(
127  'form_attrs' => array(
128  'name' => 'apply_ip_list_form',
129  'action' => $this->_sActionUrl,
130  'method' => 'post',
131  ),
132  'params' => array (
133  'db' => array(
134  'table' => 'sys_ip_list',
135  'key' => 'ID',
136  'submit_name' => 'add_button',
137  ),
138  ),
139  'inputs' => array(
140  'FromIP' => array(
141  'type' => 'text',
142  'name' => 'from',
143  'caption' => $sFromC,
144  'info' => $sSampleC . ': 10.0.0.0',
145  'required' => true,
146  'checker' => array (
147  'func' => 'length',
148  'params' => array(7,15),
149  'error' => $sErrorC,
150  ),
151  ),
152  'ToIP' => array(
153  'type' => 'text',
154  'name' => 'to',
155  'caption' => $sToC,
156  'info' => $sSampleC . ': 10.0.0.100',
157  'required' => true,
158  'checker' => array (
159  'func' => 'length',
160  'params' => array(7,15),
161  'error' => $sErrorC,
162  ),
163  ),
164  'IPRole' => array(
165  'type' => 'select',
166  'name' => 'type',
167  'caption' => $sTypeC,
168  'values' => array('allow', 'deny'),
169  'required' => true,
170  ),
171  'DateTime' => array(
172  'type' => 'datetime',
173  'name' => 'LastDT',
174  'caption' => $sDatatimeC,
175  'required' => true,
176  'checker' => array (
177  'func' => 'DateTime',
178  'error' => $sErrorC,
179  ),
180  'db' => array (
181  'pass' => 'DateTime',
182  ),
183  ),
184  'Desc' => array(
185  'type' => 'text',
186  'name' => 'desc',
187  'caption' => $sDescriptionC,
188  'required' => true,
189  'checker' => array (
190  'func' => 'length',
191  'params' => array(2,128),
192  'error' => $sErrorC,
193  ),
194  'db' => array (
195  'pass' => 'Xss',
196  ),
197  ),
198  'ID' => array(
199  'type' => 'hidden',
200  'value' => '0',
201  'name' => 'id',
202  ),
203  'add_button' => array(
204  'type' => 'submit',
205  'name' => 'add_button',
206  'value' => $sApplyChangesC,
207  ),
208  ),
209  );
210 
211  $sResult = '';
213  $oForm->initChecker();
214  if ($oForm->isSubmittedAndValid()) {
215  /*list($iDay, $iMonth, $iYear) = explode( '/', $_REQUEST['datatime']);
216  $iDay = (int)$iDay;
217  $iMonth = (int)$iMonth;
218  $iYear = (int)$iYear;
219  //$sCurTime = date("Y:m:d H:i:s");// 2012-06-20 15:46:21
220  $sCurTime = "{$iYear}:{$iMonth}:{$iDay} 12:00:00";*/
221 
222  $sFrom = sprintf("%u", ip2long($_REQUEST['from']));
223  $sTo = sprintf("%u", ip2long($_REQUEST['to']));
224 
225  $sType = ((int)$_REQUEST['type']==1) ? 'deny' : 'allow';
226 
227  $aValsAdd = array (
228  'From' => $sFrom,
229  'To' => $sTo,
230  /*'LastDT' => $sCurTime,*/
231  'Type' => $sType
232  );
233 
234  $iLastId = ((int)$_REQUEST['id']>0) ? (int)$_REQUEST['id'] : -1;
235 
236  if ($iLastId>0) {
237  $oForm->update($iLastId, $aValsAdd);
238  } else {
239  $iLastId = $oForm->insert($aValsAdd);
240  }
241 
242  $sResult = ($iLastId > 0) ? MsgBox(_t('_Success'), 3) : MsgBox($sErrorC);
243  }
244  return $sResult . $oForm->getCode();
245  }
246 
247  function ActionApplyDelete()
248  {
249  $iID = (int)$_REQUEST['id'];
250 
251  if ($iID>0) {
252  $sDeleteSQL = "DELETE FROM `sys_ip_list` WHERE `ID`='{$iID}' LIMIT 1";
253  db_res($sDeleteSQL);
254  }
255  }
256 
257  function deleteExpired ()
258  {
259  $iTime = time();
260  $r = db_res("DELETE FROM `sys_ip_list` WHERE `LastDT` <= $iTime");
261  if ($r && ($iAffectedRows = db_affected_rows($r))) {
262  db_res("OPTIMIZE TABLE `sys_ip_list`");
263  return $iAffectedRows;
264  } else {
265  return 0;
266  }
267  }
268 }
CH_WSB_LOCALE_DATE
const CH_WSB_LOCALE_DATE
Definition: utils.inc.php:16
ChTemplFormView
Definition: ChTemplFormView.php:11
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
ChWsbAdminIpBlockList\__construct
__construct($sActionUrl='')
Definition: ChWsbAdminIpBlockList.php:18
$sLimitFrom
$sLimitFrom
Definition: post_mod_crss.php:49
ch_js_string
ch_js_string($mixedInput, $iQuoteType=CH_ESCAPE_STR_AUTO)
Definition: utils.inc.php:1294
$sResult
$sResult
Definition: advanced_settings.php:26
ChWsbAdminIpBlockList\GenStoredMemIPs
GenStoredMemIPs()
Definition: ChWsbAdminIpBlockList.php:24
ChWsbAdminIpBlockList\deleteExpired
deleteExpired()
Definition: ChWsbAdminIpBlockList.php:257
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$iCurPage
$iCurPage
Definition: post_mod_crss.php:46
$sSQL
$sSQL
Definition: ads_get_list.php:11
ChWsbAdminIpBlockList\getManagingForm
getManagingForm()
Definition: ChWsbAdminIpBlockList.php:115
php
ChWsbAdminIpBlockList\GenIPBlackListTable
GenIPBlackListTable()
Definition: ChWsbAdminIpBlockList.php:78
$iPerPage
else $iPerPage
Definition: browse.php:61
process_html_output
process_html_output($text, $maxwordlen=100)
Definition: utils.inc.php:333
ch_html_attribute
ch_html_attribute($mixedInput)
Definition: utils.inc.php:1324
$oForm
$oForm
Definition: host_tools.php:42
ChWsbAdminIpBlockList\$_oDb
$_oDb
Definition: ChWsbAdminIpBlockList.php:12
$sType
$sType
Definition: actions.inc.php:11
$_GET
$_GET['debug']
Definition: index.php:67
ch_append_url_params
ch_append_url_params($sUrl, $mixedParams)
Definition: utils.inc.php:1697
$_REQUEST
$_REQUEST['action']
Definition: cmd.php:11
ChWsbPaginate
Definition: ChWsbPaginate.php:69
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
db_affected_rows
db_affected_rows($oStmt=null)
Definition: db.inc.php:56
CH_ESCAPE_STR_APOS
const CH_ESCAPE_STR_APOS
escape apostrophes only, for js strings enclosed in apostrophes, for use in
Definition: utils.inc.php:33
ChWsbAdminIpBlockList\ActionApplyDelete
ActionApplyDelete()
Definition: ChWsbAdminIpBlockList.php:247
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
$aForm
$aForm
Definition: forgot.php:43
ChWsbAdminIpBlockList\$_sActionUrl
$_sActionUrl
Definition: ChWsbAdminIpBlockList.php:13
$iTotalNum
if(isset($_POST['crsss']) &&is_array($_POST['crsss'])) $iTotalNum
Definition: post_mod_crss.php:40
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$sDesc
$sDesc
Definition: actions.inc.php:21
getLocaleDate
getLocaleDate($sTimestamp='', $iCode=CH_WSB_LOCALE_DATE_SHORT)
Definition: utils.inc.php:70
ChWsbAdminIpBlockList
Definition: ChWsbAdminIpBlockList.php:11
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10