Wednesday, November 30, 2016

Clean Recycle Bin on remote windows machine

Open Windows Command Prompt with domain admin rights.

Execute command:
rd \\computername\c$\$Recycle.Bin /q /s
Nothing happens.

When I execute command again, I receive:
The system cannot find the file specified.

Assign SSL to Wordpress, nginx, certbot

This tutorial recommends to assign SSL before installing Wordpress and only then install it directly from https. If the wordpress is already installed then delete all tables from Wordpress database. Of course all content of Wordpress site will be gone!

nginx use virtual hosts layer to put Wordpress into the air.

I have a domain name 5d61050b753b.sn.mynetname.net which comes for free when I enable VPN into the Mikrotik router. I am running Wordpress server on Raspbian Jessie operating system on Raspberry Pi 3.

The NAT for 80 port and 443 has been made.

I am hosting Wordpress on internal address 192.168.88.24

The main nginx configuration /etc/nginx/nginx.conf says:
#egrep -v "^[[:space:]]*#|^$" /etc/nginx/nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
        worker_connections 768;
}
http {
        client_max_body_size 256m;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_names_hash_bucket_size 64;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        gzip on;
        gzip_disable "msie6";
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
#nginx -t -c /etc/nginx/nginx.conf

Lets install free SSL.
#move to supper root
sudo su

#make sure all repositories are up to date and the system have already newest packages
apt-get upgrade -y && apt-get update -y

#move to the home directory of root
cd

#download certbot utility. this will take care of everything as much it can
wget https://certbot.eff.org/certbot-auto

#set cert bot executable
chmod +x certbot-auto

#generate certificate
./certbot-auto certonly
#at first time this will install a lot of python packages and modules and so on.
#this will take like 10 minutes on Raspberry Pi 3. feel free to take a cup of tea

Choose [Place files in web directory] option:

Enter email address:

Read and agree terms of service:

Enter domain name:

Choose [Enter new webroot]:

This is the complicated part. Easiest way is to write full webroot by hand:

All done. I got key and certificate now :)

All files is located:
ls /etc/letsencrypt/live/5d61050b753b.sn.mynetname.net
And here is four files:
cert.pem  chain.pem  fullchain.pem  privkey.pem
I need to use only fullchain.pem and privkey.pem!

