How To Calculate Dates In Perl Using Date::Manip

Author: , Posted on Monday, September 18th, 2017 at 5:42:51pm
1
2
3
4
my $created_at  = '2017-09-18T13:43:40Z';
my $marker      = DateCalc('today','30 days ago');
my $cmp = Date_Cmp($created_at,$marker);
if ($cmp < 0) { print "Older than marker!\n"; } else { print "Same date or later than marker\n"; } 
my $created_at  = '2017-09-18T13:43:40Z';
my $marker      = DateCalc('today','30 days ago');
my $cmp = Date_Cmp($created_at,$marker);
if ($cmp < 0) { print "Older than marker!\n"; } else { print "Same date or later than marker\n"; } 

Host to Delete a Specific Email in Postfix on Linux

Author: , Posted on Thursday, September 14th, 2017 at 1:32:30pm

root@outbound:/var/log # postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
593E2FC69D 3970 Tue Sep 12 23:15:36 MAILER-DAEMON
(connect to yourDomain.com[10.10.10.10]:25: Connection timed out)
yourUser@yourDomain.com

-- 4 Kbytes in 1 Request.

root@outbound:/var/log # postsuper -d 593E2FC69D
postsuper: 593E2FC69D: removed
postsuper: Deleted: 1 message

root@outbound:/var/log # postqueue -p
Mail queue is empty

How To Make Firefox Focus on the URL not Search in a New Tab

Author: , Posted on Tuesday, September 5th, 2017 at 10:41:53am

Set browser.autofocus to false in about:config

How To Watch https Calls to Apache 2.4 using Perl and mod_status

Author: , Posted on Tuesday, September 5th, 2017 at 8:30:04am

Step 1: Enable Apache status and lock it down:

Make sure mod_status is being loaded:

