Exemplo n.º 1
0
 public function GetEditUserLinks($id)
 {
     global $sso_settings;
     if (!$sso_settings["sso_login"]["enabled"]) {
         return array();
     }
     return array(SSO_CreateConfigLink(BB_Translate("Edit %s Info", $this->DisplayName()), "edituser", array("id" => $id)));
 }
Exemplo n.º 2
0
 public function Config()
 {
     global $sso_rng, $sso_db, $sso_db_apikeys, $sso_site_admin, $sso_settings, $sso_menuopts, $sso_select_fields;
     $sso_db_sso_remote = SSO_DB_PREFIX . "p_sso_remote";
     $sso_db_sso_remote_users = SSO_DB_PREFIX . "p_sso_remote_users";
     if ($sso_site_admin && $sso_settings["sso_remote"]["enabled"] && $_REQUEST["action2"] == "editremote") {
         $row = $sso_db->GetRow("SELECT", array("*", "FROM" => "?", "WHERE" => "id = ?"), $sso_db_sso_remote, $_REQUEST["id"]);
         if ($row) {
             $info = unserialize($row->info);
             if (isset($_REQUEST["name"])) {
                 if (strlen($_REQUEST["name"]) > 75) {
                     BB_SetPageMessage("error", "'Name' can only be 75 characters long.");
                 }
                 if ($_REQUEST["name"] != $row->name && $sso_db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "name = ?"), $sso_db_sso_remote, $_REQUEST["name"])) {
                     BB_SetPageMessage("error", "The specified remote 'Name' already exists.");
                 }
                 $apirow = $sso_db->GetRow("SELECT", array("*", "FROM" => "?", "WHERE" => "id = ?"), $sso_db_apikeys, $_REQUEST["apikey_id"]);
                 if ($apirow === false) {
                     BB_SetPageMessage("error", "The specified 'API Key ID' is not valid.");
                 } else {
                     $apiinfo = unserialize($apirow->info);
                     if (!isset($apiinfo["type"])) {
                         $apiinfo["type"] = "normal";
                     }
                     if ($apiinfo["type"] != "remote") {
                         BB_SetPageMessage("error", "The specified 'API Key ID' is not a remote API key.");
                     }
                 }
                 $info["iprestrict"] = SSO_ProcessIPFields();
                 if (BB_GetPageMessageType() != "error") {
                     try {
                         $info["icon"] = $_REQUEST["icon"];
                         $info["notes"] = $_REQUEST["notes"];
                         $info["automate"] = $_REQUEST["automate"] > 0;
                         $sso_db->Query("UPDATE", array($sso_db_sso_remote, array("name" => $_REQUEST["name"], "apikey_id" => $_REQUEST["apikey_id"], "info" => serialize($info)), "WHERE" => "id = ?"), $row->id);
                         SSO_ConfigRedirect("editremote", array("id" => $row->id), "success", BB_Translate("Successfully updated the remote."));
                     } catch (Exception $e) {
                         BB_SetPageMessage("error", "Unable to update the remote.  " . $e->getMessage());
                     }
                 }
             }
             $contentopts = array("desc" => BB_Translate("Edit the remote."), "nonce" => "action", "hidden" => array("action" => "config", "provider" => "sso_remote", "action2" => "editremote", "id" => $row->id), "fields" => array(array("title" => "Remote Key", "type" => "static", "value" => $row->remotekey . "-" . $row->id), array("title" => "Name", "type" => "text", "name" => "name", "value" => BB_GetValue("name", $row->name), "desc" => "The name of this remote.  Usually the name of the business or a business unit that will use this remote to sign in (e.g. Intel).  Must be unique."), array("title" => "API Key ID", "type" => "text", "name" => "apikey_id", "value" => BB_GetValue("apikey_id", $row->apikey_id), "desc" => "A valid remote API key ID."), array("title" => "Icon URL", "type" => "text", "name" => "icon", "value" => BB_GetValue("icon", $info["icon"]), "desc" => "An optional URL to a 48x48 pixel icon.  The URL should start with 'https://'."), array("title" => "Notes", "type" => "textarea", "name" => "notes", "value" => BB_GetValue("notes", $info["notes"]), "desc" => "Optional extra information about this remote such as contract details."), array("title" => "Automate Validation Phase?", "type" => "select", "name" => "automate", "options" => array("No", "Yes"), "select" => BB_GetValue("automate", (string) (int) $info["automate"]), "desc" => "Whether or not to attempt to automate the validation phase after authenticating the user.")), "submit" => "Save", "focus" => true);
             SSO_AppendIPFields($contentopts, $info["iprestrict"]);
             BB_GeneratePage("Edit Remote", $sso_menuopts, $contentopts);
         }
     } else {
         if ($sso_site_admin && $sso_settings["sso_remote"]["enabled"] && $_REQUEST["action2"] == "addremote") {
             if (isset($_REQUEST["name"])) {
                 if ($_REQUEST["name"] == "") {
                     BB_SetPageMessage("error", "Please fill in 'Name'.");
                 }
                 if (strlen($_REQUEST["name"]) > 75) {
                     BB_SetPageMessage("error", "'Name' can only be 75 characters long.");
                 }
                 if ($sso_db->GetOne("SELECT", array("COUNT(*)", "FROM" => "?", "WHERE" => "name = ?"), $sso_db_sso_remote, $_REQUEST["name"])) {
                     BB_SetPageMessage("error", "The specified remote 'Name' already exists.");
                 }
                 $apirow = $sso_db->GetRow("SELECT", array("*", "FROM" => "?", "WHERE" => "id = ?"), $sso_db_apikeys, $_REQUEST["apikey_id"]);
                 if ($apirow === false) {
                     BB_SetPageMessage("error", "The specified 'API Key ID' is not valid.");
                 } else {
                     $apiinfo = unserialize($apirow->info);
                     if (!isset($apiinfo["type"])) {
                         $apiinfo["type"] = "normal";
                     }
                     if ($apiinfo["type"] != "remote") {
                         BB_SetPageMessage("error", "The specified 'API Key ID' is not a remote API key.");
                     }
                 }
                 if (BB_GetPageMessageType() != "error") {
                     try {
                         $remotekey = $sso_rng->GenerateString();
                         $info = array("icon" => "", "notes" => "", "iprestrict" => SSO_InitIPFields(), "automate" => false);
                         $sso_db->Query("INSERT", array($sso_db_sso_remote, array("name" => $_REQUEST["name"], "remotekey" => $remotekey, "apikey_id" => $_REQUEST["apikey_id"], "created" => CSDB::ConvertToDBTime(time()), "info" => serialize($info)), "AUTO INCREMENT" => "id"));
                         $id = $sso_db->GetInsertID();
                         SSO_ConfigRedirect("editremote", array("id" => $id), "success", BB_Translate("Successfully created the remote."));
                     } catch (Exception $e) {
                         BB_SetPageMessage("error", "Unable to create the remote.  " . $e->getMessage());
                     }
                 }
             }
             $contentopts = array("desc" => BB_Translate("Add a remote."), "nonce" => "action", "hidden" => array("action" => "config", "provider" => "sso_remote", "action2" => "addremote"), "fields" => array(array("title" => "Name", "type" => "text", "name" => "name", "value" => BB_GetValue("name", ""), "desc" => "The name of this remote.  Usually the name of the business or a business unit that will use this remote to sign in (e.g. Intel).  Must be unique."), array("title" => "API Key ID", "type" => "text", "name" => "apikey_id", "value" => BB_GetValue("apikey_id", ""), "desc" => "A valid remote API key ID.")), "submit" => "Create", "focus" => true);
             BB_GeneratePage("Add Remote", $sso_menuopts, $contentopts);
         } else {
             if ($sso_site_admin && $sso_settings["sso_remote"]["enabled"] && $_REQUEST["action2"] == "manageremotes") {
                 $desc = "<br />";
                 $desc .= SSO_CreateConfigLink("Add Remote", "addremote");
                 $rows = array();
                 $result = $sso_db->Query("SELECT", array("r.id, r.name, r.apikey_id, a.id AS a_id", "FROM" => "? AS r LEFT OUTER JOIN ? AS a ON (r.apikey_id = a.id)"), $sso_db_sso_remote, $sso_db_apikeys);
                 while ($row = $result->NextRow()) {
                     $rows[] = array($row->id, htmlspecialchars($row->name), $row->a_id > 0 ? "<a href=\"" . BB_GetRequestURLBase() . "?action=editapikey&id=" . $row->apikey_id . "&sec_t=" . BB_CreateSecurityToken("editapikey") . "\">" . $row->apikey_id . "</a>" : BB_Translate("<i>Invalid</i>"), SSO_CreateConfigLink("Edit", "editremote", array("id" => $row->id)) . " | " . SSO_CreateConfigLink("Delete", "deleteremote", array("id" => $row->id), "Are you sure you want to delete this remote?"));
                 }
                 $contentopts = array("desc" => BB_Translate("Manage the remotes."), "htmldesc" => $desc, "fields" => array(array("type" => "table", "cols" => array("ID", "Name", "API Key", "Options"), "rows" => $rows)));
                 BB_GeneratePage("Manage Remotes", $sso_menuopts, $contentopts);
             } else {
                 if ($sso_site_admin && $sso_settings["sso_remote"]["enabled"] && $_REQUEST["action2"] == "config") {
                     if (isset($_REQUEST["configsave"])) {
                         $sso_settings["sso_remote"]["iprestrict"] = SSO_ProcessIPFields();
                         if (BB_GetPageMessageType() != "error") {
                             $sso_settings["sso_remote"]["map_remote_id"] = SSO_IsField($_REQUEST["map_remote_id"]) ? $_REQUEST["map_remote_id"] : "";
                             if (!SSO_SaveSettings()) {
                                 BB_SetPageMessage("error", "Unable to save settings.");
                             } else {
                                 if (BB_GetPageMessageType() == "info") {
                                     SSO_ConfigRedirect("config", array(), "info", $_REQUEST["bb_msg"] . "  " . BB_Translate("Successfully updated the %s provider configuration.", $this->DisplayName()));
                                 } else {
                                     SSO_ConfigRedirect("config", array(), "success", BB_Translate("Successfully updated the %s provider configuration.", $this->DisplayName()));
                                 }
                             }
                         }
                     }
                     $contentopts = array("desc" => BB_Translate("Configure the %s provider.", $this->DisplayName()), "nonce" => "action", "hidden" => array("action" => "config", "provider" => "sso_remote", "action2" => "config", "configsave" => "1"), "fields" => array(array("title" => "Map Remote ID", "type" => "select", "name" => "map_remote_id", "options" => $sso_select_fields, "select" => BB_GetValue("map_remote_id", (string) $sso_settings["sso_remote"]["map_remote_id"]), "desc" => "The field in the SSO system to map the remote ID to.  This allows applications to identify an organization and sign all users at that organization into a single instance.")), "submit" => "Save", "focus" => true);
                     SSO_AppendIPFields($contentopts, $sso_settings["sso_remote"]["iprestrict"]);
                     BB_GeneratePage(BB_Translate("Configure %s", $this->DisplayName()), $sso_menuopts, $contentopts);
                 } else {
                     if ($sso_site_admin && $sso_settings["sso_remote"]["enabled"] && $_REQUEST["action2"] == "disable") {
                         $sso_settings["sso_remote"]["enabled"] = false;
                         if (!SSO_SaveSettings()) {
                             BB_RedirectPage("error", "Unable to save settings.");
                         } else {
                             BB_RedirectPage("success", BB_Translate("Successfully disabled the %s provider.", $this->DisplayName()));
                         }
                     } else {
                         if ($sso_site_admin && !$sso_settings["sso_remote"]["enabled"] && $_REQUEST["action2"] == "enable") {
                             $sso_settings["sso_remote"]["enabled"] = true;
                             if (!SSO_SaveSettings()) {
                                 BB_RedirectPage("error", "Unable to save settings.");
                             } else {
                                 BB_RedirectPage("success", BB_Translate("Successfully enabled the %s provider.", $this->DisplayName()));
                             }
                         } else {
                             if ($sso_site_admin && !$sso_settings["sso_remote"]["installed"] && $_REQUEST["action2"] == "install") {
                                 if (isset($_REQUEST["install"])) {
                                     if ($sso_db->TableExists($sso_db_sso_remote)) {
                                         BB_SetPageMessage("error", "The database table '" . $sso_db_sso_remote . "' already exists.");
                                     }
                                     if ($sso_db->TableExists($sso_db_sso_remote_users)) {
                                         BB_SetPageMessage("error", "The database table '" . $sso_db_sso_remote_users . "' already exists.");
                                     }
                                     if (BB_GetPageMessageType() != "error") {
                                         try {
                                             $sso_db->Query("CREATE TABLE", array($sso_db_sso_remote, array("id" => array("INTEGER", 8, "UNSIGNED" => true, "NOT NULL" => true, "PRIMARY KEY" => true, "AUTO INCREMENT" => true), "name" => array("STRING", 1, 75, "NOT NULL" => true), "remotekey" => array("STRING", 1, 64, "NOT NULL" => true), "apikey_id" => array("INTEGER", 8, "UNSIGNED" => true, "NOT NULL" => true), "created" => array("DATETIME", "NOT NULL" => true), "info" => array("STRING", 3, "NOT NULL" => true)), array(array("UNIQUE", array("name"), "NAME" => $sso_db_sso_remote . "_name"), array("KEY", array("apikey_id"), "NAME" => $sso_db_sso_remote . "_apikey_id"))));
                                         } catch (Exception $e) {
                                             BB_SetPageMessage("error", "Unable to create the database table '" . htmlspecialchars($sso_db_sso_remote) . "'.  " . $e->getMessage());
                                         }
                                         if (BB_GetPageMessageType() != "error") {
                                             try {
                                                 $sso_db->Query("CREATE TABLE", array($sso_db_sso_remote_users, array("id" => array("INTEGER", 8, "UNSIGNED" => true, "NOT NULL" => true, "PRIMARY KEY" => true, "AUTO INCREMENT" => true), "remote_id" => array("INTEGER", 8, "UNSIGNED" => true, "NOT NULL" => true), "user_id" => array("STRING", 1, 255, "NOT NULL" => true), "created" => array("DATETIME", "NOT NULL" => true)), array(array("UNIQUE", array("remote_id", "user_id"), "NAME" => $sso_db_sso_remote_users . "_remote_user_id"))));
                                                 $sso_settings["sso_remote"]["installed"] = true;
                                                 $sso_settings["sso_remote"]["enabled"] = true;
                                                 if (!SSO_SaveSettings()) {
                                                     BB_SetPageMessage("error", "Unable to save settings.");
                                                 } else {
                                                     SSO_ConfigRedirect("manageremotes", array(), "success", BB_Translate("Successfully installed the %s provider.", $this->DisplayName()));
                                                 }
                                             } catch (Exception $e) {
                                                 BB_SetPageMessage("error", "Unable to create the database table '" . htmlspecialchars($sso_db_sso_remote_users) . "'.  " . $e->getMessage());
                                             }
                                         }
                                     }
                                 }
                                 $contentopts = array("desc" => BB_Translate("Install the %s provider.", $this->DisplayName()), "nonce" => "action", "hidden" => array("action" => "config", "provider" => "sso_remote", "action2" => "install", "install" => "1"), "fields" => array(), "submit" => "Install", "focus" => true);
                                 BB_GeneratePage(BB_Translate("Install %s", $this->DisplayName()), $sso_menuopts, $contentopts);
                             }
                         }
                     }
                 }
             }
         }
     }
 }