CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: Throw Down The Gauntlet:
Perl Programmers needed to help with scripts

 



suzbik
Deleted

May 31, 2000, 8:06 AM

Post #1 of 8 (6310 views)
Perl Programmers needed to help with scripts Can't Post

Hi all,

I am in the proccess of trying to write my 4th ever script, and all is not too well!

I think that I have got most of it done but it is the little parts that dont work.

The script is online at http://www.cystrix.co.uk/cgi-bin/user_pap.pl
for anyone wanting to see it as it is.

login with the username as: cystrix (the password doesnt matter)

The sourecode is at http://www.cystrix.co.uk/user_pap.txt

The parts that I am stuck on are as follows:
The email manager: I need it to be able to read a file in the fomat:-
default|address@arr.com
sales|address@arr.com
admin|address@arr.com

The idea is that the first will go into the box called default, and then for each line that follows a new box will appear along with the buttons. I have tried for ages but I cant get it to work!!

If anyone can help me out I would really appreciate it!

Thanks
Ben Periton

[This message has been edited by suzbik (edited 05-31-2000).]


monocle
User

Jun 1, 2000, 1:22 PM

Post #2 of 8 (6310 views)
Re: Perl Programmers needed to help with scripts [In reply to] Can't Post

first thing:
I am going to take a guess and say that you browse with Internet Explorer, which tends to let sloppy HTML slip by. When linking to your script (in Netscape) I see your actual HTML source not the page intended. This will likely be solved by unsing print "Content-Type: text/html\n\n"; before you ouput anything to the browser.

second thing:
I am not sure what is meant to be done here:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

local $/;{
open(FILEE, "$base/email/$user.info");
while (<FILEE> ) {
(@data) = split(/\|/,$_);
chomp($data[1]);
$default = $data[1];
chomp($data[2]);
$email1 = $data[2];
chomp($data[3]);
$email1f = $data[3];
}
close(FILEE);
}</pre><HR></BLOCKQUOTE>
but I can assume it is meant to get all the data from the data file so you can build a series of boxes and buttons using this data. This will only happen if you also put the output HTML
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

<form method="post" action="$scripturl">
<input type="hidden" name="contents" value="edit_email">
<input type="text" name="email_1" size="10" value="$email1"> goes to <input type="text" name="email_1f" size="20" value="$email1f"> <input type="submit" value="Modify" name="action"> <input type="submit" value="Delete" name="action">
</form></pre><HR></BLOCKQUOTE>
also into a loop to allow it to be printed once for each set of data you have.
But I can not even figure out how your while loop is even giving the results that you are getting on the example page. Is the example page running the exact same srcipt that is in the .txt file? How many lines of data are in the data file for this example page? You are only getting one line out and it is most likely the last line. How many fields are in each line? 2?

I wish I could be of more help, but I think I need more information.

Monocle


suzbik
Deleted

Jun 2, 2000, 1:45 AM

Post #3 of 8 (6310 views)
Re: Perl Programmers needed to help with scripts [In reply to] Can't Post

Hi, thanks for replying!

The code on the example page is exactly the
same as that in the .txt file.

In each data file, there could be an unlimited
amount of lines because it is meant to hold
all that users email forwading details.
Each line will have 2 fields, the first is
the alias and the second is the address to
forward to.

The idea was that for each lint that there
was, the script would print out:

<form method="post" action="$scripturl"><input type="hidden" name="contents" value="edit_email"><input type="text" name="email_1" size="10" value="$email1"> goes to <input type="text" name="email_1f" size="20" value="$email1f"> <input type="submit" value="Modify" name="action"> <input type="submit" value="Delete" name="action"></form>

so that the user can see what addresss they have.

I hope that is slightly clearer, and thankyou
again for replying!

Ben Periton


monocle
User

Jun 2, 2000, 12:45 PM

Post #4 of 8 (6310 views)
Re: Perl Programmers needed to help with scripts [In reply to] Can't Post

