예제 #1
0
 public static function get_blog_id($activation_key)
 {
     global $wpdb;
     $blog_id = 0;
     $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %d", $activation_key));
     if ($row && $row->activation_key == $activation_key) {
         $blog_id = domain_exists($row->domain, $row->path, $wpdb->siteid);
         // As a fallback, try the site domain
         if (empty($blog_id)) {
             $domain = $wpdb->get_var($wpdb->prepare("SELECT domain FROM {$wpdb->site} WHERE id = %d", $wpdb->siteid));
             $blog_id = domain_exists($domain, $row->path, $wpdb->siteid);
         }
     }
     return $blog_id;
 }
function cfgp_install()
{
    /* Make domain a subdomain to example.com so there's
     * 	no possible way to navigate to it from admin or
     * 	front-end */
    $domain = CFGP_SITE_DOMAIN;
    $path = '/';
    if (!domain_exists($domain, $path, $site)) {
        $new_blog_id = create_empty_blog($domain, $path, 'CF Global Posts Blog', CFGP_SITE_ID);
        /* Make the blog private */
        update_blog_status($new_blog_id, 'public', 0);
    } else {
        error_log('Domain Already Exists');
    }
}
예제 #3
0
$master = "";
if (isset($_POST['slave_master'])) {
    $master = $_POST['slave_master'];
}
$type = "SLAVE";
/*
 Check permissions
*/
do_hook('verify_permission', 'zone_slave_add') ? $zone_slave_add = "1" : ($zone_slave_add = "0");
do_hook('verify_permission', 'user_view_others') ? $perm_view_others = "1" : ($perm_view_others = "0");
if (isset($_POST['submit']) && $zone_slave_add == "1") {
    if (!is_valid_hostname_fqdn($zone, 0)) {
        error(ERR_DNS_HOSTNAME);
    } elseif ($dns_third_level_check && get_domain_level($zone) > 2 && domain_exists(get_second_level_domain($zone))) {
        error(ERR_DOMAIN_EXISTS);
    } elseif (domain_exists($zone) || record_name_exists($zone)) {
        error(ERR_DOMAIN_EXISTS);
    } elseif (!is_valid_ipv4($master, false) && !is_valid_ipv6($master)) {
        error(ERR_DNS_IP);
    } else {
        if (add_domain($zone, $owner, $type, $master, 'none')) {
            success("<a href=\"edit.php?id=" . get_zone_id_from_name($zone) . "\">" . SUC_ZONE_ADD . '</a>');
            log_info(sprintf('client_ip:%s user:%s operation:add_zone zone:%s zone_type:SLAVE zone_master:%s', $_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"], $zone, $master, $zone_template));
            unset($zone, $owner, $webip, $mailip, $empty, $type, $master);
        }
    }
}
if ($zone_slave_add != "1") {
    error(ERR_PERM_ADD_ZONE_SLAVE);
} else {
    echo "     <h2>" . _('Add slave zone') . "</h2>\n";
예제 #4
0
 /** RESTful endpoint for this multisite function.
  *
  * Get $_REQUEST options for this endpoint:
  *
  * u (optional) -- Username (if not logged in)
  * p (optional) -- Password (if not logged in)
  * domain (required) full domain of site we're checking on
  * path (required) path of the site we're checking on
  * site_id (optional) site id of the blog (defaults to 1)
  *
  */
 public function domain_exists()
 {
     global $json_api;
     $this->_verify_admin();
     extract($_REQUEST);
     if (!isset($domain)) {
         $json_api->error(__("You must send the 'domain' parameter."));
     }
     if (!isset($path)) {
         $json_api->error(__("You must send the 'path' parameter."));
     }
     if (!isset($site_id)) {
         $site_id = 1;
     }
     if (domain_exists($domain, $path, $site_id)) {
         return array("message" => __("The Domain Exists."));
     } else {
         return array("message" => __("The Domain Does Not Exist."));
     }
 }
예제 #5
0
/**
 * Create a site.
 *
 * This function runs when a user self-registers a new site as well
 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog'
 * for events that should affect all new sites.
 *
 * On subdirectory installs, $domain is the same as the main site's
 * domain, and the path is the subdirectory name (eg 'example.com'
 * and '/blog1/'). On subdomain installs, $domain is the new subdomain +
 * root domain (eg 'blog1.example.com'), and $path is '/'.
 *
 * @since MU
 * @uses domain_exists()
 * @uses insert_blog()
 * @uses wp_install_defaults()
 * @uses add_user_to_blog()
 *
 * @param string $domain The new site's domain.
 * @param string $path The new site's path.
 * @param string $title The new site's title.
 * @param int $user_id The user ID of the new site's admin.
 * @param array $meta Optional. Used to set initial site options.
 * @param int $site_id Optional. Only relevant on multi-network installs.
 * @return mixed Returns WP_Error object on failure, int $blog_id on success
 */
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1)
{
    $domain = preg_replace('/\\s+/', '', sanitize_user($domain, true));
    if (is_subdomain_install()) {
        $domain = str_replace('@', '', $domain);
    }
    $title = strip_tags($title);
    $user_id = (int) $user_id;
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path, $site_id)) {
        return new WP_Error('blog_taken', __('Site already exists.'));
    }
    if (!defined('WP_INSTALLING')) {
        define('WP_INSTALLING', true);
    }
    if (!($blog_id = insert_blog($domain, $path, $site_id))) {
        return new WP_Error('insert_blog', __('Could not create site.'));
    }
    switch_to_blog($blog_id);
    install_blog($blog_id, $title);
    wp_install_defaults($user_id);
    add_user_to_blog($blog_id, $user_id, 'administrator');
    if (is_array($meta)) {
        foreach ($meta as $key => $value) {
            if ($key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id') {
                update_blog_status($blog_id, $key, $value);
            } else {
                update_option($key, $value);
            }
        }
    }
    add_option('WPLANG', get_site_option('WPLANG'));
    update_option('blog_public', (int) $meta['public']);
    if (!is_super_admin() && !get_user_meta($user_id, 'primary_blog', true)) {
        update_user_meta($user_id, 'primary_blog', $blog_id);
    }
    restore_current_blog();
    do_action('wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta);
    return $blog_id;
}
예제 #6
0
function lti_parse_request_OLD($wp)
{
    if (!is_basic_lti_request()) {
        $good_message_type = $_REQUEST[LTI_MESSAGE_TYPE] == LTI_MESSAGE_TYPE_VALUE;
        $good_lti_version = $_REQUEST[LTI_VERSION] == LTI_VERSION_VALUE;
        $resource_link_id = $_REQUEST[RESOURCE_LINK_ID];
        if ($good_message_type && $good_lti_version && !isset($resource_link_id)) {
            $launch_presentation_return_url = $_REQUEST[LAUNCH_PRESENTATION_URL];
            if (isset($launch_presentation_return_url)) {
                header('Location: ' . $launch_presentation_return_url);
                exit;
            }
        }
        return;
    }
    // See if we get a context, do not set session, do not redirect
    $secret = lti_get_secret_from_consumer_key();
    $context = new bltiUocWrapper(false, false, null, $secret);
    if (!$context->valid) {
        //var_dump($_POST);
        echo "<hr>OAuthUtil::urldecode_rfc3986('%2B') " . OAuthUtil::urldecode_rfc3986('%2B') . "<br>";
        echo "<hr>OAuthUtil::urldecode_rfc3986('%5C') " . OAuthUtil::urldecode_rfc3986('%5C') . "<br>";
        wp_die("BASIC LTI Authentication Failed, not valid request (make sure that consumer is authorized and secret is correct) " . $context->message);
        return;
    }
    $error = is_lti_error_data($context);
    if ($error !== FALSE) {
        $launch_presentation_return_url = $_REQUEST[LAUNCH_PRESENTATION_URL];
        if (isset($launch_presentation_return_url)) {
            $error = '<p>' . $error . '</p><p>Return to site <a href="' . $launch_presentation_return_url . '">' . $launch_presentation_return_url . '</a></p>';
        }
        wp_die($error, '');
    }
    $blogType = new blogTypeLoader($context);
    if ($blogType->error < 0) {
        wp_die("BASIC LTI loading Types Aula Failed " . $blogType->error_miss);
        return;
    }
    // Set up the user...
    $userkey = getUserkeyLTI($context);
    $userkey = apply_filters('pre_user_login', $userkey);
    $userkey = trim($userkey);
    if (empty($userkey)) {
        wp_die('<p>Empty username</p><p>Cannot create a user without username</p>');
    }
    $uinfo = get_user_by('login', $userkey);
    if (isset($uinfo) && $uinfo != false) {
        // og LTI: set the user_login and user_nicename to the same value,
        // , because we want the wordpress-login cookie to have the username
        // otherwise caching won't work properly!
        $ret_id = wp_insert_user(array('ID' => $uinfo->ID, 'user_login' => $userkey, 'user_nicename' => $userkey, 'first_name' => $context->getUserFirstName(), 'last_name' => $context->getUserLastName(), 'user_email' => $context->getUserEmail(), 'user_url' => 'http://b', 'display_name' => $context->getUserName(), 'role' => get_option('default_role')));
        //error_log("og old role is set");
        if (is_object($ret_id) && isset($ret_id->errors)) {
            $msg = '';
            foreach ($ret_id->errors as $key => $error) {
                $msg .= "<p><b>{$key}</b> ";
                foreach ($error as $erroMsg) {
                    $msg .= "<p> {$erroMsg}</p>";
                }
                $msg .= "</p>";
            }
            wp_die($msg);
        }
    } else {
        // new user!!!!
        $ret_id = wp_insert_user(array('user_login' => $userkey, 'user_nicename' => $context->getUserName(), 'first_name' => $context->getUserFirstName(), 'last_name' => $context->getUserLastName(), 'user_email' => $context->getUserEmail(), 'user_url' => 'http://c', 'display_name' => $context->getUserName()));
        if (is_object($ret_id) && isset($ret_id->errors)) {
            $msg = '';
            foreach ($ret_id->errors as $key => $error) {
                $msg .= "<p><b>{$key}</b> ";
                foreach ($error as $erroMsg) {
                    $msg .= "<p> {$erroMsg}</p>";
                }
                $msg .= "</p>";
            }
            wp_die($msg);
        }
        $uinfo = get_user_by('login', $userkey);
    }
    //Eliminem del blog Principal (si no es admin) http://jira.uoc.edu/jira/browse/BLOGA-218
    if (!$is_admin) {
        $user = new WP_User($uinfo->ID);
        $user->remove_all_caps();
    }
    $_SERVER['REMOTE_USER'] = $userkey;
    $password = md5($uinfo->user_pass);
    // User is now authorized; force WordPress to use the generated password
    //login, set cookies, and set current user
    wp_authenticate($userkey, $password);
    wp_set_auth_cookie($user->ID, false);
    wp_set_current_user($user->ID, $userkey);
    $siteUrl = substr(get_option("siteurl"), 7);
    // - "http://"
    $siteUrlArray = explode("/", $siteUrl);
    $domain = $siteUrlArray[0];
    unset($siteUrlArray[0]);
    //error_log("og LTI domain: ". $domain);
    $course = $blogType->getCoursePath($context, $siteUrlArray, $domain);
    if (isset($context->info[RESOURCE_LINK_ID]) && $context->info[RESOURCE_LINK_ID]) {
        $course .= '-' . $context->info[RESOURCE_LINK_ID];
    }
    $course = sanitize_user($course, true);
    //Bug wordpress doesn't get stye sheet if has a dot
    $course = str_replace('.', '_', $course);
    $path_base = "/" . implode("/", $siteUrlArray) . "/" . $course;
    $path_base = str_replace('//', '/', $path_base);
    $path = $path_base . "/";
    $path = str_replace('//', '/', $path);
    $blog_created = false;
    $overwrite_plugins_theme = isset($context->info[OVERWRITE_PLUGINS_THEME]) ? $context->info[OVERWRITE_PLUGINS_THEME] == 1 : false;
    $overwrite_roles = isset($context->info[OVERWRITE_ROLES]) ? $context->info[OVERWRITE_ROLES] == 1 : false;
    $blog_id = domain_exists($domain, $path);
    $blog_is_new = false;
    if (!isset($blog_id)) {
        $title = __("Blog ") . $blogType->getCourseName($context);
        $blog_is_new = true;
        $meta = $blogType->getMetaBlog($context);
        $old_site_language = get_site_option('WPLANG');
        $blogType->setLanguage($context);
        $blog_id = wpmu_create_blog($domain, $path, $title, $user_id, $meta);
        update_site_option('WPLANG', $old_site_language);
        $blogType->checkErrorCreatingBlog($blog_id, $path);
        $blog_created = true;
    }
    // Connect the user to the blog
    if (isset($blog_id)) {
        switch_to_blog($blog_id);
        ob_start();
        if ($overwrite_plugins_theme || $blog_created) {
            $blogType->loadPlugins();
            $blogType->changeTheme();
        }
        //Agafem el rol anterior
        $old_role = null;
        if (!$blog_created && !$overwrite_roles) {
            $old_role_array = get_usermeta($user->id, 'wp_' . $blog_id . '_capabilities');
            if (count($old_role_array) > 0) {
                foreach ($old_role_array as $key => $value) {
                    if ($value == true) {
                        $old_role = $key;
                    }
                }
            }
        }
        remove_user_from_blog($uinfo->ID, $blog_id);
        $obj = new stdClass();
        $obj->blog_id = $blog_id;
        $obj->userkey = $userkey;
        $obj->path_base = $path_base;
        $obj->domain = $domain;
        $obj->context = $context;
        $obj->uinfoID = $uinfo->ID;
        $obj->blog_is_new = $blog_is_new;
        if ($overwrite_roles || $old_role == null) {
            $obj->role = $blogType->roleMapping($context->info[FIELD_ROLE_UOC_CAMPUS], $context->info);
        } else {
            $obj->role = $old_role;
        }
        $blogType->postActions($obj);
        add_user_to_blog($blog_id, $uinfo->ID, $obj->role);
        //Si posem el restore_current_blog ens va al principi
        //    	restore_current_blog();
        ob_end_clean();
    }
    $redirecturl = get_option("siteurl");
    //error_log("og LTI redirect URL: ".$redirecturl);
    $redirecturl = str_replace("http://", "https://", $redirecturl);
    //error_log("og LTI new redirect URL: ".$redirecturl);
    wp_redirect($redirecturl);
    exit;
}
예제 #7
0
 public function ssw_check_domain_exists()
 {
     if (wp_verify_nonce($_POST['ssw_ajax_nonce'], 'ssw_ajax_action')) {
         global $current_blog;
         global $current_site;
         global $wpdb;
         $options = $this->ssw_fetch_config_options();
         $site_address_bucket_none_value = $options['site_address_bucket_none_value'];
         $banned_root_site_address = $options['banned_root_site_address'];
         $banned_site_address = $options['banned_site_address'];
         $is_debug_mode = $options['debug_mode'];
         $site_address_bucket = sanitize_key($_POST['site_address_bucket']);
         /**
          *	Replace '-' from site address since it is being used to separate a site name from site category/bucket 
          */
         $site_address = str_replace('-', '', sanitize_key($_POST['site_address']));
         $is_banned_site = 0;
         if (in_array($site_address_bucket, $site_address_bucket_none_value) != true && $site_address_bucket != '') {
             /* Check for banned site addresses */
             if (in_array($site_address, $banned_site_address) != true) {
                 $site_exists = domain_exists($current_blog->domain, $current_site->path . sanitize_key($_POST['site_complete_path']));
             } else {
                 $is_banned_site = 1;
             }
         } else {
             /* Check for banned root site addresses and banned site addresses */
             if (in_array($site_address, $banned_root_site_address) != true && in_array($site_address, $banned_site_address) != true) {
                 $site_exists = domain_exists($current_blog->domain, $current_site->path . sanitize_key($_POST['site_complete_path']));
             } else {
                 $is_banned_site = 1;
             }
         }
         if ($is_banned_site == 1) {
             echo '2';
         } else {
             if ($site_exists) {
                 echo '1';
             } else {
                 echo '0';
             }
         }
         /* Extra wp_die is to stop ajax call from appending extra 0 to the resposne */
         wp_die();
     } else {
         wp_die("Please use valid forms to send data.");
     }
 }
예제 #8
0
파일: _step2.php 프로젝트: verbazend/AWFA
<form method="post" action="<?php 
    echo esc_url($form_url);
    ?>
">
<?php 
    wp_nonce_field('bbms-migration', 'pb_bbms_migrate');
    ?>

<p><?php 
    esc_html_e('Please verify that you are sure you would like to import the backed up site into the just-created blank site. This import cannot be undone.', 'it-l10n-backupbuddy');
    ?>
</p>
<p>
<?php 
    if (is_subdomain_install()) {
        if (domain_exists($blog_domain, '/', $current_blog->blog_id)) {
            //$newdomain = $blog_domain;
            $newdomain = $domain;
            $path = $blog_domain . '/';
        } else {
            $path = $domain . '.' . preg_replace('|^www\\.|', '', $current_blog->domain);
        }
        ?>
	<?php 
        echo '<strong>http://' . $path . '</strong>';
    } else {
        echo 'http://' . $current_blog->domain . '<strong>' . $path . '</strong>';
    }
    ?>
</p>
<input type="hidden" name="backup_file" value="<?php 
예제 #9
0
 /**
  * When a path is passed to domain_exists, it is immediately trailing slashed. A path
  * value with or without the slash should result in the same return value.
  */
 function test_slashed_path_in_domain_exists()
 {
     add_filter('domain_exists', array($this, '_domain_exists_cb'), 10, 4);
     $exists1 = domain_exists('foo', 'bar');
     $exists2 = domain_exists('foo', 'bar/');
     remove_filter('domain_exists', array($this, '_domain_exists_cb'), 10, 4);
     // Make sure the same result is returned with or without a trailing slash
     $this->assertEquals($exists1, $exists2);
 }
예제 #10
0
 /**
  * Is a site URL okay to save?
  *
  * @since 1.8.0
  *
  * @global wpdb $wpdb
  *
  * @param string $domain
  * @param string $path
  * @param string $slug
  *
  * @return boolean
  */
 function wp_validate_site_url($domain, $path, $site_id = 0)
 {
     global $wpdb;
     // Does domain exist on this network
     $exists = domain_exists($domain, $path, get_current_site()->id);
     // Bail if domain is current site ID
     if ($exists == $site_id) {
         return true;
     }
     // Bail if domain exists and it's not this site
     if (true === $exists) {
         return false;
     }
     // Bail if site is in signups table
     $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE domain = %s AND path = %s", $domain, $path));
     if (!empty($signup)) {
         return false;
     }
     // Bail if user is a super admin
     if (is_super_admin()) {
         return true;
     }
     // Get pieces of domain & path
     $paths = explode('/', $path);
     $domains = substr_count($domain, '.') > 1 ? (array) substr($domain, 0, strpos($domain, '.')) : array();
     $pieces = array_filter(array_merge($domains, $paths));
     // Loop through pieces
     foreach ($pieces as $slug) {
         // Bail if empty
         if (empty($slug)) {
             return false;
         }
         // Bail if not lowercase or numbers
         if (preg_match('/[^a-z0-9]+/', $slug)) {
             return false;
         }
         // All numeric?
         if (preg_match('/^[0-9]*$/', $slug)) {
             return false;
         }
         // Bail if less than 4 chars
         if (strlen($slug) < 3) {
             return false;
         }
         // Get illegal names
         $illegal_names = get_site_option('illegal_names');
         // Maybe merge reserved names
         if (!is_subdomain_install()) {
             $illegal_names = array_merge($illegal_names, get_subdirectory_reserved_names());
         }
         // Bail if contains illegal names
         if (in_array($slug, $illegal_names, true)) {
             return false;
         }
         // Bail if username exists
         if (username_exists($slug)) {
             return false;
         }
         // Bail if subdirectory install and page exists on primary site of network
         if (!is_subdomain_install()) {
             switch_to_blog(get_current_site()->blog_id);
             $page = get_page_by_path($slug);
             restore_current_blog();
             if (!empty($page)) {
                 return false;
             }
         }
     }
     // Okay, s'all good
     return true;
 }
예제 #11
0
function pmpron_checkSiteName($sitename)
{
    global $pmpro_msg, $pmpro_msgt, $current_site;
    //they entered something. is it available
    $site_domain = preg_replace('|^www\\.|', '', $current_site->domain);
    if (!is_subdomain_install()) {
        $site = $current_site->domain;
        $path = $current_site->path . "/" . $sitename;
    } else {
        $site = $sitename . '.' . $site_domain;
        $path = $current_site->path;
    }
    $domain = preg_replace('/\\s+/', '', sanitize_user($site, true));
    if (is_subdomain_install()) {
        $domain = str_replace('@', '', $domain);
    }
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path)) {
        //dupe
        $pmpro_msg = "That site name is already in use.";
        $pmpro_msgt = "pmpro_error";
        return false;
    } else {
        //looks good
        return true;
    }
}
 public function CheckTextBox($surname, $name, $NameOfFather, $NameOfMother, $Address, $Phone, $DateOfBorn, $Age, $PoliceID, $AMKA, $NumberIdentificationIKA, $AFM, $Situation, $RelationshipOfWork, $DateOfUptake, $Service, $Section, $Node, $Specialty, $GradeSelection, $NumsFor0To6, $Email, $NumberIdentificationEmployee)
 {
     //                        echo "Άδεια οδήγησης οχήματος(After): ".$DriveLicense."<br>";
     //                        echo "Κάρτα POL(After): ".$CardPOL."<br>";
     //                        echo "Ημερομηνία πρόσληψης: ".$DateOfUptake."<br>";
     //                        $FieldArray = array(0=>$name, 1=>$surname, 2=>$PoliceID, 3=>$NameOfFather,
     //                                            4=>$NameOfMother, 5=>$DateOfBorn, 6=>$Situation, 7=>$RelationshipOfWork,
     //                                            8=>$DateOfUptake, 9=>$Specialty, 10=>$Phone, 11=>$AFM, 12=>$Service,
     //                                            13=>$AMKA, 14=>$Age, 15=>$NumsFor0To6, 16=>$GradeSelection, 17=>$Address,
     //                                            18=>$Section, 19=>$Email, 20=>$Node);
     //                        $LengthOfFieldArray = count($FieldArray);
     if (!is_numeric($NumberIdentificationEmployee) || strlen($NumberIdentificationEmployee) != 6) {
         $this->failed = true;
         $this->NumberIdentificationEmployeeFailed = true;
     }
     if (!is_numeric($NumberIdentificationIKA) || strlen($NumberIdentificationIKA) != 7) {
         $this->failed = true;
         $this->NumberIdentificationIKAFailed = true;
     }
     if (is_numeric($Age) == false || ($Age < 18 || $Age > 80)) {
         $this->failed = true;
         $this->AgeFailed = true;
     }
     if (is_numeric($AFM) == false || strlen($AFM) != 9) {
         $this->failed = true;
         $this->AFMfailed = true;
     }
     if ((is_numeric($AMKA) == false || strlen($AMKA) != 11) && $AMKA != null) {
         $this->failed = true;
         $this->AMKAfailed = true;
     }
     $PoliceIDLenght = mb_strlen($PoliceID, 'utf-8');
     //                            echo  "<br> PoliceId: ".$PoliceID." PoliceIdLength: ".$PoliceIDLenght;
     if ($PoliceIDLenght == 7 || $PoliceIDLenght == 8) {
         if ($PoliceIDLenght == 7) {
             $Firstletter = mb_substr($PoliceID, 0, 1, "utf-8");
             //Put on variable '$Firstletter' first letter of PoliceId field
             $RestLetters = mb_substr($PoliceID, 1, $PoliceIDLenght, "utf-8");
             //Put on variable '$RestLetters' restt letters of PoliceId field
             if (!is_string($Firstletter) || !is_numeric($RestLetters)) {
                 $this->failed = true;
                 $this->PoliceIdfailed = true;
             }
         }
         if ($PoliceIDLenght == 8) {
             $First2letters = mb_substr($PoliceID, 0, 2, "utf-8");
             //Put on variable '$First2letters' first 2 letters of PoliceId field
             $RestLetters = mb_substr($PoliceID, 2, $PoliceIDLenght, "utf-8");
             //Put on variable '$RestLetters' restt letters of PoliceId field
             if (!is_string($First2letters) || !is_numeric($RestLetters)) {
                 $this->failed = true;
                 $this->PoliceIdfailed = true;
             }
         }
     } else {
         $this->failed = true;
         $this->PoliceIdLengthFailed = true;
     }
     if (strlen($Phone) != 10 && $Phone != null) {
         $this->failed = true;
         $this->PhoneFailed = true;
     } else {
         if (!is_numeric($Phone) && $Phone != null) {
             $this->failed = true;
             $this->PhoneStirngFailed = true;
         } else {
             if ($Phone == null) {
             }
         }
     }
     if (check_email_address($Email) == true && $Email != null) {
         if (domain_exists($Email)) {
         } else {
             $this->failed = true;
             $this->EmailFailed = true;
         }
     } else {
         if ($Email == null || ($Email = " ")) {
         } else {
             $this->failed = true;
             $this->EmailFormFailed = true;
         }
     }
 }
