QNAP

Retaining mounted USB-disk locations on QNAP reboot
https://forum.qnap.com/viewtopic.php?f=25&p=636810#p636810

raid 5 failed after disk swap
https://forum.qnap.com/viewtopic.php?f=25&t=135753

Drive failure while rebuilding
https://forum.qnap.com/viewtopic.php?f=25&t=122300

Changing shell prompt and title of PuTTY
.profile
export PS1=”\[\e]2;\u@\H:\w\a\[\e[32;1m\][\W #] \[\e[0m\]”

My posts:
https://forum.qnap.com/search.php?author_id=190665&sr=posts

PHP

How to Convert MySQL to MySQLi PHP Code to Upgrade to PHP7 Doing the PHP MySQL MySQLi Migration

https://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html

This is my (very rough) method, search and replace in all .php and .inc files using Perl. To re-use my code, you HAVE to make modifications and take a backup of every .php and .inc file in case somwthing goes wrong.

I converted one project at a time, these commands were used for my Amiga user’s database, so some commands will reflect specific changes/searches I did in the code to find lines to change, I also did some mistakes and corrected those. Read the commands before you try these on your code:

find . -type f -name '*.php' -exec grep -l mysql_numrows {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_numrows|mysqli_num_rows|g' {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_num_rows|mysqli_num_rows|g' {} \;

find . -type f -name '*.php' -exec perl -pi -e 's|mysql_selectdb|mysqli_select_db|g' {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_select_db|mysqli_select_db|g' {} \;
find . -type f -name '*.php' -exec grep mysqli_select_db {} \;
#
# Change to match your database name and the MySQL connection link (db name and calling parameters found above)
# Using mysql_select_db, the MySQL link identifier was optional, and sent as the second parameter
#  with mysqli_select_db it is required as a first parameter
#
find . -type f -name '*.php' -exec grep 'db("minimig_reg",\$link' {} \;
find . -type f -name '*.php' -exec grep 'db("minimig_reg")' {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|db\("minimig_reg",\$link|db\(\$link,"minimig_reg"|g' {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|db\("minimig_reg"\)|db\(\$link,"minimig_reg"\)|g' {} \;

#
# mysqli_connect returns the link identifier and also requires the database name as the fourth parameter, add it manually after this replacement
#
find . -type f -name '*.php' -exec grep mysql_connect {} \; 
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_connect|mysqli_connect|g' {} \;  

find . -type f -name '*.php' -exec grep mysql_error {} \;    
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_error()|mysqli_error(\$link)|g' {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysqli_error\(\$link\)\(\)|mysqli_error\(\$link\)|g' {} \;

find . -type f -name '*.php' -exec grep mysql_insert {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_insert_id\(\)|mysqli_insert_id\(\$link\)|g' {} \;

find . -type f -name '*.php' -exec grep mysql_query {} \;  
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_query\(|mysqli_query\(\$link,|g' {} \;

find . -type f -name '*.php' -exec perl -pi -e 's|mysql_fetch_assoc|mysqli_fetch_assoc|g' {} \;

find . -type f -name '*.php' -exec grep mysql_fetch_array {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_fetch_array\(\$result\)|mysqli_fetch_array\(\$result,MYSQLI_BOTH\)|g' {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_fetch_array\(\$result_migs\)|mysqli_fetch_array\(\$result_migs,MYSQLI_BOTH\)|g' {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_fetch_array\(\$result_info\)|mysqli_fetch_array\(\$result_info,MYSQLI_BOTH\)|g' {} \;

find . -type f -name '*.php' -exec grep mysql_real_escape_string {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_real_escape_string\(|mysqli_real_escape_string\(\$link,|g' {} \;

find . -type f -name '*.php' -exec grep mysql_affected_rows {} \;
find . -type f -name '*.php' -exec perl -pi -e 's|mysql_affected_rows\(\)|mysqli_affected_rows\(\$link\)|g' {} \;

The include files (mostly the same command lines):

find . -type f -name '*.inc' -exec grep -l mysql_numrows {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_numrows|mysqli_num_rows|g' {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_num_rows|mysqli_num_rows|g' {} \;

find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_selectdb|mysqli_select_db|g' {} \;
find . -type f -name '*.inc' -exec grep '"minimig_reg",\$link' {} \;   
find . -type f -name '*.inc' -exec perl -pi -e 's|"minimig_reg",\$link|\$link,"minimig_reg"|g' {} \;

find . -type f -name '*.inc' -exec grep mysql_connect {} \; 
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_connect|mysqli_connect|g' {} \;  

find . -type f -name '*.inc' -exec grep mysql_error {} \;    
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_error\(\)|mysqli_error\(\$link\)|g' {} \;

find . -type f -name '*.inc' -exec grep mysql_insert {} \;  
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_insert_id\(\)|mysqli_insert_id\(\$link\)|g' {} \;

find . -type f -name '*.inc' -exec grep mysql_query {} \;  
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_query\(|mysqli_query\(\$link,|g' {} \;

find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_fetch_assoc|mysqli_fetch_assoc|g' {} \;

find . -type f -name '*.inc' -exec grep mysql_fetch_array {} \;  
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_fetch_array\(\$result\)|mysqli_fetch_array\(\$result,MYSQLI_BOTH\)|g' {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_fetch_array\(\$result_migs\)|mysqli_fetch_array\(\$result_migs,MYSQLI_BOTH\)|g' {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_fetch_array\(\$result_info\)|mysqli_fetch_array\(\$result_info,MYSQLI_BOTH\)|g' {} \;

find . -type f -name '*.inc' -exec grep mysql_real_escape_string {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_real_escape_string\(|mysqli_real_escape_string\(\$link,|g' {} \;

find . -type f -name '*.inc' -exec grep mysql_affected_rows {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_affected_rows\(\)|mysqli_affected_rows\(\$link\)|g' {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|mysql_result|mysqli_result|g' {} \;

find . -type f -name '*.inc' -exec grep split {} \;
find . -type f -name '*.inc' -exec perl -pi -e 's|split\(|explode\(|g' {} \;
find . -type f -name '*.php' -exec grep split {} \;

Missing function mysqli_result (to replace mysql_result)

function mysqli_result($res,$row=0,$col=0){
    $numrows = mysqli_num_rows($res);
    if ($numrows && $row <= ($numrows-1) && $row >=0){
        mysqli_data_seek($res,$row);
        $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
        if (isset($resrow[$col])){
            return $resrow[$col];
        }
    }
    return false;
}

qmail

Installing FreeBSD and qmail
http://www.bsd-guide.net/freebsd/freebsd-base/index.php
http://www.bsd-guide.net/freebsd/freebsd-mailserver/index.php
http://www.bsd-guide.net/freebsd/freebsd-spambox/guide/index.php
http://qmailrocks.thibs.com/daemontools.php
http://qmailrocks.thibs.com/qmail-ucspi.php
https://qmail.jms1.net/history.shtml
https://qmail.jms1.net/tls-auth.shtml

Combined Patch AMD64 qmail–smtpd segfault (status 11)
https://www.google.se/search?q=tcpserver+status+11+on+64-bit+freebsd
http://qmail-patch.jms1.narkive.com/TlSh70Q7/combined-patch-amd64-qmail-smtpd-segfault
https://lists.gt.net/qmail/users/137862
https://lists.gt.net/qmail/users/116314
https://forums.freebsd.org/threads/qmail-tls-smtp-auth-patch-broken.31976/
http://qmailwiki.org/Qmail_smtps

ucspi-ssl
http://www.superscript.com/ucspi-ssl/index.html

qmail-smtpd starttls on freebsd 8.0 amd64
http://article.gmane.org/gmane.mail.qmail.jms1-patch/3514

Re: Combined Patch AMD64 qmail–smtpd segfault
http://permalink.gmane.org/gmane.mail.qmail.jms1-patch/3605

Bug 77380 – qmail-smtpd fails after starttls
https://bugs.gentoo.org/77380

https://www.google.se/search?q=DENY_TLS+64-bit+bsd

Mail stuck in queue (JMS1 qMail-patch mailinglist)
http://qmail-patch.jms1.narkive.com/NvOwqxit/mail-stuck-in-the-new-server

ClamAV fails to scan emails
https://www.virtualmin.com/node/16156

UNIX / GNU find command

Find all directories within a path that contain files matching pattern:

find . -type f -iname *adf -printf "%h\n" | sort | uniq >/tmp/adf_dirs.txt

Above is using simple wildcard matching, it is also possible to use regex:

find . -regextype sed -iregex ".*/.*\.adf$" -printf "%h\n"|sort|uniq >/tmp/adf_dirs.txt

https://stackoverflow.com/questions/6844785/how-to-use-regex-with-find-command

FreeBSD 11 installation notes

Base install

Ports, first time
portsnap fetch
portsnap extract

Ports, updating
portsnap fetch
portsnap update

Checking installed packages against ports
Using portupgrade, (“pkg install portupgrade” first)
portversion -v
Updating, using ports binaries or source
portupgrade -vaP

Cleanup of /var/db/pkg/

Apache HTTPd

Default document root
/usr/local/www/apache24/data
Configuration location
/usr/local/etc/apache24/

MySQL

Configuration file: /usr/local/etc/mysql/my.cnf
Datadir: /var/db/mysql
Initial MySQL root password in $HOME/.mysql_secret

To change password for root
root@localhost [(none)]> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this
root@localhost [(none)]>
root@localhost [(none)]> alter user ‘root@localhost’ IDENTIFIED BY ‘new_password’;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
root@localhost [(none)]> set password = ‘new_password’;
Query OK, 0 rows affected (0.02 sec)

PHP

Configuration location
/usr/local/etc/
/usr/local/etc/php/

Prepare
pkg install png-1.6.29
pkg install jpeg
pkg install libxml2
pkg install libltdl
pkg install gmake
pkg install freetype2
pkg install curl

Install PHP and modules
pkg install php71
pkg install php71-imap
pkg install php71-mcrypt
pkg install php71-curl
pkg install php71-ctype
pkg install php71-dom
pkg install php71-fileinfo
pkg install php71-filter
pkg install php71-gd
pkg install php71-hash
pkg install php71-iconv
pkg install php71-json
pkg install php71-mysql
pkg install php71-mysqli
pkg install php71-openssl
pkg install php71-pcntl
pkg install php71-session
pkg install php71-simplexml
pkg install php71-tokenizer
pkg install php71-xml
pkg install php71-zlib

Install Apache module
pkg install mod_php71