Ben,
Concider this rewrite of your &email subroutine. It makes the assumtion that the deafult alias is infact the first one in the list. I did not spend any time trying to optimize it. I think you may have been able to do this different, but I see nothing about this way that would make it slow or unstable. So if it works, use it. Someone may be able to simplify this. I got it to run on my server, but that is no promise it will run on yours. Good luck.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


sub email {

if ($user ne ""){

local $/;{
open(FILEE, "$base/email/$user.info");
while (<FILEE> ) {
(@data) = split(/\|/,$_);
}
close(FILEE);
}

chomp($data[1]);
$default = $data[1];

print qq~
<html>

<head>
<title>Personal Admin Panel for $user</title>
</head>

<body bgcolor="#99CCFF" link="#FFFFFF" vlink="#FFFFFF">
<p align="center">
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" width="59%" height="37" bordercolor="#000000">
<tr>
<td bgcolor="#003399" height="9" width="577">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
<tr>
<td valign="middle" align="left">
<p align="left"><font face="Arial" size="3" color="#FFFFFF"><b> Personal
Admin Panel for <i>$user</i></b></font></td>
<center>
<td valign="middle"><font face="Arial" size="3" color="#FFFFFF"> </font></td>
</center>
<td valign="middle">
<p align="right"><font face="Arial" size="3" color="#800000"><b><a href="$scriptul?mainmenu"><font color="#FFFFFF">MAIN MENU</a></b></font></td> </tr>
</table>
</div>
</td>
</tr>
<center>
<tr>
<td height="180" bgcolor="#3366FF" valign="top" align="left" width="59%"></center>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td>
<p align="center"><br>
<b><u><font face="Arial" color="#FFFF99" size="4">Email Manager</font></u></b></p>
<p align="left"><font face="Arial" size="2"><b><font color="#FFCD04"></p>

With the Email Manager you have complete control over where you emails are forwared to. You can add new fowarding addresses,
delete addresses and edit addresses.
<br><br>
<center>
<hr width="80%">
Email format: anything\@$user.cystrix.co.uk
<hr width="80%">
</center>
<br>
<form method="post" action="$scripturl">
<input type="hidden" name="contents" value="new_default">
Default Fowarding: <input type="text" name="default" value="$default"> <input type="submit" value="Change default">
</form>
<form method="post" action="$scripturl">
<input type="hidden" name="contents" value="new_email">
Add new alias: <input type="text" name="new_email" size="10"> forwards to <input type="text" name="new_email_for" size="20"><br>
<br><center><input type="submit" value="Add new alias"></center>
</form>
<hr width="80%">
Currently available aliases:<br><br>
~;

$number = @data - 2;
$i = 2;
while ($i < $number) {
chomp($data[$i]);
$email1 = $data[$i];
$i++;
chomp($data[$i]);
$email1f = $data[$i];
$i++;
print qq~
<form method="post" action="$scripturl">
<input type="hidden" name="contents" value="edit_email">
<input type="text" name="email_1" size="10" value="$email1"> goes to <input type="text" name="email_1f" size="20" value="$email1f"> <input type="submit" value="Modify" name="action"> <input type="submit" value="Delete" name="action">
</form>
~;
}

print qq~
<hr width="80%">
</font></b></p>
<p></td>
<td> </td>
</tr>
</table>
</center>
</div>
</td>
</tr>
<center>
<tr>
<td height="12" width="577" bgcolor="#FFFFFF">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td><b><font face="Arial" size="3"> Copyright 2000 Cystrix
Web Services</font></b></td>
<td></td>
</center>
<td>
<p align="right"><a href="mailto:Support\@cystrix.co.uk"><font face="Arial" size="3" color="#800000"><b>Support\@cystrix.co.uk</b></font></a>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>

</body>

</html>
~;
} else{&login;}
}
</pre><HR></BLOCKQUOTE>

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle


suzbik
Deleted

Jun 3, 2000, 1:40 AM

Post #5 of 8 (6310 views)
Re: Perl Programmers needed to help with scripts [In reply to] Can't Post

Hi,

Thanks so much for helping me with that!!

I hope this doesnt sound too rude, but there is one other part that has got me stumped.
It is the modification and delete buttons.

IS it possible for perl to overwrite a specific line, or to delete a specific line?

