Web + Mobile Blog / Berlin http://sebastianviereck.de/en/ PHP Freelancer Mon, 15 Apr 2019 09:25:29 +0000 en hourly 1 http://wordpress.org/?v=3.5.1 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';

@Injectable()
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);
              observer.next(response);
              observer.complete();
        }
      }
      xhr.open('GET', url, true);
      xhr.send(zero);
    });
  }
}

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

TranslateModule.forRoot({
  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:

extension=php_win32service.dll

Create service

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

<?php
//No timeouts, Flush Content immediatly
set_time_limit(0);
ob_implicit_flush();

$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
        ));
        break;
    }
    case  'uninstall': {
        $result = win32_delete_service($serviceName);
        break;
    }
    case  'stop': {
        $result = win32_stop_service($serviceName);
        break;
    }
    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";
        }
        exit;
    }
    default: {
        throw new Exception('unknow argument');
    }
}

switch($result) {
    case WIN32_ERROR_SERVICE_DOES_NOT_EXIST:
        throw new Exception('service not found');
    case WIN32_SERVICE_ERROR_IGNORE:
        die('service successfully installed/uninstalled');
    case WIN32_ERROR_ACCESS_DENIED:
        throw new Exception('access denied, run command as administrator');
    case WIN32_ERROR_SERVICE_EXISTS:
        throw new Exception('service already exists, uninstall service prior');
    case WIN32_ERROR_SERVICE_MARKED_FOR_DELETE:
        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'));
    case WIN32_SERVICE_START_PENDING:
        throw new Exception('service start is pending');
    case WIN32_ERROR_FAILED_SERVICE_CONTROLLER_CONNECT:
        echo 'can not connect to service controller'. PHP_EOL;
        break;
    default:
        # search for hex value of result win32service lib
        debug_zval_dump($result);
}

and run (Run CMD as administrator) with:

run with: php win32_service.php install
//or
run with: php win32_service.php uninstall
//or
run with: php win32_service.php status
//or
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

<?php
set_time_limit(0);
ob_implicit_flush();
$serviceName = 'FooCommand';

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

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

win32_set_service_status(WIN32_SERVICE_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:

<?php
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);
    curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);

    $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):

lsblk
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 proftp user log traffic with mod_sql http://sebastianviereck.de/en/proftp-user-log-traffic-with-mod_sql/?utm_source=rss&utm_medium=rss& http://sebastianviereck.de/en/proftp-user-log-traffic-with-mod_sql/#comments Thu, 21 Feb 2019 08:56:23 +0000 Sebastian Viereck http://sebastianviereck.de/?p=3922-en Continue reading ]]> To the user traffic in proftp log to a MySQL database, you only need the user table a column “traffic” Add type BIGINT, Default 0:

ALTER TABLE `ftpuser` ADD COLUMN `traffic` BIGINT NOT NULL DEFAULT '0';

Then you can use a SQLNamedQuery kan in the sql.conf, to cut with the amount of traffic:

SQLLog RETR,STOR,APPE extendedlog
SQLNamedQuery extendedlog UPDATE "traffic= (traffic + %b) WHERE usertraffic" ftpuser

Attention, die Verwendung führt zu erhöhtem Traffic auf der Datenbank.

]]>
http://sebastianviereck.de/en/proftp-user-log-traffic-with-mod_sql/feed/ 0