diff options
Diffstat (limited to 'Aufgabe7')
| -rw-r--r-- | Aufgabe7/db-passwd-create.pl | 48 | ||||
| -rw-r--r-- | Aufgabe7/db-passwd-fill-table.pl | 52 | ||||
| -rw-r--r-- | Aufgabe7/db-passwd-read-table.pl | 42 | ||||
| -rw-r--r-- | Aufgabe7/dbinc.pl | 28 | ||||
| -rw-r--r-- | Aufgabe7/passwd | 32 |
5 files changed, 202 insertions, 0 deletions
diff --git a/Aufgabe7/db-passwd-create.pl b/Aufgabe7/db-passwd-create.pl new file mode 100644 index 0000000..0c9c470 --- /dev/null +++ b/Aufgabe7/db-passwd-create.pl @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: db-passwd-create.pl +# +# USAGE: ./db-passwd-create.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Stefan Suhren (su), suhren.stefan@fh-swf.de +# ORGANIZATION: FH Südwestfalen, Iserlohn +# VERSION: 1.0 +# CREATED: 06.01.2016 13:40:30 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use utf8; + +# Add database modul +use DBI; + +# Get database config +my %dbconf = do 'dbinc.pl'; + +my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}) or die 'DB not accessible'; + +#Create DB +$dbhandle->do("CREATE TABLE stsuh_passwort + ( + nr INT AUTO_INCREMENT, + loginname VARCHAR(20), + password VARCHAR(20), + uid INT, + gid INT, + comment CHAR(255), + homedir CHAR(255), + commandinterpreter CHAR(255), + PRIMARY KEY (nr) + ) +") or die 'Could not create database'; + +$dbhandle->disconnect; diff --git a/Aufgabe7/db-passwd-fill-table.pl b/Aufgabe7/db-passwd-fill-table.pl new file mode 100644 index 0000000..c33f89a --- /dev/null +++ b/Aufgabe7/db-passwd-fill-table.pl @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: db-passwd-fill-table.pl +# +# USAGE: ./db-passwd-fill-table.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Stefan Suhren (su), suhren.stefan@fh-swf.de +# ORGANIZATION: FH Südwestfalen, Iserlohn +# VERSION: 1.0 +# CREATED: 06.01.2016 14:24:22 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use utf8; + +# Add database modul +use DBI; + +# Get database config +my %dbconf = do 'dbinc.pl'; + +my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}) or die 'DB not accessible'; + +my $passwdInsertSth = $dbhandle->prepare("INSERT INTO stsuh_passwort (loginname, password, uid, gid, comment, homedir, commandinterpreter) VALUES (?, ?, ?, ?, ?, ?, ?)") or die 'Preparation failed'; + +my $passwdFile_file_name = 'passwd'; # input file name + +open my $passwdFile, '<', $passwdFile_file_name + or die "$0 : failed to open input file '$passwdFile_file_name' : $!\n"; + +while (<$passwdFile>) +{ + my @passwdLine = split(':', $_); + + chomp @passwdLine; + + $passwdInsertSth->execute(@passwdLine) or die 'Execution failed'; +} + +close $passwdFile + or warn "$0 : failed to close input file '$passwdFile_file_name' : $!\n"; + +$dbhandle->disconnect; diff --git a/Aufgabe7/db-passwd-read-table.pl b/Aufgabe7/db-passwd-read-table.pl new file mode 100644 index 0000000..8e06a80 --- /dev/null +++ b/Aufgabe7/db-passwd-read-table.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: db-passwd-read-table.pl +# +# USAGE: ./db-passwd-read-table.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Stefan Suhren (su), suhren.stefan@fh-swf.de +# ORGANIZATION: FH Südwestfalen, Iserlohn +# VERSION: 1.0 +# CREATED: 06.01.2016 14:44:13 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use utf8; + +# Add database modul +use DBI; + +# Get database config +my %dbconf = do 'dbinc.pl'; + +my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}) or die 'DB not accessible'; + +my $passwdArray = $dbhandle->selectall_arrayref("SELECT * FROM stsuh_passwort"); + +printf ("%-4s | %-13s | %-8s | %-6s | %-6s | %-35s | %-25s | %-20s\n", "nr", "loginname", "password", "uid", "gid", "comment", "homedir", "commandinterpreter"); +printf ('%1$s'x140 . "\n", "-"); +foreach my $passwdRow (@$passwdArray) +{ + printf ("%4d | %-13s | %-8s | %6d | %6d | %-35s | %-25s | %-20s\n", @$passwdRow); +} + +$dbhandle->disconnect; diff --git a/Aufgabe7/dbinc.pl b/Aufgabe7/dbinc.pl new file mode 100644 index 0000000..33da66c --- /dev/null +++ b/Aufgabe7/dbinc.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +#=============================================================================== +# +# FILE: dbinc.pl +# +# USAGE: ./dbinc.pl +# +# DESCRIPTION: Config file for database parameter. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: Stefan Suhren (su), suhren.stefan@fh-swf.de +# ORGANIZATION: FH Südwestfalen, Iserlohn +# VERSION: 1.0 +# CREATED: 06.01.2016 13:56:31 +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use utf8; + +dbhost => 'localhost', +dbdatabase => 'skript', +dbuser => 'root', +dbpasswd => '', diff --git a/Aufgabe7/passwd b/Aufgabe7/passwd new file mode 100644 index 0000000..0d98a7a --- /dev/null +++ b/Aufgabe7/passwd @@ -0,0 +1,32 @@ +at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash +avahi:x:492:490:User for Avahi:/var/run/avahi-daemon:/bin/false +avahi-autoipd:x:499:498:User for Avahi IPv4LL:/var/lib/avahi-autoipd:/bin/false +bin:x:1:1:bin:/bin:/bin/bash +daemon:x:2:2:Daemon:/sbin:/bin/bash +dnsmasq:x:493:65534:dnsmasq:/var/lib/empty:/bin/false +ftp:x:40:49:FTP account:/srv/ftp:/bin/bash +games:x:12:100:Games account:/var/games:/bin/bash +kdm:x:486:484:KDM Display Manager daemon:/var:/bin/false +lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash +mail:x:8:12:Mailer daemon:/var/spool/clientmqueue:/bin/false +man:x:13:62:Manual pages viewer:/var/cache/man:/bin/bash +messagebus:x:498:494:User for D-Bus:/run/dbus:/bin/false +mysql:x:60:499:MySQL database admin:/var/lib/mysql:/bin/false +news:x:9:13:News system:/etc/news:/bin/bash +nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash +nscd:x:495:492:User for nscd:/var/run/nscd:/sbin/nologin +ntp:x:74:497:NTP daemon:/var/lib/ntp:/bin/false +polkitd:x:490:489:User for polkitd:/var/lib/polkit:/sbin/nologin +postfix:x:51:51:Postfix Daemon:/var/spool/postfix:/bin/false +pulse:x:488:487:PulseAudio daemon:/var/lib/pulseaudio:/sbin/nologin +root:x:0:0:root:/root:/bin/bash +rtkit:x:489:488:RealtimeKit:/proc:/bin/false +scard:x:487:485:Smart Card Reader:/var/run/pcscd:/usr/sbin/nologin +sshd:x:496:493:SSH daemon:/var/lib/sshd:/bin/false +statd:x:491:65534:NFS statd daemon:/var/lib/nfs:/sbin/nologin +tftp:x:494:491:TFTP account:/srv/tftpboot:/bin/false +usbmux:x:497:65534:usbmuxd daemon:/var/lib/usbmuxd:/sbin/nologin +uucp:x:10:14:Unix-to-Unix CoPy system:/etc/uucp:/bin/bash +wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false +student:x:1000:100:Student:/home/student:/bin/bash +svn:x:485:483:user for Apache Subversion svnserve:/srv/svn:/sbin/nologin |
