-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1ac737
commit c1b9f49
Showing
7 changed files
with
782 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
header('Access-Control-Allow-Origin: *'); | ||
|
||
$action = "none"; | ||
|
||
if(isset($_POST['action'])){ | ||
$action = htmlspecialchars($_POST['action']); | ||
} | ||
|
||
if ($action == "validate"){ | ||
|
||
require_once('stu-account.php'); | ||
|
||
if(!isset($_POST['uid']) || !isset($_POST['pass'])){ | ||
echo "missing parameter"; | ||
}else{ | ||
$response = new StuAccount(); | ||
$response->login($_POST['uid'], $_POST['pass']); | ||
$response->output(); | ||
} | ||
} | ||
|
||
if ($action == "stu-info"){ | ||
|
||
require_once('stu-info.php'); | ||
|
||
if(!isset($_POST['uid']) || !isset($_POST['pass'])){ | ||
echo "missing parameter"; | ||
}else{ | ||
$response = new StuInfo(); | ||
$response->parse_stu_info($_POST['uid'], $_POST['pass']); | ||
$response->output(); | ||
} | ||
} | ||
|
||
if ($action == "stu-score"){ | ||
|
||
require_once('stu-score.php'); | ||
|
||
if(!isset($_POST['uid']) || !isset($_POST['pass'])){ | ||
echo "missing parameter"; | ||
}else{ | ||
$response = new StuScore(); | ||
$response->parse_stu_Score($_POST['uid'], $_POST['pass']); | ||
$response->output(); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
class LanyangAPI{ | ||
|
||
private $filename = ""; | ||
private $version = ""; | ||
private $dependencies = ""; | ||
private $description = ""; | ||
private $response = ""; | ||
|
||
private $isLogin = "FALSE"; | ||
|
||
|
||
public function getFilename(){ | ||
return $this->filename; | ||
} | ||
|
||
public function getVersion(){ | ||
return $this->version; | ||
} | ||
|
||
public function getDependencies(){ | ||
return $this->dependencies; | ||
} | ||
|
||
public function getDescription(){ | ||
return $this->description; | ||
} | ||
|
||
public function getIsLogin(){ | ||
return $this->isLogin; | ||
} | ||
|
||
public function getResponse(){ | ||
return $this->response; | ||
} | ||
|
||
public function setFilename($value){ | ||
$this->filename = $value; | ||
} | ||
|
||
public function setVersion($value){ | ||
$this->version = $value; | ||
} | ||
|
||
public function setDependencies($value){ | ||
$this->dependencies = $value; | ||
} | ||
|
||
public function setDescription($value){ | ||
$this->description = $value; | ||
} | ||
|
||
public function setIsLogin($value){ | ||
$this->isLogin = $value; | ||
} | ||
|
||
public function setResponse($value){ | ||
$this->response = $value; | ||
} | ||
|
||
public function output(){ | ||
$json = array( | ||
"information" => array( | ||
"filename" => $this->filename, | ||
"version" => $this->version, | ||
"dependencies" => $this->dependencies, | ||
"description" => $this->description | ||
), | ||
"response" => $this->response | ||
); | ||
|
||
echo "<pre>"; | ||
echo $this->json_encode_unicode($json); | ||
echo "</pre>"; | ||
} | ||
|
||
public function json_encode_unicode($data) { | ||
if (defined('JSON_UNESCAPED_UNICODE')) { | ||
return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); | ||
} | ||
return preg_replace_callback('/(?<!\\\\)\\\\u([0-9a-f]{4})/i', | ||
function ($m) { | ||
$d = pack("H*", $m[1]); | ||
$r = mb_convert_encoding($d, "UTF8", "UTF-16BE"); | ||
return $r!=="?" && $r!=="" ? $r : $m[0]; | ||
}, json_encode($data) | ||
); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
header('Access-Control-Allow-Origin: *'); | ||
|
||
$action = "error"; | ||
$status = "error"; | ||
$response = "error"; | ||
|
||
if(isset($_POST['action'])){ | ||
$action = htmlspecialchars($_POST['action']); | ||
} | ||
|
||
if ($action == "validate"){ | ||
include("stu-account.php"); | ||
|
||
if(!isset($_POST['uid']) || !isset($_POST['pass'])){ | ||
$status = "Fail"; | ||
}else{ | ||
$status = "OK"; | ||
$response = login($_POST['uid'], $_POST['pass']); | ||
} | ||
} | ||
|
||
if ($action == "stu-info"){ | ||
include("stu-info.php"); | ||
|
||
if(!isset($_POST['uid']) || !isset($_POST['pass'])){ | ||
$status = "Fail"; | ||
}else{ | ||
$status = "OK"; | ||
$response = parse_stu_info($_POST['uid'], $_POST['pass']); | ||
} | ||
} | ||
|
||
if ($action == "stu-score"){ | ||
include("stu-score.php"); | ||
|
||
if(!isset($_POST['uid']) || !isset($_POST['pass'])){ | ||
$status = "Fail"; | ||
}else{ | ||
$status = "OK"; | ||
$response = parse_stu_score($_POST['uid'], $_POST['pass']); | ||
} | ||
} | ||
|
||
$json = array( | ||
"action" => $action, | ||
"timestamp" => date("Y-m-d H:i:s"), | ||
"status" => $status, | ||
"response" => $response | ||
); | ||
|
||
$final = json_encode_unicode($json); | ||
|
||
echo "<pre>"; | ||
echo $final; | ||
echo "</pre>"; | ||
|
||
function json_encode_unicode($data) { | ||
if (defined('JSON_UNESCAPED_UNICODE')) { | ||
return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); | ||
} | ||
return preg_replace_callback('/(?<!\\\\)\\\\u([0-9a-f]{4})/i', | ||
function ($m) { | ||
$d = pack("H*", $m[1]); | ||
$r = mb_convert_encoding($d, "UTF8", "UTF-16BE"); | ||
return $r!=="?" && $r!=="" ? $r : $m[0]; | ||
}, json_encode($data) | ||
); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
require_once('class.php'); | ||
$filename = "stu-account.php"; | ||
$version = "0.0.2"; | ||
$dependencies = "none"; | ||
$description = "validate student account credential"; | ||
|
||
class StuAccount extends LanyangAPI{ | ||
|
||
function __construct(){ | ||
parent::setFilename($GLOBALS['filename']); | ||
parent::setVersion($GLOBALS['version']); | ||
parent::setDependencies($GLOBALS['dependencies']); | ||
parent::setDescription($GLOBALS['description']); | ||
} | ||
|
||
function login($username, $password){ | ||
|
||
$status = ""; | ||
|
||
$curl = curl_init(); | ||
$url = "portal.tku.edu.tw/NEAI/login2.do?action=EAI&myurl=http://portal.tku.edu.tw/aissinfo/emis/tmw0012.aspx&ln=en_US&username=$username&password=$password&loginbtn=Login"; | ||
curl_setopt($curl, CURLOPT_URL, $url); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | ||
curl_setopt($curl, CURLOPT_COOKIEJAR, 1); | ||
|
||
$curlResult = curl_exec($curl); | ||
curl_close($curl); | ||
|
||
if (strpos($curlResult, 'Tamkang University Single Sign On(SSO)') !== false) { | ||
$status = "FAILED"; | ||
parent::setIsLogin("FALSE"); | ||
}else{ | ||
$status = "OK"; | ||
parent::setIsLogin("TRUE"); | ||
} | ||
|
||
$response = array( | ||
"username" => $username, | ||
"status" => $status | ||
); | ||
|
||
return parent::setResponse($response); | ||
} | ||
|
||
} | ||
|
||
|
||
?> |
Oops, something went wrong.