ToHo-Blog

Mein Foto
Name:
Standort: Germany

made 62

Freitag, Oktober 22, 2021

mypath - Command line Tool für einfache PATH-Änderung auf Windows (Perl)

 mypath - Command line Tool  for easy changing PATH on Windows (Perl)

Dieses Tool ist als Project auf github abgelegt. Eine Suche auf github findet es: "mypath perl" . Der direkte Link bei Klick auf diese Worte mypath changing path windows perl  Wie oft bei solch kleinen Projekten lag der Schwerpunkt auf Funktionalität und nicht auf Schönheit. 

Der Hauptgedanke dahinter war, bei kurzfristigen Änderungen des PATH nicht immer den Schritt über 

Systemsteuerung >> System >> Erweiterte Systemeinstellungen (Systemeigenschaften) >> Umgebungsvariablen

 gehen zu müssen. Zudem ist der Zugang auf die Erweiterten Einstellungen oft an die Rechte eines local Admin gebunden.

Die Vorbedingungen sind:

  • ein installiertes Perl und der Pfad der ausführbaren Datei (perl.exe) im PATH,
  • alle notwendigen Dateien befinden sich in D:\temp , sonst Programmierung ändern,
  • das Verzeichnis D:\temp befindet sich bereits in der PATH-Variable im Environment

Die Benutzung 
bietet zwei verschiedene Aufrufe:

Die Bearbeitung:

perl mypath.pl [-q] {delete|unshift|push} (dir1) [{delete|unshift|push} (dir2) ..]

Damit können Verzeichnisse gelöscht, am Anfang oder am Ende zum PATH hinzugefügt werden. Bei Verzeichnissen mit Leerzeichen müssen diese in Anführungszeichen (double quote) eingeschlossen werden. Da der PATH durch Perl unter Windows nicht an die übergeordnete Instanz der Kommandozeile durchgereicht werden kann, muss anschließend die Batch-Datei mypathnew.bat ausgeführt werden, die auch im Verzeichnis D:\temp liegt.

Die Auflistung:

perl mypath.pl list [-all|(dir-fragment)]

Damit können alle oder ausgewählte Verzeichnisse der Path-Variable aufgelistet werden. Der Parameter -all ist dabei optional. Für die Suche nach bestimmten Verzeichnissen genügt ein Bruchstück des Verzeichnisnamens.

Es existiert ein Schalter -q für stille (quiet) Verarbeitung. Dabei werden ein paar Ausgaben während der Verarbeitung unterdrückt. Zu diesem Schalter gibt es eine Alternative, man setzt die Environment Variable: 

MYPATH_QUIET=[Ja|Yes|true|1|-q|On]

Beim Auflisten (zweite Form der Benutzung) hat dieser Schalter keine Wirkung.

Labels: , , , , ,

Dienstag, April 03, 2018

User authentication in XAMPP with Apache webserver under Windows

What is the starting point?

Under some circumstances there may be the need for a litte project on a webserver under Windows. There may exist more applications than this, but XAMPP has gained space in this task area and its utilisation is spread wide. XAMPP comes with Apache webserver, a DB, PHP and Perl. It is easy to install also by non-experts.

For some reasons parts of the webserver or its applications may have the need for restriction and user authentication. One way to implement this is the use of the .htaccess mechanism.

Why to use .htaccess mechanism?

With the file .htaccess you have the possibility to configure the user authentication without the need to change the Apache configuration files. Because the first character of the file name is a dot the file will be hidden in the directory for simple usage cases.

The file can be created with a text editor. Pay attention to give as the name only ".htaccess" (without the quotation marks) without a further file name extension. Then copy it to the website directory which you want to secure.

Be sure to place the file .htaccess exactly in the directory you want the user authentication to apply to. The settings in this .htaccess will affect everything in this directory and the below placed directories.
______________________________________________


Not with XAMPP - but in case you would use a Linux server or a Raspberry Pi you would have to activate the .htaccess file:

Activate the .htaccess file

