Posts

Showing posts from 2020

CakePHP 4: Firebase Cloud Messaging Component in CakePHP for Push Notification

Image
Easily deploy an SSD cloud server on @DigitalOcean in 55 seconds. Sign up using this link and receive $100 in cloud credits: https://m.do.co/t/335732d1df0b <?php namespace   App\Controller\Component ; use  Cake\Controller\ Component ; use  Cake\Http\ Client ; class   FirebaseComponent   extends   Component {         public   function   headers () {         $header  =    [ 'headers'   =>    [                                          'Accept'   =>   'application/json' ,                                          'Content-Type'   =>   'application/json' ,                                          'Authorization'   =>   'key=AAAAeh0kVhs4ums9A0SYyO2xbCgXvT_jfUUi-0jXs0GfMpZ5DZPqKylqht-TPXGPiqFVj81hBPLL_st9NkjspAarhbfufFHBQN_7'                                     ]                     ];          return  $header;     }      public   function   sendSingleNotification ()  //FCM     {         $fcToken  =   'e_tHOI1XT3udZvMYS

CakePHP 4 : Using Component inside Command ( Shell )

Image
Easily deploy an SSD cloud server on @DigitalOcean in 55 seconds. Sign up using this link and receive $100 in cloud credits: https://m.do.co/t/335732d1df0b src>Command>AppCommand.php <?php namespace   App\Command ; use  Cake\Console\ Arguments ; use  Cake\Console\ Command ; use  Cake\Console\ ConsoleIo ; use  Cake\Console\ ConsoleOptionParser ; use  Cake\Http\ Client ; use  Cake\Log\ Log ; //need this two line use  Cake\Controller\ ComponentRegistry ; use  App\Controller\Component\ FirebaseComponent ; class   AppCommand   extends   Command {      protected   function   buildOptionParser ( ConsoleOptionParser  $parser) :   ConsoleOptionParser     {         $parser -> addArgument ( 'command' , [ 'help'   =>   'What your parameter?' ]);         $parser -> addArgument ( 'params' , [ 'help'   =>   'What your parameter?' ]);          return  $parser;     }      public   function   execute ( Arguments  $args,  ConsoleIo  $io

LIMIT SSH ACCESS BY COUNTRY

Image
This is useful when being attack of constant login brute-force attempts mainly from countries like China and Russia. Install GeoLite2 Country Database      $ sudo apt-get install geoip-bin Make sure that geoiplookup is working before implementing the script below.      $ geoiplookup 8.8.8.8 Create bash script that will filter ssh access by country.      $ sudo nano /usr/local/bin/sshfilter.sh      #!/bin/bash     # UPPERCASE space-separated country codes to ACCEPT     ALLOW_COUNTRIES="PH"     if [ $# -ne 1 ]; then       echo "Usage:  `basename $0` <ip>" 1>&2       exit 0 # return true in case of config issue     fi     COUNTRY=`geoiplookup $1 | awk -F ": " '{ print $2 }' | awk -F "," '{ print $1 }' | head -n 1`     [[ $COUNTRY = "IP Address not found" || $ALLOW_COUNTRIES =~ $COUNTRY ]] && RESPONSE="ALLOW" || RESPONSE="DENY"     if [ $RESPONSE = "ALLOW" ]     then       e

CakePHP 3/4 File Manager for CKEditor with Roxy Fileman

Image
Create plugins directory in your webroot directory. Download  CKEditor 4 Extract CKEditor inside webroot/plugins directory. Download latest Roxy Fileman  Extract Roxy Fileman inside webroot/plugins  directory. Create uploaded directory inside webroot directory. This is the folder which can be browsed and where the new files will be uploaded. Edit Roxy Fileman conf.json to finish your setup. Below configuration is based the directories we created. Set configuration option INTEGRATION to "ckeditor".  See the  Roxy Fileman configuration options  for details In your view/template add an element that CKEditor should replace:      Load CKEditor. Set these options when initializing CKEditor. All must point to index.html in the Fileman's installation directory. If you encounter this issue E_LoadingAjax /plugins/fileman/php/dirtree.php Comment verifyAction content in your functions.inc.php