Lets assign these files to virtual host file:
#cat /etc/nginx/sites-available/5d61050b753b.sn.mynetname.net
server {
server_name 5d61050b753b.sn.mynetname.net;
#listen 80;
listen 443;
ssl on;
ssl_certificate /etc/letsencrypt/live/5d61050b753b.sn.mynetname.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/5d61050b753b.sn.mynetname.net/privkey.pem;
root /var/www/5d61050b753b.sn.mynetname.net/;
access_log /var/log/nginx/5d61050b753b.sn.mynetname.net-access.log;
error_log /var/log/nginx/5d61050b753b.sn.mynetname.net-error.log;
index index.php index.html index.htm;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
#nginx -t -c /etc/nginx/nginx.conf
#/etc/init.d/nginx restart

Now I only need to restart nginx:
/etc/init.d/nginx restart

Tuesday, November 29, 2016

Remove 450 MB Recovery Partition

I have Windows 8.1 workstation which has installed Widows.
This Windows installation has generated 4 partition.

Now I clone the disk to bigger and it is unable to extend the third/main partition because the 450 Mb partition is in my way:

It is unable to delete this 450 mb partition in windows. I succeed to delete this partition Using Hirens 15.2 Partition Magic.

Now I can extend third partition and the Windows is still working.

Reinstall Wordpress, clear database tables first


If I have Wordpress database 'wpdb', user 'wpuser' together with password 'HAL3jpz4v7xzvGLZ' then I enter databse mode:
mysql -uwpuser -pHAL3jpz4v7xzvGLZ
Execute MySQL commands:
use wpdb;
show tables;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS wp_commentmeta;
DROP TABLE IF EXISTS wp_comments;
DROP TABLE IF EXISTS wp_links;
DROP TABLE IF EXISTS wp_options;
DROP TABLE IF EXISTS wp_postmeta;
DROP TABLE IF EXISTS wp_posts;
DROP TABLE IF EXISTS wp_term_relationships;
DROP TABLE IF EXISTS wp_term_taxonomy;
DROP TABLE IF EXISTS wp_termmeta;
DROP TABLE IF EXISTS wp_terms;
DROP TABLE IF EXISTS wp_usermeta;
DROP TABLE IF EXISTS wp_users;
show tables;
SET FOREIGN_KEY_CHECKS = 1;
exit

Monday, November 28, 2016

StaffCop, LTVserv, AtomPark Software Inc

I have this combination:
  • Windows 8.1 64-bit operating system
  • Firefox and Google Chrome can not connect to any site which is served over https (port 443)
  • Every https site in Chrome and Firefox says Your connection is not private. Attackers might be trying to steal your information
  • The http sites (port 80) still works fine on Firefox and Chrome
  • Internet Explorer still can handle booth ports 443 and 80
  • I got running LTVsrv service
  • There are some StaffCop directory in program files (x86)

When I open Outlook client I can see that the certificate is now issued by
AtomPark Software Inc:

When I run msconfig and go to services I see there is LTVsrv service running

Hand on on solving this case!

Open msconfig, Boot and check safe boot:

Restart computer.

Delete service with:
sc delete ltvsrv
Open regedit and delete all that contains LTVserv and StaffCop.
LTVserv is in a LOT of places including firewall rules.
I need to delete at least 30 keys or registry items.

Delete directories StaffCop with files like:
AuxiliarySVC.exe
files.log
GdiPlus.dll
Languages
libeay32.dll
logo.gif
ReportWizard.exe
RunHiddenConsole.exe
rwdata
SCFNT.TTF
SchedulerHSVC.exe
ssleay32.dll
StaffCopHome.exe
Search all computer for directory names which includes StaffCop. It must be on program files and also in users %appdata% directory.

Delete C:\Windows\System32\Ltprx directory which includes files:
CertInstaller.dll
COMDLG32.OCX
files.log
freebl3.dll
install.cmd
install64.cmd
libnspr4.dll
libplc4.dll
libplds4.dll
ltvlib.dll
ltvlib64.dll
LTVSrv.exe
MSCOMCTL.OCX
nss3.dll
nssckbi.dll
nssdbm3.dll
nssutil3.dll
NtrED.dll
PCController.exe
ProxyConfigurator.exe
RegisterLSP.exe
registerlsp.ini
RegisterLSP64.exe
RunHiddenConsole.exe
Sleep.exe
smime3.dll
softokn3.dll
sqlite3.dll
ssl3.dll
uninstall.cmd
uninstall64.cmd
Make sure there are no mysterious keys under:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Open services.msc, refresh service list and make sure LTVsrv service do not exist.

Open msconfig and uncheck Safe Boot!
Restart.

Install Wordpress on nginx virtual host directory

This is third part of setting up Wordpress on the top of nginx web server using MySQL database. This all happens Raspberry Pi which use Raspbian Jessie operating system.

It all began with:
1. nginx, php, virtual hosts, raspbian jessie, minimal
In this part I installed nginx and php module. I configured my router or windows machine so the DNS name 'wp.nginx' sends as forward to an IP address. I love this mechanism so much :)

2. Create MySQL database, non-root user, permissions
It is nice practice to run 'wpdb' database with different user than root. I call this use 'wpuser' and assign for it its own password. Also I need to let MySQL database engine from what location I can run MySQL queries and so. here comes 'localhost' in place.

