Category Archives: Miscellaneous

Firebase Web Push Browser Issue

As of today, 2nd of July 2021. FCM libraries have some bugs due to which it fails to get tokens sometimes in Chrome browsers current version.

Errors that occurs :

  1. Uncaught (in promise) FirebaseError: Messaging: A problem occured while subscribing the user to FCM: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. (messaging/token-subscribe-failed)
  2. “Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

How to integrate Firebase Push Notifications for Websites: https://www.kolkataonweb.com/code-bank/miscellaneous/website-push-notification-with-google-firebase/

 

Paypal REST API get token

Request URL
https://api-m.paypal.com/v1/oauth2/token

Method
Post

Headers
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  // xxxxxxxxxxxxxxxx  is base64 encoded Client ID:Secret  // base64_encode(client_id_string:client_secret_string) – note the colon in between

Body
grant_type:client_credentials

Return

{

"scope": "https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/payment/authcapture openid https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/applications/webhooks",
"access_token": "AYYYYYYYYYYWmTopNAjV__Yuk_6AP9RZWQpzxxxxxxxxxxxxxx1ifvHLHrE6RW_Zqjbieo3jcZr9999999999999999lyDA",
"token_type": "Bearer",
"app_id": "APP-XYXYXYXYXYXYCCCC",
"expires_in": 32400,
"nonce": "2021-06-18T16:42:YUKJUKJHTGTYJKHGRRFHFHFGFGBFBG-spy-N9iguUHTJbTgVjht"

}

Solar panel online calculators

Free Solar Panel Calculator and Solar Power Calculator

Solar Panel Output Calculator- Estimate the Real Energy You Can Get From Your Solar Panels

 

https://www.renogy.com/calculators#tab_solar-size

 

Kolkataonweb.com doesn’t have any affiliation to the above websites. Neither Kolkataonweb.com warranties or guarantees any calculations.  You may use them as a guide to calculate solar panel and battery sizes and wattages.

Cross Origin or CORS Issue

We often get the CORS error when we try to run some code from localhost or XAMPP. The following steps will help to solve it. Please note you will need access to server side code or server configurations. 

  1. Set Access-Control-Allow-Origin to “*” in the code
  2. Set Header set Access-Control-Allow-Headers to “*” in the code 
  3. If the above didn’t work then add the same to .htaccess
  4. If still not solved then set the same in Apache / HTTPD configuration

In my case setting it in the code didn’t work. So it set it in the .htaccess but it also didn’t work. I was getting the error “Reason: header ‘access-control-allow-headers’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response“. The point to note is CORS Preflight. Which indicated that the error happened before the request reached the code. So I thought to set it in Apache config and it worked.

In my case the server had ISPConfig, so I set it through ISPConfig instead of changing the actual Apache configuration file.
The configuration needs to be put under “Sites” -> “<Site Name>” ->  “Options” -> “Apache Directives”.
The exact lines to be put
Header set Access-Control-Allow-Origin “*”
Header set Access-Control-Allow-Headers “*”

 

Apple In-app Purchase and App Rejections

Developers and app owners often have doesn’t have clear view on where in-app purchase is must and when other payment gateways are allowed in their iOS App. Confusions often lead to app rejection.

Apple has clear guidelines (read rules) on when in-app purchase is must and when other payment gateways are allowed.

Here I am putting which kind of payments can be taken through third party gateways. It is an exact excerpt from the full Apple guidelines

3.1.3 Other Purchase Methods: The following apps may use purchase methods other than in-app purchase. Apps in this section cannot, either within the app or through communications sent to points of contact obtained from account registration within the app (like email or text), encourage users to use a purchasing method other than in-app purchase.

3.1.3(a) “Reader” Apps: Apps may allow a user to access previously purchased content or content subscriptions (specifically: magazines, newspapers, books, audio, music, and video). Reader apps may offer account creation for free tiers, and account management functionality for existing customers.

3.1.3(b) Multiplatform Services: Apps that operate across multiple platforms may allow users to access content, subscriptions, or features they have acquired in your app on other platforms or your web site, including consumable items in multi-platform games, provided those items are also available as in-app purchases within the app.

3.1.3(c) Enterprise Services: If your app is only sold directly by you to organizations or groups for their employees or students (for example professional databases and classroom management tools), you may allow enterprise users to access previously-purchased content or subscriptions. Consumer, single user, or family sales must use in-app purchase.

3.1.3(d) Person-to-Person Services: If your app enables the purchase of realtime person-to-person services between two individuals (for example tutoring students, medical consultations, real estate tours, or fitness training), you may use purchase methods other than in-app purchase to collect those payments. One-to-few and one-to-many realtime services must use in-app purchase.

3.1.3(e) Goods and Services Outside of the App: If your app enables people to purchase physical goods or services that will be consumed outside of the app, you must use purchase methods other than in-app purchase to collect those payments, such as Apple Pay or traditional credit card entry.

3.1.3(f) Free Stand-alone Apps: Free apps acting as a stand-alone companion to a paid web based tool (eg. VOIP, Cloud Storage, Email Services, Web Hosting) do not need to use in-app purchase, provided there is no purchasing inside the app, or calls to action for purchase outside of the app.

Except the above mentioned cases all other payments will have to be in-app purchases.

