PCI compliance section showing tokenization/encryption status and SAQ level
[freeside.git] / httemplate / view / Status.html
index 7fd019e..ff2d243 100644 (file)
 <& /elements/footer.html &>
 <%init>
 
+###
+# Basics and Daemons
+###
+
 my $os;
 -e '/usr/bin/lsb_release' and run( ['lsb_release', '-d'], '>',\$os );
 if ( ! $@ && $os =~ /^\s*Description:\s*(.+)$/ ) {
@@ -36,9 +40,7 @@ if ( $db eq 'PostgreSQL' && $db_ver =~ /^\s*PostgreSQL\s+([\w\.]+)\s+on\s+/ ) {
 my $db_size = 'Unknown';
 if ( $db eq 'PostgreSQL' ) {
   $db_size = FS::Record->scalar_sql(qq(
-    SELECT pg_size_pretty(pg_database_size(datname))
-      FROM pg_catalog.pg_database
-     WHERE datname = 'freeside'
+    SELECT pg_size_pretty(pg_database_size('freeside'))
   ));
 }
 
@@ -99,6 +101,11 @@ tie my %status, 'Tie::IxHash',
   ],
 ;
 
+
+###
+# Replication
+###
+
 if ( $db eq 'PostgreSQL' ) {
 
   my $enabled =    FS::Record->scalar_sql('SHOW wal_level')    eq 'hot_standby'
@@ -143,6 +150,11 @@ if ( $db eq 'PostgreSQL' ) {
 
 }
 
+
+###
+# CDR Processing
+###
+
 if ( _is_running('cdrd') ) {
 
   my $delay = FS::Record->scalar_sql('
@@ -202,6 +214,73 @@ if ( _is_running('cdrd') ) {
 
 }
 
+
+###
+# PCI Compliance
+###
+
+my($store, $tokenize) = (0,0);
+foreach my $agent (
+  qsearch({
+    'table'     => 'agent',
+    'hashref'   => { 'disabled' => '', },
+    'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+  })
+) {
+  my $gateway = $agent->payment_gateway('method'=>'VISA card');
+  next unless $gateway->gateway_namespace eq 'Business::OnlinePayment';
+  eval "use Business::OnlinePayment";
+  die $@ if $@; #die?
+  my $bop = new Business::OnlinePayment( $gateway->gateway_module,
+                                         $gateway->gatewaynum
+                                           ? $gateway->options
+                                           : @{ $gateway->get('options') }
+                                       );
+  my %actions = $bop->info('supported_actions');
+  if ( $actions{'CC'} && grep /^Tokenize$/, @{$actions{'CC'}} ) {
+    $tokenize++;
+  } else {
+    $store++;
+  }
+  
+}
+
+if ( $tokenize && ! $store ) {
+
+  $status{'PCI Compliance'} = [
+    { 'title' => 'Tokenization',
+      'value' => 'Enabled',
+    },
+    { 'title' => 'SAQ type',
+      'value' => 'A / A-EP',
+    },
+  ];
+
+} elsif ( $store ) {
+
+  my $conf = new FS::Conf; #wow, didn't need this before?
+
+  $status{'PCI Compliance'} = [
+    { 'title' => 'Tokenization',
+      'value' => $tokenize ? 'Partialy enabled (some agents)' : 'Disabled'
+    },
+    { 'title' => 'Encryption',
+      'value' =>
+        ( $conf->exists('encryption') && $conf->config('encryptionpublickey')
+            ? 'Enabled' : 'Disabled'
+        ),
+    },
+    { 'title' => 'SAQ type',
+      'value' => 'D (enable tokenization for A / A-EP)',
+    },
+  ];
+
+}
+
+###
+# Subroutines
+###
+
 sub _is_running {
   my $thing = shift;