And now the final block to install Wordpress.
#!/bin/bash
#this is tested on fresh 2016-09-23-raspbian-jessie-lite.img
#sudo su
#apt-get update -y && apt-get upgrade -y && apt-get install git -y
#git clone https://github.com/catonrug/wordpress-install-raspbian-jessie-mysql-nginx-virtual-hosts.git && cd wordpress-install-raspbian-jessie-mysql-nginx-virtual-hosts && chmod +x *.sh
#nginx and php5-fpm must be installed, virtual hosts must be configured see more at 1-nginx-php-install.sh
#MySQL database 'wpdb', MySQL user 'wpuser' with password 'HAL3jpz4v7xzvGLZ' must exist. see more at 2-mysql-install-wordpress-database.sh
#./3-wordpress-install-nginx-mysql.sh

#move to virtual host direcotry
cd /var/www/wp.nginx

#remove everything
rm -rf *

#download latest wordpress
wget http://wordpress.org/latest.tar.gz

#extract and remove the archive
tar xzvf latest.tar.gz && rm latest.tar.gz

#move to wordpress direcotry
cd wordpress

#move all content to the parrent direcotry
mv * ..

#move back
cd ..

#remove wordpress dir
rm -rf wordpress

#install adition libraries for wordpress
apt-get install php5-curl php5-gd libssh2-php -y

#to improve php5-fpm performance install cacher
apt-get install php-apc -y

#nginx service is runned by www-data user
#lets allow nginx service to really change the content in wordpress dir
#this will allow us to do the default wordpress wizard using web interface
chown -R www-data:www-data /var/www/wp.nginx

#restart config file for php and nginx
/etc/init.d/php5-fpm reload && /etc/init.d/nginx reload

#everything done
#i can go to http://wp.nginx and folow the wizard
#at first it looks nginx is slower than apache, but after restart it server good

#all credits go to
#https://www.stewright.me/2014/06/tutorial-install-wordpress-on-a-raspberry-pi-using-nginx/

When I configure through web interface I use credentials:

All code can be downloaded from github:
https://github.com/catonrug/wordpress-install-raspbian-jessie-mysql-nginx-virtual-hosts

Sunday, November 27, 2016

Create MySQL database, non-root user, permissions

This is sample code how to:
1) Install MySQL server on Raspbian Jessie operating system
2) Create database for Wordpress
3) Create custom MySQL user just to use Wordpress database only
4) Let the database know that it can be used from localhost
5) Allow connect to the database from another host 192.168.99.254. Just in case I have front-end and database on separated servers or I want to browse database from another workstation.

Here is the result I made:
#!/bin/bash

#before doing this I have installed nginx, php5-fpm and configured some custom settings like virtual hosts. see more at:
#https://github.com/catonrug/nginx-php-virtual-hosts-raspbian-jessie/blob/master/nginx-php-install.sh

#install mysql-server. the password for root account I set 'password'. very secure. I know :)
apt-get install mysql-server -y
#this will automatically install additional packages such as: libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18 libterm-readkey-perl mysql-client-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5

apt-get install mysql-client php5-mysql -y
#note that mysql-client is not the same as mysql-client-5.5
#this will do some merging with preinstalled php-fpm

#create database 'wpdb'
mysql -uroot -ppassword <<< 'CREATE DATABASE wpdb;'

#create new user 'wpuser' with password 'HAL3jpz4v7xzvGLZ'
mysql -uroot -ppassword <<< 'CREATE USER "wpuser"@"localhost" IDENTIFIED BY "HAL3jpz4v7xzvGLZ";'

#let the user 'wpuser' manage all content for database 'wpdb'
mysql -uroot -ppassword <<< 'GRANT ALL PRIVILEGES ON wpdb.* TO "wpuser"@"localhost";'

#to browse wordpress database from different location use something like
mysql -uroot -ppassword <<< 'GRANT ALL PRIVILEGES ON wpdb.* TO "wpuser"@"192.168.99.254";'

#let the new permissions goes on production
mysql -uroot -ppassword <<< 'FLUSH PRIVILEGES;'

#test if I can really use this new user 'wpuser' together with password 'HAL3jpz4v7xzvGLZ'
mysql -uwpuser -pHAL3jpz4v7xzvGLZ <<< 'SHOW DATABASES;'

