first commit

This commit is contained in:
2019-05-25 23:11:05 -04:00
commit 16f48376bc
6139 changed files with 990356 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /user/
#RewriteBase /
#Checks to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
+221
View File
@@ -0,0 +1,221 @@
<?php
include '../config.php';
include '../constants.php';
include '../formerter.php';
$endpoints = array(
'getdrycleanservicelist' => array('POST'),
'createuser' => array('POST'),
'userlogin' => array('POST'),
'updateprofile' => array('POST'),
'updsprofile' => array('POST'),
'newlundrypickup' => array('POST'),
'newdrycleanpickup' => array('POST'),
'confirmlundrypickup' => array('POST'),
'savecardpayment' => array('POST'),
'getlundrylocation' => array('POST'),
'getcardpaymentlist' => array('POST'),
'getmyservicelist' => array('POST'),
'getoneserviceitem' => array('POST'),
'loadprofile' => array('POST'),
'deletecard' => array('POST')
);
/*
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
//header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header('Content-type: application/json');
if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
die();
}
*/
header("Access-Control-Allow-Origin: *");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS");
header('Content-type: application/json');
if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
exit();
}
$endpoint = strtolower(str_replace('/user/', '', strtok($_SERVER['REQUEST_URI'],'?')));
$id = 0; // update, get & delete actions require ID
if (substr($endpoint,0,19)=='gettransportrequest'
|| substr($endpoint,0,13)=='updateprofile') {
$endpoint = strtok($endpoint,'/');
$id = strtok('/');
}
if (!isset($endpoints[$endpoint])) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Invalid endpoint url\"}";
exit();
}
$methods = $endpoints[$endpoint];
if (array_search($_SERVER['REQUEST_METHOD'], $methods)===false) {
header('HTTP/1.1 405 Method Not Allowed');
header('Status: 405 Method Not Allowed');
echo "{\"status\":\"Invalid request method\"}";
exit();
}
include '../rest_api.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($endpoint == "uploadfile") {
upload_file_call();
exit();
} else {
$in = flatten(json_decode(file_get_contents('php://input'), true));
}
}
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
parse_str(file_get_contents('php://input'), $in);
}
$in["loc"] = $_SERVER["REMOTE_ADDR"]; // get who is connecting IP
$in["pid"] = 100;
switch ($endpoint) {
case 'getdrycleanservicelist': $in["action"] = MOBIDELIV_USER_DRYCLIST;
break;
case 'createuser': $in["action"] = MOBIDELIV_USER_CREATE;
$in["street1"] = $in["streetaddress"];
$in["zipcode"] = $in["zip"];
$in["country"] = "US";
$in["loc"] = $_SERVER["REMOTE_ADDR"];
break;
case 'userlogin': $in["action"] = MOBIDELIV_USER_LOGIN;
break;
case 'updateprofile': $in["action"] = MOBIDELIV_USER_PROFILE;
$in["street1"] = $in["streetaddress"];
$in["zipcode"] = $in["zip"];
$in["country"] = "US";
$in["loc"] = $_SERVER["REMOTE_ADDR"];
break;
case 'updsprofile': $in["action"] = MOBIDELIV_USER_COMPLETEPROFILE;
break;
case 'getcardpaymentlist': $in["action"] = MOBIDELIV_USER_GETCCLIST;
break;
case 'newlundrypickup': $in["action"] = MOBIDELIV_USER_NEWLUNDRYPICK;
$in["service_type"] = 1;
$in["service_date"] = $in["pickupdate"] . " " . $in["pickuptime"];
break;
case 'newdrycleanpickup': $in["action"] = MOBIDELIV_USER_NEWLUNDRYPICK;
$in["service_type"] = 2;
$in["service_date"] = $in["pickupdate"] . " " . $in["pickuptime"];
break;
case 'confirmlundrypickup': $in["action"] = MOBIDELIV_USER_CONFIRMPICKUP;
break;
case 'savecardpayment': $in["action"] = MOBIDELIV_USER_SAVECARDPAYMENT;
break;
case 'getlundrylocation': $in["action"] = MOBIDELIV_USER_LUNDRYLOCATION;
$in["limit"] = 100;
break;
case 'getmyservicelist': $in["action"] = MOBIDELIV_USER_GETSERVICELIST;
break;
case 'getoneserviceitem': $in["action"] = MOBIDELIV_USER_GETSERVICEITEM;
break;
case 'loadprofile': $in["action"] = MOBIDELIV_USER_PROFILE;
break;
case 'deletecard': $in["action"] = MOBIDELIV_USER_DELETECARD;
break;
}
$in["pid"] = 100;
//file_put_contents("in_debug.log", $in); // DEBUG
$out = array();
external_internal_call($in, $out);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
//$out = array_merge($in, $out); // DEBUG
echo json_encode(processOutJson($in, $out));
exit();
function flatten($data, $parentkey="") {
$result = array();
foreach ($data as $key=>$val) {
if (is_array($val)) {
$result = array_merge($result, flatten($val, $parentkey.$key."_"));
} else {
$result[$parentkey.$key] = $val;
}
}
return $result;
}
function upload_file_call()
{
global $target_url;
$data = $_POST;
$url = $target_url."/../internal_upload.php";
$uploaddir = realpath('./') . '/files/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);
if (!move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
$in["uploadfile"] = $uploadfile;
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Failed to upload file\"}";
exit();
}
//-----------------------------------------------------------
$file_name_with_full_path = realpath($uploadfile);
/* curl will accept an array here too.
* Many examples I found showed a url-encoded string instead.
* Take note that the 'key' in the array will be the key that shows up in the
* $_FILES array of the accept script. and the at sign '@' is required before the
* file name.
*/
$data['file_contents'] = '@'.$file_name_with_full_path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST,1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Error: call to URL $url failed with status $status, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)."\"}";
}
curl_close($curl);
unlink($file_name_with_full_path);
//$response = json_decode($json_response, true);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
echo $json_response;
}
// vi:ts=2
+60
View File
@@ -0,0 +1,60 @@
<?php
require_once '../config.php';
$url = $local_url . "/user/createuser";
$username = urlencode("ses66181+" . rand(1000, 9999) . "@gmail.com");
$phone = (rand(1, 2) > 1) ? "770222" . rand(2222, 9999) : '';
include '../sample_data.php'; // just for sample data
$firstname = random_name(); //
$lastname = random_name(); //
$company_name = '';
if (rand(0, 1) == 1) {
$company_name = "Company name which is optional " . rand(1000, 9999);
}
$data = array(
"username" => $username,
"password" => "kleenuser",
"email" => $username,
"firstname" => $firstname,
"lastname" => $lastname,
"phone" => $phone,
"company_name" => $company_name
);
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
//echo "<pre>";var_dump($json_response);echo "</pre>";
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
echo ("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
var_dump($response);
echo "<hr/>";
var_dump($data);
echo "<hr/>";
echo highlight_string(file_get_contents(__FILE__));
?>