Friday, December 25, 2020

Free Mac OS X Windows Management Tool - Productivity app

Spectacle is for me an easy to use Tool which instantly increased my Productivity.

Steps do to the same for you:

 1. Download the tool from here:

https://www.spectacleapp.com/


2. Follow the easy straight forward steps to install.


3. You're done. My favorite one is 3 window screen split:





Friday, July 3, 2020

How to use bash For Loop In One Line


Just enter below command and will get the magic - below runs your-script.sh 5 times:


for i in {1..5}; do echo "------------------------ Iteration ".$i."    ----------------------"; sh your-script.sh;sleep 3; done

Thursday, July 2, 2020

Schedule send email - Online Web Version Outlook O365

Yes - this is finally true. You can now schedule emails to be sent at a specific time from online Outlook.

Very happy to have this feature, it was requested for some time to be available.

You now get the following option when sending a new message - Send Later:





Choose the date and time you want the message to be sent:



Optionally, you can double check that message appears under Draft Folder with the proper scheduled note:



Thursday, June 18, 2020

Saturday, June 13, 2020

Solve AH10034: The mpm module (prefork.c) is not supported by mod_http2


Complete error.log line:

[Sat Jun 13 15:57:54.049273 2020] [http2:warn] [pid 23029] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.

You would need to change mpm loaded module:

vi /etc/httpd/conf.modules.d/00-mpm.conf

Comment this line:
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

Uncomment this line:
LoadModule mpm_event_module modules/mod_mpm_event.so

Redirect www to apex domain

This is also to solve certificate error in case DNS Name from certificate only contains apex domain.

To quickly solve this, following redirect is needed - e.g. for domain easybiny.com:

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.easybiny.com
RewriteRule ^ https://easybiny.com%{REQUEST_URI} [END,NE,R=permanent]

Solve AH01909: server certificate does NOT include an ID which matches the server name

This is just to make sure ServerName directive has the same name as the one from certificate.

Example:
...
        ServerName easybiny.com
...


Certificate:
...
easybiny.com
...

Solve AH01276: Cannot serve directory No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive


I get the following error in error.logs:

[Sat Jun 13 13:20:28.420637 2020] [autoindex:error] [pid 23018] [client 44.224.22.196:40224] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

To quickly solve it, make sure DocumentRoot points to a valid folder where index.php or index.html is found:

vi /etc/httpd/conf/httpd.conf
Replace:
DocumentRoot "/var/www/html"

With:
DocumentRoot "/var/www/html/easybiny/prod"

Friday, May 29, 2020

Deny Apache access by public IP - Fix error "script not found or unable to stat"

If you noticed following error in Apache error.log:

[Sat May 30 05:47:30.731862 2020] [php7:error] [pid 18581] [client 188.131.234.5 :2359] script '/var/www/html/easybiny/elrekt.php' not found or unable to stat

And corresponding Apache access.log:

188.131.234.5 - - [20/May/2020:05:47:30 +0000] "GET /elrekt.php HTTP/1.1" 404 415 0 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.0;en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6)" "[XF -]" 52.203.153.105

You will be noticing that user/crawler is trying to access via your public server IP - 52.203.153.105

To prevent this, you need to add the following vhost to your httpd.conf file and reload apache configs:

<VirtualHost *:80>
    ServerName 52.203.153.105
    Redirect 403 /
    ErrorDocument 403 "Access Denied"
    DocumentRoot /var/www/html/easybiny
    UseCanonicalName Off
    UserDir disabled
</VirtualHost>

You can now test with a simple curl:

curl 52.203.153.105/elrekt.php

Access Denied


Yes - you get 403 access denied and no more errors in logs.



Saturday, May 9, 2020

Solution for Dynamics Message: To group conditions, select two or more conditions or groups ...

When trying a Group OR, following message appears:


Simply make sure you select each condition that needs to be part of OR clause:



Once all selected, you can get the desired selection as per below:



Saturday, April 25, 2020

Quick parse Apache httpd error log

[user@logs]# cat error_log | cut -d " " -f 11,13,14 | sort -n | uniq -c | sort -r
    728 script not found
    101 AH01276: serve directory
     57 AH02811: not found
     25 PHP  Undefined
      3 server does NOT
      3 PHP  session_start():
      1 slotmem mod_heartmonitor
      1 mpm (prefork.c) is
      1 line: -D FOREGROUND'
      1 () PHP/7.3.11 configured
     

      ---

So most often error message is "script not found". A concrete example of error that needs to be addressed is the below:
[client 173.212.201.253:34544] script '/var/www/html/sitedomain/prod/wp-login.php' not found or unable to stat, referer: http://sitedomain.com/wp-login.php

This is to be tackled in another article :)

Tuesday, April 21, 2020

Fix PHP Notice: Undefined index: HTTP_HOST in php on line

It might be that $_SERVER['HTTP_HOST'] is undefined.

To check this, better to verify using isset before instantiating it:


$link .= "http://";

if (isset($_SERVER['HTTP_HOST'])) {
        $link .= $_SERVER['HTTP_HOST'];
}

Saturday, April 18, 2020

Script to check when specific SSL website certificate is to expire

#!/bin/bash
expire=$(echo | openssl s_client -servername easybiny.com -connect easybiny.com:443 2>/dev/null | openssl x509 -noout -dates | awk 'BEGIN{FS="After="} {print $2}')

date_today=$(date -d "now" +%s)
date_expire=$(date -d "$expire" +%s)
result=$(( (date_expire - date_today) / 86400 ))-days

echo $result


Running the above will prodice the desired output:

[root@x.x.x.x monitoring]# ./check-easybiny-certificate.sh
75-days

SSL Certificate - Get expiration date from shell with openssl

Very simple, just run the following command:

[root@ip-172-31-39-55 monitoring]# echo | openssl s_client -servername www.easybiny.com -connect www.easybiny.com:443 2>/dev/null | openssl x509 -noout -dates
 

notBefore=Mar 28 13:43:20 2020 GMT
notAfter=Jun 26 13:43:20 2020 GMT

Fixed: Where PHP sessions are stored?

This is setup using the following parameter:

session.save_path  

By default, at least in PHP 7.3, this is commented in php.ini:
;session.save_path = "/tmp"

It means default location is the following one:
/var/lib/php/session

In there you'll get files like the below:
[root@ip-172-31-39-55 session]# ls -l
-rw------- 1 apache apache 71 Apr 18 18:31 sess_0a2bbj0u9nsf9gh5vbddte855e
-rw------- 1 apache apache  0 Apr 18 11:13 sess_0uttil3jnenoos2kcf6t45gqj5
-rw------- 1 apache apache  0 Apr 17 15:30 sess_1f57jnsc28gj06km301b4von1a
-rw------- 1 apache apache  0 Apr 18 10:39 sess_2ips2j6djo8fst8lm4lq9q7l6n
-rw------- 1 apache apache  0 Apr 18 09:23 sess_32ta8talaki4a7umbuq6ivfqdi



If you also have have session parameters ($_SESSION['parameter']), you shall see those in file:
cat sess_vssets4hr5b1h89ad7k93q3rhl
loggedin|b:1;name|s:1:"D";id|i:6;

PHP 7.3 - Find php.ini file

Simply run this command:

php -i | grep "Loaded Configuration File"

In my case it found the file here:

[root@x.x.x.x etc]# php -i | grep "Loaded Configuration File"
Loaded Configuration File => /etc/php.ini

Friday, April 17, 2020

Crontab -e log history on Amazon Linux 2

This is located here:

/var/log/cron

Example of usage:

tail -500f /var/log/cron

You shall find your scripts from crontab -e being run:

Apr 17 22:43:01 ip-172-31-39-55 CROND[1407]: (root) CMD (sh /home/dtech/monitoring/check-daily-requests.sh)
Apr 17 22:43:01 ip-172-31-39-55 CROND[1408]: (root) CMD (sh /home/dtech/monitoring/check-cpu)

Thursday, April 16, 2020

Splunk: Split URL Path by removing query parameters

If you have something like the below:

/easybiny.stockprice.json?dt=123213

and want only to get the path without query string:
/easybiny.stockprice.json

Then easy way is to do this in the Splunk search statement:

eval url=mvindex(split(request, "?"), 0) | table request,url

Saturday, April 4, 2020

MariaDB/MySQL show privilegies for DB User


MariaDB [xxxx]> show grants for 'xxxx'@"localhost";
+------------------------------------------------------------------------+
|Grants for xxxx@localhost                                              |
+------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'xxxx'@'localhost' IDENTIFIED BY PASSWORD '*xxx'
| GRANT SELECT, INSERT ON `dtech`.`bins` TO 'xxxx'@'localhost'          
+------------------------------------------------------------------------+

Fix "PHP Fatal error: Uncaught Error: Call to a member function bind_param() on bool in"

First of all, please make sure you have proper verbose error to identify root cause:


if ($stmt = $conn->prepare("SELECT id, password FROM accounts WHERE email = ?")) {
        $stmt->bind_param("s", $_POST['username']);
        $stmt->execute();
        $stmt->store_result();

....

else{
$error = $conn->errno . ' ' . $conn->error;
echo $error;

}


Once this in place, I can get the exact error message in browser:

1142 SELECT command denied to user 'xxxx'@'localhost' for table 'accounts'DB error

So my xxxx user does not have proper access. 

This is easily to be fixed by running the following command:

GRANT SELECT ON db.accounts TO xxxx@'localhost';


Redirect www subdomain to "apex" like subdomain

First, please always use https and proper certificate.

Secondly, add the following rule to your virtual host:

...

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.stage.easybiny.com
RewriteRule ^ https://stage.easybiny.com%{REQUEST_URI} [END,NE,R=permanent]


...

Note: In this example, stage.easybiny.com is the "apex" like subdomain.

Saturday, March 28, 2020

Connect to MySQL MariaDB

Connect to MariaDB:

1.
mysql

Following prompt is to appear:
MariaDB [(none)]>

2.
show databases;

3.
use databasename;
E.g.
use dtech;

3.
show tables;


E.g.
MariaDB [dtech]> show tables;
+-----------------+
| Tables_in_dtech |
+-----------------+
| bins            |
+-----------------+
1 row in set (0.000 sec)

4.
select * from bins;

5.
exit;

Saturday, January 4, 2020

Validate html w3school using cURL

Example of command:
curl -s https://validator.w3.org/nu/?doc=https%3A%2F%2Feasybiny.com | grep "The document validates according to the specified schema(s)" | wc -l

where you can add your url in RED.

Result interpretation:
if 0 -> not valid
if 1 -> HTML is valid

Thursday, January 2, 2020

Implement HTTP Basic Authentification for your website

1. Create password file and add user/pass:
sudo htpasswd -c /etc/httpd/passwd/.easybiny user

2. Add the following directive to your desired virtual host/folder:
<Directory "/var/www/html/easybiny/stage">
    AuthType Basic
        AuthName "Restricted Content"
        AuthUserFile /etc/httpd/passwd/.easybiny
        Require valid-user
</Directory>


3. Test - it shall work like a charm: