[SUCS Devel] [Git][sucs/doorkey][master] 2 commits: fixed paths to external files

Imran Hussain imranh at sucs.org
Wed May 2 11:37:10 BST 2018


Imran Hussain pushed to branch master at sucs / doorkey


Commits:
113face8 by Imran Hussain at 2018-05-01T20:22:12+01:00
fixed paths to external files
- - - - -
d26c7a0a by Imran Hussain at 2018-05-01T20:23:05+01:00
add my ldap auth php to the project
- - - - -


2 changed files:

- + ldap-auth.php
- public/index.php


Changes:

=====================================
ldap-auth.php
=====================================
--- /dev/null
+++ b/ldap-auth.php
@@ -0,0 +1,105 @@
+<?php
+
+/*
+Written by Imran Hussain ~imranh
+
+Used to auth people, will check SUCS then the uni ldap, will only check
+students on the uni ldap.
+
+will return "sucs" if the username/password passed is a sucs member
+will return "uni" if the user/pass passed has a student swan uni account
+will return "nope" if the user/pass passed is inavlid
+
+Example usage:
+
+include_once("ldap-auth.php");
+
+isAuthd = ldapAuth("usaername", "password");
+
+if (isAuthd == "sucs"){
+	//do stuff for sucs auth
+}elseif (isAuthd == "uni"){
+	//do stuff for uni auth
+}else{
+	//do stuff for not authd peeps
+}
+
+*/
+
+// we don't care about warnings, we write our own
+error_reporting(E_ERROR | E_PARSE);
+
+function ldapAuth($username, $password)
+{
+
+    if ($username != "" && $password != "") {
+
+        // people like to use emails to login so lets detect and strip
+        if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
+            //valid email, lets strip
+            // split the email into a string array "@" as a delim
+            $s = explode("@", $username);
+            // remove the last element (domain)
+            array_pop($s);
+            // put the array back togther using "@" as a seperator
+            $username = implode("@", $s);
+        }
+
+        // ldap servers
+        $sucsLDAPServer = 'silver.sucs.swan.ac.uk';
+        $lisLDAPServer = 'ccs-suld1.swan.ac.uk';
+
+        // lis auth stuffs
+        $lisUsernameOu = substr($username, -1);
+        $lisOtherOu = "Moved";
+
+        // how to bind
+        $sucsBindDn = "uid=$username,ou=People,dc=sucs,dc=org";
+        $lisBindDn1 = "cn=$username,ou=$lisUsernameOu,ou=Students,ou=SWANSEA,o=SWANUNI";
+        $lisBindDn2 = "cn=$username,ou=$lisOtherOu,ou=Students,ou=SWANSEA,o=SWANUNI";
+
+        // Main auth
+
+        // Try and connect to silver
+        $ldapconnSUCS = ldap_connect($sucsLDAPServer) or die("Could not connect to SUCS LDAP server.");
+
+        if ($ldapconnSUCS) {
+
+            //echo "Connected to $sucsLDAPServer <br>";
+
+            // try and bind to sucs ldap
+            $ldapbindSUCS = ldap_bind($ldapconnSUCS, $sucsBindDn, $password);
+
+            if ($ldapbindSUCS) {
+                //echo "Auth'd as $username using SUCS LDAP<br>";
+                return "sucs";
+                // turns out they didn't give us valid sucs creds, lets try lis now
+            } else {
+
+                // try and connect to the lis ldap server
+                $ldapconnLIS = ldap_connect($lisLDAPServer) or die("Could not connect to uni LDAP server.");
+                //echo "Connected to $lisLDAPServer <br>";
+
+                // lets try and bind to the uni ldap
+                $ldapbindLIS1 = ldap_bind($ldapconnLIS, $lisBindDn1, $password);
+                if ($ldapbindLIS1) {
+                    //echo "Auth'd as $username using uni LDAP using ou=$lisUsernameOu<br>";
+                    return "uni";
+                } else {
+                    $ldapbindLIS2 = ldap_bind($ldapconnLIS, $lisBindDn2, $password);
+                    if ($ldapbindLIS2) {
+                        //echo "Auth'd as $username using uni LDAP using ou=moved<br>";
+                        return "uni";
+                        // shit, couldn't bind to anything
+                    } else {
+                        //exit("Invalid Username or Password");
+                        return "nope";
+                    }
+                }
+            }
+        }
+    } else {
+        return "nope";
+    }
+}
+


=====================================
public/index.php
=====================================
--- a/public/index.php
+++ b/public/index.php
@@ -28,12 +28,12 @@ if(isset($_REQUEST['password'])) {
 	$password = $_REQUEST['password'];
 }
 
-include_once("./ldap-auth.php");
+include_once("../ldap-auth.php");
 
 $isAuthd = ldapAuth($username, $password);
 
 if ($isAuthd == "sucs"){
-	include_once("./doorkey.php");
+	include_once("../doorkey.php");
 	//curl door
 	$curl = curl_init();
 	curl_setopt($curl, CURLOPT_URL, "http://door.sucs.org/sendstatus.py?text=${username}%20via%20de%20web&timeout=1&fg=0,0,0&bg=128,255,128&unlock=1&key=${doorkey}");



View it on GitLab: https://projects.sucs.org/sucs/doorkey/compare/6c6dc81e829a7b3a7d9ae6ce8eaeb44c770c056e...d26c7a0abee7fc362b8220a149b65cb0cccf70ee

---
View it on GitLab: https://projects.sucs.org/sucs/doorkey/compare/6c6dc81e829a7b3a7d9ae6ce8eaeb44c770c056e...d26c7a0abee7fc362b8220a149b65cb0cccf70ee
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20180502/6e7673f3/attachment-0001.html>


More information about the Devel mailing list