safe web demo operation! closes: Bug#217
authorivan <ivan>
Mon, 18 Feb 2002 08:39:21 +0000 (08:39 +0000)
committerivan <ivan>
Mon, 18 Feb 2002 08:39:21 +0000 (08:39 +0000)
fix bug in edit/part_pkg: s/bkg/pkg/

edit/part_pkg.cgi - plan <SELECT> is now properly stick on errors, closes: Bug#323

FS/FS/Conf.pm
FS/FS/part_bill_event.pm
FS/FS/part_pkg.pm
htetc/global.asa
httemplate/edit/part_pkg.cgi

index 7a4a719..f8d6462 100644 (file)
@@ -734,8 +734,8 @@ httemplate/docs/config.html
   {
     'key'         => 'vpopmailrestart',
     'section'     => 'mail',
-    'description' => 'If defined, the command which is run on vpopmail machines after files are copied.  An example can be found in eg/vpopmailrestart of the source distribution.',
-    'type'        => 'text',
+    'description' => 'If defined, the shell commands to run on vpopmail machines after files are copied.  An example can be found in eg/vpopmailrestart of the source distribution.',
+    'type'        => 'textarea',
   },
 
   {
@@ -746,6 +746,13 @@ httemplate/docs/config.html
   },
 
   {
+    'key'         => 'safe-part_bill_event',
+    'section'     => 'UI',
+    'description' => 'Validates invoice event expressions against a preset list.  Useful for webdemos, annoying to powerusers.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'show_ss',
     'section'     => 'UI',
     'description' => 'Turns on display/collection of SS# in the web interface.',
index fb1daa2..70c8a56 100644 (file)
@@ -3,6 +3,7 @@ package FS::part_bill_event;
 use strict;
 use vars qw( @ISA );
 use FS::Record qw( qsearch qsearchs );
+use FS::Conf;
 
 @ISA = qw(FS::Record);
 
@@ -114,6 +115,28 @@ sub check {
 
   $self->weight(0) unless $self->weight;
 
+  my $conf = new FS::Conf;
+  if ( $conf->exists('safe-part_bill_event') ) {
+    my $error = $self->ut_anything('eventcode');
+    return $error if $error;
+
+    my $c = $self->eventcode;
+
+    $c =~ /^\s*\$cust_main\->(suspend|cancel|invoicing_list_addpost|bill|collect)\(\);\s*("";)?\s*$/
+
+      or $c =~ /^\s*\$cust_bill\->(comp|realtime_card|realtime_card_cybercash|batch_card|send)\(\);\s*$/
+
+      or $c =~ /^\s*\$cust_main\->apply_payments; \$cust_main->apply_credits; "";\s*$/
+
+      or $c =~ /^\s*\$cust_main\->charge\( \s*\d*\.?\d*\s*,\s*\'[\w \!\@\#\$\%\&\(\)\-\+\;\:\"\,\.\?\/]*\'\s*\);\s*$/
+
+      or do {
+        #log
+        return "illegal eventcode: $c";
+      };
+
+  }
+
   $self->ut_numbern('eventpart')
     || $self->ut_enum('payby', [qw( CARD BILL COMP )] )
     || $self->ut_text('event')
index 86af954..3d536e7 100644 (file)
@@ -178,19 +178,55 @@ insert and replace methods.
 sub check {
   my $self = shift;
 
-  $self->ut_numbern('pkgpart')
-    || $self->ut_text('pkg')
-    || $self->ut_text('comment')
-    || $self->ut_anything('setup')
-    || $self->ut_number('freq')
-    || $self->ut_anything('recur')
-    || $self->ut_alphan('plan')
-    || $self->ut_anything('plandata')
-    || $self->ut_enum('setuptax', [ '', 'Y' ] )
-    || $self->ut_enum('recurtax', [ '', 'Y' ] )
-    || $self->ut_enum('disabled', [ '', 'Y' ] )
-  ;
+  my $conf = new FS::Conf;
+  if ( $conf->exists('safe-part_pkg') ) {
+
+    my $error = $self->ut_anything('setup')
+                || $self->ut_anything('recur');
+    return $error if $error;
+
+    my $s = $self->setup;
+
+    $s =~ /^\s*\d*\.?\d*\s*$/ or do {
+      #log!
+      return "illegal setup: $s";
+    };
+
+    my $r = $self->recur;
+
+    $r =~ /^\s*\d*\.?\d*\s*$/
+
+      or $r =~ /^my \$mnow = \$sdate; my \(\$sec,\$min,\$hour,\$mday,\$mon,\$year\) = \(localtime\(\$sdate\) \)\[0,1,2,3,4,5\]; my \$mstart = timelocal\(0,0,0,1,\$mon,\$year\); my \$mend = timelocal\(0,0,0,1, \$mon == 11 \? 0 : \$mon\+1, \$year\+\(\$mon==11\)\); \$sdate = \$mstart; \( \$part_pkg->freq \- 1 \) \* \d*\.?\d* \/ \$part_pkg\-\>freq \+ \d*\.?\d* \/ \$part_pkg\-\>freq \* \(\$mend\-\$mnow\) \/ \(\$mend\-\$mstart\) ;\s*$/
+
+      or $r =~ /^my \$error = \$cust_pkg\->cust_main\->credit\( \s*\d*\.?\d*\s* \* scalar\(\$cust_pkg\->cust_main\->referral_cust_main_ncancelled\(\s*\d+\s*\)\), "commission" \); die \$error if \$error; \s*\d*\.?\d*\s*;\s*$/
+
+      or $r =~ /^my \$error = \$cust_pkg\->cust_main\->credit\( \s*\d*\.?\d*\s* \* scalar\(\$cust_pkg\->cust_main->referral_cust_pkg\(\s*\d+\s*\)\), "commission" \); die \$error if \$error; \s*\d*\.?\d*\s*;\s*$/
+
+      or $r =~ /^my \$error = \$cust_pkg\->cust_main\->credit\( \s*\d*\.?\d*\s* \* scalar\( grep \{ my \$pkgpart = \$_\->pkgpart; grep \{ \$_ == \$pkgpart \} \(\s*(\s*\d+,\s*)*\s*\) \} \$cust_pkg\->cust_main->referral_cust_pkg\(\s*\d+\s*\)\), "commission" \); die \$error if \$error; \s*\d*\.?\d*\s*;\s*$/
+
+      or $r =~ /^my \$hours = \$cust_pkg\->seconds_since\(\$cust_pkg\->bill \|\| 0\) \/ 3600 \- \s*\d*\.?\d*\s*; \$hours = 0 if \$hours < 0; \s*\d*\.?\d*\s* \+ \s*\d*\.?\d*\s* \* \$hours;\s*$/
+
+      or $r =~ /^my \$min = \$cust_pkg\->seconds_since\(\$cust_pkg\->bill \|\| 0\) \/ 60 \- \s*\d*\.?\d*\s*; \$min = 0 if \$min < 0; \s*\d*\.?\d*\s* \+ \s*\d*\.?\d*\s* \* \$min;\s*$/
+
+      or do {
+        #log!
+        return "illegal recur: $r";
+      };
+
+  }
 
+    $self->ut_numbern('pkgpart')
+      || $self->ut_text('pkg')
+      || $self->ut_text('comment')
+      || $self->ut_anything('setup')
+      || $self->ut_number('freq')
+      || $self->ut_anything('recur')
+      || $self->ut_alphan('plan')
+      || $self->ut_anything('plandata')
+      || $self->ut_enum('setuptax', [ '', 'Y' ] )
+      || $self->ut_enum('recurtax', [ '', 'Y' ] )
+      || $self->ut_enum('disabled', [ '', 'Y' ] )
+    ;
 }
 
 =item pkg_svc
@@ -228,7 +264,7 @@ sub svcpart {
 
 =head1 VERSION
 
-$Id: part_pkg.pm,v 1.7 2002-02-10 21:30:05 ivan Exp $
+$Id: part_pkg.pm,v 1.8 2002-02-18 08:39:21 ivan Exp $
 
 =head1 BUGS
 
index db37bf1..ce3bc27 100644 (file)
@@ -66,7 +66,9 @@ sub Script_OnFlush {
     $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
       or warn "can't remove";
   
-    $$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
+    #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
+    #  wtf?  konqueror...
+    $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()). '</PRE>';
 
     $$ref .= '</BODY></HTML>';
     
index f4ebd67..ae26881 100755 (executable)
@@ -29,8 +29,10 @@ if ( $cgi->param('clone') ) {
 } elsif ( $query && $query =~ /^(\d+)$/ ) {
   $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
 } else {
-  $part_pkg ||= new FS::part_pkg {};
-  $part_pkg->plan('flat');
+  unless ( $part_pkg ) {
+    $part_pkg = new FS::part_pkg {};
+    $part_pkg->plan('flat');
+  }
 }
 unless ( $part_pkg->plan ) { #backwards-compat
   $part_pkg->plan('flat');
@@ -279,7 +281,7 @@ tie my %plans, 'Tie::IxHash',
     },
     'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_hours', 'recur_hourly_charge' ],
     'setup' => 'what.setup_fee.value',
-    'recur' => '\'my $hours = $cust_pkg->seconds_since($cust_bkg->bill || 0) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; \' + what.recur_flat.value + \' + \' + what.recur_hourly_charge.value + \' * $hours;\'',
+    'recur' => '\'my $hours = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; \' + what.recur_flat.value + \' + \' + what.recur_hourly_charge.value + \' * $hours;\'',
   },
 
   'sesmon_minute' => {
@@ -300,7 +302,7 @@ tie my %plans, 'Tie::IxHash',
     },
     'fieldorder' => [ 'setup_fee', 'recur_flat', 'recur_included_min', 'recur_minly_charge' ],
     'setup' => 'what.setup_fee.value',
-    'recur' => '\'my $min = $cust_pkg->seconds_since($cust_bkg->bill || 0) / 60 - \' + what.recur_included_min.value + \'; $min = 0 if $min < 0; \' + what.recur_flat.value + \' + \' + what.recur_minly_charge.value + \' * $min;\'',
+    'recur' => '\'my $min = $cust_pkg->seconds_since($cust_pkg->bill || 0) / 60 - \' + what.recur_included_min.value + \'; $min = 0 if $min < 0; \' + what.recur_flat.value + \' + \' + what.recur_minly_charge.value + \' * $min;\'',
 
   },