-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.php
More file actions
56 lines (53 loc) · 1.76 KB
/
handler.php
File metadata and controls
56 lines (53 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require 'includes/geoip2.phar';
use GeoIp2\Database\Reader;
define('SU_RUN',0);
include_once 'config.php';
include_once 'constant.php';
include_once 'dbconn.php';
$target = $_GET['id'];
//Handle incorrect type of ID
if( SU_ID_TYPE == 58){
$target = str_replace(array('0','1','l','o'),array('O','I','I','O'),$target);
}else if( SU_ID_TYPE == 36 ){
$target = str_replace(array('l'),array('I'),$target);
$target = strtoupper($target);
}else if( SU_ID_TYPE == 34 ){
$target = str_replace(array('0','1','l','o'),array('O','I','I','O'),$target);
$target = strtoupper($target);
}
$stmt = $db->prepare('SELECT * FROM '.SU_TABLE_ENTRY.' WHERE `id`=?');
$stmt->execute(array($target));
if($stmt->rowCount() == 0){
header("HTTP/1.1 404 Not Found");
include 'info/404.php';
return;
}
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if(!($row['flags'] & SU_FLAG_ENABLE) || ($row['flags'] & SU_FLAG_ADMIN_DISABLE)){
header("HTTP/1.1 403 Forbidden");
include 'info/403.php';
return;
}
$needLog = true;
#TODO : Check is logging needed
if($row['flags'] & SU_FLAG_NOLOG )
$needLog = false;
if($needLog){
$record = 'XX';
if(SU_LOG_GEOINFO){
$reader = new Reader(SU_GEO_DB);
try{
$record = $reader->city($_SERVER['REMOTE_ADDR'])->country->isoCode;
}catch(GeoIp2\Exception\AddressNotFoundException $e){
$record = 'XX';
}
}
if(empty($_SERVER['HTTP_REFERER']))
$refer = '';
else
$refer =$_SERVER['HTTP_REFERER'];
$stmt = $db->prepare('INSERT INTO '.SU_TABLE_LOG.'(`id`,`num`,`datetime`,`source`,`refer`,`country`) VALUES (?,ROUND(RAND()*1000000000),NOW(),?,?,?);');
$stmt->execute(array($target,$_SERVER['REMOTE_ADDR'],$refer,$record));
}
header('Location: '.$row['url']);