Permalink
Browse files

Renamed primary scripts

  • Loading branch information...
1 parent b6a2eb6 commit 889e0412a289127d45994d74c6b10c4e593c289c @craig552uk committed Jan 16, 2011
Showing with 198 additions and 3 deletions.
  1. +97 −0 raplet-login.php
  2. +98 −0 raplet-main.php
  3. +1 −1 settings.php
  4. +2 −2 test.html
View
@@ -0,0 +1,97 @@
+<?php
+
+include_once('settings.php');
+include_once('lib-ldap.php');
+include_once('lib-oauth.php');
+
+// Get parameters
+$param['redirect_uri'] = (isset($_GET['redirect_uri'])) ? htmlspecialchars($_GET['redirect_uri']) : "";
+$param['client_id'] = (isset($_GET['client_id'])) ? htmlspecialchars($_GET['client_id']) : "";
+$param['response_type'] = (isset($_GET['response_type'])) ? htmlspecialchars($_GET['response_type']) : "";
+$param['username'] = (isset($_GET['username'])) ? htmlspecialchars($_GET['username']) : "";
+$param['password'] = (isset($_GET['password'])) ? htmlspecialchars($_GET['password']) : "";
+
+// Check parameters meet expected values
+$param_ok['redirect_uri'] = ("https://rapportive.com/raplets" == substr($param['redirect_uri'],0,30)) ? true : false;
+$param_ok['client_id'] = ("rapportive" == $param['client_id']) ? true : false;
+$param_ok['response_type'] = ("token" == $param['response_type']) ? true : false;
+
+// Allow form if
+$params_ok = ($param_ok['redirect_uri'] && $param_ok['client_id'] && $param_ok['response_type']) ? true : false;
+
+if (isset($_GET['submit'])){
+ // Attempt to authenticate
+ $conn = my_ldap_connect();
+ $data = my_ldap_authenticate($conn, $param['username'], $param['password']);
+ $authenticated = (isset($data['dn'])) ? true : false;
+
+ if ($authenticated){
+ // Get token
+ $token = contains_token($data['tokens']);
+ // Set new token if needed
+ if (!is_string($token)) $token = gen_token($data['dn']);
+ }
+}
+
+?>
+
+
+<?php if($params_ok): /* Safe to show form */ ?>
+ <?php if (!$authenticated): /* Not authenticated */ ?>
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>Authenticate</title>
+ <meta charset="utf-8">
+ <style>
+ body {font-family: ariel, helvetica, sans-serif;}
+ legend {font-weight: bold;}
+ input, label {float: left; padding: 3px; margin: 5px 0;}
+ label {clear: left; width: 200px;}
+ input[type=submit] {clear: left; margin-left: 205px; margin-right: 10px;}
+ </style>
+ <head>
+ <body>
+
+ <fieldset>
+ <legend>Authenticate</legend>
+ <form method="get" action="raplet-login.php">
+ <label for="username">User Name</label> <input type="text" id="username" name="username" value="<?php echo $param['username'];?>" />
+ <label for="password">Password</label> <input type="password" id="password" name="password" />
+
+ <input type="hidden" id="redirect_uri" name="redirect_uri" value="<?php echo $param['redirect_uri'];?>" />
+ <input type="hidden" id="client_id" name="client_id" value="<?php echo $param['client_id'];?>" />
+ <input type="hidden" id="response_type" name="response_type" value="<?php echo $param['response_type'];?>" />
+
+ <input type="submit" id="submit" name="submit" value="Login" />
+ <input type="button" id="cancel" name="cancel" value="Cancel" onClick="window.close();"/>
+ </form>
+ </fieldset>
+ </body>
+ </html>
+ <?php else: /* Redirect back to Rapportive */ ?>
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>Authenticate</title>
+ <meta charset="utf-8">
+ <meta http-equiv="refresh" content="0; url=<?php echo urlencode($param['redirect_uri']) . '#' . urlencode($token);?>">
+ <head>
+ <body>
+ <p>If you are not redirected <a href="<?php echo urlencode($param['redirect_uri']) . '#' . urlencode($token);?>">click here</a>.<p>
+ </body>
+ </html>
+ <?php endif; ?>
+<?php else: /* Invalid query string data */ ?>
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>Authenticate</title>
+ <meta charset="utf-8">
+ <head>
+ <body>
+ <h1>Invalid Request</h1>
+ </body>
+ </html>
+<?php endif; ?>
+
View
@@ -0,0 +1,98 @@
+<?php
+/****************************************
+Author: Craig Russell
+Date: 11 Jan 2011
+
+Plugin for Raportive http://rapportive.com/
+API development docs and discussion at http://groups.google.com/group/raplet-dev
+
+Searches for user in LDAP Directory based upon email address.
+Returns various attributes for display alongside GMail thread.
+
+Requires LDAP and JSON modules for PHP
+http://php.net/manual/en/book.ldap.php
+http://php.net/manual/en/book.json.php
+
+****************************************/
+
+include_once('settings.php');
+include_once('lib-ldap.php');
+
+// Get data from query String
+$get_data['email'] = (isset($_GET['email'])) ? $_GET['email'] : "";
+$get_data['name'] = (isset($_GET['name'])) ? $_GET['name'] : "";
+$get_data['twitter_username'] = (isset($_GET['twitter_username'])) ? $_GET['twitter_username'] : "";
+$get_data['callback'] = (isset($_GET['callback'])) ? $_GET['callback'] : "";
+$get_data['show'] = (isset($_GET['show'])) ? $_GET['show'] : "";
+$get_data['oauth_token'] = (isset($_GET['oauth_token'])) ? $_GET['oauth_token'] : "";
+
+if ($get_data['show'] == "metadata"){
+
+ // Set required metadata values
+ $json_data['name'] = $rapplet_meta['name'];
+ $json_data['description'] = $rapplet_meta['description'];
+ $json_data['welcome_text'] = $rapplet_meta['welcome_text'];
+ $json_data['icon_url'] = $rapplet_meta['icon_url'];
+ $json_data['config_url'] = $rapplet_meta['config_url'];
+ $json_data['preview_url'] = $rapplet_meta['preview_url'];
+ $json_data['provider_name'] = $rapplet_meta['provider_name'];
+ $json_data['provider_url'] = $rapplet_meta['provider_url'];
+
+ // Set optional metadata values
+ if ($rapplet_meta['data_provider_name'] != "") $json_data['data_provider_name'] = $rapplet_meta['data_provider_name'];
+ if ($rapplet_meta['data_provider_url'] != "") $json_data['dat_provider_url'] = $rapplet_meta['data_provider_url'];
+
+}else{ // ($get_data['show'] != "metadata")
+
+ // Found_info flag defaults to true
+ $found_info = true;
+
+ $conn = my_ldap_connect();
+
+ // If connected to server and provided valid token
+ if (is_resource($conn) && my_ldap_verify_token($conn, $get_data['oauth_token'])) {
+ // Search for users with matching email address
+ $search_result = my_ldap_search($conn, "mail=".$get_data['email']);
+
+ // No matching users found
+ if (count($search_result) == 0) { $found_info = false; }
+ }else{
+ // Bind to LDAP server failed
+ $found_info = false;
+ }
+
+ // If user information has been found...
+ if ($found_info){
+
+ // Build HTML list of user information
+ $html = "<ul>";
+ foreach ($search_result as $k => $v){
+ $html = $html."<li><span>".htmlspecialchars($k)."</span>".htmlspecialchars($v)."</li>";
+ }
+ $html = $html."</ul>";
+ // Set return status
+ $status = 200;
+
+ }else{
+
+ // No user info to return
+ $html = "";
+ $status = 404;
+
+ }
+ $json_data = array('html'=>$html, 'css'=>$css, 'js'=>$js, 'status'=>$status);
+
+} // End if($get_data['show'] == "metadata")
+
+// Repair escape slash bug in json_encode()
+// http://bugs.php.net/bug.php?id=49366
+$json_return = str_replace('\\/', '/', json_encode($json_data));
+
+
+// Set Content-type
+header('Content-type: text/javascript');
+
+// Return Callback and JSON for Rapportive
+echo $get_data['callback']."(".$json_return.")";
+
+?>
View
@@ -21,7 +21,7 @@
$rapplet_meta['welcome_text'] = "Thanks for using LDAP Raplet";
$rapplet_meta['icon_url'] = "http://localhost/LDAP-Raplet/icon.png";
$rapplet_meta['preview_url'] = "http://localhost/LDAP-Raplet/preview.png";
-$rapplet_meta['config_url'] = "http://localhost/LDAP-Raplet/ldap-login.php";
+$rapplet_meta['config_url'] = "http://localhost/LDAP-Raplet/raplet-login.php";
$rapplet_meta['provider_name'] = "Craig Russell";
$rapplet_meta['provider_url'] = "http://www.craig-russell.co.uk";
$rapplet_meta['data_provider_name'] = "";
View
@@ -16,7 +16,7 @@
<fieldset>
<legend>Raplet Test Data</legend>
- <form method="get" action="ldap-raplet.php">
+ <form method="get" action="raplet-main.php">
<label for="email">Email</label> <input type="text" id="email" name="email" value="ijones01@example.com" />
<label for="name">Name</label> <input type="text" id="name" name="name" value="Indiana Jones" />
<label for="twitter_username">Twitter Name</label> <input type="text" id="twitter_username" name="twitter_username" value="@ijones01" />
@@ -29,7 +29,7 @@
<fieldset>
<legend>Login Form Test Data</legend>
- <form method="get" action="ldap-login.php">
+ <form method="get" action="raplet-login.php">
<label for="redirect_uri">Redirect URI</label> <input type="text" id="redirect_uri" name="redirect_uri" value="https://rapportive.com/raplets/" />
<label for="client_id">Client ID</label> <input type="text" id="client_id" name="client_id" value="rapportive" />
<label for="response_type">Response Type</label> <input type="text" id="response_type" name="response_type" value="token" />

0 comments on commit 889e041

Please sign in to comment.