Hi monks,
I Have wrote the script below but cannot find out what it is complaining about when i try to run it. I try to fix it and then make it worse!! Help much appreciated.
#! /usr/bin/perl -wT
use strict;
# where grab account details from file goes
my $username = 'bob';
my $realname = 'Bob The Great';
my $emailadd = 'a@b.com';
my $service = 'Yes';
my $ipaddr = '1.2.3.4';
my $file = 'nothing';
# Sanitise Passed Variables
if ($realname !~ /^[-.\w\s]{3,30}$/) {
# unlink $file;
print "Realname Invalid\n";
exit; }
if ($username !~ /^[A-Za-z][-.\w]{2,29}) {
# unlink $file;
print "Username Invalid\n";
exit; }
# Generate Random Password And Encrypt It
my @chars = ('a'..'z', 'A'..'Z', 0..9);
my $password = do {{
local $_ = join "" => map {$chars [rand @chars]} 1..8;
redo unless /[a-z]/ && /[A-Z]/ && /\d/;
$_;
}};
my $salt = join '',
('.', '/', 0..9,
'A'..'Z', 'a'..'z')[rand 64, rand 64];
my $encrpass = crypt($password, $salt);
#Take Current System Date And Add Two Weeks On For Trial
use constant WEEK => 60 * 60 * 24 * 7;
my $expires = sprintf '%04d-%02d-%02d',
sub { $_[5]+1900, $_[4]+1, $_[3] }->(localtime(time + 2 * WEEK));
# Create Unix User Account
# Do Stuff Here
Judging by the errors, my code is in a complete mess:
In string, @chars now must be written as \@chars at ./adduser.pl line
+22, near "$file;
print "Username Invalid\n";
exit; }
# Generate Random Password And Encrypt It
my @chars"
Global symbol "@chars" requires explicit package name at ./adduser.pl
+line 22.
Global symbol "$password" requires explicit package name at ./adduser.
+pl line 22.
Global symbol "$chars" requires explicit package name at ./adduser.pl
+line 22.
In string, @chars now must be written as \@chars at ./adduser.pl line
+22, near "$chars [rand @chars"
Global symbol "@chars" requires explicit package name at ./adduser.pl
+line 22.
syntax error at ./adduser.pl line 33, near "redo unless /["
(Might be a runaway multi-line // string starting on line 22)
Unmatched right curly bracket at ./adduser.pl line 35, at end of line
syntax error at ./adduser.pl line 35, near "}"
Execution of ./adduser.pl aborted due to compilation errors.