If you can't run like this please stay at home quietly! pic.twitter.com/eJgfwmFmfY
— Ila Sharma (@ila_home) March 31, 2020
Category Archives: Uncategorized
How to get the size of the MySQL database?
SELECT table_schema "Databases",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
Run this query and you’ll probably get what you’re looking for.
क बाट आउने २० अंग हरु यिनै हुन् बुझ!
क बाट आउने २० अंग हरु यिनै हुन् बुझ!
— Bhaktaraz Bhatta (@bhaktaraz) August 25, 2019
केश
कन्चेट
कुहुनु
कपाल
कलेजों
काखी
करंग
कन्सिरी
कानेगुजी
कुर्कुच्चा
कटी
कान
कम्मर
कापा
कान्छिऔला
काँध
कुम
कँदो
कोखो
कन्पारो
Add SSH Keys to authorized_keys file
cat ~/.ssh/id_rsa.pub
Copy the key from terminal.
Then, login to server.
sudo vi ~/.ssh/authorized_keys
Paste your key.
Done!
Or,
cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Done!!
Installing Dnsmasq for wildcard local domains on Debian
Install
sudo apt-get install dnsmasq
Configure
sudo vim /etc/dnsmasq.conf
Add this:
address=/example.com/127.0.0.1 listen-address=127.0.0.1
This maps *.example.com
to 127.0.0.1
– replace with the domain you want to use. It also makes dnsmasq only respond to local requests for security – this is optional.
Restart to load the new configuration:
sudo /etc/init.d/dnsmasq restart
Test it:
nslookup abc.example.com 127.0.0.1
It should say something like:
Server: 127.0.0.1 Address: 127.0.0.1#53 Name: abc.example.com Address: 127.0.0.1
Override the nameserver to use for lookups
sudo vim /etc/dhcp/dhclient.conf
Add:
prepend domain-name-servers 127.0.0.1;
Restart the network:
sudo ifdown eth0; sudo ifup eth0
Adjust as necessary if your interface is not named eth0
. Run ifconfig
to get the interface name if you’re not sure.
Check that it worked:
cat /etc/resolv.conf
It should say something like:
domain home search home nameserver 127.0.0.1 nameserver 192.168.32.254
Note that 127.0.0.1
is the first nameserver.
Test:
nslookup abc.example.com
It should say the same thing as it did above.
The original post is here.
Nepals Top Payment Gateway nPay Integration – Symfony 3 Example
Here today I’m going to post a piece of code to integrate Nepal’s one of top payment gateway nPay.
<?php | |
/** | |
* Created by PhpStorm. | |
* User: bhaktaraz | |
* Date: 6/13/18 | |
* Time: 2:47 PM | |
*/ | |
namespace Fundprabhu\Bundle\PaymentBundle\Controller; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use Fundprabhu\Bundle\MainBundle\Entity\Donation; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
class NpayController extends Controller | |
{ | |
/** | |
* @param Donation $donation | |
* @return array | |
*/ | |
public function validateMerchant($donation) | |
{ | |
$merchantId = $this->getParameter('npay_merchant_id'); | |
$merchantUserName = $this->getParameter('npay_merchant_username'); | |
$merchantPassword = $this->getParameter('npay_merchant_password'); | |
$merchantSignaturePassCode = $this->getParameter('npay_merchant_signature'); | |
$merchantValidateEndpoint = $this->getParameter('npay_validate_merchant_url'); | |
$merchantTransactionId = $donation->getId(); | |
$amount = $donation->getAmount(); | |
$paymentMode = 'SCT'; | |
$merchantPasswordEncoded = hash('sha256', $merchantUserName.$merchantPassword); | |
$signature = hash('sha256', $merchantSignaturePassCode.$merchantUserName.$merchantTransactionId); | |
# Initialize webservice with WSDL | |
$client = new \SoapClient($merchantValidateEndpoint); | |
# Set your parameters for the request | |
$params = array( | |
"MerchantId" => $merchantId, | |
"MerchantTxnId" => $merchantTransactionId, | |
"MerchantUserName" => $merchantUserName, | |
"MerchantPassword" => $merchantPasswordEncoded, | |
"Signature" => $signature, | |
"AMOUNT" => $amount, | |
"purchaseDescription" => '', | |
"PaymentMode" => $paymentMode, | |
); | |
# Invoke webservice method with parameters, Function Name: ValidateMerchant | |
$response = $client->__soapCall("ValidateMerchant", array($params)); | |
if($response->ValidateMerchantResult->STATUS_CODE != "0") | |
{ | |
$STATUS_CODE = $response->ValidateMerchantResult->STATUS_CODE; | |
# Error occured while validating merchant. End process. | |
die("Error on validating merchant. <br> Error Code: " . $STATUS_CODE . " <br>MESSAGE: " . $response->ValidateMerchantResult->MESSAGE); | |
} | |
$data = array(); | |
$data['processID'] = $response->ValidateMerchantResult->PROCESSID; | |
$data['MerchantID'] = $merchantId; | |
$data['MerchantTxnID'] = $merchantTransactionId; | |
$data['PayAmount'] = $amount; | |
$data['MerchantUsername'] = $merchantUserName; | |
$data['PaymentMode'] = $paymentMode; | |
return $data; | |
} | |
public function redirectAction(Request $request) | |
{ | |
$donationId = $request->get('donation_id'); | |
/** @var Donation $donation */ | |
$donation = $this->getDoctrine()->getRepository(Donation::class)->find($donationId); | |
$data = $this->validateMerchant($donation); | |
$data['description'] = 'Donation for campaign '.$donation->getCampaign()->getTitle(); | |
return $this->render('FundprabhuPaymentBundle:Npay:redirect.html.twig', $data); | |
} | |
public function failureAction(Request $request) | |
{ | |
$em = $this->getDoctrine()->getManager(); | |
$donationId = $this->get('session')->get('donation_id'); | |
$donation = $em->getRepository(Donation::class)->find($donationId); | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($donation); | |
$em->flush(); | |
$this->addFlash('error', 'Unable to make donation for campaign ' . $donation->getCampaign()->getTitle()); | |
return $this->redirectToRoute('fundprabhu_web_user_donations'); | |
} | |
public function successAction(Request $request) | |
{ | |
$transactionId = $request->get('MERCHANTTXNID'); | |
$gateWayRefNo = $request->get('GTWREFNO'); | |
$em = $this->getDoctrine()->getManager(); | |
$donation = $em->getRepository(Donation::class)->find($transactionId); | |
$merchantId = $this->getParameter('npay_merchant_id'); | |
$merchantUserName = $this->getParameter('npay_merchant_username'); | |
$merchantPassword = $this->getParameter('npay_merchant_password'); | |
$merchantSignaturePassCode = $this->getParameter('npay_merchant_signature'); | |
$merchantValidateEndpoint = $this->getParameter('npay_validate_merchant_url'); | |
$merchantTransactionId = $donation->getId(); | |
$merchantPasswordEncoded = hash('sha256', $merchantUserName.$merchantPassword); | |
$signature = hash('sha256', $merchantSignaturePassCode.$merchantUserName.$merchantTransactionId); | |
# Initialize webservice with WSDL | |
$client = new \SoapClient($merchantValidateEndpoint); | |
# Set your parameters for the request | |
$params = array( | |
"MerchantId" => $merchantId, | |
"MerchantTxnId" => $transactionId, | |
"MerchantUserName" => $merchantUserName, | |
"MerchantPassword" => $merchantPasswordEncoded, | |
"Signature" => $signature, | |
"GTWREFNO" => $gateWayRefNo, | |
); | |
# Merchant must send query to gateway SOAP to get STATUS against GTWREFNO for transaction verification | |
# Invoke webservice method with parameters, Function Name: CheckTransactionStatus | |
$response = $client->__soapCall("CheckTransactionStatus", array($params)); | |
# Print webservice response | |
// print_r($response); // Uncomment to print | |
# if successfully query executed, STATUS_CODE is returned as 0 (ZERO) else validation error. | |
if($response->CheckTransactionStatusResult->STATUS_CODE != "0") | |
{ | |
$STATUS_CODE = $response->CheckTransactionStatusResult->STATUS_CODE; | |
# Error occured while validating merchant. End process. | |
// die("Error occured while getting Transaction STATUS . <br> Error Code: " . $STATUS_CODE . " <br>MESSAGE: " . $response->CheckTransactionStatusResult->MESSAGE); | |
return false; | |
} | |
# Proceed as query execution is successful. | |
$STATUS_CODE = $response->CheckTransactionStatusResult->STATUS_CODE; | |
$TRANSACTION_STATUS = $response->CheckTransactionStatusResult->TRANSACTION_STATUS; | |
$AMOUNT = $response->CheckTransactionStatusResult->AMOUNT; | |
$MERCHANT_TRANSACTIONID = $response->CheckTransactionStatusResult->MERCHANT_TRANSACTIONID; | |
$REMARKS = $response->CheckTransactionStatusResult->REMARKS; | |
$GTWREFNO = $response->CheckTransactionStatusResult->GTWREFNO; | |
if($TRANSACTION_STATUS == "SUCCESS") | |
{ | |
$transactionAmount = $donation->getAmount(); | |
if($transactionAmount != $AMOUNT){ | |
throw new \Exception('Man in the middle attack'); | |
} | |
$donation->setStatus(Donation::DONATION_STATUS_SUCCESS); | |
$em->persist($donation); | |
$em->flush(); | |
$this->addFlash('success', 'You have successfully donated for campaign ' . $donation->getCampaign()->getTitle()); | |
} | |
else | |
{ | |
$this->addFlash('error', 'Unable to make donation for campaign ' . $donation->getCampaign()->getTitle()); | |
} | |
return $this->redirectToRoute('fundprabhu_web_user_donations'); | |
} | |
public function deliveryAction(Request $request) | |
{ | |
$transactionId = $request->get('MERCHANTTXNID'); | |
$gateWayRefNo = $request->get('GTWREFNO'); | |
$em = $this->getDoctrine()->getManager(); | |
$donation = $em->getRepository(Donation::class)->find($transactionId); | |
$merchantId = $this->getParameter('npay_merchant_id'); | |
$merchantUserName = $this->getParameter('npay_merchant_username'); | |
$merchantPassword = $this->getParameter('npay_merchant_password'); | |
$merchantSignaturePassCode = $this->getParameter('npay_merchant_signature'); | |
$merchantValidateEndpoint = $this->getParameter('npay_validate_merchant_url'); | |
$merchantTransactionId = $donation->getId(); | |
$merchantPasswordEncoded = hash('sha256', $merchantUserName.$merchantPassword); | |
$signature = hash('sha256', $merchantSignaturePassCode.$merchantUserName.$merchantTransactionId); | |
# Initialize webservice with WSDL | |
$client = new \SoapClient($merchantValidateEndpoint); | |
# Set your parameters for the request | |
$params = array( | |
"MerchantId" => $merchantId, | |
"MerchantTxnId" => $transactionId, | |
"MerchantUserName" => $merchantUserName, | |
"MerchantPassword" => $merchantPasswordEncoded, | |
"Signature" => $signature, | |
"GTWREFNO" => $gateWayRefNo, | |
); | |
# Merchant must send query to gateway SOAP to get STATUS against GTWREFNO for transaction verification | |
# Invoke webservice method with parameters, Function Name: CheckTransactionStatus | |
$response = $client->__soapCall("CheckTransactionStatus", array($params)); | |
# Print webservice response | |
// print_r($response); // Uncomment to print | |
# if successfully query executed, STATUS_CODE is returned as 0 (ZERO) else validation error. | |
if($response->CheckTransactionStatusResult->STATUS_CODE != "0") | |
{ | |
$STATUS_CODE = $response->CheckTransactionStatusResult->STATUS_CODE; | |
# Error occured while validating merchant. End process. | |
die("Error occured while getting Transaction STATUS . <br> Error Code: " . $STATUS_CODE . " <br>MESSAGE: " . $response->CheckTransactionStatusResult->MESSAGE); | |
} | |
# Proceed as query execution is successful. | |
$STATUS_CODE = $response->CheckTransactionStatusResult->STATUS_CODE; | |
$TRANSACTION_STATUS = $response->CheckTransactionStatusResult->TRANSACTION_STATUS; | |
$AMOUNT = $response->CheckTransactionStatusResult->AMOUNT; | |
$MERCHANT_TRANSACTIONID = $response->CheckTransactionStatusResult->MERCHANT_TRANSACTIONID; | |
$REMARKS = $response->CheckTransactionStatusResult->REMARKS; | |
$GTWREFNO = $response->CheckTransactionStatusResult->GTWREFNO; | |
# Check Transaction Status and proceed required steps | |
if($TRANSACTION_STATUS == "SUCCESS") | |
{ | |
// execute transaction success steps | |
} | |
else | |
{ | |
// execute transaction failure steps | |
} | |
# Print '0' (ZERO) value to let gateway know you have received Delivery status successfully. | |
return new Response("0", 200); | |
} | |
public function getSctNpayBankListAction(Request $request) | |
{ | |
$merchantId = $this->getParameter('npay_merchant_id'); | |
$merchantUserName = $this->getParameter('npay_merchant_username'); | |
$merchantPassword = $this->getParameter('npay_merchant_password'); | |
$signaturePassCode = $this->getParameter('npay_merchant_signature'); | |
$merchantValidateEndpoint = $this->getParameter('npay_validate_merchant_url'); | |
$dateTime = date('Y-m-d h:i:s'); | |
# Initialize webservice with WSDL | |
$client = new \SoapClient($merchantValidateEndpoint); | |
$merchantPasswordEncoded = hash('sha256', $merchantUserName.$merchantPassword); | |
$signature = hash('sha256', $merchantUserName.$signaturePassCode.$dateTime); | |
# Set your parameters for the request | |
$params = array( | |
"MerchantId" => $merchantId, | |
"MerchantUserName" => $merchantUserName, | |
"MerchantPassword" => $merchantPasswordEncoded, | |
"Signature" => $signature, | |
"Datetime" => $dateTime, | |
); | |
# Invoke webservice method with parameters, Function Name: ValidateMerchant | |
$response = $client->__soapCall("EBankLists", array($params)); | |
$banks = json_decode(json_encode($response->EBankListsResult), True); | |
if(array_key_exists('STATUS_CODE', $banks['EBankList'])){ | |
return null; | |
} | |
$this->get('logger')->error(json_encode($response->EBankListsResult)); | |
return $banks['EBankList']; | |
} | |
} |
<h1>Redirecting…</h1> | |
<div style="display: none;"> | |
<form action="{{ npay_payment_url }}" method="post" target="_parent" name="npay"> | |
<input type="hidden" value="{{ processID }}" name="ProcessID"> | |
<input type="hidden" value="{{ MerchantID }}" name="MerchantID"> | |
<input type="hidden" value="{{ MerchantTxnID }}" name="MerchantTxnID"> | |
<input type="hidden" value="{{ PayAmount }}" name="PayAmount"> | |
<input type="hidden" value="{{ MerchantUsername }}" name="MerchantUsername"> | |
<input type="hidden" value="{{ description }}" name="Description"> | |
<input value="Continue to Payment" type="submit"> | |
</form> | |
</div> | |
<script> | |
window.onload = function () { | |
document.forms['npay'].submit() | |
} | |
</script> |
Setting server for first time to deploy PHP application to cloud
Apache
- sudo apt-get update
- sudo apt-get install apache2
Click Here for more details.
MySql
- sudo apt-get update
- sudo apt-get install mysql-server
- mysql_secure_installation
Click Here for more details.
Composer
- sudo apt-get update
- sudo apt-get install composer
Click Here for more details.
PHP
- sudo add-apt-repository ppa:ondrej/php
- sudo apt-get update
- sudo apt-get install php7.1 php7.1-common
- sudo apt-get install php7.1-curl php7.1-xml php7.1-zip php7.1-gd php7.1-mysql php7.1-mbstring
Click Here for more details.
Upgrade from PHP 7.0 to PHP 7.1
Add Ondrejs PPA Repo
PPA’s or Personal Package Archive, is a collection of software not included in Ubuntu by default. Typically these repositories focus on a single program, but they can include more depending on the person maintaining them. Ondřej Surý has created this PPA which has the latest versions of PHP in it. Lets add it to your system, and update to get a list of all the software we can install.
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
Install PHP 7.1
Lets stop our server first, then install PHP 7.1.
$ service apache2 stop
$ sudo apt-get install php7.1 php7.1-common
We’ll also install some extra packages for our PHP installation – these are needed for Laravel and Composer!
$ sudo apt-get install php7.1-curl php7.1-xml php7.1-zip php7.1-gd php7.1-mysql php7.1-mbstring php7.1-mysql
Once that is done, lets check PHP is updated on the CLI
$ php -v
If the first row looks like this, we’ve done good so far! PHP 7.1.11-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Oct 27 2017 13:49:56) ( NTS )
Remove PHP 7.0
Now we have PHP7.1, lets get rid of PHP7.0
$ sudo apt-get purge php7.0 php7.0-common
Once this has been done, I usually restart the server.
$ sudo shutdown -r now
Make PHP7.1 used by Apache
Finally, we need to tell Apache to use PHP7.1 now PHP 7.0 is not being used. Lets enable the PHP mod!
$ a2enmod php7.1
$ service apache2 restart
Thats it – PHP should now be using PHP 7.1 – enjoy your amazing new features such as function return types and multiple error catch’s! If you are having issues, feel free to prod me on Twitter at @bhaktaraz
Bhamkeni Dham, Bhimdatta Nagar, Kanchanpur, Nepal
My last visit to vamkeni dham a historic hindu place.
Detect OnePlus5 in Ubuntu in MTP mode
So if you have connected OnePlus 5 to Ubuntu, you will notice that you can only see “OnePlus Drivers” as mounted but you cannot access the internal memory using MTP, although ptp works!
So here is what you need to do to make it possible
1. Enable Developer options in Settings
2. Enable ADB ( this needs to be enabled else, mtp doesnt work )
3. Open a terminal window and follow this :
– we will edit 2 files and add some lines in them. My preferred editor is vim. you may use nano / emacs etc.
COMMAND :
sudo vim /lib/udev/rules.d/69-mtp.rules
ADD LINE :
ATTR{idVendor}==”2a70″, ATTR{idProduct}==”9011″, SYMLINK+=”libmtp-%k”, ENV{ID_MTP_DEVICE}=”1″, ENV{ID_MEDIA_PLAYER}=”1″
save and exit
COMMAND :
sudo vim /etc/udev/rules.d/51-android.rules
ADD LINE :
ATTR{idVendor}==”2a70″, ATTR{idProduct}==”9011″, MODE=”0666″
save and exit
COMMAND :
sudo service udev restart
Now disconnect and reconnect your phone, you will have “Android Device” as the mtp device.
If you still cannot see, reboot and try to see if the device is now visible!
Thankyou!