#all credits go to
#https://www.stewright.me/2014/06/tutorial-install-mysql-server-on-raspberry-pi/

Saturday, November 26, 2016

nginx, php, virtual hosts, raspbian jessie, minimal

This is the minimal nginx web server installation with php support.
It is based only on two main paskages nginx and php-fpm.
Since I am in love with virtual host concept so I will do this in virtual host way :)

Before I go any further I have already made some static DNS record :)
What this picture says that DNS record wp.nginx points to IP address 192.168.99.62

This can be also implemented with basic widows host file:
notepad %systemroot%\system32\drivers\etc\hosts

These are the steps I do on the Raspbian Jessie side:
#!/bin/sh
#this is tested on fresh 2016-09-23-raspbian-jessie-lite.img
#sudo su
#apt-get update -y && apt-get upgrade -y && apt-get install git -y
#cd
#git clone https://github.com/catonrug/nginx-php-virtual-hosts-raspbian-jessie.git && cd nginx-php-virtual-hosts-raspbian-jessie && chmod +x nginx-php-install.sh
#./nginx-php-install.sh

#install nginx
apt-get install nginx -y
#this will install packages such as: fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libtiff5 libvpx1 libxpm4 libxslt1.1 nginx nginx-common nginx-full

#check nginx status
service nginx status

#if knginx is not active then start it
service nginx start

#check if there is any content hosting on port 80
wget -qO- http://localhost | sed -e "s/<[^>]*>//g"

#install php support for nginx by installing php5-fpm package. FPM stands for FastCGI Process Manager. https://php-fpm.org/
apt-get install php5-fpm -y
#this will install packages such as: libapparmor1 libonig2 libperl4-corelibs-perl libqdbm14 lsof php5-cli php5-common php5-fpm php5-json php5-readline

#check the status of service
service php5-fpm status

#check of there is any virtual hosts before
ls -l /etc/nginx/sites-available