예제 #13
0
    } else {
        echo $avaible . $lang['Pstrong'];
    }
    exit;
}
if (isset($_POST["checkRepass"])) {
    if ($_POST["checkRepass"] === $_POST["checkpassO"]) {
        echo $avaible . $lang["PGood"];
    } else {
        echo $notAvaible . $lang['PdoesnotMatch'];
    }
    exit;
}
if (isset($_POST["checkMail"])) {
    if (filter_var($_POST["checkMail"], FILTER_VALIDATE_EMAIL)) {
        if (domain_exists($_POST["checkMail"])) {
            echo $avaible . $lang["PGood"];
        } else {
            echo $notAvaible . $lang["PDomainNotExist"];
        }
    } else {
        echo $notAvaible . $lang["PBadSyntax"];
    }
    exit;
}
//check we have username post var
if (isset($_POST["checkUsername"])) {
    //check if its an ajax request, exit if not
    if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
        die;
    }
예제 #14
0
<?php

// ------------------------------------------------------------
// VALIDATE E-MAIL
// ------------------------------------------------------------
if (!filter_var($txbEmail, FILTER_VALIDATE_EMAIL)) {
    $emailNotValid = $email_error;
    $emailValidate_error = 1;
}
// ------------------------------------------------------------
// WARNING! THE BELOW CODE REQUIRES PHP 5.3 OR LATER on windows
// ------------------------------------------------------------
if (filter_var($txbEmail, FILTER_VALIDATE_EMAIL)) {
    if (domain_exists($txbEmail)) {
        $emailValidate_error = 0;
    } else {
        $emailNotValid = $emailMx_error;
        $emailValidate_error = 1;
    }
}
// check if mx records exist
function domain_exists($emailtocheck, $record = 'MX')
{
    list($user, $domain) = preg_split('/@/', $emailtocheck);
    //return checkdnsrr($domain,$record);
    return 1;
}
예제 #15
0
 private function generate_new_blogid()
 {
     $blog_title = __('Migrated site (from UpdraftPlus)', 'updraftplus');
     if (empty($_POST['updraftplus_migrate_blogname'])) {
         $this->getinfo_form();
         return false;
     }
     // Verify value given
     $result = wpmu_validate_blog_signup($_POST['updraftplus_migrate_blogname'], $blog_title);
     if (count($result['errors']) > 0 && $result['errors']->get_error_code()) {
         if (is_wp_error($result['errors'])) {
             $err_msg = '<ul style="list-style: disc inside;">';
             foreach ($result['errors']->get_error_messages() as $key => $msg) {
                 $err_msg .= '<li><strong>' . __('Error:', 'updraftplus') . '</strong> ' . htmlspecialchars($msg) . '</li>';
             }
             $err_msg .= '</ul>';
         }
         if (isset($err_msg)) {
             $this->getinfo_form($err_msg, $_POST['updraftplus_migrate_blogname']);
             return false;
         }
     }
     $blogname = $_POST['updraftplus_migrate_blogname'];
     global $wpdb;
     if (domain_exists($result['domain'], $result['path'], $wpdb->siteid)) {
         // A WordPress-native string
         $this->getinfo_form(__('<strong>ERROR</strong>: Site URL already taken.'), $_POST['updraftplus_migrate_blogname']);
         return false;
     }
     $create = create_empty_blog($result['domain'], $result['path'], $blog_title, $wpdb->siteid);
     if (is_integer($create)) {
         $url = untrailingslashit($result['domain'] . $result['path']);
         echo '<strong>' . __('New site:', 'updraftplus') . '</strong> ' . $url . '<br>';
         // Update record of what we want to rewrite the URLs to in the search/replace operation
         // TODO: How to detect whether http or https???
         $this->siteurl = 'http://' . $url;
         // ???
         $this->home = 'http://' . $url;
         return $create;
     } else {
         $this->getinfo_form(print_r($create, true), $_POST['updraftplus_migrate_blogname']);
         return false;
     }
 }
