How To Create a Single Custom Post Type Template for Genesis in WordPress

Author: , Posted on Saturday, October 21st, 2017 at 8:37:25am

wordpress/wp-content/themes/yourTheme/single-yourCPTslug.php

1
2
3
4
5
6
7
8
9
10
11
add_action( 'genesis_before_entry_content', 'display_custom_fields' );
function display_custom_fields() {
    $jobTitle = get_field('_jobTitle') ?: '-';
    print <<<EOT
    <br style="clear:both"/>
    <p>Job Title: $jobTitle</p>
EOT;
}
 
// Genesis Loop
genesis();
add_action( 'genesis_before_entry_content', 'display_custom_fields' );
function display_custom_fields() {
	$jobTitle = get_field('_jobTitle') ?: '-';
	print <<<EOT
	<br style="clear:both"/>
	<p>Job Title: $jobTitle</p>
EOT;
}

// Genesis Loop
genesis();

How to Manage Remote Branches in Git

Author: , Posted on Thursday, October 19th, 2017 at 6:29:42am

Git does not download all branches unless you tell it to. Until then, they are ‘remote’ branches.

Use -r to list remote branches:
git branch -r
git fetch --all
git pull --all

If you see this error:
fatal: The current branch CT-37 has no upstream branch.

Push the current branch and set the remote as upstream:
git push --set-upstream origin CT-37

How To Revert a Single File in Git to Match the Master Branch

Author: , Posted on Thursday, October 19th, 2017 at 6:21:04am

If you want to revert the file to its state in master:

git checkout origin/master [filename]

How To Clean Up Lost Disk Space in MacOS High Sierra

Author: , Posted on Thursday, October 12th, 2017 at 10:17:46am

Reposted from https://mcbguru.blog/2017/10/12/macos-high-sierra-disk-space/

The new APFS creates snapshots during local Time Machine backups, and this can mean, especially if you’be been dealing with some large files, that when you delete them and empty the wastebasket, you don’t get your disk space back.
The key is to look at your local backups, and the easiest method for that is the tmutil command. In particular, check the list of local snapshots:

1
2
3
4
5
6
7
8
$ tmutil listlocalsnapshots /
com.apple.TimeMachine.2017-10-06-163649
com.apple.TimeMachine.2017-10-07-065814
com.apple.TimeMachine.2017-10-11-165349
com.apple.TimeMachine.2017-10-11-19345
com.apple.TimeMachine.2017-10-11-203645
com.apple.TimeMachine.2017-10-12-003803
com.apple.TimeMachine.2017-10-12-124712
$ tmutil listlocalsnapshots /
com.apple.TimeMachine.2017-10-06-163649
com.apple.TimeMachine.2017-10-07-065814
com.apple.TimeMachine.2017-10-11-165349
com.apple.TimeMachine.2017-10-11-19345
com.apple.TimeMachine.2017-10-11-203645
com.apple.TimeMachine.2017-10-12-003803
com.apple.TimeMachine.2017-10-12-124712

These are normally managed automatically using a combination of the date/age of the backup and the space they are using compared to how much disk space you need. All this happens automatically in the background for you.
But, if you’ve just done some house cleaning, or you’ve come back from using a lot of disk space and want to free it up, you’ll need to get rid of those old snapshots. You can do them individually using:
$ tmutil deletelocalsnapshots
But it’s easier to just purge the snapshots and specify how many you many want to get rid of. That will leave you with some recent snapshots but still recover some diskspace, for that, use this command:
$ tmutil thinlocalsnapshots [purgeamount] [urgency]
That [purgeamount] is how much space you want to recover in the process, and the [urgency] is a number (1-4) of how quickly you want the space recovered. Both are optional.
For me, I just ran the thinning and that left me with:

1
2
3
4
$ tmutil thinlocalsnapshots /
Thinned local snapshots:
2017-10-06-163649
2017-10-07-065814
$ tmutil thinlocalsnapshots /
Thinned local snapshots:
2017-10-06-163649
2017-10-07-065814

How To get haproxy status via socket using cli

Author: , Posted on Friday, October 6th, 2017 at 10:25:17am

echo "show stat" | nc -U /var/lib/haproxy/stats | cut -d "," -f 1,2,5-11,18,24,27,30,36,50,37,56,57,62 | column -s, -t

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