Friday, April 20, 2018

mod_qos(004): failed to create mutex (ACT)(/var/tmp/K564968484.mod_qos): No space left on device

Solution :
Apache cannot be started because of this error, it means you have installed and enabled qos module in apache to avoid ddos attack. Now apache is crashed automatically and you are not able to start it.

Disable qos module

sudo a2dismod qos
Restart apache2

Error : django.db.utils.ProgrammingError: permission denied for relation django_migrations

While running django migrations for postgresql if you get above error, there may be chances that postgresql user which is used in connection file does not have sufficient permissions to run the migrations command. You need to provide privileges to postgresql user using super user.
1. Log into the database which is going to be migrated using super user
\c database name

2. Run following queries
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public to username;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public to username;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public to username;

Change text username with postgresql user which is used in server side postgresql connection file.

Note :
Generally you get this error while running python manage.py migrate 
and above solution works well for this error.

Apache - Block IP or an IP Range to prevent opening your site


If you want to block IPs from accessing your site, you can simply achieve it using an htaccess file. Add following line in .htaccess and IP owner will not be able to open your site anymore.


Suppose you want that your site should not be opened from IP 46.161.9.67, you need to add a line your .htaccess file.
Deny from 46.161.9.67
If there are multiple IPs and you want to block them all. Add following line in .htaccess.
Deny from 46.161.9.67 46.161.10.187 46.161.58.89
Block a whole IP Range
Here is the tricky part, If you want to block a whole IP Range like 69.0.0.0 to 69.0.0.255. Use following code in your .htaccess 

Deny from 69.208.0.0/24
If it is from 69.0.0.0 to 69.0.255.255
Deny from 69.208.0.0/16
And If it is from 69.0.0.0 to 69.255.255.255
Deny from 69.208.0.0/8

Refer Link for more wide Range :
https://www.mediawiki.org/wiki/Help:Range_blocks

Sort all files of present working directory and sub directories by modified date and time

If you want to sort all files of a folder and its subfolders by modified date and time, Here is the command.
find . -type f -printf "%T@ %Tc %p\n" | sort -n
Latest modified file will be last in the sequence.

If you want to reverse the sequence i.e. latest modified should be on top.
find . -type f -printf "%T@ %Tc %p\n" | sort -nr

Dot (.) indicates the present working directory. You can use absolute path also.

Laravel Error - No supported encrypter found. The cipher and / or key length are invalid.

While running  composer install or php artisan optimize, If you get this error, here is the solution.

Solution :

Change values in config/app.php

'cipher' => 'AES-256-CBC',
to
'cipher' => MCRYPT_RIJNDAEL_128,

Now run again composer install or php artisan optimize , you will not get the same error again.

Tuesday, March 6, 2018

AWS RDS - Create mysql user with superuser Privileges

Login as super user on command prompt.

Run following query to create user.
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
Just change username and password in above query and execute as root user. A new user will be created.

Now give super user privileges to new user.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'username'@'%' WITH GRANT OPTION;
Just change username in above query. Your new created user will be a super user now.

AWS RDS - Give Superuser Privileges to Regular mysql User

Login as super user on command prompt.

Run following query to give superuser privileges to normal user.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'username'@'%' WITH GRANT OPTION;
Just change username in above query and execute as root user. Your regular user will be a super user now.

Wordpress Permissions - Upload plugin using wp-admin

Upload plugin using wp-admin without ftp.

If you are not able to install plugin using wp-admin because of forbidden error or a permission issue, you simply change the permission of whole wordpress directory to fix it. That is very dangerous and a common security loophole.

Here is the minimum permission for your plugin directory which is enough to instal plugin using wp-admin.

Give 777 to wp-content/plugins and wp-content/upgrade Non-Recursively. It will allow admin to install plugin using wp-admin.


postgresql error : ERROR: database is being accessed by other users

ERROR:  database "X" is being accessed by other users
DETAIL:  There is 1 other session using the database


Solution :
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'database-name';
You need to replace only database name in above query.

Now you can drop the database or perform other activity what you were trying to perform.

composer update - exceeded the timeout of 300 seconds

Failed to download from source: The process  exceeded the timeout of 300 seconds.

Solution :
Increase the timeout limit globally for composer
composer --global config process-timeout 6000
Now run
composer update
You should not get timeout issue.

gitlab forbidden issue

This feature has been added by default in recent update of gitlab.
When there are number of failed login attempts while cloning or pushing files into gitlab repository, gitlab blocks UI as well as pull and push for the IP. Technically, it bans the IP.

Solution :
Disable this feature.