예제 #16
0
 function admin_quick_clone_link($action_links, $blog_id, $blog_name)
 {
     global $domain;
     $site_domain = str_replace('www.', '', $domain);
     $site_base = get_current_site()->path;
     // determine the new clone's name and title
     // this has to make sure there will be no conflicts with existing sites so keep bumping up the copy number until no existing conflicting sites are found
     $duplicate_count = 1;
     do {
         $duplicate_count++;
         $target_name = preg_replace(array('|/|', '/\\..+$/'), '', $blog_name) . "-{$duplicate_count}";
         $target_domain = is_subdomain_install() ? $target_name . '.' . $site_domain : $site_domain;
         $target_path = is_subdomain_install() ? $site_base : $site_base . $target_name . '/';
     } while (domain_exists($target_domain, $target_path));
     $target_title = get_blog_option($blog_id, 'blogname') . " {$duplicate_count}";
     // add the link to the site action links
     $link = $this->build_url(array("action" => "process", "clone_mode" => "core", "source_id" => $blog_id, "target_name" => $target_name, "target_title" => $target_title, "disable_addons" => true, "clone_nonce" => wp_create_nonce("ns_cloner")));
     $action_links['clone'] = '<span class="clone"><a href="' . $link . '" target="_blank">Clone</a></span>';
     return $action_links;
 }
