From 710295fea36edc88ff0df73446917ab4c1b0bebf Mon Sep 17 00:00:00 2001 From: JunBarroga Date: Fri, 1 Mar 2024 10:28:18 +0800 Subject: [PATCH] first commit --- admin-test.php | 99 +++++++++++ functions-test.php | 401 +++++++++++++++++++++++++++++++++++++++++++ header.php | 65 +++++++ index.php | 3 + login/action.php | 37 ++++ login/index.php | 74 ++++++++ logout.php | 6 + users/index.php | 3 + users/users-test.php | 102 +++++++++++ 9 files changed, 790 insertions(+) create mode 100644 admin-test.php create mode 100644 functions-test.php create mode 100644 header.php create mode 100644 index.php create mode 100644 login/action.php create mode 100644 login/index.php create mode 100644 logout.php create mode 100644 users/index.php create mode 100644 users/users-test.php diff --git a/admin-test.php b/admin-test.php new file mode 100644 index 0000000..a2158c5 --- /dev/null +++ b/admin-test.php @@ -0,0 +1,99 @@ + + + + + + + + +
+

Transactions

+ + + + + + + + + + + + + + + + $val) { + echo ""; + echo ""; + echo ""; + echo ""; + //echo ""; + echo ""; + //echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
IDDateTimeFromToAmountNotesRef. No.
" . $val['transaction']['_id'] . "" . substr($val['transaction']['createdAt'], 0, 10) . "" . substr($val['transaction']['createdAt'], 11, 8) . "" . $val['userDetails']['senderNumber'] . "" . $val['userDetails']['senderName'] . "" . $val['userDetails']['receiverNumber'] . "" . $val['userDetails']['receiverName'] . "" . number_format($val['transaction']['amount'], 2, '.', ',') . "" . $val['transaction']['notes'] . "" . $val['transaction']['ref_no'] . "
+
+ + + \ No newline at end of file diff --git a/functions-test.php b/functions-test.php new file mode 100644 index 0000000..4b9ba1e --- /dev/null +++ b/functions-test.php @@ -0,0 +1,401 @@ + '172.17.0.3:3000/api/users/id/648058013436143c807101e4', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MmUzYTIzOTQwNTg5Y2UxM2Q4MjVlOSIsImlhdCI6MTY4MDc1MTI4M30.nk_GgSbyA8WuGYa9DgKJNvCVjl5GLHPAOt2rOujwUxs' + ), + ) + ); + $response = curl_exec($curl); + curl_close($curl); + $array = json_decode($response, true); + if ($array['user']['password'] == $pwd) { + return true; + } else { + return false; + } +} + +function get_user_info($email) +{ + $curl = curl_init(); + //$url = "172.17.0.3:3000/api/users/id/$email"; + $url = "172.17.0.3:3000/api/users/$email"; + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt_array($curl, array( + //CURLOPT_URL => '172.17.0.3:3000/api/users/egalang@premiummegastructures.com', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MmUzYTIzOTQwNTg5Y2UxM2Q4MjVlOSIsImlhdCI6MTY4MDc1MTI4M30.nk_GgSbyA8WuGYa9DgKJNvCVjl5GLHPAOt2rOujwUxs' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function get_user_info2($email) +{ + $curl = curl_init(); + $url = "http://172.17.0.3:3000/api/users/id/$email"; + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt_array($curl, array( + //CURLOPT_URL => 'https://api.obananapay.com/api/users/egalang@premiummegastructures.com', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MmUzYTIzOTQwNTg5Y2UxM2Q4MjVlOSIsImlhdCI6MTY4MDc1MTI4M30.nk_GgSbyA8WuGYa9DgKJNvCVjl5GLHPAOt2rOujwUxs' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function activate_account($user_id) +{ + $curl = curl_init(); + $url = "172.17.0.3:3000/api/users/$user_id/sub"; + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt_array($curl, array( + //CURLOPT_URL => '172.17.0.3:3000/api/users/645a0c93008258b5e9a2cd20/sub', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'PATCH', + CURLOPT_POSTFIELDS => '{"status":"validated"}', + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json', + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjRkOTYyZmNiMWU0ZjgyNDU0NmM4OSIsImlhdCI6MTY4MDEzNzU2NH0.9EHOeaXkYS5mGYG-g-_tgRpw338JzxECLec9cU2zhys' + ), + )); + $response = curl_exec($curl); + curl_close($curl); + return $response; +} + +function get_transactions() +{ + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => '172.17.0.3:3000/api/transactions/', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MmUzYTIzOTQwNTg5Y2UxM2Q4MjVlOSIsImlhdCI6MTY4MDc1MTI4M30.nk_GgSbyA8WuGYa9DgKJNvCVjl5GLHPAOt2rOujwUxs' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function get_users() +{ + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => '172.17.0.3:3000/api/users/', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MmUzYTIzOTQwNTg5Y2UxM2Q4MjVlOSIsImlhdCI6MTY4MDc1MTI4M30.nk_GgSbyA8WuGYa9DgKJNvCVjl5GLHPAOt2rOujwUxs' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function user_login($email, $password) +{ + $curl = curl_init(); + $postfields = '{"users":"' . $email . '", "password":"' . $password . '"}'; + curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); + curl_setopt_array($curl, array( + CURLOPT_URL => '172.17.0.3:3000/api/auth/login', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + //CURLOPT_POSTFIELDS => '{"users":"webdev@obanana.com", "password":"P@$$w0rd!"}', + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function user_balance($user_id, $token) +{ + $curl = curl_init(); + $url = "172.17.0.3:3000/api/users/id/$user_id"; + $httpheader = "Authorization: Bearer $token"; + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_HTTPHEADER, array($httpheader)); + curl_setopt_array($curl, array( + //CURLOPT_URL => '172.17.0.3:3000/api/users/id/6458dd6066139b3fee29a9cf', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + //CURLOPT_HTTPHEADER => array('Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MmUzYTIzOTQwNTg5Y2UxM2Q4MjVlOSIsImlhdCI6MTY4MDc1MTI4M30.nk_GgSbyA8WuGYa9DgKJNvCVjl5GLHPAOt2rOujwUxs'), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function random_string($n) +{ + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $randomString = ''; + + for ($i = 0; $i < $n; $i++) { + $index = rand(0, strlen($characters) - 1); + $randomString .= $characters[$index]; + } + + return $randomString; +} + +function cash_in($user_id, $amount, $notes, $refno) +{ + $curl = curl_init(); + $postfields = '{ + "from_id":"6458dd6066139b3fee29a9cf", + "to_id":"' . $user_id . '", + "amount": ' . $amount . ', + "type":"cash in", + "status":"new", + "notes":"' . $notes . '", + "ref_no":"' . $refno . '" + }'; + curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); + curl_setopt_array($curl, array( + CURLOPT_URL => '172.17.0.3:3000/api/transactions/create', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json', + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjRkOTYyZmNiMWU0ZjgyNDU0NmM4OSIsImlhdCI6MTY4MDEzNzU2NH0.9EHOeaXkYS5mGYG-g-_tgRpw338JzxECLec9cU2zhys' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function cash_out($user_id, $amount, $notes, $refno) +{ + $curl = curl_init(); + $postfields = '{ + "from_id":"' . $user_id . '", + "to_id":"6458dd6066139b3fee29a9cf", + "amount": ' . $amount . ', + "type":"cash in", + "status":"new", + "notes":"' . $notes . '", + "ref_no":"' . $refno . '" + }'; + curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); + curl_setopt_array($curl, array( + CURLOPT_URL => '172.17.0.3:3000/api/transactions/create', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json', + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjRkOTYyZmNiMWU0ZjgyNDU0NmM4OSIsImlhdCI6MTY4MDEzNzU2NH0.9EHOeaXkYS5mGYG-g-_tgRpw338JzxECLec9cU2zhys' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function create_notification($to_id, $amount) +{ + $curl = curl_init(); + $postfields = '{ + "from_id":"6458dd6066139b3fee29a9cf", + "to_id":"' . $to_id . '", + "title":"Cash-In Received", + "message":"You have received PHP' . $amount . '.", + "status":"new" + } + '; + curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); + curl_setopt_array($curl, array( + CURLOPT_URL => '172.17.0.3:3000/api/notifications/create', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json', + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjE1NmU0ZTVhMTUwNjk2MTI3NGYyMCIsImlhdCI6MTY3OTkwNjU2OH0.1hDJwO760_p83FsQQwCduz0PIBBNFnMKYK3RvDqE9dA' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function create_notification_co($from_id, $amount) +{ + $curl = curl_init(); + $postfields = '{ + "from_id":"' . $from_id . '", + "to_id":"6458dd6066139b3fee29a9cf", + "title":"Cash-out completed", + "message":"You have sent PHP' . $amount . '.", + "status":"new" + } + '; + curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); + curl_setopt_array($curl, array( + CURLOPT_URL => '172.17.0.3:3000/api/notifications/create', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json', + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjE1NmU0ZTVhMTUwNjk2MTI3NGYyMCIsImlhdCI6MTY3OTkwNjU2OH0.1hDJwO760_p83FsQQwCduz0PIBBNFnMKYK3RvDqE9dA' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function sendSMSotp($phone, $otp) +{ + $curl = curl_init(); + $url = "http://124.6.185.87:1688/services/api/messaging/?To=$phone&Message=Your%20One-Time%20PIN%20is%20$otp.%20DO%20NOT%20SHARE%20THIS%20WITH%20ANYONE.%20If%20you%20did%20not%20request%20for%20an%20OTP%2C%20pls%20call%20(02)%208807-6379"; + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt_array($curl, array( + //CURLOPT_URL => 'http://124.6.185.87:1688/services/api/messaging/?To=09475367847&Message=Your%20One-Time%20PIN%20is%20OgsKLi.%20DO%20NOT%20SHARE%20THIS%20WITH%20ANYONE.%20If%20you%20did%20not%20request%20for%20an%20OTP%2C%20pls%20call%20(02)%208807-6379', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} + +function getUserById($id) +{ + $curl = curl_init(); + $url = "172.17.0.3:3000/api/users/id/".$id; + curl_setopt($curl,CURLOPT_URL,$url); + curl_setopt_array($curl, array( + //CURLOPT_URL => 'https://api.obpay.online/api/users/id/6458dd6066139b3fee29a9cf', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MmUzYTIzOTQwNTg5Y2UxM2Q4MjVlOSIsImlhdCI6MTY4MDc1MTI4M30.nk_GgSbyA8WuGYa9DgKJNvCVjl5GLHPAOt2rOujwUxs' + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; +} diff --git a/header.php b/header.php new file mode 100644 index 0000000..eb76437 --- /dev/null +++ b/header.php @@ -0,0 +1,65 @@ + + oBananaPay + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..fc27b96 --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/login/action.php b/login/action.php new file mode 100644 index 0000000..fa54f21 --- /dev/null +++ b/login/action.php @@ -0,0 +1,37 @@ + '172.17.0.4:3000/api/auth/login', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json' + ), +)); + +$response = curl_exec($curl); + +curl_close($curl); +$array = json_decode($response, true); +if($array['token']!=null){ + if($array['user']['type']!='admin'){ + header("Location: /login/?msg=1"); + } else { + $_SESSION['token']=$array['token']; + $_SESSION['user_id']=$array['user']['_id']; + $_SESSION['user_type']=$array['user']['type']; + header("Location: /admin-test.php".$_SESSION['url']); + } +} else { + header("Location: /login/?msg=2"); +} \ No newline at end of file diff --git a/login/index.php b/login/index.php new file mode 100644 index 0000000..3acb713 --- /dev/null +++ b/login/index.php @@ -0,0 +1,74 @@ + + + + + + +
+

Please Login

+ "; + echo "×"; + echo "Warning! Only administrators allowed."; + echo "
"; + } + if ($_GET['msg'] == 2) { + echo "
"; + echo "×"; + echo "Login Failed! Please check your credentials."; + echo "
"; + } + ?> +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..1b7ea5a --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/users/index.php b/users/index.php new file mode 100644 index 0000000..64681ad --- /dev/null +++ b/users/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/users/users-test.php b/users/users-test.php new file mode 100644 index 0000000..a640dde --- /dev/null +++ b/users/users-test.php @@ -0,0 +1,102 @@ + + + + + + + + +
+

Users

+ + + + + + + + + + + + + + + + + $val) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + $json = getUserById($val['_id']); + $balance = json_decode($json,true); + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
IDNameEmailPhoneTypeStatusBalanceReg. DateReg. Time
" . $val['_id'] . "" . $val['fName'] . ' ' . $val['lName'] . "" . $val['email'] . "" . $val['phone'] . "" . $val['type'] . "" . $val['status'] . "".$balance['balance']."" . substr($val['createdAt'], 0, 10) . "" . substr($val['createdAt'], 11, 8) . "
+
+ + + \ No newline at end of file