Use psexec to troll your work colleagues

If you’re an admin in a windows environment you can troll your friends a little bit 🙂

Install psexec and use bellow command to run Rick Astley’s famous “sweet troll of mine” on a remote computer (background, no window!).

psexec64 -s /user:domain\user -i \\xxx.xxx.xxx.xxx "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --app="https://youtu.be/dQw4w9WgXcQ"

xxx.xxx.xxx.xxx – stands for an ip number of a trolled person.

PS. Make sure you’re using psexec64 not psexec because it may not work on modern systems (tested on Windows 10).

How to change priority on Windows scheduled task using Powershell?

By default Windows setups task priority in scheduler to 7 (which is kinda low). The side effect of this is that for eg. backups are taking very long to take. In my case all databases were backed up in about 40-50 minutes…

Continue reading How to change priority on Windows scheduled task using Powershell?

How to force https on IIS webiste?

Edit web.config file in your website directory and carefully add this lines (remember to change domain name):


File: web.config
----------------

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Force HTTPS" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://website.com/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Brutal fix for “Incorrect string value:” error in Matomo (Piwik)

If you’re using Matomo (previously Piwik) on MS IIS and MariaDB  and you’re getting a lot of these:

[06-Jun-2018 11:56:36 UTC] Error in Matomo (tracker): Error query: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xC3_\xC6\x92\xC3\x82...' for column 'name' at row 1 In query: INSERT INTO matomo_log_action (name, hash, type, url_prefix) VALUES (?,CRC32(?),?,?) Parameters: array (   0 => 'website.com/Ă_ƒÂ¢',   1 => 'website.com/Ă_ƒÂ¢',   2 => 1,   3 => 1, )

You can use my fix (because literally nothing that can be found in the internet is helpful in this case).

Continue reading Brutal fix for “Incorrect string value:” error in Matomo (Piwik)

Backup script for PostgreSQL with zip support (Windows)

Simplest solution for backing up PostgreSQL databases. With this bat file you can dump one database to a file and compress it using 7-zip.

PS. If you want a date in your filename simply add %date% var to it’s string.
PS2. Of course check your paths before complaining it does not work 😛

@echo off
:: Global config
SET PG_BIN="C:\Program Files\PostgreSQL\9.6\bin\pg_dump.exe"
SET PG_HOST=localhost
SET PG_PORT=5432
SET PG_PATH="C:\inetpub\temporary_backups"
SET ZIP_BIN="C:\Program Files\7-Zip\7z.exe"

:: Database config for 
SET PG_DATABASE=your_database_name
SET PG_USER=your_database_user
SET PGPASSWORD=youe_database_password

SET PG_FILENAME=%PG_PATH%\%PG_DATABASE%_postgres.sql
%PG_BIN% -h %PG_HOST% -p %PG_PORT% -U %PG_USER% %PG_DATABASE% > "%PG_FILENAME%"
%ZIP_BIN% a "%PG_FILENAME:~0,-4%.zip" "%PG_FILENAME%" &DEL "%PG_FILENAME%"

@echo Backup Taken Complete %PG_PATH%%PG_FILENAME%

E-mail extraction from an Outlook copied string

Sometimes you need to extract an e-mail address from a format like this:

Name Surname <[email protected]>

In such cases use this function:

/**
 * Extract mail address from a string
 * 
 * @param string $emailString
 * @return mixed match on success, false on error
 */
function extractEmail( $emailString ) {
    /** @var string $result **/
    $result = preg_match( '/^(?:[\w.\- ]+<)?([\w._-][email protected][\da-z\.-]+\.[a-z\.]{2,6})>?$/iu', $emailString, $matches );
                               
    if( $result === 1 || $result !== false ) {
        return $matches[1];
    } else {
        return false;
    }      
}

Link to test regular expression used by me is here.