예제 #17
0
 if (empty($domain)) {
     $messages['errors'][] = __('Missing or invalid site address.', 'it-l10n-backupbuddy');
 }
 if (is_subdomain_install()) {
     global $current_site;
     //$current_site must be used here since sub-domains treat the current_blog's domain as ron1.domain.com whereas $current_site uses domain.com
     $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain);
     $path = $base;
 } else {
     $newdomain = $current_blog->domain;
     $path = $base . $domain . '/';
 }
 $blog_id = 0;
 $old_blog_id = $current_blog->blog_id;
 if (domain_exists($newdomain, $path, $current_blog->blog_id)) {
     $blog_id = domain_exists($newdomain, $path, $current_blog->blog_id);
     $messages['errors'][] = __('Site already exists.', 'it-l10n-backupbuddy');
 } elseif (count($messages['errors']) == 0) {
     $messages['updates'][] = __('The site has been created.', 'it-l10n-backupbuddy');
     //$blog_id = wpmu_create_blog( $newdomain, $path, 'temp title', $current_user->ID, array( 'public' => 1 ) );
 }
 //Output alerts
 foreach ($messages['updates'] as $update) {
     $this->_parent->alert($update);
 }
 foreach ($messages['errors'] as $error) {
     $this->_parent->alert($error, true);
 }
 if (count($messages['errors']) > 0) {
     $errors = true;
     require_once 'step1.php';
    $zone = trim($_POST['domain']);
}
$master = "";
if (isset($_POST['slave_master'])) {
    $master = $_POST['slave_master'];
}
$type = "SLAVE";
/*
Check permissions
*/
verify_permission('zone_slave_add') ? $zone_slave_add = "1" : ($zone_slave_add = "0");
verify_permission('user_view_others') ? $perm_view_others = "1" : ($perm_view_others = "0");
if (isset($_POST['submit']) && $zone_slave_add == "1") {
    if (!is_valid_hostname_fqdn($zone, 0)) {
        error(ERR_DNS_HOSTNAME);
    } elseif (domain_exists($zone)) {
        error(ERR_DOMAIN_EXISTS);
    } elseif (!is_valid_ipv4($master) && !is_valid_ipv6($master)) {
        error(ERR_DNS_IP);
    } else {
        if (add_domain($zone, $owner, $type, $master, 'none')) {
            success("<a href=\"edit.php?id=" . get_zone_id_from_name($zone) . "\">" . SUC_ZONE_ADD . '</a>');
            unset($zone, $owner, $webip, $mailip, $empty, $type, $master);
        }
    }
}
if ($zone_slave_add != "1") {
    error(ERR_PERM_ADD_ZONE_SLAVE);
} else {
    echo "     <h2>" . _('Add slave zone') . "</h2>\n";
    $users = show_users();
예제 #19
0
 public static function activate_blog($data, $trial = false, $period = 1, $level = 1, $expire = false)
 {
     global $psts, $wpdb;
     $user_pass = false;
     if (!is_array($data)) {
         $key = $data;
     } else {
         $key = isset($data['activation_key']) ? $data['activation_key'] : false;
         $user_pass = isset($data['new_blog_details']['user_pass']) ? $data['new_blog_details']['user_pass'] : false;
     }
     if (empty($key)) {
         return false;
     }
     // In case we're in session
     $session_data['new_blog_details'] = ProSites_Helper_Session::session('new_blog_details');
     $user_pass = empty($user_pass) && isset($session_data['new_blog_details']['user_pass']) ? $session_data['new_blog_details']['user_pass'] : $user_pass;
     if (!empty($user_pass)) {
         self::$temp_pass = $user_pass;
         add_filter('update_welcome_email', array('ProSites_Helper_Registration', 'update_welcome_email'), 10, 6);
     }
     // Activate the user signup
     $result = wpmu_activate_signup($key);
     $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $key));
     // If the blog has already been activated, we still need some information from the signup table
     if (is_wp_error($result)) {
         $result = array();
         if (empty($signup)) {
             return 0;
         }
         $user_id = username_exists($signup->user_login);
         $blog_id = domain_exists($signup->domain, $signup->path, $wpdb->siteid);
         // As a fallback, try the site domain
         if (empty($blog_id)) {
             $domain = $wpdb->get_var($wpdb->prepare("SELECT domain FROM {$wpdb->site} WHERE id = %d", $wpdb->siteid));
             $blog_id = domain_exists($domain, $signup->path, $wpdb->siteid);
         }
         $result['user_id'] = $user_id;
         $result['blog_id'] = (int) $blog_id;
     }
     /**
      * Update coupon information
      */
     if (!empty($signup)) {
         //				$blog_id = $result['blog_id'];
         //				$signup_meta = maybe_unserialize( $signup->meta );
         //
         //				// Unlikely that this will have a coupon, but make sure
         //				$used = (array) get_blog_option( $blog_id, 'psts_used_coupons' );
         //
         //				// Is there a coupon stored in the signup_meta?
         //				if( isset( $signup_meta['psts_used_coupons'] ) && ! empty( $signup_meta['psts_used_coupons'] ) && is_array( $signup_meta['psts_used_coupons'] ) ) {
         //					// Merge and make sure we don't record the same coupon twice
         //					$used = array_merge( $used, $signup_meta['psts_used_coupons'] );
         //					$used = array_unique( $used );
         //					// Remove from signup meta
         //					unset( $signup_meta['psts_used_coupons'] );
         //					$psts->update_signup_meta( $signup_meta, $key );
         //				}
         //				if( ! empty( $used ) ) {
         //					// Add to blog options
         //					update_blog_option( $blog_id, 'psts_used_coupons', $used );
         //				}
     }
     /**
      * @todo: Make sure we dont over extend
      */
     //Set Trial
     if ($trial) {
         $trial_days = $psts->get_setting('trial_days', 0);
         // Set to first level for $trial_days
         $psts->extend($result['blog_id'], $period, 'Trial', $level, '', strtotime('+ ' . $trial_days . ' days'));
         //Redirect to checkout on next signup
         /**
          * @todo May not be needed here anymore
          */
         //update_blog_option( $result['blog_id'], 'psts_signed_up', 1 );
     }
     if (!empty($user_pass)) {
         $result['password'] = $user_pass;
     }
     // Contains $result['password'] for new users
     return $result;
 }