sudo nano /etc/gitlab/gitlab.rb
Uncomment these lines.
gitlab_rails['rack_attack_git_basic_auth'] = {
'enabled' => false,
}
Reconfigure gitlab.
sudo gitlab-ctl reconfigure
Now it will not block that ip after number of failed login attempts.

ubuntu 16.04 - wkhtmltopdf error - QSslSocket: cannot resolve CRYPTO_num_locks

wkhtmltopdf error on ubuntu 16.04 :
Loading pages (1/6)
QSslSocket: cannot resolve CRYPTO_num_locks                  ] 10%
QSslSocket: cannot resolve CRYPTO_set_id_callback
QSslSocket: cannot resolve CRYPTO_set_locking_callback
QSslSocket: cannot resolve sk_free
QSslSocket: cannot resolve sk_num

Solution :

sudo apt-get install libssl-dev=1.0.2g-1ubuntu4.10 openssl=1.0.2g-1ubuntu4

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

Ruby Error while installing charlock_holmes 

Error :
Fetching charlock_holmes 0.7.5
Installing charlock_holmes 0.7.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.



Solution : 1

If you are using debian or ubuntu
sudo apt-get install libicu-dev

If you are using Centos or fedora
sudo yum install libicu-devel

Solution : 2
Try to install other version of charlock_holmes
gem pristine charlock_holmes --version 0.6.9.4
or
gem install charlock_holmes -v '0.6.9'

Friday, February 23, 2018

Skipping ssh-dss key id_dsa - not in PubkeyAcceptedKeyTypes

SSH keeps skipping my pubkey and asking for a password

You have correct ssh key but still it is asking password to login or if password authentication is prohibited, it stopped accepting correct keys.

If it was working before and suddenly it starts giving above error, it means you have upgraded your openssh. The new openssh version - 7.0+ does not support DSA keys anymore  (Neither on server nor on client). 

If openssh client has been upgraded and openssh server still supports DSA keys, make the changes in client side ssh config.

Solution  :
sudo nano /etc/ssh/ssh_config
Add following line in the file.
PubkeyAcceptedKeyTypes=+ssh-dss
Restart ssh.

If openssh server has been upgraded and openssh client still supports DSA keys, make the changes in server side sshd config.

Solution  :
sudo nano /etc/ssh/sshd_config
Add following line in the file.
PubkeyAcceptedKeyTypes=+ssh-dss
Restart ssh.

Note :  The best solution, you must use RSA keys. It has strong and secure algorithm and it is better than the patch you are finding.

Saturday, February 10, 2018

openedx installation on Linux | openedx installation on Ubuntu


Easy way :
1. Download the installer (.run file)
https://bitnami.com/stack/edx/installer
2. Make it executable.
chmod a+x filename.run
3. Run the installer.
./filename.run

Hard way:
Install using bash script. Why it is hard because it is gonna give many errors, you need to fix them one by one and start installing again and again until it is installed completely.
wget https://raw.githubusercontent.com/edx/configuration/$OPENEDX_RELEASE/util/install/sandbox.sh -O - | bash

You choose the version of Open edX by setting the OPENEDX_RELEASE variable before running the commands. See Open edX Releases for the tags you can use.
https://openedx.atlassian.net/wiki/spaces/DOC/pages/11108700/Open+edX+Releases
Release names like open-release/ginkgo.2, open-release/eucalyptus.3, open-release/ficus.4 etc

Example:
wget https://raw.githubusercontent.com/edx/configuration/open-release/ginkgo.2/util/install/sandbox.sh -O - | bash

Helpful url :
https://openedx.atlassian.net/wiki/spaces/OpenOPS/pages/146440579/Native+Open+edX+Ubuntu+16.04+64+bit+Installation

Hardest way:
Install each package separately like these guides are suggesting. Similar guides you can find for centos and fedora.
https://www.iblstudios.com/step-step-guide-install-open-edx-platform-ficus-release/
I would suggest you to install on virtual machine like docker, vagrant or vmware instead of start installing on your system.

Friday, January 26, 2018

postgresql - Check ip of logged in user

To get Logged in user IP

Run Query :
postgres=> select inet_client_addr();

Tuesday, January 9, 2018

mysql - Check IP of logged in user


Run Query :

mysql> select user();



Mysql 5.7 - Update root password

mysql 5.7 does not have password field in user table of mysql database. They have come up with new idea i.e. authentication_string for security purpose.

