Results 1 to 10 of 12
I had to make a webmin Module and since I had to do that in Perl I thought.. oh crud..
Well, Ive never coded before in Perl but yea its ...
- 09-14-2007 #1
My very First Perl Script..
I had to make a webmin Module and since I had to do that in Perl I thought.. oh crud..
Well, Ive never coded before in Perl but yea its good to learn it isnt it..
But I prefer to start with Hello World next time... (lol)
Anywho, I am already a good friend with C++ and a accuintence(Guess this is wrong writen, I mean someone who you know but isnt your friend) with Assembler.. and I also know C# and VB (Yea my school wants to turn is into Microsoft Dudes.. I am for example not allowed to run A linux live USB as Desktop..)
But ok since I am known with Coding I thought, perl.. Piece a Cake..
well I guess I was wrong XD
Anywho,
well I wrote my Code.. And it is a bit messy I guess and well it doesnt work..
When I upload it to my Webmin as a Module and Install it it gives me the error:
Error - Perl execution failed
syntax error at /usr/libexec/webmin/iDesk/index.cgi line 10, near "head>"
And Ive no Idea what why or how that comes since that part is still just plain HTML :/
Anywho, here is my code:
well is here someone who wants to help me with stepping into the Great world of Perl and give me a Hand?Code:#!/usr/local/bin/perl print "content-type: text/html print " #Show all users in table in the Following format: #Username | EnabledIcons | <Enabled/Disabled Status> | <edit button> #On the Button put Button Change Global Settings <head><title>iDesk Webmin Module</title></head> <body> <TABLE border=4> <TR> <TD><strong>Username</strong></TD><TD><strong>Enabled Icons</strong></TD><TD><strong>Status</strong></TD><TD><strong>Edit</strong></TD>"; #Read File /etc/passwd open (PASSWDFILE, "/etc/passwd"); while ($record = <PASSWDFILE>) { #Filter out everyone from UID 1000 of Bigger #Thats the 3th Collum and set %HOMEDIR% to the 6th Collum $FirstCollumEnds = index($record,":"0) $SecondCollumEnds = index($record,":"FirstCollumEnds) $ThirthCollumEnds = index($record,":"SecondCollumEnds) $FourthCollumEnds = index($record,":"ThirthCollumEnds) $FifthCollumEnds = index($record,":"FourthCollumEnds) $SixthCollumEnds = index($record,":"FifthCollumEnds) $SeventhCollumEnds = index($record,":"SixthCollumEnds) #THIRT COLLUM IS 1000 OR HIGHER if(substr($record, $SecondCollumEnds, ($ThirthCollumEnds-$SecondCollumEnds))=<1000) { #Set %Username% to First Collum Value $Username = substr($record, 0, $SecondCollumEnds); print "<TD> $Username </TD>"; #Read "ls %HOMEDIR%/.idesktop" $homedir = substr($record, $FifthCollumEnds, $SixthCollumEnds); $output = ls($homedir/.idesktop); print "<TD> $output </TD>"; #Read if iDesk files and directorys exist: #File %HOMEDIR%/.ideskrc and dir %HOMEDIR%/.idesktop if(($homedir/.idesktop/)&& ($homedir/.ideskrc)) {print "<TD> FOUND </TD>";}else {print "<TD> Not Found </TD>";} print "<TD> <form ONCLICK="window.location.href = "./edituser.cgi %Username""><button>Edit</button></form> </TD> #I assume that Perl can parse Arguments.. </TR>"; } }#Check for another. close(PASSWDFILE); #When everything is found do: print "<form ONCLICK="window.location.href = "./changeglobal.cgi""><button>Change Global Settings</button></form> </body>";
Any help will be usefull I guess..
And yea, I know I can better start with Hello World as first script..
But, I dont have time for a Large How To Learn perl in 14 Days tutorial.
Cheers
- Robin
- 09-14-2007 #2Just Joined!
- Join Date
- Sep 2007
- Location
- Oxford, Uk
- Posts
- 6
I not too familier with perl, but your placements of quotes dont look right, you havent closed a quote before opening another. maybe that is causing the problem. It just creates simular results when i tried it in my interpreter
- 09-14-2007 #3
lol, ok well that is just a Stupid mistake.. Lets see if it works now..
Since I am not anymore at work now I cant test it but I can next monday..
Thanks ^^
(I am such an Idiot.. -.-' )
After browsing in my code I found some more myself..
I really need coffee..Code:#!/usr/local/bin/perl print "content-type: text/html #Show all users in table in the Following format: #Username | EnabledIcons | <Enabled/Disabled Status> | <edit button> #On the Button put Button Change Global Settings <head><title>iDesk Webmin Module</title></head> <body> <TABLE border=4> <TR> <TD><strong>Username</strong></TD><TD><strong>Enabled Icons</strong></TD><TD><strong>Status</strong></TD><TD><strong>Edit</strong></TD></TR>"; #Read File /etc/passwd open (PASSWDFILE, "/etc/passwd"); while ($record = <PASSWDFILE>) { #Filter out everyone from UID 1000 of Bigger #Thats the 3th Collum and set %HOMEDIR% to the 6th Collum $FirstCollumEnds = index($record,":",0); $SecondCollumEnds = index($record,":",$FirstCollumEnds); $ThirthCollumEnds = index($record,":",$SecondCollumEnds); $FourthCollumEnds = index($record,":",$ThirthCollumEnds); $FifthCollumEnds = index($record,":",$FourthCollumEnds); $SixthCollumEnds = index($record,":",$FifthCollumEnds); $SeventhCollumEnds = index($record,":",$SixthCollumEnds); #THIRT COLLUM IS 1000 OR HIGHER if(substr($record, $SecondCollumEnds, ($ThirthCollumEnds-$SecondCollumEnds))ge 1000) #ge is: >= { #Set %Username% to First Collum Value $Username = substr($record, 0, $SecondCollumEnds); print "<TD> $Username </TD>"; #Read "ls %HOMEDIR%/.idesktop" $homedir = substr($record, $FifthCollumEnds, $SixthCollumEnds); $output = ls("$homedir/.idesktop"); print "<TD> $output </TD>"; #Read if iDesk files and directorys exist: #File %HOMEDIR%/.ideskrc and dir %HOMEDIR%/.idesktop if(("$homedir/.idesktop/")&& ("$homedir/.ideskrc")) {print "<TD> FOUND </TD>";}else {print "<TD> Not Found </TD>";} print "<TD> <form ONCLICK="window.location.href = "./edituser.cgi?$Username?$homedir""><button>Edit</button></form> </TD> </TR>"; } }#Check for another. close(PASSWDFILE); #When everything is found do: print "<form ONCLICK="window.location.href = "./changeglobal.cgi""><button>Change Global Settings</button></form> <form ONCLICK="window.location.href = "./reapply.cgi""><button>Rebuild All Files</button></form> </body>";
- 09-14-2007 #4Just Joined!
- Join Date
- Sep 2007
- Location
- Oxford, Uk
- Posts
- 6
some coffee and a editor that does syntax highlighting properly
- 09-14-2007 #5
- 09-14-2007 #6Just Joined!
- Join Date
- Sep 2007
- Location
- Oxford, Uk
- Posts
- 6
if you working ona windows based system, may this be the best time to recommend Notepad++, it much better then wordpad.
- 09-14-2007 #7
I agree with Notepad++. Excellent editing software for a WinBlows system. Still will always use vi on my nix systems though! :P
- 09-14-2007 #8
- 09-14-2007 #9
Hehehehe. You like that, eh?
Now introducing WinBlows V.I.S.T.A (Very Insecure Still Terrible Architecture)! Yet another product from MicroSucks! :P
Wow, we need Nix vs PC commercials!
- 09-15-2007 #10Just Joined!
- Join Date
- Sep 2007
- Posts
- 5
This is a job for a here document. It is common to Perl, bash, and a few other scripting languages, and allows an arbitrarily long string to be inserted without having to be so careful about quotes.
print <<EOL;
Blah blah blah
"Really long strings with a bunch of '' " and `` quotery type things strewn about within all willy-nill."
EOL
This says to perl: Everything that follows is a single string, until I tell you it isn't (EOL is arbitrary...you could use "SwellJoeIsCoolAndSmartAndGoodLooking", but that's a bit long to type and convention tells us to use EOL or EOF or END).
Also, you need a better editor, and you need a local Perl environment, or you need to develop in place on your server using vim or emacs (or whatever editor you like with good perl syntax highlighting). It'll take you weeks of upload, see errors, fix errors, upload again cycles to get things working. Webmin modules are harder to develop than command line Perl scripts--actually any UI application is harder to develop, and it takes more than one file. So you'll probably want to get it working on the command line, first, and then add the Webmin toppings.


Reply With Quote