A few more things on in-app purchases

  1. The purchase screen, must have the Item Name, Description, Benefits and Price clearly mentioned.
  2. In case of subscriptions the time duration must be clearly mentioned.
  3. The Item Name and Price must match with that defined in the app store.
  4. On the screen where the Payment button is there, or before the user can initiate the payment process, he/she should be shown a few texts. Below are some guidelines only, it should be properly phrased
    1. Payment will be charged to iTunes account
    2. The purchase will renew or not
      Example text for auto renewal subscriptions – Subscription will automatically renew for the same time length for the same price until it is cancelled in iTunes store at least 24 hours prior to the end of the current period.

      Example text for Consumables – This is a consumable product and doesn’t require any renewal.
    3. When the account will be charged
      Account will be charged for renewal of Subscriptions within 24 hours prior to the end of the current period with the same price 
      – this is required in case of auto renewing subscriptions.
      This consumable doesn’t have any validity period or expiry date — For Consumables.
    4. Links to app’s Privacy Policy and Terms & Conditions.

Submit the in-app items while submitting the app for review.

Here is the full guidelines of Apple – https://developer.apple.com/app-store/review/guidelines/#in-app-purchase . Somehow this link is not returned in searches easily.

The above thing can be done for the Android version also.

FFMPEG Rotating Video – Transpose vs Rotate

FFMpeg can be used to rotate a video or change the video orientation. There are two ways to do that – Transpose and Rotate.

But there is a difference – with Transpose the whole video gets rotated (as is expected to happen) but with Rotate the video gets cropped to fit the existing height of the video and on the sides black border will appear.

ffmpeg -y -i INPUT.mp4 -c:v libx264 -crf 23 -acodec copy -vf "transpose=1" -metadata:s:v rotate=0 -movflags +faststart OUTPUT.mp4

transpose=1 will rotate the video clock-wise by 90 degrees.
ffmpeg -y -i INPUT.mp4 -c:v libx264 -crf 23 -acodec copy -vf "rotate=PI/2" -metadata:s:v rotate=0 -movflags +faststart OUTPUT.mp4

rotate=PI/2 will also rotate the video clock-wise by 90 degrees but the resultant video will get cropped.

Media Streaming (MP4 file streaming) with Apache2

#wget http://h264.code-shop.com/download/apache_mod_h264_streaming-2.2.7.tar.gz

#tar -zxvf apache_mod_h264_streaming-2.2.7.tar.gz

#cd /apache_mod_h264_streaming-2.2.7

#./configure –with-apxs=`which apxs2`

#make

#make install

#LoadModule h264_streaming_module /usr/lib/apache2/modules/mod_h264_streaming.so

#AddHandler h264-streaming.extensions .mp4

#service apache2 restart

The file is attached below in case the main link goes down. The link to the original download location :  http://h264.code-shop.com/download/

Working on Apache/2.4.41 (Ubuntu) on day of writing.

 

apache mod h264 streaming v2.2.7

Google FCM all Push Notification parameters

All Firebase Push Notification parameters are available from the Google API test console. The direct link to the Send method test console – https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send

From the above URL other details can be navigated to.

To open the console click on the “Try it!” blue button on right.

Now clicking the blue dots in the basic JSON  will show the relevant params of that section.

 

Outgoing email problem with Roundcube, ISPConfig 3.2 and Ubuntu 20.04 on AWS

I had setup an ISPConfig system with Roundcube on Ubuntu 20.04 hosted with AWS EC2.

The setup was all fine, logged in into Roundcube and tried to send a mail. There was the problem – Roundcube says Error 250: Authentication failed.

It seems others also faced the same issue and different solutions worked for different people. I tested the most popular solutions and below are the results

  1. Changing $config[‘smtp_port’] = 587;  to   $config[‘smtp_port’] = 25; in /etc/roundcube/config.inc.php worked instantly but didn’t want to send things over plain text port
  2. Most popular solution was to remove the values of the below settings in /etc/roundcube/config.inc.php:
    $config[‘smtp_user’] = ‘%u’;
    $config[‘smtp_pass’] = ‘%p’;
    The suggested solution is to remove the %u and %p. Though it worked for many but not for me.
  3. Tried setting the $config[‘smtp_server’] = ‘localhost’;  to  $config[‘smtp_server’] = ‘tls://localhost’;
    $config[‘default_host’] = ‘localhost’;  to  $config[‘default_host’] = ‘tls://localhost’;

    But didn’t work
    With these changes was unable to login to Roundcube.
  4. Tried using $config[‘smtp_auth_type’] = ‘PLAIN’;  Didn’t work.
  5. There were also other suggestions to tweak smtpd_use_tls, smtpd_sasl_auth_enable,  smtpd_tls_auth_only etc. But none of these worked either.
  6. The configuration that worked was 
    
    $config['default_host'] = 'localhost';
    $config['smtp_server'] = 'tls://localhost';
    $config['smtp_port'] = 587;
    $config['smtp_user'] = '%u';
    $config['smtp_pass'] = '%p';
    ....
    ....
    $config['imap_conn_options'] = array(
       'ssl' => array(
          'verify_peer' => false,
          'verfify_peer_name' => false,
        ),
    );
    
    $config['smtp_conn_options'] = array(
       'ssl' => array(
           'verify_peer' => false,
           'verify_peer_name' => false,
        ),
    );

    Which indicates it was a SSL issue. But changing the default SSL set by Postfix is a lot work, someday will delve into it.

There was another issue due to which mails were not going out sometimes. The error was “Our
system has detected that 550-5.7.1 this message does not meet IPv6 sending
guidelines regarding PTR 550-5.7.1 records and authentication. Please
review 550-5.7.1

Needed to set
inet_protocols = all  to  inet_protocols = ipv4 in /etc/postfix/main.cf  to force Postfix to use IPv4 only