2013-08-19 22:30:57 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· Q V I T T E R ·
|
|
|
|
· ·
|
|
|
|
· http://github.com/hannesmannerheim/qvitter ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· <o) ·
|
|
|
|
· /_//// ·
|
|
|
|
· (____/ ·
|
|
|
|
· (o< ·
|
|
|
|
· o> \\\\_\ ·
|
|
|
|
· \\) \____) ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· Qvitter is free software: you can redistribute it and / or modify it ·
|
|
|
|
· under the terms of the GNU Affero General Public License as published by ·
|
|
|
|
· the Free Software Foundation, either version three of the License or (at ·
|
|
|
|
· your option) any later version. ·
|
|
|
|
· ·
|
|
|
|
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
|
|
|
|
· WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
|
|
|
|
· FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
|
|
|
|
· more details. ·
|
|
|
|
· ·
|
|
|
|
· You should have received a copy of the GNU Affero General Public License ·
|
|
|
|
· along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
|
|
|
|
· ·
|
|
|
|
· Contact h@nnesmannerhe.im if you have any questions. ·
|
|
|
|
· ·
|
|
|
|
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
|
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
class QvitterApiAction extends ApiAction
|
|
|
|
{
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
protected $needPost = true;
|
2014-02-24 03:18:51 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
protected function prepare(array $args=array())
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
protected function handle()
|
|
|
|
{
|
|
|
|
parent::handle();
|
|
|
|
|
|
|
|
$apiroot = common_path('api/', true);
|
|
|
|
|
|
|
|
header("Content-type: application/json; charset=utf-8");
|
|
|
|
|
|
|
|
// post requests
|
|
|
|
if(isset($_POST['postRequest'])) {
|
|
|
|
$query = http_build_query($_POST, '', '&');
|
|
|
|
$ch=curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $apiroot.urldecode($_POST['postRequest']));
|
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, $_POST['username'].":".$_POST['password']);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
|
|
|
|
session_write_close(); // fix problem with curling to local
|
|
|
|
$reply=curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
// get requests
|
|
|
|
} elseif(isset($_POST['getRequest'])) {
|
|
|
|
$ch=curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $apiroot.$_POST['getRequest']);
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
if(isset($_POST['username'])) {
|
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, $_POST['username'].":".$_POST['password']);
|
|
|
|
}
|
2013-08-19 22:30:57 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
session_write_close();
|
|
|
|
$reply=curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
} else {
|
|
|
|
// 400 Bad request, since neither postRequest or getRequest were included
|
|
|
|
http_response_code(400);
|
|
|
|
exit;
|
|
|
|
}
|
2014-02-24 03:18:51 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
session_start();
|
2014-02-24 03:18:51 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
echo $reply;
|
2014-02-24 03:18:51 +09:00
|
|
|
|
2014-05-14 16:46:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-08-19 22:30:57 +09:00
|
|
|
|
|
|
|
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
|
|
|
|
· ·
|
|
|
|
· (o> >o) ·
|
|
|
|
· \\\\_\ /_//// .
|
|
|
|
· \____) (____/ ·
|
|
|
|
· ·
|
2014-02-24 03:18:51 +09:00
|
|
|
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */?>
|