Implementing CredTypes plugin support and created first stage of AutoAuth plugin. See #20
Implementing CredTypes plugin support and created first stage of AutoAuth plugin. See #20

--- a/conf/plugins.php
+++ b/conf/plugins.php
@@ -15,6 +15,7 @@
 $plugins->Logging = array('AffinityLive');
 $plugins->Customers = array();
 $plugins->Creds = array();
+$plugins->CredTypes = array();
 $plugins->Cron = array();
 
 

--- /dev/null
+++ b/conf/plugins/AutoAuth/config.php
@@ -1,1 +1,19 @@
+<?php
+/** Affinity Live API Integration plugin Config
+*
+* Copyright (C) 2012 B Tasker
+* Released under GNU GPL V2
+* See LICENSE
+*
+*/
+defined('_CREDLOCK') or die;
 
+// Set this to false to disable the plugin
+$this->active = false;
+
+// Set this to true to stop the plugin sending data to AL (Debug output will be generated instead
+$this->testmode = true;
+
+
+
+?>

--- /dev/null
+++ b/conf/plugins/AutoAuth/index.html
@@ -1,1 +1,8 @@
-
+<html>
+  <head>
+    <title></title>
+    <meta content="">
+    <style></style>
+  </head>
+  <body></body>
+</html>

--- /dev/null
+++ b/plugins/Blargle/AutoAuth/AutoAuth.php
@@ -1,1 +1,178 @@
+<?php
+/** Affinity Live API Integration plugin
+*
+* Copyright (C) 2012 B Tasker
+* Released under GNU GPL V2
+* See LICENSE
+*
+*/
+defined('_CREDLOCK') or die;
 
+/** Class for logging plugin support
+*
+*/
+class plugin_AutoAuth_CredTypes{
+
+/** Load the plugin configuration
+*
+*/
+function config(){
+require 'conf/plugins/AutoAuth/config.php';
+}
+
+
+/** Return details for the Plugin information view
+*
+* Will be displayed in a table, with the key as the head and the value as the content
+* HTML is _NOT_ allowed
+*
+*
+* @return object
+*/
+function getPlgDetails(){
+$details->Name = "plg_AutoAuth";
+$details->Description = "Allows certain credtypes to display a 'Login' button";
+$details->author = 'B Tasker';
+$details->License = 'GNU GPL V2';
+
+return $details;
+
+}
+
+
+
+/** Return Plugin status (i.e. is it enabled)
+*
+* Return true, false or 'In Test Mode'
+*
+* @return boolean or string
+*/
+function getPlgStatus(){
+$this->config();
+
+if ($this->testmode && $this->active){
+return "In Test Mode";
+}
+
+return $this->active;
+
+}
+
+
+
+/** Class Entry Point
+*
+* @arg data - object, will contain
+*  user - string - username of user performing the logged action
+*  cred - string - Identified for the credential, User, Group or Credential type being edited. May be null (login, logout)
+*  timestamp - PHP date format timestamp for the action. Exact format controlled by main config, use strtotime to convert if needed
+*  action - INT - Action identifier (see loggingdb documentation)
+*
+*  If you need extra data, run a query. Don't decrypt encrypted data unless you know you can do so without creating a security risk!
+*
+* return values are ignored
+*/
+function PlgCall($data){
+// Load the plugin config
+$this->config();
+
+// Check the plugin is actually enabled
+if (!$this->active){ return; }
+
+
+switch($data->action){
+
+    case 'add':
+    return $this->display_addsettings();
+    break;
+
+
+    case 'added':
+    return $this->store_addsettings($data->newid);
+    break;
+
+}
+
+
+
+}
+
+
+
+
+
+function store_addsettings($id){
+
+    if (BTMain::getVar('frmAutoAuthEnable')){
+      // More settings to be added later
+      $conf->URL = BTMain::getVar('frmAutoAuthURL');
+      
+      $settings = json_encode($conf);
+
+
+
+
+      $db = new BTDB;
+      $crypt = new Crypto;
+
+      // Make sure the settings table exists - Will make this more graceful later
+      $sql = "CREATE TABLE IF NOT EXISTS `#__AutoAuth` (  `CredType` int(11) DEFAULT NULL,  `Settings` blob, PRIMARY KEY (`CredType`));";
+      $db->setQuery($sql);
+      $db->runQuery();
+
+
+      // We encrypt using the newly created key as that'll be available when decrypting passwords
+      $settings = $crypt->encrypt($settings,'Cre'.$id);
+      $settings = $db->stringEscape($settings);
+
+
+      $sql = "INSERT INTO #__AutoAuth VALUES('$id','$settings')";
+      $db->setQuery($sql);
+      $db->runQuery();
+
+  }
+return;
+}
+
+
+
+function display_addsettings(){
+
+ob_start();
+?>
+<div id="AAuth">
+
+
+<label for="frmAutoAuthEnable">Enable Auto Login button</label><input type="checkbox" value="1" id="frmAutoAuthEnable" name="frmAutoAuthEnable" onchange="AAuthboxChange(this.checked);">
+
+<div id="AAuthSettings" style="display: none;">
+
+<label for="frmAutoAuthURL">Additional address path</label><input type="text" title="Additional URL params to add, for example for CPanel you need /login/" id="frmAutoAuthURL" name="frmAutoAuthURL">
+
+</div>
+
+</div>
+
+<script type="text/javascript">
+function AAuthboxChange(checked){
+if (checked){
+
+document.getElementById('AAuthSettings').style.display = 'block';
+}else{
+document.getElementById('AAuthSettings').style.display = 'none';
+}
+
+}
+
+$('#AAuth *').tooltip({track: true, fade: 250});
+
+</script>
+
+<?php
+return ob_get_clean();
+}
+
+
+
+}
+?>

