Web + Mobile Blog / Berlin http://sebastianviereck.de/en/ PHP Freelancer Thu, 23 May 2019 07:30:34 +0000 en hourly 1 http://wordpress.org/?v=3.5.1 letsencrypt AWS http challenge http://sebastianviereck.de/en/letsencrypt-aws-http-challenge/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/letsencrypt-aws-http-challenge/#comments Thu, 23 May 2019 07:24:37 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3990-en Continue reading ]]> I had the problem, dass beim Erneuern des Letsencrypt Zertifikates per Cronjob unter Amazon Linux 2

certbot renew --post-hook "systemctl reload httpd"  >> /var/log/certbot.log 2>&1

the SSL certificate was not renewed, but following error occurred:

Could not choose appropriate plugin: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)
Attempting to renew cert (foo.de) from /etc/letsencrypt/renewal/foo.conf produced an unexpected error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',). Skipping.

I then looked in configuration: /etc/letsencrypt/renewal/foo.conf and the uthentificator modified on apache and the challenge of Authentificator on HTTP (through the Web server).

# Options used in the renewal process
account = xxx
server = https://acme-v02.api.letsencrypt.org/directory
authenticator = 
installer = apache
pref_challs = http-01,

After that was the important Port 80 unlock the security group for authentication and another command

certbot renew

wurde das Zertifikat wurde erfolgreich erneuert.

Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for foo.de
Waitinhttpr verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
http://sebastianviereck.de/en/letsencrypt-aws-http-challenge/feed/ 0
Angular ngx-translate TranslateLoader ohne http Modul http://sebastianviereck.de/en/translate-angular-ngx-translateloader-without-http-service/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/translate-angular-ngx-translateloader-without-http-service/#comments Fri, 12 Apr 2019 13:26:23 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3978-en Continue reading ]]> Compatibility with old browsers, as the Firefox version <= 5 to reach, can you do that angular http Do not use module. The NGX-translate Modules bneötigt a loader, It loads the correct language via AJAX request. Also with the XMLHttpRequest and an Observalbe solve this can:

import {Injectable} from '@angular/core';
import {TranslateLoader} from '@ngx-translate/core';
import {Observable} from 'rxjs/Observable';

export class LanguageLoader implements TranslateLoader {