#install new virtual host - wp.nginx
cat > /etc/nginx/sites-available/wp.nginx << EOF
server {
server_name wp.nginx;
listen 80;
root /var/www/wp.nginx/;
access_log /var/log/nginx/wp.nginx.com-access.log;
error_log /var/log/nginx/wp.nginx-error.log;
index index.php index.html index.htm;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
EOF

#once I use [fastcgi_split_path_info ^(.+.php)(/.+)$;] in nginx config I have to enable it also in php.ini
sed -i "s/^.*cgi\.fix_pathinfo=.*$/cgi\.fix_pathinfo=1/" /etc/php5/fpm/php.ini

#make symbolic limk. This will enable the site
ln -s /etc/nginx/sites-available/wp.nginx /etc/nginx/sites-enabled/wp.nginx

#create directory for web page
mkdir -p /var/www/wp.nginx

#create php sample file
echo "<?php phpinfo(); ?>" > /var/www/wp.nginx/index.php

#restart config file for php and nginx
/etc/init.d/php5-fpm reload && /etc/init.d/nginx reload

#all done. now open web browser and type http://wp.nginx

#all credits to
#https://www.raspberrypi.org/documentation/remote-access/web-server/nginx.md
#https://www.stewright.me/2014/06/tutorial-install-nginx-and-php-on-raspbian/

On Github:
https://github.com/catonrug/nginx-php-virtual-hosts-raspbian-jessie/blob/master/nginx-php-install.sh

Friday, November 25, 2016

Zabbix templates I use at home

Is it is Linux computer zabbix agent can be installed. In this case the only thing I need to know is it online or offline:
Click Save Target As AgentPingOnly

Raspberry Pi 3 is getting very hot when it is doing something. I can easily reach 80°C
In this scenario I put heatsing on the cpu and use use 56°C theshhold.
Click Save Target As MaxHeatSink

Raspberry Pi 2 is lees heat friendly. In this case I use 52°C theshhold.
Click Save Target As NoHeatSink

Windows Computers during windows update process ask for reboot.
In this case WindowsRebootRequired template comes in handy.
Click Save Target As WindowsRebootRequired

Thursday, November 24, 2016

Wordpress import blogger limited to 2MB

I am testing Wordpress 4.6 and trying to import xml archive from blogger.

I am bit of stuck because the default upload size is 2 MB

I am using Raspberry Pi Raspbian Jessie operating system. This is basically Debian.
By the way to install Wordpress on Raspberry Pi is very easy.

The options I am interested to change is these:
grep "^upload_max_filesize" /etc/php5/apache2/php.ini
grep "^file_uploads" /etc/php5/apache2/php.ini
grep "^memory_limit" /etc/php5/apache2/php.ini
grep "^post_max_size" /etc/php5/apache2/php.ini
grep "^max_execution_time" /etc/php5/apache2/php.ini

So I set max file size to 64MB and time limit to 5 minutes:
sed -i "s/^upload_max_filesize = .*$/upload_max_filesize = 64M/" /etc/php5/apache2/php.ini
sed -i "s/^file_uploads = .*$/file_uploads = On/" /etc/php5/apache2/php.ini
sed -i "s/^memory_limit = .*$/memory_limit = 64M/" /etc/php5/apache2/php.ini
sed -i "s/^post_max_size = .*$/post_max_size = 64M/" /etc/php5/apache2/php.ini
sed -i "s/^max_execution_time = .*$/max_execution_time = 300/" /etc/php5/apache2/php.ini

Now I need to restart the apache daemon:
service apache2 restart

Appendix
I can specify custom upload temp directory with upload_tmp_dir option.

To set up custom temp directory I need to look for line
grep "upload_tmp_dir" /etc/php5/apache2/php.ini

To set /tmp as upload temp dir:
sed -i "s/^.*upload_tmp_dir =.*$/upload_tmp_dir = \/tmp/" /etc/php5/apache2/php.ini

To set back defaults:
sed -i "s/^.*upload_tmp_dir =.*$/;upload_tmp_dir =/" /etc/php5/apache2/php.ini

Appendix:
I the web server is server by nginx, php5-fpm:
#grep values for php5-fpm/nginx
grep "^upload_max_filesize" /etc/php5/fpm/php.ini
grep "^file_uploads" /etc/php5/fpm/php.ini
grep "^memory_limit" /etc/php5/fpm/php.ini
grep "^post_max_size" /etc/php5/fpm/php.ini
grep "^max_execution_time" /etc/php5/fpm/php.ini

#increase php5-fpm/nginx settings
sed -i "s/^upload_max_filesize = .*$/upload_max_filesize = 256M/" /etc/php5/fpm/php.ini
sed -i "s/^file_uploads = .*$/file_uploads = On/" /etc/php5/fpm/php.ini
sed -i "s/^memory_limit = .*$/memory_limit = 256M/" /etc/php5/fpm/php.ini
sed -i "s/^post_max_size = .*$/post_max_size = 256M/" /etc/php5/fpm/php.ini
sed -i "s/^max_execution_time = .*$/max_execution_time = 300/" /etc/php5/fpm/php.ini

#reload nginx
/etc/init.d/php5-fpm reload
/etc/init.d/nginx reload

Wednesday, November 23, 2016

Screenshot web interface in standard resolution

I have a need to take a screenshot of web interface in standard resolution which is lower than 1920x1080. Usually I use 800x600, 1024x768 or 1280x1024.

The way I do it so is temporary set desktop resolution to this and then I take a screenshot.

Now I found a way without changing resolution.
It is using ActivePresenter

All I need to do is open ActivePresenter, select app and set resolution.
Now My Google Chrome are switched to 1024x768.

Next thing I use is Google Chrome plugin "Full Page Screen Capture"

Tuesday, November 22, 2016

Zabbix Server, first things first

Now I am creating again zabbix server from source on my Raspberry Pi.

This is automation I use. It is tested and works nicely on 2016-09-23-raspbian-jessie-lite.img https://github.com/catonrug/raspberry-pi-zabbix/blob/master/server-install.sh

Of course I export all templates and host from old server :)

