Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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 ...
  1. #1
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422

    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:
    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>";
    well is here someone who wants to help me with stepping into the Great world of Perl and give me a Hand?

    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
    New Users, please read this..
    Google first, then ask..

  2. #2
    Just 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

  3. #3
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    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..

    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>";
    I really need coffee..
    New Users, please read this..
    Google first, then ask..

  4. #4
    Just Joined!
    Join Date
    Sep 2007
    Location
    Oxford, Uk
    Posts
    6
    some coffee and a editor that does syntax highlighting properly

  5. #5
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    True this is all done in... Wordpad... yea a Microsoft program..

    I guess I need to get a good Perl IDE..
    New Users, please read this..
    Google first, then ask..

  6. #6
    Just 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.

  7. #7
    Just Joined! Freedom's Avatar
    Join Date
    Feb 2006
    Posts
    77
    I agree with Notepad++. Excellent editing software for a WinBlows system. Still will always use vi on my nix systems though! :P

  8. #8
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    I hate vi though.. :o
    And itis for Linux, but Im developing it in WinBlows (Good one ) since I can easy copy paste then ^^
    New Users, please read this..
    Google first, then ask..

  9. #9
    Just Joined! Freedom's Avatar
    Join Date
    Feb 2006
    Posts
    77
    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!

  10. #10
    Just 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.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...