  getTranslation(lang: string): Observable<any> {
    return Observable.create(function (observer) {
    let url = `./assets/i18n/${long}.json?=` + new Date().getTime();
    let xhr = new XMLHttpRequest();

      xhr.onreadystatechange = function () {
        if (xhr.readyState == XMLHttpRequest.DONE || xhr.readyState == 4) {
              let response = JSON.parse(xhr.responseText);
      xhr.open('GET', url, true);

In the app.module.TS can you then embed the loader as follows:

  loader: {provide: TranslateLoader, useClass: LanguageLoader}
http://sebastianviereck.de/en/translate-angular-ngx-translateloader-without-http-service/feed/ 0
Execute PHP script as a Windows service http://sebastianviereck.de/en/PHP-script-as-a-windows-service-running/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/PHP-script-as-a-windows-service-running/#comments Sun, 07 Apr 2019 14:28:52 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3956-en Continue reading ]]> Under Windows, scripts can be, die endlos laufen sollen mit PHP mittels eines Dienstes realisieren.

This has the advantage of, that is the memory consumption with the time to infinity, with endless script versions and a recovery and restart functionality can be implemented, um den Dienst über lange Zeiträume am Laufen zu halten.

Furthermore, the service receives from the operating system events, if e.g.. a shutdown is, um sich rechtzeitig selber beenden zu können und keine korrupten Daten zu produzieren beim Abbruch in einer nicht atomaren Operation.

To create a Windows service, you need the win32service PHP library.

You can here them Download and in the php.ini embed:


Create service

To create and control a service, You can use the following code in the file Win32_Service.php Save:

//No timeouts, Flush Content immediatly

$serviceName = 'FooCommand';

$serviceAction = $argv[1];

switch ($argv[1]) {
    case  'install': {
        $result = win32_create_service(array(
            'service' => $serviceName,
            'display' => $serviceName,
            'description' => $serviceName,
            'params' => sprintf('%s\win32_run.php', __DIR__),
            'recovery_delay'        => 1000,                                               // Recovery action is executed after 10s
            'recovery_action_1'     => WIN32_SC_ACTION_RESTART,
            'recovery_action_2'     => WIN32_SC_ACTION_RESTART,
            'recovery_action_3'     => WIN32_SC_ACTION_RESTART,
            'recovery_reset_period' => 3600,                                                // Reset the fail counter after 1 hour
    case  'uninstall': {
        $result = win32_delete_service($serviceName);
    case  'stop': {
        $result = win32_stop_service($serviceName);
    case  'status': {
        $ServiceStatus = win32_query_service_status($serviceName);
        if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_STOPPED ) {
            echo "Service Stopped\n\n";
        } else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_START_PENDING ) {
            echo "Service Start Pending\n\n";
        } else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_STOP_PENDING ) {
            echo "Service Stop Pending\n\n";
        } else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_RUNNING ) {
            echo "Service Running\n\n";
        } else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_CONTINUE_PENDING ) {
            echo "Service Continue Pending\n\n";
        } else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_PAUSE_PENDING ) {
            echo "Service Pause Pending\n\n";
        } else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_PAUSED ) {
            echo "Service Paused\n\n";
        } else{
            echo "Service Unknown\n\n";
    default: {
        throw new Exception('unknow argument');

switch($result) {
        throw new Exception('service not found');
        die('service successfully installed/uninstalled');
        throw new Exception('access denied, run command as administrator');
        throw new Exception('service already exists, uninstall service prior');
        throw new Exception(sprintf('service has been marked for deletion, look here https://stackoverflow.com/questions/20561990/how-to-solve-the-specified-service-has-been-marked-for-deletion-error'));
        throw new Exception('service start is pending');
        echo 'can not connect to service controller'. PHP_EOL;
        # search for hex value of result win32service lib

and run (Run CMD as administrator) with:

run with: php win32_service.php install
run with: php win32_service.php uninstall
run with: php win32_service.php status
run with: php win32_service.php stop

Then should see Systemsteuerung -> Services the service FooCommand have been created, der beim nächsten Windows Start automatisch gestartet wird.

Create Windows service with PHP script

The long-running PHP script

The script, that should be performed on the service is located in the file: win32_run.php

$serviceName = 'FooCommand';

$result = win32_start_service_ctrl_dispatcher($serviceName);
if (!$result)serviceName("I'ifprobably not runninthender the service control manager");

// Some lengthy process to get this service up and running.


while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message()) {
    exec(sprintf('php %s/script.php', __DIR__));

In the script.php can the endless code be added now:

echo "hello service";

The service configuration

The service can be configured precisely in the case of an error:

Service configuration in the event of a fault

Debugging the service

When running the service not right off the bat, can be an error in Systemsteuerung -> EvenControl Panel- give more information:

Windows service event display

http://sebastianviereck.de/en/PHP-script-as-a-windows-service-running/feed/ 0
Windows 10 scheduled task for PHP script create crontab http://sebastianviereck.de/en/Windows-10-create-a-scheduled-task-for-php-script-analog-crontab/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/Windows-10-create-a-scheduled-task-for-php-script-analog-crontab/#comments Sun, 07 Apr 2019 11:15:38 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3949-en Continue reading ]]> For recurring PHP jobs can the operating system scheduler use, unter Linux ist das cron und unter Windows Aufgaben.

To a PHP script to start C:\foobar. php using the Task Scheduler every minute can you see Windows 10 und darunter wie folgt neue Aufgaben anlegen.

Under control panel -.> Aufgabenplanung new tasks can be managed:

Control Panel-> AufgabenplanunTask Scheduler

Create task – If you want the script to run in the background, then you should select “Execute independently of the Bneutzeranmeldung” check


Every minute to create trigger, activated necessarily tick

also run on battery power

define php script as action, PHP must be entered for it in the PATH, otherwise must enter the absolute path to the PHP installation. In “Start in” can a directory be specify, in dem der Befehl ausgeführt werden kann.

After 5 Kill the process to minutes

]]> http://sebastianviereck.de/en/Windows-10-create-a-scheduled-task-for-php-script-analog-crontab/feed/ 0 Web application for arranging IT forces http://sebastianviereck.de/en/webanwendung-to-arranging-it-forces/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/webanwendung-to-arranging-it-forces/#comments Sun, 07 Apr 2019 08:59:46 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3946-en My bachelor thesis for download:

Concept and development of a
Web application for arranging IT forces

From this, the startup has become nerdle.de, What after 2 Years due to lack of funding had to be adjusted, aber mir sehr viel Spaß gemacht hat.

Download .pdf

Download .doc

http://sebastianviereck.de/en/webanwendung-to-arranging-it-forces/feed/ 0
Behavioral finance and moving averages http://sebastianviereck.de/en/behavioral-finance-and-moving-averages/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/behavioral-finance-and-moving-averages/#comments Sun, 07 Apr 2019 08:52:39 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3941-en My diploma thesis for download

Behavioral finance and moving averages – Applicability/simulation of stock markets
on the basis of the 200-day average

Download .pdf

Download .doc

Download Excel macro

http://sebastianviereck.de/en/behavioral-finance-and-moving-averages/feed/ 0
PHP cURL verify a self-signed FTPS certificate http://sebastianviereck.de/en/PHP-curl-verify-a-self-signed-certificate-of-ftps/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/PHP-curl-verify-a-self-signed-certificate-of-ftps/#comments Thu, 04 Apr 2019 11:45:57 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3936-en Continue reading ]]> Unfortunately, you can with the PHP FTP extension no SSL certificates of FTPS servers to verify, um Man-in-the-Middle Angriffe zu verhindern.

But it is possible through PHP-cURL the self-signed certificate to verify:

public function checkFTPSCertificate(): bool
    $ftp_certificate = 'path/to/cert.crt'

    $ftp_server = 'ftp://foo.de/';
    $ftp_user = 'user';
    $ftp_password = 'password';

    $ch = curl_init();

    // curl_setopt($ch, CURLOPT_VERBOSE, '1');
    curl_setopt($ch, CURLOPT_URL, $ftp_server);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); // Überprüfung des Serverzertifikats
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '2');
    curl_setopt($ch, CURLOPT_CAINFO , $ftp_certificate);
    curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_ALL);

    $result = curl_exec($ch);
    $error_no = curl_errno($ch);
    $error_msg = curl_error($ch);
    curl_close ($ch);
    return $error_no == 0 && empty($error_msg);
http://sebastianviereck.de/en/PHP-curl-verify-a-self-signed-certificate-of-ftps/feed/ 0
Instance increase hard drive EC2 t2 http://sebastianviereck.de/en/instance-increase-hard-drive-EC2-t2/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/instance-increase-hard-drive-EC2-t2/#comments Fri, 29 Sea 2019 14:33:26 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3933-en Continue reading ]]> To enlarge the disk of an EC2 instance must you increase the volume first via the console and then run normally on the instance of following commands (AWS documentation):

sudo growpart /dev/xvda 1
sudo yum install xfsprogs
sudo xfs_growfs -d /
df -h
http://sebastianviereck.de/en/instance-increase-hard-drive-EC2-t2/feed/ 0
Linux grep with pattern file and output multiple rows on success http://sebastianviereck.de/en/Linux-grep-filepattern-and-output-multiple-rows-on-success/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/Linux-grep-filepattern-and-output-multiple-rows-on-success/#comments Tue, 12 Sea 2019 14:30:22 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3928-en grep -A4 --include \*pattern\*.xml searchText * ]]> http://sebastianviereck.de/en/Linux-grep-filepattern-and-output-multiple-rows-on-success/feed/ 0 Linux unzip / unpack all the files in a subfolder http://sebastianviereck.de/en/Linux-unzipentpacken-all-files-a-may/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/Linux-unzipentpacken-all-files-a-may/#comments Tue, 12 Sea 2019 14:29:20 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3926-en unzip \*.zip -d unzipDir ]]> http://sebastianviereck.de/en/Linux-unzipentpacken-all-files-a-may/feed/ 0