Пример #1
0
<?php 
/**
 * Created by  Vlad Karapetyan
 */
session_start();
//session_destroy();exit;
if (isset($_POST['submit']) && isset($_POST['your_mail']) && !empty($_POST['your_mail']) && isset($_POST['gluu_server_url']) && !empty($_POST['gluu_server_url'])) {
    if (empty($_SESSION['oxd_id'])) {
        require_once './Register_site.php';
        $register_site = new Register_site();
        $register_site->setRequestOpHost($_POST['gluu_server_url']);
        $register_site->setRequestAcrValues(Oxd_RP_config::$acr_values);
        $register_site->setRequestAuthorizationRedirectUri(Oxd_RP_config::$authorization_redirect_uri);
        $register_site->setRequestPostLogoutRedirectUri(Oxd_RP_config::$post_logout_redirect_uri);
        $register_site->setRequestContacts([$_POST['your_mail']]);
        $register_site->setRequestGrantTypes(Oxd_RP_config::$grant_types);
        $register_site->setRequestResponseTypes(Oxd_RP_config::$response_types);
        $register_site->setRequestScope(Oxd_RP_config::$scope);
        $register_site->request();
        if ($register_site->getResponseOxdId()) {
            //save in your database
            $_SESSION['oxd_id'] = $register_site->getResponseOxdId();
            require_once './Update_site_registration.php';
            $update_site_registration = new Update_site_registration();
            $update_site_registration->setRequestAcrValues(Oxd_RP_config::$acr_values);
            $update_site_registration->setRequestOxdId($_SESSION['oxd_id']);
            $update_site_registration->setRequestAuthorizationRedirectUri(Oxd_RP_config::$authorization_redirect_uri);
            $update_site_registration->setRequestPostLogoutRedirectUri(Oxd_RP_config::$post_logout_redirect_uri);
            $update_site_registration->setRequestContacts([$_POST['your_mail']]);
            $update_site_registration->setRequestGrantTypes(Oxd_RP_config::$grant_types);
            $update_site_registration->setRequestResponseTypes(Oxd_RP_config::$response_types);
 function gluu_openid_save_settings()
 {
     if (is_admin() && get_option('Oxd_Activated_Plugin') == 'Plugin-Slug') {
         delete_option('Oxd_Activated_Plugin');
         update_option('oxd_openid_message', 'Go to plugin <b><a href="admin.php?page=oxd_openid_settings&tab=login">settings</a></b> to enable login by gluu.');
         add_action('admin_notices', array($this, 'oxd_openid_activation_message'));
     }
     if (isset($_POST['option']) and $_POST['option'] == "oxd_openid_connect_register_site_oxd") {
         $illegal = "#\$%^*()+=[]';,/{}|:<>?~";
         $illegal = $illegal . '"';
         if ($this->oxd_openid_check_empty_or_null($_POST['email']) || $this->oxd_openid_check_empty_or_null($_POST['oxd_host_port'])) {
             update_option('oxd_openid_message', 'All the fields are required. Please enter valid entries.');
             $this->oxd_openid_show_error_message();
             return;
         } else {
             if (!$_POST['users_can_register']) {
                 update_option('oxd_openid_message', 'Need to choose anyone can register checkbox.');
                 $this->oxd_openid_show_error_message();
                 return;
             } else {
                 if ((int) $_POST['oxd_host_port'] > 65535 && (int) $_POST['oxd_host_port'] < 0) {
                     update_option('oxd_openid_message', 'Enter your oxd host port (Min. number 0, Max. number 65535)');
                     $this->oxd_openid_show_error_message();
                     return;
                 } else {
                     if (strpbrk($_POST['email'], $illegal)) {
                         update_option('oxd_openid_message', 'Please match the format of Email. No special characters are allowed.');
                         $this->oxd_openid_show_error_message();
                         return;
                     } else {
                         $email = $_POST['email'];
                         $oxd_host_port = $_POST['oxd_host_port'];
                         $oxd_host_ip = '127.0.0.1';
                     }
                 }
             }
         }
         update_option('users_can_register', $_POST['users_can_register']);
         update_option('default_role', $_POST['default_role']);
         update_option('oxd_openid_admin_email', $email);
         update_option('oxd_openid_oxd_ip', $oxd_host_ip);
         update_option('oxd_openid_oxd_port', $oxd_host_port);
         $config_option = array("oxd_host_ip" => $oxd_host_ip, "oxd_host_port" => $oxd_host_port, "authorization_redirect_uri" => site_url() . '/wp-login.php?option=oxdOpenId', "logout_redirect_uri" => site_url() . '/index.php?option=allLogout', "scope" => ["openid", "profile", "email", "address", "clientinfo", "mobile_phone", "phone"], "application_type" => "web", "redirect_uris" => [site_url() . '/wp-login.php?option=oxdOpenId'], "response_types" => ["code"], "grant_types" => ["authorization_code"], "acr_values" => [], "am_host" => "");
         update_option('oxd_config', $config_option);
         $register_site = new Register_site();
         $register_site->setRequestAcrValues($config_option['acr_values']);
         $register_site->setRequestAuthorizationRedirectUri($config_option['authorization_redirect_uri']);
         $register_site->setRequestRedirectUris($config_option['redirect_uris']);
         $register_site->setRequestGrantTypes($config_option['grant_types']);
         $register_site->setRequestResponseTypes(['code']);
         $register_site->setRequestLogoutRedirectUri($config_option['logout_redirect_uri']);
         $register_site->setRequestContacts([$email]);
         $register_site->setRequestApplicationType('web');
         $register_site->setRequestClientLogoutUri($config_option['logout_redirect_uri']);
         $register_site->setRequestScope($config_option['scope']);
         $status = $register_site->request();
         if (!$status['status']) {
             update_option('oxd_openid_message', $status['message']);
             $this->oxd_openid_show_error_message();
             return;
         }
         if ($register_site->getResponseOxdId()) {
             if (get_option('oxd_id')) {
                 update_option('oxd_id', $register_site->getResponseOxdId());
             } else {
                 add_option('oxd_id', $register_site->getResponseOxdId());
             }
             update_option('oxd_openid_message', 'Your settings are saved successfully.');
             $this->oxd_openid_show_success_message();
         } else {
             update_option('oxd_openid_message', 'Gluu server url, oxd ip or oxd host is not a valid.');
             $this->oxd_openid_show_error_message();
         }
     } else {
         if (isset($_POST['option']) and $_POST['option'] == "oxd_openid_config_info_hidden") {
             if (is_oxd_registered()) {
                 $custom_scripts = get_option('oxd_openid_custom_scripts');
                 foreach ($custom_scripts as $custom_script) {
                     update_option('oxd_openid_' . $custom_script['value'] . '_enable', isset($_POST['oxd_openid_' . $custom_script['value'] . '_enable']) ? $_POST['oxd_openid_' . $custom_script['value'] . '_enable'] : 0);
                 }
                 $error = true;
                 $error_array = array();
                 $oxd_config = !empty(get_option('oxd_config')) ? get_option('oxd_config') : array();
                 $oxd_config['response_types'] = !empty($_POST['response_types']) && isset($_POST['response_types']) ? $_POST['response_types'] : $oxd_config['response_types'];
                 $oxd_config['scope'] = !empty($_POST['scope']) && isset($_POST['scope']) ? $_POST['scope'] : $oxd_config['scope'];
                 update_option('oxd_config', $oxd_config);
                 if (!empty($_POST['new_scope']) && isset($_POST['new_scope'])) {
                     foreach ($_POST['new_scope'] as $scope) {
                         if ($scope) {
                             $get_scopes = get_option('oxd_openid_scops');
                             array_push($get_scopes, $scope);
                             update_option('oxd_openid_scops', $get_scopes);
                         }
                     }
                 }
                 if (!empty($_POST['delete_scope']) && isset($_POST['delete_scope'])) {
                     $custom_scripts = get_option('oxd_openid_scops');
                     $check = false;
                     $up_cust_sc = array();
                     foreach ($custom_scripts as $custom_script) {
                         if ($custom_script == $_POST['delete_scope']) {
                             $check = true;
                         } else {
                             array_push($up_cust_sc, $custom_script);
                         }
                     }
                     update_option('oxd_openid_scops', $up_cust_sc);
                     if ($check) {
                         echo 1;
                         exit;
                     } else {
                         echo 0;
                         exit;
                     }
                 }
                 if (!empty($_POST['delete_value']) && isset($_POST['delete_value'])) {
                     $custom_scripts = get_option('oxd_openid_custom_scripts');
                     $check = false;
                     $up_cust_sc = array();
                     foreach ($custom_scripts as $custom_script) {
                         if ($custom_script['value'] == $_POST['delete_value']) {
                             $check = true;
                         } else {
                             array_push($up_cust_sc, $custom_script);
                         }
                     }
                     update_option('oxd_openid_custom_scripts', $up_cust_sc);
                     if ($check) {
                         echo 1;
                         exit;
                     } else {
                         echo 0;
                         exit;
                     }
                 }
                 if (isset($_POST['count_scripts'])) {
                     for ($i = 1; $i <= $_POST['count_scripts']; $i++) {
                         if (isset($_POST['new_custom_script_name_' . $i]) && !empty($_POST['new_custom_script_name_' . $i]) && isset($_POST['new_custom_script_value_' . $i]) && !empty($_POST['new_custom_script_value_' . $i]) && isset($_POST['image_url_' . $i]) && !empty($_POST['image_url_' . $i])) {
                             $custom_scripts = get_option('oxd_openid_custom_scripts');
                             foreach ($custom_scripts as $custom_script) {
                                 if ($custom_script['value'] == $_POST['new_custom_script_value_' . $i] || $custom_script['name'] == $_POST['new_custom_script_name_' . $i]) {
                                     $error = false;
                                     array_push($error_array, $i);
                                 }
                             }
                             if ($error) {
                                 array_push($custom_scripts, array('name' => $_POST['new_custom_script_name_' . $i], 'image' => $_POST['image_url_' . $i], 'value' => $_POST['new_custom_script_value_' . $i]));
                                 update_option('oxd_openid_custom_scripts', $custom_scripts);
                             } else {
                                 update_option('oxd_openid_message', 'Name = ' . $_POST['new_custom_script_name_' . $i] . ' or value = ' . $_POST['new_custom_script_value_' . $i] . ' is exist.');
                                 $this->oxd_openid_show_error_message();
                             }
                         }
                     }
                 }
                 if (!$error) {
                     $error_message = '';
                     foreach ($error_array as $error_a) {
                         $error_message .= 'Name = ' . $_POST['new_custom_script_name_' . $error_a] . ' or value = ' . $_POST['new_custom_script_value_' . $error_a] . ' is exist.<br/>';
                     }
                     update_option('oxd_openid_message', $error_message);
                     $this->oxd_openid_show_error_message();
                 } else {
                     $config_option = get_option('oxd_config');
                     $update_site_registration = new Update_site_registration();
                     $update_site_registration->setRequestOxdId(get_option('oxd_id'));
                     $update_site_registration->setRequestAcrValues($config_option['acr_values']);
                     $update_site_registration->setRequestAuthorizationRedirectUri($config_option['authorization_redirect_uri']);
                     $update_site_registration->setRequestRedirectUris($config_option['redirect_uris']);
                     $update_site_registration->setRequestGrantTypes($config_option['grant_types']);
                     $update_site_registration->setRequestResponseTypes(['code']);
                     $update_site_registration->setRequestLogoutRedirectUri($config_option['logout_redirect_uri']);
                     $update_site_registration->setRequestContacts([get_option('oxd_openid_admin_email')]);
                     $update_site_registration->setRequestApplicationType('web');
                     $update_site_registration->setRequestClientLogoutUri($config_option['logout_redirect_uri']);
                     $update_site_registration->setRequestScope($config_option['scope']);
                     $status = $update_site_registration->request();
                     if (!$status['status']) {
                         update_option('oxd_openid_message', $status['message']);
                         $this->oxd_openid_show_error_message();
                         return;
                     }
                     if ($update_site_registration->getResponseOxdId()) {
                         if (get_option('oxd_id')) {
                             update_option('oxd_id', $update_site_registration->getResponseOxdId());
                         } else {
                             add_option('oxd_id', $update_site_registration->getResponseOxdId());
                         }
                         $this->oxd_openid_show_success_message();
                     } else {
                         update_option('oxd_openid_message', 'Gluu server url, oxd ip or oxd host is not a valid.');
                         $this->oxd_openid_show_error_message();
                     }
                     update_option('oxd_id', $update_site_registration->getResponseOxdId());
                     update_option('oxd_openid_message', 'Your settings are saved successfully.');
                     $this->oxd_openid_show_success_message();
                 }
             } else {
                 update_option('oxd_openid_message', 'Please register an account before trying to enable any app');
                 $this->oxd_openid_show_error_message();
             }
         } else {
             if (isset($_POST['option']) and $_POST['option'] == "oxd_openid_reset_config") {
                 $this->oxd_openid_deactivate();
                 $this->oxd_openid_activating();
             } else {
                 if (isset($_POST['option']) and $_POST['option'] == "oxd_openid_enable_apps") {
                     if (is_oxd_registered()) {
                         $custom_scripts = get_option('oxd_openid_custom_scripts');
                         foreach ($custom_scripts as $custom_script) {
                             update_option('oxd_openid_' . $custom_script['value'] . '_enable', isset($_POST['oxd_openid_' . $custom_script['value'] . '_enable']) ? $_POST['oxd_openid_' . $custom_script['value'] . '_enable'] : 0);
                         }
                         update_option('oxd_openid_default_login_enable', isset($_POST['oxd_openid_default_login_enable']) ? $_POST['oxd_openid_default_login_enable'] : 0);
                         update_option('oxd_openid_default_register_enable', isset($_POST['oxd_openid_default_register_enable']) ? $_POST['oxd_openid_default_register_enable'] : 0);
                         update_option('oxd_openid_default_comment_enable', isset($_POST['oxd_openid_default_comment_enable']) ? $_POST['oxd_openid_default_comment_enable'] : 0);
                         update_option('oxd_openid_woocommerce_login_form', isset($_POST['oxd_openid_woocommerce_login_form']) ? $_POST['oxd_openid_woocommerce_login_form'] : 0);
                         //Redirect URL
                         update_option('oxd_openid_login_redirect', $_POST['oxd_openid_login_redirect']);
                         update_option('oxd_openid_login_redirect_url', $_POST['oxd_openid_login_redirect_url']);
                         //Logout Url
                         update_option('oxd_openid_logout_redirection_enable', isset($_POST['oxd_openid_logout_redirection_enable']) ? $_POST['oxd_openid_logout_redirection_enable'] : 0);
                         update_option('oxd_openid_logout_redirect', $_POST['oxd_openid_logout_redirect']);
                         update_option('oxd_openid_logout_redirect_url', $_POST['oxd_openid_logout_redirect_url']);
                         //auto register
                         update_option('oxd_openid_auto_register_enable', isset($_POST['oxd_openid_auto_register_enable']) ? $_POST['oxd_openid_auto_register_enable'] : 0);
                         update_option('oxd_openid_register_disabled_message', $_POST['oxd_openid_register_disabled_message']);
                         update_option('oxd_openid_login_widget_customize_text', $_POST['oxd_openid_login_widget_customize_text']);
                         update_option('oxd_openid_login_button_customize_text', $_POST['oxd_openid_login_button_customize_text']);
                         update_option('oxd_openid_login_theme', $_POST['oxd_openid_login_theme']);
                         update_option('oxd_openid_message', 'Your settings are saved successfully.');
                         //customization of icons
                         update_option('oxd_login_icon_custom_size', $_POST['oxd_login_icon_custom_size']);
                         update_option('oxd_login_icon_space', $_POST['oxd_login_icon_space']);
                         update_option('oxd_login_icon_custom_width', $_POST['oxd_login_icon_custom_width']);
                         update_option('oxd_login_icon_custom_height', $_POST['oxd_login_icon_custom_height']);
                         update_option('oxd_openid_login_custom_theme', $_POST['oxd_openid_login_custom_theme']);
                         update_option('oxd_login_icon_custom_color', $_POST['oxd_login_icon_custom_color']);
                         // avatar
                         update_option('oxdOpenId_gluu_login_avatar', isset($_POST['oxdOpenId_gluu_login_avatar']) ? $_POST['oxdOpenId_gluu_login_avatar'] : 0);
                         //Attribute collection
                         update_option('oxdOpenId_user_attributes', isset($_POST['oxdOpenId_user_attributes']) ? $_POST['oxdOpenId_user_attributes'] : 0);
                         $this->oxd_openid_show_success_message();
                     } else {
                         update_option('oxd_openid_message', 'Please register an account before trying to enable any app');
                         $this->oxd_openid_show_error_message();
                     }
                 }
             }
         }
     }
 }