ADD Subscribers option?

Discussion related to NP Subscriber.

ADD Subscribers option?

Postby outaline » Mon Mar 12, 2007 3:46 am

I tried the Pro version but I really love the simplicity of the regular Subscriber version. The only part I miss is the ability to add subscribers in the admin interface.

I tried to copy add_subs function from the Pro version but it didn't work. Is there anything I need to do to make the add_subs function work in the Subscriber version?

Thanks for your time!

Master of the Copy and Paste Coding Technique :)
outaline
 
Posts: 3
Joined: Mon Mar 12, 2007 3:25 am

Postby Admin-BS » Mon Mar 12, 2007 11:42 am

It's actually far more complicated than that. You need to add these lines where they belong toward the top of the subscriber.cgi file:
Code: Select all
elsif ($query eq "add_subs") {&add_subs}
elsif ($FORM{'action'} eq "add_subs" && &check_ip) {&add_subs2}


Then you need to basically copy the add_subs2 function from the pro version. Within this function you can strip out any SQL related code, the reference to the banned_domains file, and of course any occurrence of $FORM{'list'} (making sure to remove the trailing slash too since the paths are relative) since the basic version only supports one list.

Or... you can just add the addresses manually to the subscribers.txt file if you really need to. The format for the file is just simply the address followed by a return. I would say that's the easier option. ;)
Admin-BS
Site Admin
 
Posts: 99
Joined: Sat Dec 31, 2005 6:52 pm
Location: USA

Postby outaline » Mon Mar 12, 2007 5:43 pm

OK. I am a glutton for punishment. The thing is that the person that will be manually adding subscribers won't have FTP access so a web based option will work better.

I added the query thingamajiggy in the right spot I think and I now actually get to the page where I can add subscribers but after I click add nothing happens. I feel like I am so close yet so far. I deleted the sql and banned stuff, although I wasn't sure about the $FORM{'list'} part. Could you take a peek at it when you get a spare moment?



######################################################################
# ADD SUBSCRIBERS
######################################################################
# SUB ADD_SUBS : SCREEN TO ADD SUBSCRIBERS
####
sub add_subs {
print <<ENDofHTML;
<HTML>
<head><title>Admin :: Add Subscribers</title></head>
$header

<center><font size=+2><b><u>Add Subscribers</u></b></font></center>

<p align="justify">Here you can add subscribers to your subscribers.txt file. Each address must be seperated by a newline (no commas, semicolons, colons, intestines, or spaces!), just like the subscribers.txt file itself. These addresses are added automatically (the addresses will not have to be confirmed).</p>

<form action="$script" method="POST">

<textarea name="subs" cols=50 rows=15></textarea><BR><BR>

Do you want your subscribers to be subscribed as HTML or plain text subscribers?

<select name="html"><option>Plain Text</option><option>HTML</option></select><BR><BR>

<input type="hidden" name="action" value="add_subs">
<input type="Submit" name="Submit" value="Add">
</form>


<center><FORM ACTION="$script?testpass" METHOD="POST"><INPUT TYPE="hidden" NAME="password" value="$pass"><input type="hidden" name="list" value="ADD"><input type="submit" name="action" value="BACK TO ADMIN"></FORM></CENTER>

$footer
</body></html>

ENDofHTML
}