--- /dev/null
+++ b/plugins/Blargle/AutoAuth/README.html
@@ -1,1 +1,90 @@
+<h3><a name='contents'>Contents</a></h3>
+<ul>
+  <li><a href='#PreReqs'>Pre-Requisites</a></li>
+  <li><a href='#Installation'>Installation</a></li>
+  <li><a href='#Use'>Plugin Use</a></li>
+  <li><a href='#EventsLogged'>Events Logged</a></li>
+  <li><a href="#Excluding">Excluding Customers</a></li>
+</ul>
 
+<h3><a name="PreReqs">Pre-Requisites</a></h3>
+
+You must have an AffinityLive account, and the server running CredLockerPHP must have php-curl (libcurl) enabled
+<br /><br />
+That's it!
+
+
+<h3><a name="Installation">Installation</a></h3>
+
+Installation is achieved in 4 easy steps
+
+<ol>
+
+
+<li>Place the plugin files into <i>plugins/AffinityLive/</i></li><br />
+<li>Edit config/plugins.php and enable the Plugin by adding the string <i>AffinityLive</i> to the Logging array. <br /><Br />
+<i>Example: $plugins->Logging = array('AffinityLive');</i>
+</li><br />
+<li>Edit plugins/AffinityLive/config.php and set the variables to the relevant values
+<br /><br />
+      <ul style='list-style: none;'>
+	<li><b><i>active</i>:</b> When <b>true</b> the plugin is active, when <b>false</b> the plugin is disabled</li>
+	<li><b><i>testmode</i>:</b> Only used for testing the system. Should normally be <b>false</b>, setting <b>true</b> will prevent data being sent to the API and simply output the data that would be sent</li>
+	<li><b><i>loggingurl</i>:</b> The URL to post the data to. Usually <i>http://yourdomain.affinitylive.com/forms/public/issue</i></li>
+	<li><b><i>loggingstatus</i>:</b> The status to set the issue to. You can check this in AffinityLive, but 4 usually = Closed</i>
+	<li><b><i>loggingpriority</i>:</b> The Priority to set for the issue (1 = high, 5 = none)</li>
+	<li><b><i>loggingissuetype:</i>:</b> The issue type (get ID's from AffinityLive</li>
+	<li><b><i>dateform:</i></b> PHP Date format to use when creating ticket in AffinityLive</li>
+
+      </ul>
+</li><br />
+<li>
+<a href="http://www.affinitylive.com/company/blog/new-security-feature-for-the-forms-api/" target=_blank>Disable Captcha for Issues in AffinityLive</a> (or disable for a specific class of support ticket if preferred)
+</li>
+
+</li><br />
+</ol>
+
+
+
+<h3><a name="Use">Plugin Use</a></h3>
+
+In order for the plugin to push an event to AffinityLive a customer must have <b>all</b> of the following set in PHPCredLocker
+<br />
+<ul>
+<li>Company Name</li>
+<li>First Name</li>
+<li>Surname</li>
+<li>Email</li>
+</ul>
+<br />
+Each of these must match the relevant record in AffinityLive (i.e. the Company Name <b>must</b> be the same and a contact must be recorded against that company with details matching those set above)
+
+
+
+<h3><a name="EventsLogged">Events Logged</a></h3>
+
+The plugin will push an event to AffinityLive for each of the following<br />
+<ul>
+<li>Credential Added</li>
+<li>Credential Viewed</li>
+<li>Credential Edited</li>
+<li>Credential Deleted</li>
+</ul>
+
+<br />
+A closed issue will be created with the following content
+<br />
+<i>
+Subject: {CREDENTIAL TYPE} Credentials {ACCESS} by {USER} at {DATE}<br/>
+Content: {DATE}: User {USER} {ACCESS} the {CREDENTIAL TYPE} credentials for this account
+</i>
+<br /><br /><b>Example</b><br /><br />
+<i>
+Subject: CPanel Credentials Added by Ben at 26-11-2012 20:33:00<br />
+Content: 26-11-2012 20:33:00: User Ben Added the CPanel credentials for this account
+</i>
+
+<h3><a name="Excluding">Excluding Customers</a></h3>
+
+In the event you don't want events for a given customer logged to AffinityLive, simply leave either First Name, Surname or Email blank in PHPCredLocker.

--- /dev/null
+++ b/plugins/Blargle/AutoAuth/index.html
@@ -1,1 +1,8 @@
-
+<html>
+  <head>
+    <title></title>
+    <meta content="">
+    <style></style>
+  </head>
+  <body></body>
+</html>

--- a/views/Creds/addtype.php
+++ b/views/Creds/addtype.php
@@ -10,6 +10,7 @@
 BTMain::checkSuperAdmin();
 
 global $notifications;
+$plugins = new Plugins;
 
 $notifications->setPageTitle("Add " . Lang::_('Credential Type'));
 
@@ -21,11 +22,18 @@
   if ($newid = $db->AddCredType(BTMain::getVar('frmName'))){
     $notifications->setNotification("addCredTypeSuccess");
     ?><script type="text/javascript">if (document.getElementById('CredTypeNeedsAdding')){ document.getElementById('CredTypeNeedsAdding').style.display = 'none';}</script><?php
+   
+   
     }else{
     $notifications->setNotification("addCredTypeFail");
 
 
   }
+
+
+
+
+
 $submitted = 1;
 include('lib/includes/gatherEntropy.php');
 unset($submitted);
@@ -35,6 +43,11 @@
 
 $notifications->setNotification("KeyGenerationFailed");
 }
+
+    $data->action = 'added';
+    $data->newid = $newid;
+    echo $plugins->loadPlugins("CredTypes",$data)->plgOutput;
+
 
 }
 
@@ -57,6 +70,15 @@
 
 <?php
 include('lib/includes/gatherEntropy.php');
+
+
+
+
+$data->action = 'add';
+echo $plugins->loadPlugins("CredTypes",$data)->plgOutput;
+
+
+
 ?>
 
 

--- a/views/plugins/loaded.php
+++ b/views/plugins/loaded.php
@@ -141,3 +141,26 @@
 
 }
 
+
+
+
+if (isset($plugins->CredTypes)){
+
+?>
+<h2>Credential Type Plugins</h2>
+<table class="table table-hover">
+<tr><th>Plugin</th><th>Status</th><th></th></tr>
+<?php
+
+    foreach($plugins->CredTypes as $plugin=>$status){
+
+    ?>
+    <tr>
+	<td><?php echo $plugin; ?></td><td><?php echo Plugins::transStatus($status);?></td><td><a href="index.php?option=plgInfo&plg=<?php echo $plugin;?>&type=Creds">View ReadMe</a></td>
+    </tr>
+    <?php
+    }
+?><table><br /><br /><?php
+
+
+}