diff --git a/checkin.html b/checkin.html deleted file mode 100644 index ffdbaa0..0000000 --- a/checkin.html +++ /dev/null @@ -1,84 +0,0 @@ - - -Ushio Auth - - - - - diff --git a/checkin.php b/checkin.php index 9c8bdd4..ba4ead4 100644 --- a/checkin.php +++ b/checkin.php @@ -1,62 +1,48 @@ connect('redis',6379); -$fp = $_REQUEST['fp']; -$mask = $_REQUEST['mask']; -$token = $_REQUEST['token']; -$ip = $_REQUEST['ip']; -if(!isset($fp)) die(); -if(!isset($mask)) die(); +$hash = $_REQUEST['token']; +$from = $_REQUEST['from']; +if(!isset($hash)) die(); +if(!isset($from)) die(); - -$id = md5($fp.$mask); - - -if(isset($token) && isset($ip)){ - $fip = md5($fp.$ip); - $redis->set('auth/fip/'.$fip, $token); - $redis->expire('auth/fip/'.$fip, 3600*72); +if(strlen($hash) != 64){ + echo ""; + die(); } -if(isset($ip) && !isset($token)){ - $fip = md5($fp.$ip); - if($redis->exists('auth/fip/'.$fip)){ - $token = $redis->get('auth/fip/'.$fip); - }else{ - die(); - } -} -if(!$redis->exists('auth/token/'.$token)){ - $redis->set('session/redirect/'.$id, $token); - if(!$redis->exists('session/dialog/'.$token)){ - $redis->hSet('session/dialog/'.$token, "group", "anonymous"); - } - echo $token; - die(); +$token = $_COOKIE['_token']; +if(!isset($token)){ + $token = hash('sha256', time().$from.$hash); + setcookie("_token", $token, time()+60*60*24*30*6); } + $cnn = db__connect(); -$hash = $redis->get('auth/token/'.$token); -if(!db__rowNum($cnn, "account", "hash", $hash)){ - $redis->set('session/redirect/'.$id, $token); - $redis->del('auth/token/'.$token); - if(!$redis->exists('session/dialog/'.$token)){ - $redis->hSet('session/dialog/'.$token, "group", "anonymous"); - } + +if(db__rowNum($cnn, "token", "token", $token)){ + db__pushData($cnn, "token", array( + "hash"=>$hash, + "updated_at"=>date("Y-m-d H:i:s", time()), + "state"=>'1' + ), array( + "token"=>$token + )); }else{ - $redis->set('session/redirect/'.$id, $token); - if(!$redis->exists('session/dialog/'.$hash)){ - $data = db__getData($cnn, "account", "hash", $hash); - foreach($data[0] as $key=>$val){ - $redis->hSet('session/dialog/'.$hash, $key, $val); - } - } + db__pushData($cnn, "token", array( + "hash"=>$hash, + "token"=>$token, + "created_at"=>date("Y-m-d H:i:s", time()), + "state"=>'1' + )); } -echo $token; + +echo ''; +echo ''; +echo 'Ushio Auth - set token
正在检测您的设备安全( • ̀ω•́ )✧
Anti-DDOS..
'; +echo ""; diff --git a/checkout.php b/checkout.php index c93c96d..8d4b983 100644 --- a/checkout.php +++ b/checkout.php @@ -7,12 +7,11 @@ $cnn = db__connect(); if(isset($_COOKIE['_token']) && db__rowNum($cnn, "token", "token", $_COOKIE['_token'])){ db__pushData($cnn, "token", array( - "state"=>'0' + "state"=>'0', + "updated_at"=>date("Y-m-d H:i:s", time()) ), array( "token"=>$_COOKIE['_token'] )); - } -setcookie("_token", "", time()-3600); echo ''; diff --git a/functions.php b/functions.php index 153f9af..6670a65 100755 --- a/functions.php +++ b/functions.php @@ -3,6 +3,11 @@ include '/mnt/config/dbKeys/auth.php'; include '/mnt/config/php/config.php'; /**database connection**/ + +$redis = new redis(); +$redis->connect('redis',6379); + + //connect to database function db__connect($servername="",$username="",$password="",$dbname="") { @@ -37,7 +42,7 @@ function db__connect($servername="",$username="",$password="",$dbname="") } //get table row number::(data_cnnct var,table name) ::(row number) -function db__rowNum($conn,$table,$clmnName="",$value="",$clmnName2="",$value2="") +function db__rowNum($conn,$table,$clmnName="",$value="",$clmnName2="",$value2="",$clmnName3="",$value3="",$clmnName4="",$value4="") { $table=db__antisql($table); @@ -49,7 +54,9 @@ function db__rowNum($conn,$table,$clmnName="",$value="",$clmnName2="",$value2="" if($clmnName=="") $sql = "SELECT COUNT(*) FROM $table"; elseif($clmnName2=="") $sql = "SELECT COUNT(*) FROM $table where $clmnName='$value'"; - else $sql = "SELECT COUNT(*) FROM $table where $clmnName='$value' AND $clmnName2='$value2'"; + elseif($clmnName3=="") $sql = "SELECT COUNT(*) FROM $table where $clmnName='$value' AND $clmnName2='$value2'"; + elseif($clmnName4=="") $sql = "SELECT COUNT(*) FROM $table where $clmnName='$value' AND $clmnName2='$value2' AND $clmnName3='$value3'"; + else $sql = "SELECT COUNT(*) FROM $table where $clmnName='$value' AND $clmnName2='$value2' AND $clmnName3='$value3' AND $clmnName4='$value4'"; $row_count = $conn->query($sql); list($row_num) = $row_count->fetch_row(); diff --git a/index.html b/index.html deleted file mode 100644 index fbf2d0b..0000000 --- a/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/setToken.php b/index.php similarity index 79% rename from setToken.php rename to index.php index ef7d47a..9dfebe7 100644 --- a/setToken.php +++ b/index.php @@ -1,27 +1,44 @@ connect('redis',6379); +$from = $_REQUEST['from']; + -if (isset($_COOKIE["_token"])){ - $redis->del('auth/token/'.$_COOKIE['_token']); +/* deal from */ +if(!isset($from)){ + $from = 'https://ushio.cool/'; +}else{ + try{ + $from = base64_decode($from); + }catch(Exception $e){} } -$token = $_REQUEST['token']; -$from = $_REQUEST['from']; -if(!isset($token)) die(); -if(!isset($from)) die(); -if(strlen($token) < 60 || !$redis->exists('auth/token/'.$token)){ - echo ""; - die(); -} -setcookie("_token", $token, time()+60*60*24*30*6); +/* deal with none local token */ +if (!isset($_COOKIE["_token"])){ + $token = hash('sha256', $from.time()); + setcookie("_token", $token, time()+6*30*24*3600); +}else{ + $token = $_COOKIE['_token']; +} +/* set tmp seed */ +$seed = hash('sha256', time().$from); +$redis->set('auth/seed/'.$seed, $token); +$redis->expire('auth/seed/'.$seed, 30); -echo ''; +echo ''; echo ''; echo 'Ushio Auth
正在检测您的设备安全( • ̀ω•́ )✧
Anti-DDOS..
'; -echo ""; +echo ""; diff --git a/setFip.php b/setFip.php new file mode 100644 index 0000000..df27ccf --- /dev/null +++ b/setFip.php @@ -0,0 +1,48 @@ +16 || !isset($fp) || strlen($fp)!=6) { + header('status: 505 Illegal Params'); + die(); +}; + + +header("Content-Type: application/json;charset=utf-8"); + +$fip = md5($fp.$ip); + + +// bad seed +if(!$redis->exists('auth/seed/'.$seed)){ + echo json_encode(array( + "code"=>400, + "message"=>"Bad Seed!" + )); + die(); +} + + +$token = $redis->get('auth/seed/'.$seed); + +//bad token +if(strlen($token)!=64){ + echo json_encode(array( + "code"=>500, + "message"=>"Bad token!" + )); + die(); +} + + +//good +$redis->set('auth/fip/'.$fip, $token); +$redis->expire('auth/fip/'.$fip, 60); +echo json_encode(array( + "code"=>200 +)); + diff --git a/who.php b/who.php new file mode 100644 index 0000000..531c1c3 --- /dev/null +++ b/who.php @@ -0,0 +1,86 @@ +16 || !isset($fp) || strlen($fp)!=6) { + header('status: 505 Illegal Params'); + die(); +}; + +/* special php program */ +set_time_limit(0); +ob_end_clean(); +header("Connection: close"); +header("HTTP/1.1 200 OK"); +header("Content-Type: application/json;charset=utf-8"); +header('Access-Control-Allow-Origin:*'); +ob_start(); + + + +$cnn = db__connect(); + +if(db__rowNum($cnn, "mask", "mask", $mask)){ + $token = db__getData($cnn, "mask", "mask", $mask)[0]['token']; + echo json_encode(array( + "code"=> 200 + )); +}else{ + $fip = md5($fp.$ip); + if($redis->exists('auth/fip/'.$fip)){ + $token = $redis->get('auth/fip/'.$fip); + db__pushData($cnn, "mask", array( + "mask"=>$mask, + "token"=>$token, + "created_at"=>date("Y-m-d H:i:s", time()) + ), array( + "mask"=>$mask + )); + echo json_encode(array( + "code"=> 200 + )); + }else{ + echo json_encode(array( + "code"=> 404 + )); + } + die(); +} + + +/* close connection */ +ob_end_flush(); +flush(); +if (function_exists("fastcgi_finish_request")) { + fastcgi_finish_request(); +} +sleep(2); +ignore_user_abort(true); +set_time_limit(0); + +if(db__rowNum($cnn, "fip", "token", $token, "mask", $mask, "fp", $fp, "ip", $ip)){ + db__pushData($cnn, "fip", array( + "updated_at"=>date("Y-m-d H:i:s", time()) + ), array( + "token"=>$token, + "mask"=>$mask, + "fp"=>$fp, + "ip"=>$ip + )); +}else{ + db__pushData($cnn, "fip", array( + "token"=>$token, + "mask"=>$mask, + "fp"=>$fp, + "ip"=>$ip, + "created_at"=>date("Y-m-d H:i:s", time()) + )); +} + +die();