Here is way to update mysql superuser password using command line.
UPDATE mysql.user SET authentication_string=PASSWORD('sToituY78hebrt'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';

where sToituY78hebrt is my root password

Friday, December 15, 2017

Invalid command '\xef\xbb\xbf#', perhaps misspelled or defined by a module not included in the server configuration


\xef\xbb\xbf are three invisible junk characters (at least from Apache's perspective) called the Unicode BOM, or byte order mark. Apache thinks that those characters are part of the command that follows right after. This is what you see in the log, though the characters are escaped so they're visible to the naked eye. \xef\xbb\xbfRewriteEngine

Copy the content in any advanced notepad editor which will detect the characters and you can easily remove them.

If you are not able to see these characters, remove this file completely and write again.

cpanel - wordpress - internal server error because of invalid permissions

cpanel - wordpress application - fix wordpress permissions of complete directory

cpanel > wordpress tool kit > Manage your site (Click on manage button) > Fix Permissions

It will fix all permissions of wordpress directory.

s3cmd : Configure multiple s3 buckets of multiple aws accounts on same server


First configure s3 bucket of 'AWS account - A' with s3cmd
s3cmd --configure
Add Access key and Secret Key of your 'AWS account A'.

Now rename ~/.s3cfg to ~/.s3cfg-first
You can find .s3cfg file in your home directory of logged in user.

Now configure s3 bucket of 'AWS account - B'
s3cmd --configure
Add Access key and Secret Key of your 'AWS account B'.
Now rename ~/.s3cfg to ~/.s3cfg-second

 
Configure third and so on

If you do not define config file parameter in command, it takes default config file i.e. .s3cfg


You need to define config file with command and you can communicate with different s3 buckets of one AWS account or multiple AWS accounts.
s3cmd ls s3://bucketname -c ~/.s3cfg-first
Above command will list the content of the defined s3 bucket of AWS account - A.
s3cmd ls s3://bucketname -c ~/.s3cfg-second
Similarly it will list the content of the defined s3 bucket of AWS account - B.

Now you can copy content, delete content or move them with different s3cmd commands.

Note : Number of buckets you can access of AWS account A or AWS account B, it depends on the privileges provided to access key and secret key and privileges are defined by the policy attached to the user whose access key and secret key you are using. 

If a policy which has read, write and list access of only one bucket 'Bucket-A' of an AWS account and this is the only policy attached to a user whose access key and secret key you are using then you can access only Bucket-A of that AWS account by using the access key and secret key of the user.

Use Redirect and Proxypass under one virtualhost in apache


If you need to redirect your domain on another domain or you need to redirect http to https, you use Redirect Permanent in your virtualhost to achieve but if your application is running on different port (node, python, ruby etc) and you have resolved port using proxy pass then your redirect attribute might not be working.

To solve this issue, use redirect under proxy directive.

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

<Proxy *>
    Redirect permanent / https://domain.co.in
</Proxy>

</VirtualHost>

Now your port will be resolved with domain as well as you can redirect domain too.

/opt/lampp/bin/httpd: relocation error: .so: symbol SSL_library_init, version OPENSSL_1.0.0 not defined in file libssl.so.1.0.0 with link time reference

Xampp apache is not starting after adding stomp extension or mongo extension in php.ini file. After installation using pecl, you have added following line in php.ini file.
extension=mongo.so
extension=stomp.so

Now when you try to restart xampp, apache does not start. 

When you check the apache log, you see following error.

/opt/lampp/bin/httpd: relocation error: stomp.so: symbol SSL_library_init, version OPENSSL_1.0.0 not defined in file libssl.so.1.0.0 with link time reference

/opt/lampp/bin/httpd: relocation error: mongo.so: symbol SSL_library_init, version OPENSSL_1.0.0 not defined in file libssl.so.1.0.0 with link time reference

If you remove the extension line in php.ini, apache works fine but you need to use the extension so you can not remove it, here is the solution.

Solution :

Install stomp or mongo or other extension with disable ssl support


Choose no option while installing stomp/mongo/extension-name

OpenSSL install prefix (no to disable SSL support) [/usr] : no

Now when you add extension in php.ini, the apache works fine and you are able to use the installed extension.



XAMPP is currently only available as 32 bit application. Please use a 32 bit compatibility library for your system.

Solution - I
If you have latest 64 bit Linux Operating system like recent versions of Ubuntu / Debian / CentOS or Fedora and you want to use older version of php or mysql ( php 5.3 or php 5.4) then you should follow Solution - I.

Older libraries of xampp supports 32 bit operating system so your latest 64 bit operating system is not able to install older xampp.

To make it working install Ubuntu 12.04 LTS or Debian 7.0 in Vmware or Virtualbox
or 
Download ubuntu 12.04 docker image and install xampp inside it, it is faster solution and will not occupy too much RAM.

Solution - II
If your xampp was working fine and suddenly it has started giving this error then this solution is for you

Most common reason of this error, you have added an extension in xampp and after adding it in php.ini, the lampp is not getting started. You are getting following error :

XAMPP is currently only available as 32 bit application. Please use a 32 bit compatibility library for your system.

Here is the solution for you.

Comment following code in the file /opt/lampp/lampp

#case `uname -m` in
#    *_64)
#    if $XAMPP_ROOT/bin/php -v > /dev/null 2>&1
#    then
#        :
#    else
#        $GETTEXT -s "XAMPP is currently only availably as 32 bit application. Please use a 32 bit compatibility library for your system."
#        exit 1
#    fi
#    ;;
#esac


Now restart xampp and you should not get above error.

If still there is error and it was because of new installed extension, I would suggest to comment the extension .so line in php.ini and restart xampp.

You can see the solution in the following video.
 


Error : pecl/pecl_http requires PHP (version >= 7.0.0), installed version is 5

Not able to install STOMP extension in XAMPP

Solution :

Current stable version of stomp is 2.0 which supports php 7.0, 
if we run

pecl install stomp
or
/opt/lampp/bin/pecl install stomp

it installs stomp-2.0 by default which needs php 7.0 so we need to install stomp which supports php 5.x,


Run :
pecl install stomp-1.0.9
or
/opt/lampp/bin/pecl install stomp-1.0.9

Stomp 1.0.9 is for php 5.x versions.
Now you should not get php version error.

Tuesday, November 7, 2017

phpmyadmin exporting html in place of sql

Solution :

Add/Uncomment following attribute in php.ini

max_input_vars = 5000
Restart Apache.

FATAL: Peer authentication failed for user "postgres"

psql dump database from other user without loginto postgres user

$ whoami
ubuntu

$ pg_dump -U postgres dbname > db.sql
FATAL:  Peer authentication failed for user "postgres"


Solution :

sudo nano /etc/postgresql/9.4/main/pg_hba.conf

Change

local   all             postgres                                peer
to
local   all             postgres                                trust


Restart postgresql.

mysqli::mysqli(): Headers and client library minor version mismatch. Headers:50552 Library:100120


In centos or fedora, If you are facing above error.

Solution :


yum remove php56w-mysql

yum install php56w-mysqlnd

I used php56  in command as I installed php with php56 package because I wanted php 5.6 on my server. If you have installed php using simple php or php5 command, remove php-mysql or php5-mysql package and install php-mysqlnd or php5-mysqlnd.

Restart apache and verify the issue. It should be fixed.

Error: EACCES: permission denied, mkdir 'node_modules/node-sass'



Unable to save binary /usr/lib/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/node-sass/vendor'
    at Object.fs.mkdirSync (fs.js:891:18)
    at sync (/usr/lib/node_modules/node-sass/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/usr/lib/node_modules/node-sass/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/usr/lib/node_modules/node-sass/scripts/install.js:111:11)
    at Object.<anonymous> (/usr/lib/node_modules/node-sass/scripts/install.js:154:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)



You are trying these commands in project directory
sudo npm install node-sass
or
npm install node-sass
and it is giving above error and module is not getting installed.

Solution :

sudo chmod -R 777 projectfolder
Now it has sufficient permission to create files inside it. 
Do not use sudo with npm, it does not need root access to install package(module).
Now Run :
npm install node-sass
Now it will be installed. You can give correct permission to folder and files again, 777 is a security breach. We just made it for installing this module.

Magento Installation Error : set always_populate_raw_post_data to -1

Magento Installation Error :

PHP Settings Check * Need Help? PHP Documentation Your PHP Version is 5.6.30, but always_populate_raw_post_data = 0. $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0. This will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1. If you need more help please call your hosting provider.

Solution :
 Open .htaccess file of magento and add line php_value always_populate_raw_post_data -1 between tags <IfModule mod_php5.c> and </IfModule>

<IfModule mod_php5.c>    php_value always_populate_raw_post_data -1
</IfModule>


Now Try to install again. You should not get same error again.

Monday, October 2, 2017

Convert Text into Hexadecimal and Hexadecimal into Text on command line


Convert Text into Hexadecimal using command line :
printf "linux is awesome" | xxd

or

echo -n "linux is awesome" | od -A n -t x1


Convert Hexadecimal into Text using command line:
echo "6c 69 6e 75 78 20 69 73 20 61 77 65 73 6f 6d 65" | xxd -r -p && echo ""

Monday, September 4, 2017

No PostgreSQL clusters exist; see "man pg_createcluster"

Solution :

Run commands :
dpkg-reconfigure locales

pg_createcluster 9.3 main --start
or
pg_createcluster 9.4 main --start
or
pg_createcluster 9.5 main --start
(depends on your postgresql version.)

Ubuntu Apache php error : Class 'NumberFormatter' not found

Solution :

Install Package :
apt-get install php5-intl
or
apt-get install php-intl


Make sure intl.so file is generated and it is defined as an extension in .ini file.

Tuesday, August 15, 2017

Regression testing of Web Application using Automation

Human beings try to explore new things that's why they do not want to do same work again and again. It is in their jeans, deep inside. The similar work appears monotonous for them. 

Regression testing is something that no tester wants to do and when developer tries to fix a bug and breaks a functionality which was working absolutely fine before, this condition disturbs a tester psychologically. It increases irritation and makes a tester annoyed, impatient and angry.

But for automation, it is a different story. The tools do not feel bad if you assign them same task again and again. That's why a script is a best friend of a tester whose work is regression.

If you want to do automation testing, the first tool comes in mind is Selenium. Definitely it gives the result efficiently and it is quite flawless. Big companies are using it as their primary testing tool and testers who are seeking good career opportunities are trying to learn it as fast as possible but it is not the only tool which can give you automation results.

Today I am going to discuss two less used web application automation test tools.

First is CURL yes you heard right, I am not joking. If you enjoy working on terminal and you like scripting, curl is one of the best tool to achieve regression testing task. It is so efficient that hacker started using to manipulate data that's why many big sites have blocked it.

How to do regression testing using CURL
1. Create a curl command for login or registration what you want to test by passing valid data with valid method like POST or GET.
If your form uses cookies, you can save and reuse again in CURL.

Example :
curl -c cookie.txt -d "LoginName=someuser" -d "password=somepass" https://oursite/a 

curl -b cookie.txt https://oursite/myaccount


2. You can use this command in BASH script and after running the script new user will be registered or existing user will be logged in successfully.

3. You can achieve login protected task like edit profile, create category, edit tasks, schedule tasks using CURL. You need to make script for each task and while regression, you do not need to do it again and again manually

A failed script is enough to notify that functionality is broken. Not only it will be efficient but it will save your time too.

Second one is JMETER. You must be thinking that we are not talking about performance testing, first we should achieve a working functionality. You can use JMETER for functionality testing too. It has a UI interface so it is quite easier than CURL.

How to do regression testing using JMETER
1. Record a script of functionality like login or registration.
2. Save the test plan as .jmx file 
Now this is a script which you can use in regression testing.

Jmeter has cookie manager using it you can achieve cookie based login to test login protected functionlity. Using regular expression extractor, you can test CSRF based login functionality or pass dynamic values by storing them in variables. Using csv set config, you can run data driven tests as well as parametrization can be done. Not only REST API and LDAP tasks but you can perform all types of java based web application functionality testing tasks.

This is very little that I have listed advantages of JMETER, once you start using it, you will come to know that it is fine tool to perform regression testing. 

Tutorials to Learn Jmeter : 
https://www.youtube.com/watch?v=f6AvTKLrD8A
https://www.youtube.com/watch?v=KgKtM48ujxQ
https://www.youtube.com/watch?v=LLTZG6tbyC8
https://www.youtube.com/watch?v=EdABL-1Z1qU
https://www.youtube.com/watch?v=hlnjD650oMY

Friday, August 11, 2017

Copy files into sd card which is mounted as mtp on Linux Command ine

mtp is media transfer protocol. These devices are mounted in /run/user/$UID/gvfs/mtp*

/run/user/0/gvfs/mtp\:host\=%5Busb%3A002%2C075%5D/Internal\ storage/Documents/

we can copy into this location


just use back slash (\) before spaces in file name (if you have spaces)) in cp command.


Similar way, you can use scp to copy from remote location

Examples :
cp /root/Documents/perl.pdf /run/user/0/gvfs/mtp\:host\=%5Busb%3A002%2C075%5D/Internal\ storage/Documents

or

scp 192.168.0.99:/root/Documents/perl.pdf  /run/user/0/gvfs/mtp\:host\=%5Busb%3A002%2C075%5D/Internal\ storage/Documents/


Zurmo CRM Error - Notice: Undefined property: WebApplication::$minScript in app/protected/core/views/PageView.php

If you are trying to open zurmo using url and not able to open because of following errors

Notice: Undefined property: WebApplication::$minScript in zurmo/app/protected/core/views/PageView.php on line 268

Fatal error: Call to a member function generateScriptMap() on a non-object in zurmo/app/protected/core/views/PageView.php on line 268


Solution :

Remove content of runtime Folder.

sudo rm -r zurmo/app/protected/runtime/*

Now try to open it again. You should not get the error now.