The activation has to be done in the Apache configuration to allow the .htaccess to override the Apache config settings. BTW you need sudo rights to do this.
sudo nano /etc/apache2/sites-available/default
Or instead of nano use your prefered editor. In editing this file input the necessary content:
 <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
 </Directory>
After saving this file do a restart for Apache
 sudo service apache2 restart
______________________________________________

Create the new .htaccess file

If you did install XAMPP in D:\XAMPP and your application is in directory D:\XAMPP\htdocs\myapp (with underlying directory cgi-bin) then edit the .htaccess file this way (again, choose your prefered editor instead of nano):
nano D:/XAMPP/htdocs/myapp/.htaccess
.. input the content:
AuthUserFile /xampp/usr/.htpasswd
AuthGroupFile /dev/null
AuthName "Please Enter Password"
AuthType Basic
Require valid-user
Create the .htpasswd file

Besides the .htaccess file you need the user authentication file .htpasswd . Place it outside the web-home dir i.e. as sibbling usr in this path: D:/XAMPP/usr
To create the file use the webserver password creation application htpasswd (for XAMPP in D:\xampp\apache\bin\).

 D:\xampp\apache\bin\htpasswd -c -b D:\xampp\usr\.htpasswd jsmith awesome
This will create a line in the .htpasswd file looking like this: jsmith:VtweQU73iyETM
I had another case where the generated encrypted password was different and much longer. To be sure, every time use the htpasswd application. The switch -c creates a new file and the switch -b tells the generation to use the password given at the command line.

First time I did test it with these steps, unfortunately it didn't work. The solution included more parts. One was the usage of the password generation application htpasswd instead of creating it by using the simple crypt() function. In case of XAMPP under Windows the line ending had to be Windows style with \r\n (carriage return + line feed) instead of Linux style under a Linux system which consists only of \n (line feed or new line).

If you have difficulties don't hesitate to contact me.

Labels: , , , , , , ,

Montag, Oktober 30, 2017

Google Mail and blocked attachments

little helper Perl-script

Subject:
Since Oct 24. 2017 I noticed changes in GMail behaviour on attachments.

What was the starting point?

Some years ago I had the requirement to send me or a colleague some
files. These files did include executables, which is impossible as
GMail attachment. Gmail blocks this for security reasons. I know that
there are other ways like Dropbox or other Cloud services. But in this
case e-mail was prefered for some reasons.

I'm working on Windows OS. So there may be better solutions under
Linux systems. The goal was to set up a script for comfortable
handling these mail attachments which means simple encrypting and
decrypting for sending in GMail. Also it should self set some
preferences as the destination filename in encrypting. And it should
recognize if it was an already encoded file on it's file-extension
(.b64). Besides this it further should cover and change known
file-extensions such as *.zip, *.bat, *.cmd, *.exe in replacing last
character with "_" (*.zi_ and so on). This did work fine with simple
base64 encrypting till the Oct 24 2017. The base64 encoded files could
be attached without any issues on a GMail e-mail.

What did happen? / What is the solution?

On the named date it did not work any longer. It seems Google did
recognize base64 encoded files. I thought on a simple solution to keep
the process running. The idea was that Google should not _see_ that it
was base64 .. and look into if there are zip's or executables. I
simply added a following ROT13 character shift in encoding. The
file-ext for encoding was set to *.b64.r13 .

The script runs with a Perl installation. On missing destination file
name it automatically sets an file-ext for destination. It recognizes
an already encrypted file on it's extension *.b64.r13 and does a
decode in this case. The base64 and ROT13-encoded files can be
attached without any difficulty to a GMail e-mail. The call on an
encrypted file does the reverse. The call of the Perl-script is done
with a batch-file wich should be able to found through PATH-variable.
An possibly overwrite is recognized and can be avoided.

The help message states:

baserot.pl - Benutzung/Usage: 
[perl] baserot.pl [-e|-d] [-o] (quelldatei/source) [(zieldatei/destination)]
-e       encode (default)
-d       decode
-o       overwrite existing
-h|help  diese Hilfe/this help
ext(encode) = .b64.r13 (if no dest set)
source ext .b64.r13 = action: decode
Project is on Github: https://github.com/toohoo/base64rot13

Labels: , , , , ,