# SUB ADD_SUBS2 : ACTUALLY ADDS SUBSCRIBERS
####
sub add_subs2 {
$FORM{'subs'} =~ s/\r//g;

@subs = split(/\n/,$FORM{'subs'});
SUB_CHECK: foreach $sub(@subs) {
if ($sub =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(,)/ || $sub !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) {push(@bad_format,$sub); next SUB_CHECK;}

# CHECK FOR ALREADY SUBSCRIBED

{
open(SUBS,"subscribers.txt");
@current_subs = <SUBS>;
close(SUBS);

foreach $current_sub(@current_subs) {
@subber = split(/ :: /,$current_sub);
if ($sub eq "$subber[0]") {push(@already_subscribed,$subber[0]); next SUB_CHECK;}
}
}




}

if ($FORM{'html'} eq "HTML") {$html = "1";}
else {$html = "0";}





# TEXT FILE
{
open(SUBS,"subscribers.txt") || die "can't open susbcribers.txt... WHAT???";
foreach $subscriber(@to_add) {
@nums = qw(0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z);
$newcode0 = int(rand(@nums));
$newcode1 = int(rand(@nums));
$newcode2 = int(rand(@nums));
$newcode3 = int(rand(@nums));
$newcode4 = int(rand(@nums));
$newcode5 = int(rand(@nums));
$newcode6 = int(rand(@nums));
$newcode7 = int(rand(@nums));
$newcode8 = int(rand(@nums));
$newcode9 = int(rand(@nums));
$newcode = "$newcode0$newcode1$newcode2$newcode3$newcode4$newcode5$newcode6$newcode7$newcode8$newcode9";
print SUBS "$subscriber :: $newcode :: $html :: :: :: :: :: :: ";
@time = localtime;
print SUBS "@time";
print SUBS "\n";
}
close(SUBS);
}

&req;

print <<ENDofHTML;
<HTML>
<head><title>Admin :: Addresses Added</title></head>
$header

<center><font size=+2><b><u>Addresses Added</u></b></font></center>
ENDofHTML

print "<p>The following addresses have been subscribed to <b>$listname</b>:";
foreach $address(@to_add) {print "<li type=square>$address</li>";}
if (@already_subscribed) {print "</p><p>The following addresses were already subscribed so they weren't added:";
foreach $address(@already_subscribed) {print "<li type=square>$address</li>";}}
if (@bad_format) {print "</p><p>The following addresses aren't formatted correctly and weren't added :</b>";
foreach $address(@bad_format) {print "<li type=square>$address</li>";}}
if (@old_subscribers) {print "</p><p>These are addresses of previous subscribers, so they weren't added:</b>";
foreach $address(@old_subscribers) {print "<li type=square>$address</li>";}}
if (@banned_subs) {print "</p><p>The following addresses are banned from subscribing:</b>";
foreach $address(@banned_subs) {print "<li type=square>$address</li>";}}
if (@banned_domains) {print "</p><p>The following addresses contain banned domains:</b>";
foreach $address(@banned_domains) {print "<li type=square>$address</li>";}}
print <<ENDofHTML;
</p>
<center><FORM ACTION="$script?testpass" METHOD="POST"><INPUT TYPE="hidden" NAME="password" value="$pass"><input type="hidden" name="list" value="ADD"><input type="submit" name="action" value="BACK TO ADMIN"></FORM></CENTER>

$footer
</body></html>

ENDofHTML

}
######################################################################
# END ADD SUBSCRIBERS
######################################################################
outaline
 
Posts: 3
Joined: Mon Mar 12, 2007 3:25 am

Postby Admin-BS » Mon Mar 12, 2007 6:43 pm

For starters, if you haven't already, you should probably go ahead and make sure the line use CGI::Carp "fatalsToBrowser"; is uncommented.

The line where subscribers are going to be written to the subscribers.txt file (the one with the sorta sarcastic error message...) needs to be opened with +>> so that it is appended (or created if it somehow doesn't exist). So, the line should be:
open(SUBS,"+>>subscribers.txt") || die "can't open susbcribers.txt... WHAT???";

Also, you need to remove some of the enclosing curly braces from what used to be an else statement (which it isn't anymore since you removed all the SQL stuff).

I don't quite know if this will fix it, but it's a start. Maybe at least now you'll get an error message...
Admin-BS
Site Admin
 
Posts: 99
Joined: Sat Dec 31, 2005 6:52 pm
Location: USA


Return to Subscriber

Who is online

Users browsing this forum: No registered users and 1 guest

cron