예제 #20
0
	function test_domain_exists() {
		$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
		$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) );

		$details = get_blog_details( $blog_id, false );

		$this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path ) );
		$this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path, $details->site_id ) );
		$this->assertEquals( null, domain_exists( $details->domain, $details->path, 999 ) );
		$this->assertEquals( null, domain_exists( 'foo', 'bar' ) );

		add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
		$this->assertEquals( 1234, domain_exists( 'foo', 'bar' ) );
		$this->assertEquals( null, domain_exists( 'foo', 'baz' ) );
		$this->assertEquals( null, domain_exists( 'bar', 'foo' ) );

		// Make sure the same result is returned with or without a trailing slash
		$this->assertEquals( domain_exists( 'foo', 'bar' ), domain_exists( 'foo', 'bar/' ) );

		remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
		$this->assertEquals( null, domain_exists( 'foo', 'bar' ) );

		wpmu_delete_blog( $blog_id );
		$this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path ) );
		wpmu_delete_blog( $blog_id, true );
		$this->assertEquals( null, domain_exists( $details->domain, $details->path ) );
	}
예제 #21
0
    $enable_dnssec = true;
}
/*
 Check user permissions
*/
do_hook('verify_permission', 'zone_master_add') ? $zone_master_add = "1" : ($zone_master_add = "0");
do_hook('verify_permission', 'user_view_others') ? $perm_view_others = "1" : ($perm_view_others = "0");
if (isset($_POST['submit']) && $zone_master_add == "1") {
    $error = false;
    foreach ($domains as $domain) {
        if (!is_valid_hostname_fqdn($domain, 0)) {
            error($domain . ' failed - ' . ERR_DNS_HOSTNAME);
        } elseif ($dns_third_level_check && get_domain_level($domain) > 2 && domain_exists(get_second_level_domain($domain))) {
            error($domain . ' failed - ' . ERR_DOMAIN_EXISTS);
            $error = true;
        } elseif (domain_exists($domain) || record_name_exists($domain)) {
            error($domain . ' failed - ' . ERR_DOMAIN_EXISTS);
            // TODO: repopulate domain name(s) to the form if there was an error occured
            $error = true;
        } elseif (add_domain($domain, $owner, $dom_type, '', $zone_template)) {
            $domain_id = get_zone_id_from_name($domain);
            success("<a href=\"edit.php?id=" . $domain_id . "\">" . $domain . " - " . SUC_ZONE_ADD . '</a>');
            log_info(sprintf('client_ip:%s user:%s operation:add_zone zone:%s zone_type:%s zone_template:%s', $_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"], $domain, $dom_type, $zone_template));
            if ($pdnssec_use) {
                if ($enable_dnssec) {
                    dnssec_secure_zone($domain);
                }
                dnssec_rectify_zone($domain_id);
            }
        }
    }
예제 #22
0
/**
 * Create a site.
 *
 * This function runs when a user self-registers a new site as well
 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog'
 * for events that should affect all new sites.
 *
 * On subdirectory installs, $domain is the same as the main site's
 * domain, and the path is the subdirectory name (eg 'example.com'
 * and '/blog1/'). On subdomain installs, $domain is the new subdomain +
 * root domain (eg 'blog1.example.com'), and $path is '/'.
 *
 * @since MU
 *
 * @param string $domain  The new site's domain.
 * @param string $path    The new site's path.
 * @param string $title   The new site's title.
 * @param int    $user_id The user ID of the new site's admin.
 * @param array  $meta    Optional. Used to set initial site options.
 * @param int    $site_id Optional. Only relevant on multi-network installs.
 * @return int|WP_Error Returns WP_Error object on failure, int $blog_id on success
 */
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = array(), $site_id = 1)
{
    $defaults = array('public' => 0);
    $meta = wp_parse_args($meta, $defaults);
    $domain = preg_replace('/\\s+/', '', sanitize_user($domain, true));
    if (is_subdomain_install()) {
        $domain = str_replace('@', '', $domain);
    }
    $title = strip_tags($title);
    $user_id = (int) $user_id;
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path, $site_id)) {
        return new WP_Error('blog_taken', __('Sorry, that site already exists!'));
    }
    if (!wp_installing()) {
        wp_installing(true);
    }
    if (!($blog_id = insert_blog($domain, $path, $site_id))) {
        return new WP_Error('insert_blog', __('Could not create site.'));
    }
    switch_to_blog($blog_id);
    install_blog($blog_id, $title);
    wp_install_defaults($user_id);
    add_user_to_blog($blog_id, $user_id, 'administrator');
    foreach ($meta as $key => $value) {
        if (in_array($key, array('public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'))) {
            update_blog_status($blog_id, $key, $value);
        } else {
            update_option($key, $value);
        }
    }
    add_option('WPLANG', get_site_option('WPLANG'));
    update_option('blog_public', (int) $meta['public']);
    if (!is_super_admin($user_id) && !get_user_meta($user_id, 'primary_blog', true)) {
        update_user_meta($user_id, 'primary_blog', $blog_id);
    }
    restore_current_blog();
    /**
     * Fires immediately after a new site is created.
     *
     * @since MU
     *
     * @param int    $blog_id Blog ID.
     * @param int    $user_id User ID.
     * @param string $domain  Site domain.
     * @param string $path    Site path.
     * @param int    $site_id Site ID. Only relevant on multi-network installs.
     * @param array  $meta    Meta data. Used to set initial site options.
     */
    do_action('wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta);
    return $blog_id;
}
예제 #23
0
파일: contact.php 프로젝트: 72juju/Luna
 $strSubject = $_POST['subject'];
 $strMessage = $_POST['comments'];
 if (!isset($strUsername) || !isset($strEmail) || !isset($strSubject) || !isset($strMessage)) {
     sendError('One or more fields has not been completed, please fill in everything');
 }
 $strUsername = mysqli_real_escape_string($resDBCon, $strUsername);
 $strEmail = mysqli_real_escape_string($resDBCon, $strEmail);
 $strSubject = mysqli_real_escape_string($resDBCon, $strSubject);
 $strMessage = mysqli_real_escape_string($resDBCon, $strMessage);
 $strUsername = stripslashes($strUsername);
 $strEmail = stripslashes($strEmail);
 $strSubject = stripslashes($strSubject);
 $strMessage = stripslashes($strMessage);
 if (!filter_var($strEmail, FILTER_VALIDATE_EMAIL)) {
     sendError('Invalid email address! Please recheck your email');
 } elseif (!domain_exists($strEmail)) {
     sendError('Invalid domain for email address! Please use a valid domain');
 } elseif (!ctype_alnum($strUsername) && strlen($strUsername) > 10 && strlen($strUsername) <= 3) {
     sendError('Invalid username! Please make sure the username is alphanumeric and not too long or short');
 } elseif (!ctype_alnum($strSubject) && strlen($strSubject) < 5 && strlen($strSubject) > 20) {
     sendError('Invalid title! Please enter a valid subject, make sure it is alphanumeric and more than 5 and lesser than 10 characters long');
 } elseif (!ctype_alnum($strMessage) && strlen($strMessage) < 5 && strlen($strMessage) > 500) {
     sendError('Invalid message! Please enter a valid message, make sure it is alphanumeric and more than 5 and lesser than 500 characters long');
 }
 $strSecretKey = '6Lee7RMTAAAAAD_B4-4nEt2Amni4XC3EfGmKEI_K';
 //edit this, its your secret/private key for the captcha
 $recaptcha = new \ReCaptcha\ReCaptcha($strSecretKey);
 $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $strIP);
 if (!$resp->isSuccess()) {
     sendError('You are a bot, get the f**k out');
 } else {
/**
 * Create an empty blog.
 *
 * @since MU 1.0
 * @deprecated 4.4.0
 *
 * @param string $domain       The new blog's domain.
 * @param string $path         The new blog's path.
 * @param string $weblog_title The new blog's title.
 * @param int    $site_id      Optional. Defaults to 1.
 * @return string|int The ID of the newly created blog
 */
function create_empty_blog($domain, $path, $weblog_title, $site_id = 1)
{
    _deprecated_function(__FUNCTION__, '4.4.0');
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path, $site_id)) {
        return __('<strong>ERROR</strong>: Site URL already taken.');
    }
    // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
    // Need to get blog_id from wp_blogs, and create new table names.
    // Must restore table names at the end of function.
    if (!($blog_id = insert_blog($domain, $path, $site_id))) {
        return __('<strong>ERROR</strong>: problem creating site entry.');
    }
    switch_to_blog($blog_id);
    install_blog($blog_id);
    restore_current_blog();
    return $blog_id;
}
 /**
  * Check if given path is already taken by another site or not
  *
  * @since  1.0
  * @return int 2 if it is banned_site, 1 if site already exits and 0 if doesn't exist.
  */
 public function ssw_check_domain_exists()
 {
     if (wp_verify_nonce($_POST['ssw_ajax_nonce'], 'ssw_ajax_action')) {
         global $current_blog;
         global $current_site;
         global $wpdb;
         $options = $this->ssw_fetch_config_options();
         $site_category = $options['site_user_category'];
         $site_category_no_prefix = $options['site_category_no_prefix'];
         $banned_site_address = $options['banned_site_address'];
         $is_debug_mode = $options['debug_mode'];
         $site_category_selected = sanitize_key($_POST['site_category']);
         // Replace '-' from site address since it is being used to separate a
         // site name from site category/bucket
         $site_address = str_replace('-', '', sanitize_key($_POST['site_address']));
         $is_banned_site = 0;
         for ($i = 0; $i < count($site_category_no_prefix); $i++) {
             $site_category_no_prefix[$i] = $this->ssw_sanitize_option('sanitize_url', $site_category_no_prefix[$i]);
         }
         if (in_array($site_category_selected, $site_category_no_prefix) != true && $site_category_selected != '') {
             $path = $site_category_selected . '-' . $site_address;
         } else {
             $path = $site_address;
         }
         $this->ssw_debug_log('ssw_check_domain_exists()', 'site path', $path);
         // Validate if user's given path is a banned site address
         if (in_array($path, $banned_site_address) != true) {
             $site_exists = domain_exists($current_blog->domain, $current_site->path . $path);
         } else {
             $is_banned_site = 1;
         }
         // Validate if user's given path is name of a site category
         // Super admins are allowed to create sites with address as one of site category
         if (!is_super_admin()) {
             foreach ($site_category as $site_category_user => $site_category_user_value) {
                 foreach ($site_category_user_value as $key => $value) {
                     if ($path == $this->ssw_sanitize_option('sanitize_url', $value)) {
                         $is_banned_site = 1;
                     }
                 }
             }
         }
         // Validate for error flags if set
         if ($is_banned_site == 1) {
             echo '2';
         } else {
             if ($site_exists) {
                 echo '1';
             } else {
                 echo '0';
             }
         }
         // Extra wp_die is to stop ajax call from appending extra 0 to the resposne
         wp_die();
     } else {
         wp_die("Please use valid forms to send data.");
     }
 }