grep -Rn mod_status /etc/httpd/*

1
/etc/httpd/conf.modules.d/00-base.conf:58:LoadModule status_module modules/mod_status.so
/etc/httpd/conf.modules.d/00-base.conf:58:LoadModule status_module modules/mod_status.so

Add support for the call just under the first DocumentRoot statement:

vim /etc/httpd/conf/httpd.conf

1
2
3
4
5
6
<Location /server-status>
    SetHandler server-status
    Require ip 127.0.0.1
    Require ip ::1
    Require ip {Your_IP_Here}
</Location>
<Location /server-status>
    SetHandler server-status
    Require ip 127.0.0.1
    Require ip ::1
    Require ip {Your_IP_Here}
</Location>

Step 2. Prepare your environment:

cpan YAML HTML::TableExtract

Step 3: Create and run the status script:

vim /root/astat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl
 
use strict;
 
use HTML::TableExtract;
 
# PATH to "curl" utility
my $CURL = "/usr/bin/curl";
 
# URL of the server-status we want to process
my $STATUS_URL = "http://localhost/server-status";
 
# those are the headers in the first row of the table we want to extract
# Used by HTML::TableExtract to search for our table, within the whole HTML output
my $headers =['Srv','PID','Acc','M','CPU','SS','Req','Conn','Child','Slot','Client','VHost','Request'];
 
 
# Let's fetch the status page...
my $output = `$CURL -s $STATUS_URL`;
 
# Let's search for our table within the HTML...
my $tables = HTML::TableExtract->new( headers => $headers );
 
# We found it (hopefully), so let's parse it...
$tables->parse($output);
 
# ...and let's stick to the first one
my $status_table = $tables->first_table_found;
 
# Now let's loop allover the rows...
foreach my $row_ref ($status_table->rows) {
      # Let's de-reference the ARRAY reference, so to better manager
      # the various elements...
      my @row = @$row_ref;
 
      # Let's check for IP
      next if $row[10]=~/127.0.0.1/;
      next if $row[10]=~/216.66.125.161/;
      next if $row[10]=~/69.162.124.235/;
 
      # Let's check for an OPTIONS row...
      if ($row[12]=~/OPTIONS/) {
         # simply skip to next row in the loop
         next;
      }
 
      # Let's choose whatever columns we want (first column has index "0")
      # So here we have Srv, PID, Client and Request
      #foreach my $column (0,1,10,12) {
      foreach my $column (10,11,12) {
        print $row[$column]."|";
      }
      print "\n";
}
#!/usr/bin/perl

use strict;

use HTML::TableExtract;

# PATH to "curl" utility
my $CURL = "/usr/bin/curl";

# URL of the server-status we want to process
my $STATUS_URL = "http://localhost/server-status";

# those are the headers in the first row of the table we want to extract
# Used by HTML::TableExtract to search for our table, within the whole HTML output
my $headers =['Srv','PID','Acc','M','CPU','SS','Req','Conn','Child','Slot','Client','VHost','Request'];


# Let's fetch the status page...
my $output = `$CURL -s $STATUS_URL`;

# Let's search for our table within the HTML...
my $tables = HTML::TableExtract->new( headers => $headers );

# We found it (hopefully), so let's parse it...
$tables->parse($output);

# ...and let's stick to the first one
my $status_table = $tables->first_table_found;

# Now let's loop allover the rows...
foreach my $row_ref ($status_table->rows) {
      # Let's de-reference the ARRAY reference, so to better manager
      # the various elements...
      my @row = @$row_ref;

      # Let's check for IP
      next if $row[10]=~/127.0.0.1/;
      next if $row[10]=~/216.66.125.161/;
      next if $row[10]=~/69.162.124.235/;

      # Let's check for an OPTIONS row...
      if ($row[12]=~/OPTIONS/) {
         # simply skip to next row in the loop
         next;
      }

      # Let's choose whatever columns we want (first column has index "0")
      # So here we have Srv, PID, Client and Request
      #foreach my $column (0,1,10,12) {
      foreach my $column (10,11,12) {
        print $row[$column]."|";
      }
      print "\n";
}

chmod 755 /root/astat
while true; do sleep 5; /root/astat; done

How To Configure Apache 2.4 to Renew LetsEncrypt running WordPress and https

Author: , Posted on Monday, August 21st, 2017 at 1:23:32pm

This post does not cover configuring letsencrypt or ssl/https.

First, make sure your LetsEncrypt configuration points to the actual WordPress document root directory

cat /etc/letsencrypt/renewal/www.yourdomain.com.conf

1
2
3
4
...
[[webroot_map]]
yourdomain.com = /volumes/data/www/yourdomain.com/prod/wordpress
www.yourdomain.com = /volumes/data/www/yourdomain.com/prod/wordpress
...
[[webroot_map]]
yourdomain.com = /volumes/data/www/yourdomain.com/prod/wordpress
www.yourdomain.com = /volumes/data/www/yourdomain.com/prod/wordpress

Second, use the new macro language feature in Apache 2.4 to configure an https redirect macro which does NOT redirect to https for anything in the .well-known subdirectory. This allows the renewal process to function via http with no redirect.

Apache Config:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<Macro RedirectTo $protocol $domain>
  <If "%{REQUEST_URI} =~ m#^/\.well-known(/|$)#">
    # Do nothing
  </If>
  <ElseIf "tolower(req('Host')) != '$domain' || tolower(%{REQUEST_SCHEME}) != '$protocol'">
    Redirect permanent / $protocol://$domain/
  </ElseIf>
</Macro>
 
<VirtualHost *:80>
    ServerName www.yourdomain.com
    ServerAlias *yourdomain*
 
    DocumentRoot /volumes/data/www/yourdomain.com/prod/wordpress
    DirectoryIndex index.html index.php index.cgi
    ServerAdmin apache.admin@yourdomain.com
 
    ErrorLog "| /usr/sbin/rotatelogs /volumes/data/www/yourdomain.com/prod/logs/www_errors.log 86400"
    CustomLog "| /usr/sbin/rotatelogs /volumes/data/www/yourdomain.com/prod/logs/www_access.log 86400" combined
 
    Header set Access-Control-Allow-Origin *yourdomain.com
 
    Use RedirectTo https yourdomain.com
 
    <Directory "/volumes/data/www/yourdomain.com/prod/wordpress">
        AllowOverride all 
        Options +FollowSymLinks +ExecCGI
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>
    <Files xmlrpc.php>
        Order allow,deny
        Deny from all
    </Files>
 
</VirtualHost>
 
<VirtualHost *:443>
...
</VirtualHost>
<Macro RedirectTo $protocol $domain>
  <If "%{REQUEST_URI} =~ m#^/\.well-known(/|$)#">
    # Do nothing
  </If>
  <ElseIf "tolower(req('Host')) != '$domain' || tolower(%{REQUEST_SCHEME}) != '$protocol'">
    Redirect permanent / $protocol://$domain/
  </ElseIf>
</Macro>

<VirtualHost *:80>
    ServerName www.yourdomain.com
    ServerAlias *yourdomain*

    DocumentRoot /volumes/data/www/yourdomain.com/prod/wordpress
    DirectoryIndex index.html index.php index.cgi
    ServerAdmin apache.admin@yourdomain.com

    ErrorLog "| /usr/sbin/rotatelogs /volumes/data/www/yourdomain.com/prod/logs/www_errors.log 86400"
    CustomLog "| /usr/sbin/rotatelogs /volumes/data/www/yourdomain.com/prod/logs/www_access.log 86400" combined

    Header set Access-Control-Allow-Origin *yourdomain.com

    Use RedirectTo https yourdomain.com

    <Directory "/volumes/data/www/yourdomain.com/prod/wordpress">
        AllowOverride all 
        Options +FollowSymLinks +ExecCGI
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>
    <Files xmlrpc.php>
        Order allow,deny
        Deny from all
    </Files>

</VirtualHost>

<VirtualHost *:443>
...
</VirtualHost>

Lastly, make sure your wordpress/.htaccess file contains at least the following to ensure that files are served directly:

1
2
3
4
5
6
7
8
9
10
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

R.I.P. Jerry Lewis

Author: , Posted on Monday, August 21st, 2017 at 9:38:08am

maxresdefault
803full-cinderfella-photo

tiux3ng8y6uz7z0tzh50

dean-martin-jerry-lewis

R.I.P. John Heard

Author: , Posted on Tuesday, July 25th, 2017 at 1:41:37pm
John Heard

John Heard
Born: March 7, 1945, Washington, D.C.
Died: July 21, 2017

R.I.P. Martin Landau

Author: , Posted on Sunday, July 16th, 2017 at 12:00:55pm
Born: June 20, 1928, Brooklyn, New York City, NY Died: July 15, 2017, Los Angeles, CA

Born: June 20, 1928, Brooklyn, New York City, NY
Died: July 15, 2017, Los Angeles, CA

Happy 4th of July

Author: , Posted on Monday, July 3rd, 2017 at 8:21:29am

flag

R.I.P. Stephen Furst

Author: , Posted on Sunday, June 18th, 2017 at 7:18:12am

The_Dream_Team_-_albert_the_baseball_fan