Setup User and RBAC Management in Yii2

My goal for this exercise is to have User and RBAC management in my Yii 2 application. I’ve started out with the Yii 2 Basic Project Template and I would be adding the Yii2-user and Yii2-rbac extensions to my web application. Here are some of the steps I have taken to install and configure the extensions. Step 1: Installation Install the packages. composer require dektrium/yii2-user composer require dektrium/yii2-rbac Step 2: Configure the web application NOTE: Make sure that you don’t have user component configuration in your config files. Add the user and rbac module to the web applcation config. ...

August 26, 2019

Send Telegram Message in Group using VB Script

Here’s a vb script snippet that I have used to send Telegram message in a group from an Excel sheet. Sub sendTelegramMessage() Set objHttp = CreateObject("MSXML2.ServerXMLHTTP") ' Change these accordingly strChat = "<chat_id>" strText = "*Test*\r\nThis is a message" strUrl = "https://api.telegram.org/bot<token>/sendMessage" ' Leave these alone strMode = "markdown" strJson = "{""chat_id"": """ & strChat & """, ""text"": """ & strText & """, ""parse_mode"": """ & strMode & """}" objHttp.Open "POST", strUrl, False objHttp.setRequestHeader "Content-type", "application/json" objHttp.send strJson End Sub

August 17, 2018

WAMP and curl

Often times, after a fresh install of WAMP server, curl stops working. You might get a hint of the issue in logs/php_error.log If not, it could be that the SSL/TLS Certificate Authority (CA) certificates has not bee setup properly. Download cacert.pem Move the cacert.pem file to a folder, e.g. C:\code\ssl\cacert.pem Edit the php.ini file and change the curl.cainfo parameter, e.g. curl.cainfo = “C:\code\ssl\cacert.pem”

February 9, 2018

Add and Allow New Telegram Bot to Send Message in Group

Talk to @BotFather, and request to create a new bot. (hint: /help) Give the new bot a name, and a unique username. Take note of the bot token given by the @BotFather Add the new bot to a group. Run this - https://api.telegram.org/bot<bot_token>/getUpdates , to get the group’s chat id that contains the new bot. In the group, type /start @username to activate the new bot.

February 5, 2018

Nginx Configuration for Multiple Yii2 Site Under Same Domain

This nginx configuration will allow you to run multiple instances of Yii2 in sub folders under the same domain. Eg. http://advanced.local/ and http://advanced.local/subfolder/ server { listen 80; # listen for IPv4 server_name advanced.local; set $root_path /var/www/main/web; root $root_path; index index.html index.php; charset utf-8; client_max_body_size 100M; location / { root $root_path; try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /$uri =404; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ^~ /subfolder { alias /var/www/subfolder/web; if (!-e $request_filename) { rewrite ^ /subfolder/index.php last; } location ~ \.php$ { if (!-f $request_filename) { return 404; } include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; } } location ~* \.(htaccess|htpasswd|svn|git) { deny all; } }

December 27, 2017

Magento 2 Upgrade Ritual

Assuming that you are on Magento version 2.0.6 and would like to upgrade to 2.0.7 composer require magento/product-community-edition 2.0.7 --no-update composer update rm -rf var/di var/generation/* var/view_preprocessed/* var/cache/* var/page_cache php bin/magento cache:clean php bin/magento cache:flush php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento indexer:reindex

February 28, 2017

Amazon Cloudwatch alarm to Jaconda - a Telegram Smartbot

We have setup Amazon Cloudwatch alarms to keep track of various metrics. In a situation where a particular alarm is triggered, a notification is sent to a Amazon Notification Topic. Within that Amazon Notification Topic, one of the subcription uses the lambda protocol. It is through this subscription which we would get Amazon Lambda to send a message to Jaconda - a Telegram Smartbot. Here’s a sample Node.js script that we have used. ...

February 15, 2017

RabbitMQ can not login with guest/guest

After a fresh install of RabbitMQ, I have encountered a Login Failed error when trying to access the RabbitMQ Management console at http://localhost:15672 Here’s one possible solution to overcome this issue. Create a file /etc/rabbitmq/rabbitmq.config, and add the below content into that file. [{rabbit, [{loopback_users, []}]}]. Restart the service to apply the changes.

December 20, 2016

S3cmd on CentOS 6

S3cmd is a command line tool that we’ve used for uploading, retrieving and managing data in Amazon S3. To install S3cmd, you would need to download the .repo for the tool, and then, run install. cd /etc/yum.repos.d wget http://s3tools.org/repo/RHEL_6/s3tools.repo yum install s3cmd Answer yes when asked to accept a new GPG key. Note: The latest version of s3cmd requires python 2.6. If you come across this error Problem: ImportError: No module named S3.Exceptions, chances are, you do not have the correct version. One work around is as follows:- ...

March 30, 2016

Various Backup Scripts

Here are some sample backup scripts that I’ve used to back up various things in our network. These scripts uses Amazon S3 as the storage, and also s3cmd. Application #!/bin/sh # Site Backup script # # application_backup.sh # Initialize variables specific for this server # To exclude directory, update in code under Exclude directory LOG_FILE="/var/log/site-backup.log" SITE_PATH="/var/www/" SITE_BACKUP_PATH="/var/script/backup" SITE=( name_of_directory_one name_of_directory_two ) # Definition TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"` CURRENT_YEAR=`date "+%Y"` CURRENT_MONTH=`date "+%Y-%m"` TODAY_DATE=`date "+%Y-%m-%d"` S3_PATH=s3://name-of-s3-bucket/application/${CURRENT_YEAR}/${CURRENT_MONTH} # Remove Site Backup older than 15 days /usr/bin/find ${SITE_BACKUP_PATH} -type f -mtime +15 -delete echo "Site Backup Log: " ${TIMESTAMP} >> ${LOG_FILE} echo -e "--------------------------------------------" >> ${LOG_FILE} echo -e "" >> ${LOG_FILE} # Loop through the Site Repository for i in ${SITE[@]} do # Exclude directory EXCLUDE='' case $i in account.fxprimus.com) exclude="--exclude api --exclude assets \ --exclude nfiles --exclude nimages \ --exclude nlanguages --exclude ntemplates";; esac # Backup Site cd ${SITE_PATH} tar -zcf ${SITE_BACKUP_PATH}/$i-${TODAY_DATE}.tar.gz . ${EXCLUDE} # Transfer the file to Amazon S3 s3cmd put --acl-private --guess-mime-type \ ${SITE_BACKUP_PATH}/$i-${TODAY_DATE}.tar.gz \ ${S3_PATH}/$i-${TODAY_DATE}.tar.gz >> ${LOG_FILE} 2>&1 if [ "$?" -eq 1 ] then echo -e "***SITE BACKUP JOB, THERE WERE ERRORS***" >> ${LOG_FILE} 2>&1 else echo -e "Script Completed Successfully!" >> ${LOG_FILE} 2>&1 fi done MySQL #!/bin/sh # MySQL Backup script # # db_backup.sh # In summary, this is what is going to happen. # make directory # change directory # dump file # compress directory # remove directory # upload compressed file # Initialize variables specific for this server MYSQL_SOURCE_HOST=192.168.3.100 MYSQL_DATABASE=this_is_my_database MYSQL_SOURCE_USER=i_am_db_user MYSQL_SOURCE_PASS=i_am_db_password SRC_CONN="-h${MYSQL_SOURCE_HOST} -u${MYSQL_SOURCE_USER} -p${MYSQL_SOURCE_PASS}" MYSQL_TABLE=( tbl_one tbl_two ) LOG_FILE=/var/log/mysql-backup.log MYSQL_BACKUP_PATH=/var/script/backup # Definition TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"` CURRENT_YEAR=`date "+%Y"` CURRENT_MONTH=`date "+%Y-%m"` TODAY_DATE=`date "+%Y-%m-%d"` EPOCH=`date +%s` S3_PATH=s3://name-of-s3-bucket/db/${CURRENT_YEAR}/${CURRENT_MONTH}/${TODAY_DATE} # Remove MySQL Backup older than 3 days /usr/bin/find ${MYSQL_BACKUP_PATH} -type f -mtime +3 -delete echo "MySQL Backup Log: " ${TIMESTAMP} >> ${LOG_FILE} echo -e "--------------------------------------------" >> ${LOG_FILE} echo -e "" >> ${LOG_FILE} MYSQLDUMP_OPTIONS="--hex-blob --compress --lock-tables=false" # Loop through the tables for TBL in "${MYSQL_TABLE[@]}" do FILENAME=${TBL}-${TODAY_DATE}-${EPOCH} # Backup MySQL mysqldump ${SRC_CONN} ${MYSQLDUMP_OPTIONS} ${MYSQL_DATABASE} ${TBL} \ > ${MYSQL_BACKUP_PATH}/${FILENAME}.sql # Compress today's directory tar -zcf ${MYSQL_BACKUP_PATH}/${FILENAME}.tar.gz -C ${MYSQL_BACKUP_PATH} ${FILENAME}.sql # Transfer the file to Amazon S3 s3cmd put --acl-private --guess-mime-type \ ${MYSQL_BACKUP_PATH}/${FILENAME}.tar.gz \ ${S3_PATH}/${FILENAME}.tar.gz >> ${LOG_FILE} 2>&1 done if [ "$?" -eq 1 ] then echo -e "***MySQL BACKUP JOB, THERE WERE ERRORS***" >> ${LOG_FILE} 2>&1 else echo -e "Script Completed Successfully!" >> ${LOG_FILE} 2>&1 fi SVN Repository #!/bin/sh # SVN Off Site Backup script # # svn_backup.sh # Input from command line SVN_REPOSITORY=($1) # Definition TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"` CURRENT_YEAR=`date "+%Y"` CURRENT_MONTH=`date "+%Y-%m"` TODAY_DATE=`date "+%Y-%m-%d"` EPOCH=`date +%s` LOG_FILE=/var/log/svn-backup.log SVN_BACKUP_PATH=/var/script/backup SVN_PATH=/var/svn/repos S3_PATH=s3://name-of-s3-bucket/svn/${CURRENT_YEAR}/${CURRENT_MONTH} # Remove SVN Backup older than 7 days /usr/bin/find ${SVN_BACKUP_PATH} -type f -mtime +7 -delete echo "SVN Offsite Backup Log: " ${TIMESTAMP} >> ${LOG_FILE} echo -e "--------------------------------------------" >> ${LOG_FILE} echo -e "" >> ${LOG_FILE} # Loop through the SVN Repository for i in ${SVN_REPOSITORY[@]} do FILENAME=$i-${TODAY_DATE}-${EPOCH} # Backup SVN svnadmin dump ${SVN_PATH}/$i | gzip > ${SVN_BACKUP_PATH}/${FILENAME}.svndump.gz # Transfer the file to Amazon S3 s3cmd put --acl-private --guess-mime-type \ ${SVN_BACKUP_PATH}/${FILENAME}.svndump.gz \ ${S3_PATH}/${FILENAME}.svndump.gz >> ${LOG_FILE} 2>&1 if [ "$?" -eq 1 ] then echo -e "***SVN OFFSITE BACKUP JOB, THERE WERE ERRORS***" >> ${LOG_FILE} 2>&1 else echo -e "Script Completed Successfully!" >> ${LOG_FILE} 2>&1 fi done SVN Repository to Backup #!/bin/sh # SVN Repository to Backup # # call_backup.sh svn_repository=( my-project-number-one my-project-number-two my-project-number-three ) /var/script/svn_backup.sh "${svn_repository[*]}"

March 21, 2016