if (isset($_POST['zone_template'])) {
    $zone_template = $_POST['zone_template'];
} else {
    $zone_template = "none";
}
/*
Check user permissions
*/
verify_permission('zone_master_add') ? $zone_master_add = "1" : ($zone_master_add = "0");
verify_permission('user_view_others') ? $perm_view_others = "1" : ($perm_view_others = "0");
if (isset($_POST['submit']) && $zone_master_add == "1") {
    $error = false;
    foreach ($domains as $domain) {
        if (!is_valid_hostname_fqdn($domain, 0)) {
            error($domain . ' failed - ' . ERR_DNS_HOSTNAME);
        } elseif (domain_exists($domain)) {
            error($domain . ' failed - ' . ERR_DOMAIN_EXISTS);
            // TODO: repopulate domain name(s) to the form if there was an error occured
            $error = true;
        } elseif (add_domain($domain, $owner, $dom_type, '', $zone_template)) {
            success("<a href=\"edit.php?id=" . get_zone_id_from_name($domain) . "\">" . $domain . " - " . SUC_ZONE_ADD . '</a>');
        }
    }
    if (false === $error) {
        unset($domains, $owner, $dom_type, $zone_template);
    }
}
if ($zone_master_add != "1") {
    error(ERR_PERM_ADD_ZONE_MASTER);
} else {
    echo "     <h2>" . _('Add master zone') . "</h2>\n";
예제 #27
0
function lti_do_connect($tool_provider)
{
    global $wpdb;
    // If multisite support isn't in play, go home
    if (!is_multisite()) {
        $tool_provider->message = __('The LTI Plugin requires a Multisite installation of WordPress', 'lti-text');
        return FALSE;
    }
    // Clear any existing connections
    //wp_logout();
    // Clear these before use
    $_SESSION[LTI_SESSION_PREFIX . 'return_url'] = '';
    $_SESSION[LTI_SESSION_PREFIX . 'return_name'] = '';
    // Store return URL for later use, if present
    if (!empty($tool_provider->return_url)) {
        $_SESSION[LTI_SESSION_PREFIX . 'return_url'] = strpos($tool_provider->return_url, '?') === FALSE ? $tool_provider->return_url . '?' : $tool_provider->return_url . '&';
        $_SESSION[LTI_SESSION_PREFIX . 'return_name'] = 'Return to VLE';
        if (!empty($tool_provider->consumer->name)) {
            $_SESSION[LTI_SESSION_PREFIX . 'return_name'] = 'Return to ' . $tool_provider->consumer->name;
        }
    }
    // Get what we are using as the username (unique_id-consumer_key, i.e. _21_1-stir.ac.uk)
    $options = get_site_option('lti_choices');
    $scope_userid = lti_get_scope($tool_provider->consumer->getKey());
    $user_login = $tool_provider->user->getID($scope_userid);
    //Swat edit:
    $idLoc = strpos(print_r($tool_provider->user, true), '[id:LTI_User:private] =>');
    $idEOL = strpos(print_r($tool_provider->user, true), ')', $idLoc);
    $whatwewant = substr(print_r($tool_provider->user, true), $idLoc + 25, $idEOL);
    $matches = array();
    if (preg_match('/\\d*/', $whatwewant, $matches)) {
    }
    if (sizeof($matches) > 0) {
        $moodleID = $matches[0];
    } else {
        error_log("LTI Error: No Moodle ID found.");
        $tool_provider->reason = "No Moodle ID";
        return FALSE;
    }
    error_log("!!!!!!!!!!!!!!!!!! Incoming Moodle User !!!!!!!!!!!!!!!!!!" . $moodleID);
    // Sanitize username stripping out unsafe characters
    $user_login = sanitize_user($user_login);
    // Apply the function pre_user_login before saving to the DB.
    $user_login = apply_filters('pre_user_login', $user_login);
    //Swat Edit: array of Banned Users
    $banned_users = array("www", "web", "root", "admin", "main", "invite", "administrator", "files", "blog");
    $userEmail = $tool_provider->user->email;
    $defaultEmailDomain = $tool_provider->consumer->email_domain;
    list($emailUsername, $emailDomain) = explode('@', $tool_provider->user->email);
    if ($emailDomain !== $defaultEmailDomain) {
        error_log("!!!!!!!!!!!!!!!!!! default domain is !!!!!!!!!!!!!!!!!!" . $defaultEmailDomain);
        error_log("!!!!!!!!!!!!!!!!!!Not from default domain!!!!!!!!!!!!!!!!!!");
        $user_login = $user_login . '-' . $moodleID;
    }
    // Check if this username, $user_login, is already defined
    $user = get_user_by('login', $user_login);
    if (!filter_var($tool_provider->user->email, FILTER_VALIDATE_EMAIL) || in_array($user_login, $banned_users)) {
        wp_logout();
    } elseif ($user) {
        // If user exists, simply save the current details
        $result = wp_insert_user(array('ID' => $user->ID, 'user_login' => $user_login, 'user_nicename' => $user_login, 'first_name' => $tool_provider->user->firstname, 'last_name' => $tool_provider->user->lastname, 'user_email' => $tool_provider->user->email, 'display_name' => $tool_provider->user->fullname));
    } else {
        // Create username if user provisioning is on
        $result = wp_insert_user(array('user_login' => $user_login, 'user_pass' => wp_generate_password(), 'user_nicename' => $user_login, 'first_name' => $tool_provider->user->firstname, 'last_name' => $tool_provider->user->lastname, 'user_email' => $tool_provider->user->email, 'display_name' => $tool_provider->user->fullname));
        // Handle any errors by capturing and returning to the consumer
        if (is_wp_error($result)) {
            $tool_provider->reason = $result->get_error_message();
            return FALSE;
        } else {
            // Get the new users details
            $user = get_user_by('login', $user_login);
        }
    }
    // Get user ID
    $user_id = $user->ID;
    // Staff or Learner
    $staff = FALSE;
    $learner = FALSE;
    $staff = $tool_provider->user->isStaff() || $tool_provider->user->isAdmin();
    $learner = $tool_provider->user->isLearner();
    // set up some useful variables
    $key = $tool_provider->resource_link->getKey();
    $context_id = $tool_provider->context->getId();
    //Swat Edit to get contect label
    $context_label = slugify($tool_provider->resource_link->context_label);
    $resource_id = $tool_provider->resource_link->getId();
    // Create blog
    $use_context = FALSE;
    if (!empty($context_id)) {
        $use_context = $tool_provider->resource_link->getSetting('custom_use_context') == 'true' ? TRUE : FALSE;
    }
    if ($use_context) {
        // Create new blog, if does not exist. Note this gives one blog per context, the consumer supplies a context_id
        // otherwise it creates a blog per resource_id
        $path = $key . '_' . $context_id;
    } else {
        //swat Edit to get $content_label $path = $key . $resource_id;
        $path = $context_label;
        // Create new blog, if does not exist. Note this gives one blog per resource_id
        //$path = $key . $resource_id;
    }
    // Replace any non-allowed characters in WordPress with -
    $path = preg_replace('/[^_0-9a-zA-Z-]+/', '-', $path);
    // Sanity Check: Ensure that path is only _A-Za-z0-9- --- the above should stop this.
    if (preg_match('/[^_0-9a-zA-Z-]+/', $path) == 1) {
        $tool_provider->reason = __('No Blog has been created as the name contains non-alphanumeric: (_a-zA-Z0-9-) allowed', 'lti-text');
        return FALSE;
    }
    // Get any folder(s) that WordPress might be living in
    $wppath = parse_url(get_option('siteurl'), PHP_URL_PATH);
    $path = $wppath . '/' . trailingslashit($path);
    // Get the id of the blog, if exists
    $blog_id = domain_exists(DOMAIN_CURRENT_SITE, $path, 1);
    // If Blog does not exist and this is a member of staff and blog provisioning is on, create blog
    if (!$blog_id && $staff) {
        $blog_id = wpmu_create_blog(DOMAIN_CURRENT_SITE, $path, $tool_provider->resource_link->title, $user_id, '', '1');
        update_blog_option($blog_id, 'blogdescription', __('Provisioned by LTI', 'lti-text'));
    }
    // Blog will exist by this point unless this user is student/no role.
    if (!$blog_id) {
        $tool_provider->reason = __('No Blog has been created for this context', 'lti-text');
        return FALSE;
    }
    // Create blog name if it doesn't have one defined, otherwise leave it alone. This allows admin to set a friendlier blogname in WP Settings if they'd like.
    if (!get_blog_option($blog_id, 'blogname')) {
        update_blog_option($blog_id, 'blogname', $tool_provider->consumer->name);
    }
    $role = 'subscriber';
    if ($staff) {
        $role = 'administrator';
    }
    if ($learner) {
        $role = 'author';
    }
    // Add user to blog and set role
    if (!is_user_member_of_blog($user_id, $blog_id)) {
        add_user_to_blog($blog_id, $user_id, $role);
    }
    // Users added via this route should only have access to this
    // (path) site. Remove from the default blog.
    remove_user_from_blog($user_id, 1);
    // Login the user
    wp_set_current_user($user_id, $user_login);
    wp_set_auth_cookie($user_id);
    do_action('wp_login', $user_login);
    // Switch to blog
    switch_to_blog($blog_id);
    // Note this is an LTI provisioned Blog.
    add_option('ltisite', TRUE);
    // As this is an LTI provisioned Blog we store the consumer key and
    // context id as options with the session meaning we can access elsewhere
    // in the code.
    // Store lti key & context id in $_SESSION variables
    $_SESSION[LTI_SESSION_PREFIX . 'key'] = $key;
    $_SESSION[LTI_SESSION_PREFIX . 'resourceid'] = $resource_id;
    // Store the key/context in case we need to sync shares --- this ensures we return
    // to the correct consumer and not the primary consumer
    $_SESSION[LTI_SESSION_PREFIX . 'userkey'] = $tool_provider->user->getResourceLink()->getKey();
    $_SESSION[LTI_SESSION_PREFIX . 'userresourcelink'] = $tool_provider->user->getResourceLink()->getId();
    // If users role in consumer has changed (e.g. staff -> student),
    // then their role in the blog should change
    $user = new WP_User($user_id);
    if ($user->has_cap('administrator') && $role != 'administrator') {
        $user->add_role($role);
        $user->remove_role('administrator');
    }
    if ($user->has_cap('author') && $role != 'author') {
        $user->add_role($role);
        $user->remove_role('author');
    }
    if ($user->has_cap('subscriber') && $role != 'subscriber') {
        $user->add_role($role);
        $user->remove_role('subscriber');
    }
    // Send login time to consumer if has outcomes service and can handle freetext
    $context = $tool_provider->resource_link;
    if ($context->hasOutcomesService()) {
        // Presently this is just a demo of the outcome services and updating the menu bar in WordPress
        $outcome = new LTI_Outcome($tool_provider->user->lti_result_sourcedid);
        $outcome->type = LTI_Resource_Link::EXT_TYPE_TEXT;
        $result = $context->doOutcomesService(LTI_Resource_Link::EXT_READ, $outcome);
        // If we have successfully read then update the user metadata
        if ($result) {
            update_user_meta($user_id, 'Last Login', $result);
        }
        $outcome->setValue(date('d-F-Y G:i', time()));
        $context->doOutcomesService(LTI_Resource_Link::EXT_WRITE, $outcome);
    }
    // Return URL for re-direction by Tool Provider class
    return get_bloginfo('url');
}