Now the new server is up and running and I need to do some basic setup.

Set up proxy names:

Import templates:

Import hosts:

Set up email sending.
mkdir -p /var/zabbix/alertscripts
chown -R zabbix:zabbix /var/zabbix/
cd /var/zabbix/alertscripts
wget https://gist.githubusercontent.com/superdaigo/3754055/raw/e28b4b65110b790e4c3e4891ea36b39cd8fcf8e0/zabbix-alert-smtp.sh -O zabbix-alert-smtp.py
chmod +x zabbix-alert-smtp.py
Enter email address and password at line 14 and 15:
vi zabbix-alert-smtp.py
Make sure lesssecureapps is on. Then test if sending works:
./zabbix-alert-smtp.py yourname@gmail.com "subject" "this is test"
Open Media Types and configure Email:

Assign Email to use zabbix-alert-smtp.py:

Assign email to administrator:

Click [add]

Write down email where to send all zabbix alerts:

Apply email settings:

Enable actions:

Monday, November 21, 2016

Remove Zabbix Server compiled from source

I messed up my zabbix server with upgrade. Now the log files says:
using configuration file: /usr/local/etc/zabbix_server.conf
[Z3005] query failed: [1146] Table 'zabbix.users' doesn't exist [select userid from users limit 1]
cannot use database "zabbix": database is not a Zabbix database
Before I recompile new server I take care of previous mess:
service zabbix-agent stop
service zabbix-server stop
rm /etc/init.d/{zabbix-agent,zabbix-server}
rm /usr/local/sbin/{zabbix_agent,zabbix_agentd,zabbix_server}
rm /usr/local/etc/{zabbix_agent.conf,zabbix_agentd.conf,zabbix_server.conf}
rm -rf /usr/local/etc/{zabbix_agent.conf.d,zabbix_agentd.conf.d,zabbix_server.conf.d}
rm /usr/local/bin/{zabbix_get,zabbix_sender}
rm -rf /var/www/html/zabbix
rm -rf /var/zabbix
I my case the MySQL database runs only zabbix so I can remove it too:
service mysql stop
rm -rf /var/lib/mysql/*
sudo -u mysql mysql_install_db
/usr/bin/mysqladmin -u root password 'new-password'
service mysql start

Friday, November 18, 2016

Shrink Zabbix MySQL database, ibdata1, Raspbian

I am using Raspberry Pi as a Zabbix server. ibdata1 file of zabbix database is almost 700Mb and I can not put it on a floppy disk anymore. I want to shrink this file smaller and I know it is possible.

I am using Model B of Raspberry Pi . My Zabbix server is running at least 4 months.

Basically the server has been made on the top of 2016-05-27-raspbian-jessie-lite.img and it has been updated few times.

I am running MySQL version 5.5 and zabbix server 2.4.6.

This is my preparation to do list:
  • Unused items from templates has been deleted.
  • Housekeeping override settings has been installed.

I did not find how to force housekeeping but I learned details how it works.

Starting from Zabbix server 2.4 by default housekeeping executes automatically every hour. Another time when this happens is 30 minutes after the server is started.

Ok. This is fine with me.

Before I go any further I need to modify zabbix_server.conf and set MaxHousekeeperDelete=0. This is kind of danger option. It means to delete all expired/unused items in one Housekeeping execution cycle.

Once the config file includes this option I can restart zabbix server:
service zabbix-server restart
Next phase I wait a 30 minutes and look into the zabbix_server.log:
tail -f /var/log/zabbix/zabbix_server.log
After 30 minutes there will be such line as:
24176:20161118:081340.636 executing housekeeper
No joking.

After five hours zabbix_server.log says:
24176:20161118:123832.247 housekeeper [deleted 13598 hist/trends, 5272673 items, 93 events, 34 sessions, 0 alarms, 17 audit items in 15891.600428 sec, idle 1 hour(s)]

Ok. Now the database has been reorganized and I need do final steps:
  • create mysql dump
  • delete files ibdata1, ib_logfile0, ib_logfile0
  • restore back database tables and content

To do it so..

Make sure you are still root:
sudo su
Stop Zabbix server:
service zabbix-server stop
Stop MySQL service:
service mysql stop
Move to MySQL data directory:
cd /var/lib/mysql
Note down the owner directory:
ls -l
This will report content like this. The owner is mysql and group also is mysql
total 667668
-rw-r--r-- 1 mysql mysql         0 Nov 18 07:14 debian-5.5.flag
-rw-r----- 1 mysql mysql 673185792 Nov 18 07:15 ibdata1
-rw-r----- 1 mysql mysql   5242880 Nov 18 07:15 ib_logfile0
-rw-r----- 1 mysql mysql   5242880 Nov 18 07:15 ib_logfile1
drwx------ 2 mysql mysql      4096 Nov 18 07:15 mysql
-rw------- 1 mysql mysql         6 Nov 18 07:15 mysql_upgrade_info
drwx------ 2 mysql mysql      4096 Nov 18 07:15 performance_schema
drwx------ 2 mysql mysql      4096 Nov 18 07:15 zabbix
Create a backup directory:
mkdir ~/1
Copy all content in current directory to the backup directory:
cp -R . ~/1
Start MySQL service:
service mysql start
Create a dump of mysql database:
mysqldump -uroot -pLCq9LCFCNMZEqatm --extended-insert --all-databases --add-drop-database --disable-keys --flush-privileges --quick --routines --triggers > all-databases.sql
This will output something like:
-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
Now I need to wait few minutes.

Delete ibdata1, ib_logfile0, ib_logfile0:
rm ibdata1 ib_logfile0 ib_logfile1
With mysql user recreate basic content:
sudo -u mysql mysql_install_db
Enter MySQL mode:
mysql -uroot -pLCq9LCFCNMZEqatm
Enter MySQL commands
SET FOREIGN_KEY_CHECKS=0;
SOURCE all-databases.sql;
SET FOREIGN_KEY_CHECKS=1;
exit
Start Zabbix Server:
service zabbix-server start
Appendix:
If something goes wrong with MySQL databse I restore from backup using:
sudo su
service mysql stop
cd /var/lib/mysql
cp -R ~/1/* .
chown -R mysql:mysql .
service mysql start
Related:
http://vdachev.net/2007/02/22/mysql-reducing-ibdata1/

Tuesday, November 15, 2016

Get file https://googledrive.com/host/..

https://googledrive/host/.. is dead, but I can still get to the file with:
https://drive.google.com/open?id=
for example:
https://drive.google.com/open?id=0BxJgS33zZl9bZF9LWXJhakZaVGs

Sunday, November 13, 2016

4K Video Downloader new version detect

Another windows software detection has been made. This time it is 4K Video Downloader. I am familiar with this software at least two years.

Everything starts with page where actual exe file is hosted:
https://www.4kdownload.com/products/product-videodownloader

Usually I use wet -qO- to download html but this time html is JavaScript generated so I need to use python html downloader:
python html-downloader.py https://www.4kdownload.com/products/product-videodownloader product.log
Now I can extract direct installer link easily:
grep "download-button.*http.*exe" product.log | sed "s/\d034/\n/g" | grep "^http.*exe$"
I am very happy that pestr tool can tell me exact version number of this software.
pestr 4kvideodownloader_4.1.exe | grep -m1 -A1 "ProductVersion" | grep -v "ProductVersion"| sed "s/\.[0-9]\+//4"
4.1.2.2075
Now I like this soft even more :)

Complete code can be found on github:
https://github.com/catonrug/4kvideodownloader-detect/blob/master/check.sh

The result goes on:
https://dl4ou.blogspot.com/

Thursday, November 10, 2016

Create multiple OU, Groups, PowerShell

create new Department OU into domain root location:
New-ADOrganizationalUnit -Name "Department"

Create "IT" OU into "Department" OU:
New-ADOrganizationalUnit -Name IT -Path "OU=Department,DC=contoso,DC=com"

Create IT_Development, IT_Testers, IT_Maintenance groups into IT OU:
New-ADGroup -Name IT_Development -Path "OU=IT,OU=Department,DC=contoso,DC=com" -GroupScope Global
New-ADGroup -Name IT_Testers -Path "OU=IT,OU=Department,DC=contoso,DC=com" -GroupScope Global
New-ADGroup -Name IT_Maintenance -Path "OU=IT,OU=Department,DC=contoso,DC=com" -GroupScope Global

Create IT group by itself and add IT_Development, IT_Testers, IT_Maintenance to it:
New-ADGroup -Name IT -Path "OU=IT,OU=Department,DC=contoso,DC=com" -GroupScope Global
Add-ADGroupMember -Identity IT -Members IT_Development
Add-ADGroupMember -Identity IT -Members IT_Testers
Add-ADGroupMember -Identity IT -Members IT_Maintenance

Tuesday, November 8, 2016

Wordpress 4.6 first run

Select language:

Intro:

Write down database credentials:

Run the install:

Customize site title, administrative user:

Success story:

First login screen:

Administrator panel:

Monday, November 7, 2016

Install Wordpress on Raspbian Jessie Lite

This is the very awesome tutorial how to set up LAMP server on raspberry pi:
https://www.raspberrypi.org/learning/lamp-web-server-with-wordpress/

When I merge all commands together I get:
#!/bin/bash

#tutorial from https://www.raspberrypi.org/learning/lamp-web-server-with-wordpress/worksheet/

#this code is tested un fresh 2016-09-23-raspbian-jessie-lite.img Raspberry Pi image
#sudo su
#apt-get update -y && apt-get upgrade -y && apt-get install git -y
#git clone https://github.com/catonrug/install-wordpress-raspbian-jessie-lite.git && cd install-wordpress-raspbian-jessie-lite && chmod +x install-wordpress.sh
#./install-wordpress.sh

#install apache web server
apt-get install apache2 -y

#install php
apt-get install php5 libapache2-mod-php5 -y

#install mysql. enter password 'password' for further automation
apt-get install mysql-server php5-mysql -y

#restart apache web server
service apache2 restart

cd /var/www/html/
rm *
wget http://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
mv wordpress/* .
rm -rf wordpress latest.tar.gz
chown -R www-data: .

mysql -uroot -ppassword <<< 'create database wordpress'

Now I go to web interface for example http://192.168.88.33/

On github:
https://github.com/catonrug/install-wordpress-raspbian-jessie-lite

Wednesday, November 2, 2016

List AD users, exclude group, PowerShell

How to list users from Active Directory, but eliminate some of them because it is in exception list? This exception list is another Active Directory group which has user objects.

Lets face it. I want to eliminate all users which is member of one of these group(s):
Domain Admins
Disabled Users
Additional Mailbox
Service Users
I want to list only users which are located in "Users" Organization Unit on "Contoso.com".
In this case I use this LDAP pattern "OU=Users,DC=Contoso,DC=com"

I will also want to extract some custom attributes like:
Name
EmailAddress
SamAccountName
LastLogonDate
Description
Department
Title
At the end I use this PowerShell script:
Get-ADUser -Filter * -SearchBase "OU=Users,DC=Contoso,DC=com" -Properties Name, EmailAddress, SamAccountName, LastLogonDate, Description, Department, Title, MemberOf | ? {$_.Enabled -eq $true} | ? { ($_.MemberOf | Out-String) -notmatch "Domain Admins|Disabled Users|Additional Mailbox|Service Users"} | select Name, EmailAddress, SamAccountName, LastLogonDate, Description, Department, Title | Out-GridView

Blog Archive