If it is, how would I do it in my emailmanager context?

Thanks again sooooo much!!!!

Perhaps when the site is fully operational, you would like to advertise your site on it. For free of course! It would be my way of thanking you.

Ben Periton


monocle
User

Jun 5, 2000, 12:54 PM

Post #6 of 8 (6310 views)
Re: Perl Programmers needed to help with scripts [In reply to] Can't Post

I believe I read somewhere that PERL was created to be a work horse for modifying and manipulating files. Based on that, I believe that anything is posible with PERL. If you could make the source (http://www.cystrix.co.uk/user_pap.txt) available again I can take a look. I some how lost the file I had. I make no promises, as I am a bit busy at the moment, but I will take a look.

And might I once again suggest using print "Content-Type: text/html\n\n"; before printing anything out to the browser. My Netscape is not giving me the log in form (only code for log in form) and I rather dislike using IE.

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle


suzbik
Deleted

Jun 5, 2000, 1:15 PM

Post #7 of 8 (6310 views)
Re: Perl Programmers needed to help with scripts [In reply to] Can't Post

Hi,

I have put the .txt file back, to see the form online, it is at: http://www.cystrix.co.uk/cgi-bin/user_pap.pl

because my subdomains are down at the moment.

Thanks
Ben Periton


monocle
User

Jun 5, 2000, 4:35 PM

Post #8 of 8 (6310 views)
Re: Perl Programmers needed to help with scripts [In reply to] Can't Post

Ben,

After looking at your script, I think it needs some work. Never fear, this is quite a project you've taken on for your 4th script.

This liitle piece of code can be used to delete a certain line from the alias file. You will need to look at the value of the submit button that submitted the form and make sure they want to delete that alias. Then call this snippet of code. It should work.
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# Read in the maillist file, check for the one to be deleted, spit the rest back out to the file
$alias_name_to_be_deleted = $FORM{'email_1'};
$alias_email_to_be_deleted = $FORM{'email_1f'};

open(ALIASLIST, "$base/email/$user.info") &#0124; &#0124; safe_die;
@lines = <ALIASLIST>;
close (ALIASLIST);

open(ALIASLIST, ">$base/email/$user.info") &#0124; &#0124; safe_die;

foreach $line (@lines) {
if (!($line =~ /$alias_name_to_be_deleted|$alias_email_to_be_deleted|/i)) {
print ALIASLIST $line;
}
}

close (ALIASLIST);
</pre><HR></BLOCKQUOTE>

As far as the modifying an alias goes. I would suggest, in addition to putting the test boxes with the alias info, you also put hidden fields with the same info. Then you could first compare the values of the text boxes with the values of the hidden fields to see if infact they were modified. Then if they were modified, you can locate the line on the data file using the hidden fields and then replace that line with the values of the text boxes. I believe this snippet of code will do just this.
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# Read in the maillist file, check for the one to be modified, replace it, spit the rest back out to the file
$old_alias_name = $FORM{'hidden_email_1'};
$old_alias_email = $FORM{'hidden_email_1f'};
$new_alias_name = $FORM{'email_1'};
$new_alias_email = $FORM{'email_1f'};

if (($old_alias_name ne $new_alias_name) and ($old_alias_email ne $new_alias_email)) {
open(ALIASLIST, "$base/email/$user.info") &#0124; &#0124; safe_die;
@lines = <ALIASLIST>;
close (ALIASLIST);

open(ALIASLIST, ">$base/email/$user.info") &#0124; &#0124; safe_die;

foreach $line (@lines) {
if ($line =~ /$old_alias_name|$old_alias_email|/i) {
print ALIASLIST "new_alias_name|new_alias_email|";
} else {
print ALIASLIST $line;
}
}

close (ALIASLIST);
}
</pre><HR></BLOCKQUOTE>

I will leave it up to you to integrate these snippets of code into your script. Practice makes perfect. Hope these work for you.

BTW, I would never think it rude for some one to ask for help. We all have to learn some how. I am always willing to help when I have the time and the solution.

Monocle
Hear great techno music by Monocle at http://www.mp3.com/monocle

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives