Kategorien
Allgemein Vue

Slots

Daten von außen nach innen reichen. Slots sind Platzhalter, die von außen gefüllt werden. So kann bspw. vorgegeben werden welche Angaben erwartet werden.

#default
<slot></slot>
<slot name="title"></slot>


Von außen angesteuert:
<template v-slot:title>Text der durchgereicht wird</template>

Kurzschreibweise
<template #title>Titeltext</template>

Freigabe von Daten von innen nach aussen

Definition Slot-Name
<slot name="eventdaten" :eventNameVonAussen="eventDaten"></slot>

Ansteuerung Slot mit Namen
<template #eventdaten="slotProps">{{ slotProps.eventDaten }}</template>

Die Daten werden nach aussen gereicht, Vue sammelt alle Daten, Funktion, Objekte. Wir bestimmen "slotProps" in dem alles gesammelt wurde. Name frei wählbar.

Kategorien
Allgemein

XSD Validierung direkt im XML

XML mit XSD validieren

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="validation_xsd.xsd">
    <event>
        <event_id>1</event_id>
        <event_name>ICPC</event_name>
        <event_desc>5 coding questions in 2 hrs</event_desc>
        <event_tags>
            <tag id="1" displayName="coding">coding</tag>
        </event_tags>
        <event_type_participation>Team</event_type_participation>
        <event_timing>
            <event_start_datetime>2020-04-01T10:00:00</event_start_datetime>
            <event_end_datetime>2020-04-01T12:00:00</event_end_datetime>
        </event_timing>
        <event_organizer_email>abc@gmail.com</event_organizer_email>
        <event_organizer_phone>1234567890</event_organizer_phone>
    </event>
</root>
Kategorien
Allgemein Befehle Linux

Certbot renew Certificate or add new Domain





sudo /usr/local/bin/certbot-auto --apache
sudo systemctl restart httpd

Kategorien
Allgemein Mysql,MariaDB

Export and Import all MySQL databases at one time

Export all Databases and Tables

mysqldump -u root -p --all-databases > alldb.sql

// Sometimes problems with tablespaces then use
mysqldump -u root -p --all-databases > alldb.sql

SINGLE Database

mysqldump -u root -p db1 db2 dbx > alldb.sql

mysqldump -u root -p db1 db2 dbx > db.sql

#some hoster have sometimes problems with tablespaces
mysqldump -h hostnameOrIp -u root -p --no-tablespaces db1 db2 dbx > alldb.sql

INNODB Database Export

mysqldump.exe -u root -v --single-transaction --single-transaction --skip-lock-tables database_name_to_export > filename.sql

-v show all exporting line
–single_transaction flag will start a transaction before running. Rather than lock the entire database, this will let mysqldump read the database in the current state at the time of the transaction, making for a consistent data dump.

Import Databases

All Databases

mysql> sudo mysql -u root -p db_name < export.sql

Single Database

mysql> CREATE DATABASE db_name;
mysql> sudo mysql -u root -p db_name <  export.sql

Kategorien
XML

Array →XML

Normal Array to XML Format. Sometimes i ve the competetion in projects to parse to in differently formats i.e. API response formats (JSON,XML) and so on.

1.STEP
We

$data =
                [
                    'status' =>  $exception->getStatus(),
                    'error' =>   $exception->getCode(),
                    'message' =>  $exception->getMessage(),
                    'errors'  => $exception->getErrors()
                ];

2.STEP
Create SimpleXMLElement Object then pass addChild elements and then asXML does the rest.

$xmlobj = new SimpleXMLElement('<response/>');

Flip $data 😉 Keys and Values otherwise twisted
$toxml = array_flip($data); 
array_walk_recursive($toxml, array ($xmlobj, 'addChild'));

echo $xmlobj->asXML();

Best Solution for Multidimensional Arrays

 $xmlobj = new SimpleXMLElement('<response/>');
 array2XML($obj, $data);
 
echo $xmlobj->asXML();

function array2XML($obj, $array)
    {
        foreach ($array as $key => $value)
        {
            if(is_numeric($key))
                $key = 'item' . $key;

            if (is_array($value))
            {
                $node = $obj->addChild($key);
                $this->array2XML($node, $value);
            }
            else
            {
                $obj->addChild($key, htmlspecialchars($value));
            }
        }
    }
Kategorien
Allgemein

Samba unter Centos 8

  1. Installation
sudo dnf install samba samba-common samba-client

2.Konfiguration

sudo mv /etc/samba/smb.conf /etc/samba/smb.con.bak

smb.conf

sudo nano /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos-8
security = user
map to guest = bad user
dns proxy = no

[Anonymous]
path = /srv/samba/shared
browsable =yes
writable = yes
guest ok = yes
read only = no

Mit Authorisierung

$ sudo mkdir -p /srv/samba/shared
$ sudo chmod -R 0755 /srv/samba/shared
$ sudo chown -R nobody:nobody /srv/samba/shared
$ sudo chcon -t samba_share_t /srv/samba/shared

...am Ende zur smb.conf hinzufügen

[Share01]
        # specify shared directory
        path = /home/share01
        # allow writing
        writable = yes
        # not allow guest user (nobody)
        guest ok = no
        # allow only [smbgroup01] group
        valid users = @smbgroup01
        # set permission [777] when file created
        force create mode = 777
        # set permission [777] when folder created
        force directory mode = 777
        # inherit permissions from parent folder
        inherit permissions = yes 

Ohne Authorisierung

$ sudo mkdir -p /srv/samba/mycloud
$ sudo chmod -R 0755 /srv/samba/mycloud
$ sudo chown -R nobody:nobody /srv/samba/mycloud
$ sudo chcon -t samba_share_t /srv/samba/mycloud

...am Ende zur smb.conf hinzufügen

[mycloud]
        # specify shared directory i.e. /srv/samba/private or 
        path = /home/mycloud oder 
        browseable = yes
        # allow writing
        writable = yes
        # not allow guest user (nobody)
        guest ok = yes

...SELinux allow Samba to read and write
$sudo chcon -t samba_share_t /srv/samba/mycloud -R

Konfigurationdatei testen...
$ testparm

Sambaserice neu starten
$ sudo systemctl restart {smb,nmb}

Firwallzugriff erlauben
$ sudo firewall-cmd --add-service=samba --zone=public --permanent $ sudo firewall-cmd --reload

Verbindungsfehler – Connection Errors

You do not have permission to access \\hostname\sharename. Contact your network administrator to request access.

Manchmal muss die alte Session erst beendet werden, bevor eine neue erstellt werden kann

net user \\samber-server-ip\share-name /delete

net user \\samber-server-ip\share-name /user:samba-user-password

Kategorien
Allgemein Git

.gitignore

How do I prevent .gitignore from being committed?

//open file in your local project and adding files or directories
//which excluded from commiting
.git/info/exclude

Kategorien
Allgemein IDE Stacks

XDebug with Postman

Normally we rely on browser extension to debugging with PHPStorm /VisualCode and XDebug. But Postman is an own application, so i couldnt install any extension.

The trick 🙂 only append to the end „http://myurl/service?XDEBUG_SESSION_START=PHPSTORM

Kategorien
Allgemein Git

Easy Git Deploying

You like to deploy automatically our Git Project to Production or Testing System.

We create a bare Repository and a Deployment-Directory
/home/user/project/projectname (Git Repository)
/home/user/project/testsystemname (Git Repository)

/var/www/project (Working Tree – Deployment Directory)
/var/www/testsystem (Working Tree – Deployment Directory)

  1. Create an empty „bare“ git repository on your Target (i.e. Production System or Testsystem)
mkdir -p ~/projects/projectname
cd /home/user/projects/procjectname or cd ~/projects/projectname
mkdir project-name.git

git init --bare


mkdir -p ~/projects/projectname-testsystem
cd /home/user/projects/projectname-testsystem 
alternativly cd ~/projects/testsystem
mkdir projectname-testsystem.git

git init --bare

2. User privileges, suggestioned the user has grant to Repository /home/user/projects/project/projectname.git
sudo chown -R `whoami`:`id -gn` /var/www/projectname
sudo chown -R `whoami`:`id -gn` /var/www/projectname-testsystem

3. Create a post-receive hook at 
/home/user/projects/project-name.git/hooks/post-receive/
/home/user/projects/project-name.git/hooks/post-receive

4. Edit post-receive Hook (Production Repo)
You can customize i.e. automatically composer update Project or Backup currently Project files for Rollback possibility.

This example for Production , you can also use for Testsystem.

#!/bin/sh
NOW=$(date +'%d-%m-%Y_%T')
BACKUP=/backups/project/$NOW/

TARGET="/var/www/project"
GIT_DIR="/home/birneos/projekt/guestbook"

# backup current version, in case we need to do a rollback
echo "Create Backup form Old-Version for Rollbacks"
echo "see at $BACKUP"
cp -R /var/www/project/. "$BACKUP"

while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received. Deploying master branch to production..."
        git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
    else
	echo "Ref $ref successfully received. Doing nothing: only the ${BRANCH} branch may bei deployed on this server."
    fi
done

# custom steps for deployment
# For example, let's execute composer to refresh our dependencies : 
cd /var/www/project
composer update

5. Make sure it is executable

chmod +x post-receive

6. Add the remote-repository to your local system
Let’s now add a reference to this bare repository to our local system, as a remote location. Let’s call this remote „production“. (It could also be called „staging“ or „live“ or „test“… should you want to deploy to a different system or to multiple systems.)

cd ~/path/to/working-copy/
$ git remote add production ssh://username@myserver.com:22/path/to/project/folder/project-name.git

OR THE ALTERNATIVE...
# ~/project/projectname (the tilde means login into home directory from user (user@remoteip)

cd ~/path/to/working-copy/

git remote add production user@remoteip:~/projekt/projectname

git remote add testsystem birneos@remoteip:~/projekt/projectname-testsystem

7. Check git remote references

git remote -v

8. Thats it. let go and pushing…

git push production master 
git push testsystem master
git push staging master

Kategorien
Linux

Tar Archive , Backups – Exclude Directories


tar -cvzpf backup.tar --exclude=vendor --exclude="logs/" --exclude="tmp/" /var/www/your/project/

-c … create Archive
-v …and show me
-z …compress that
-p …take over all permissions
-f …to folder

Unpacking

tar -xzf archiv.tar.gz -C /home/verzeichnis1/archiv_verzeichnis

-x ...extract archive
-z ...that compressed  
-f ...to folder