/**
  * Prepare items for querying
  */
 public function prepare_items()
 {
     // Pagination
     $per_page = $this->get_items_per_page('networks_per_page');
     $pagenum = $this->get_pagenum();
     // User vars
     $order_by = !empty($_REQUEST['orderby']) ? sanitize_key($_REQUEST['orderby']) : '';
     $order = !empty($_REQUEST['order']) ? strtoupper($_REQUEST['order']) : 'ASC';
     $search = !empty($_REQUEST['s']) ? stripslashes(trim($_REQUEST['s'])) : '';
     // Searching?
     if (false !== strpos($search, '*')) {
         $search = trim($search, '*');
     }
     // Fallback to ASC
     if (!in_array($order, array('DESC', 'ASC'), true)) {
         $order = 'ASC';
     }
     // Query arguments
     $args = array('number' => intval($per_page), 'offset' => intval(($pagenum - 1) * $per_page), 'orderby' => $order_by, 'order' => $order, 'search' => $search);
     // Get networks
     $this->items = get_networks($args);
     // Get total network count
     $count = get_networks(array_merge($args, array('count' => true, 'offset' => 0, 'number' => 0)));
     // Setup pagination
     $this->set_pagination_args(array('total_items' => $count, 'per_page' => $per_page));
 }
Пример #2
0
/**
 * Metabox for assigning which network a site is part of
 *
 * @since 1.7.0
 *
 * @param WP_Site $site Results of get_blog_details()
 */
function wpmn_move_site_list_metabox($site = null)
{
    // Get all networks
    $networks = get_networks();
    ?>

	<table class="move-site widefat">
		<tr>
			<th><?php 
    echo esc_html(get_blog_option($site->blog_id, 'blogname'));
    ?>
</th>
			<td>
				<select name="to" id="to">
					<option value="0"><?php 
    esc_html_e('&mdash; No Network &mdash;', 'wp-multi-network');
    ?>
</option><?php 
    // Loop through networks
    foreach ($networks as $new_network) {
        // Option value is network ID
        ?>
<option value="<?php 
        echo esc_attr($new_network->id);
        ?>
" <?php 
        selected($site->site_id, $new_network->id);
        ?>
><?php 
        // Include scheme, domain, & path
        echo wp_get_scheme() . esc_html($new_network->domain . '/' . ltrim($new_network->path, '/'));
        ?>
</option><?php 
    }
    ?>
</select>
			</td>
		</tr>
	</table>

<?php 
}
/**
 * Check to see if a network exists. Will check the networks object before
 * checking the database.
 *
 * @since 1.3
 *
 * @param integer $site_id ID of network to verify
 * @return boolean true if found, false otherwise
 */
function network_exists($site_id)
{
    global $wpdb;
    // Cast
    $site_id = (int) $site_id;
    $sites = get_networks();
    // Loop through sites global and look for a match
    foreach ($sites as $network) {
        if ($site_id == $network->id) {
            return true;
        }
    }
    // Loop through network list in db and look for a match
    $network_list = $wpdb->get_results("SELECT id FROM {$wpdb->site}");
    if (!empty($network_list)) {
        foreach ($network_list as $network) {
            if ($site_id == $network->id) {
                return true;
            }
        }
    }
    // Nothing found
    return false;
}
Пример #4
0
/**
 * Get the main network ID.
 *
 * @since 4.3.0
 *
 * @return int The ID of the main network.
 */
function get_main_network_id()
{
    if (!is_multisite()) {
        return 1;
    }
    $current_network = get_network();
    if (defined('PRIMARY_NETWORK_ID')) {
        $main_network_id = PRIMARY_NETWORK_ID;
    } elseif (isset($current_network->id) && 1 === (int) $current_network->id) {
        // If the current network has an ID of 1, assume it is the main network.
        $main_network_id = 1;
    } else {
        $_networks = get_networks(array('fields' => 'ids', 'number' => 1));
        $main_network_id = array_shift($_networks);
    }
    /**
     * Filters the main network ID.
     *
     * @since 4.3.0
     *
     * @param int $main_network_id The ID of the main network.
     */
    return (int) apply_filters('get_main_network_id', $main_network_id);
}
Пример #5
0
$uname = posix_uname();
if ($uname['machine'] == 'amd64') {
    ini_set('memory_limit', '250M');
}
function get_networks($pfb)
{
    $file = '/usr/local/pkg/pfblocker_aliases/' . $pfb . '.txt';
    if (file_exists($file)) {
        $return = file_get_contents($file);
    }
    print $return;
}
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
    if (preg_match("/(\\w+)/", $_REQUEST['pfb'], $matches)) {
        get_networks($matches[1]);
    }
}
if ($argv[1] == 'uc') {
    pfblocker_get_countries();
}
if ($argv[1] == 'cron') {
    require_once "/etc/inc/util.inc";
    require_once "/etc/inc/functions.inc";
    require_once "/etc/inc/pkg-utils.inc";
    require_once "/etc/inc/globals.inc";
    require_once "/etc/inc/filter.inc";
    require_once "/etc/inc/config.inc";
    $hour = date('H');
    $pfbdir = '/usr/local/pkg/pfblocker';
    $updates = 0;
 /**
  * List all networks.
  *
  *
  * [--fields=<fields>]
  * : Limit the output to specific row fields.
  *
  * [--format=<format>]
  * : Accepted values: table, csv, json, count. Default: table
  *
  * ## AVAILABLE FIELDS
  *
  * These fields will be displayed by default for each term:
  *
  * * id
  * * domain
  * * path
  *
  * @subcommand list
  */
 public function list_($args, $assoc_args)
 {
     $items = get_networks();
     $formatter = $this->get_formatter($assoc_args);
     $formatter->display_items($items);
 }
if ($global_data['dhcpoptdefault-lease-time']) {
    $defaultlease_select = "<option value='' selected>" . $LEASE_TIMES[$global_data['dhcpoptdefault-lease-time']] . " &nbsp;\n\t\t[" . $global_data['dhcpoptdefault-lease-time'] . " s]</option>";
    $dltext = "<br><b>Global vom DHCP Dienst vorgegeben</b><br>\n\t\twird nicht explizit f&uuml;r das Subnetz angelegt<br><br>\n\t\tSie k&ouml;nnen spezifisch f&uuml;r das Subnetz eine andere <b>Default</b> Lease-Time setzen";
} else {
    $defaultlease_select = "<option value='' selected> ------- </option>";
}
foreach (array_keys($LEASE_TIMES) as $sec) {
    if ($sec != $global_data['dhcpoptdefault-lease-time']) {
        $defaultlease_select .= "<option value='{$sec}'>{$LEASE_TIMES[$sec]} &nbsp;[{$sec} s]</option>";
    }
}
$defaultlease_select .= "</select>";
$ml_select = "<select name='dhcpoptmax-lease-time' size='4' class='small_form_selectbox'>" . $maxlease_select;
$dl_select = "<select name='dhcpoptdefault-lease-time' size='4' class='small_form_selectbox'>" . $defaultlease_select;
$template->assign(array("CN" => $subnetcn, "NETMASK" => $netmask, "DHCPSRVDN" => $DHCP_SERVICE, "DESCRIPTION" => "", "STATEMENTS" => "", "ALLOW" => "", "DENY" => "", "IGNORE" => "", "DDNSUPDATE" => "", "DEFAULTLEASE" => $dl_select, "MAXLEASE" => $ml_select, "DLTEXT" => $dltext, "MLTEXT" => $mltext, "USEHOSTDCL" => "", "ROUTERS" => "", "DOMAINNAME" => "", "DOMAINNAMESERVERS" => $global_data['dhcpoptdomain-name-servers'], "NEXTSERVER" => "", "FILENAME" => "", "SRVIDENT" => "", "NTPSERVERS" => "", "OPTGENERIC" => "", "MNR" => $mnr, "SBMNR" => $sbmnr, "MCNR" => $mcnr));
$freenets = get_networks();
#print_r($freenets);
$subnets = array();
if (count($freenets) != 0) {
    $template->define_dynamic("Dhcpsubnets", "Webseite");
    foreach ($freenets as $subnet) {
        $netexp = explode(".", $subnet);
        $mask = array(255, 255, 255, 255);
        for ($i = 0; $i < count($netexp); $i++) {
            if ($netexp[$i] == "0") {
                $mask[$i] = "0";
            }
        }
        $netmask = implode(".", $mask);
        $subnets[] = $subnet . "|" . $netmask;
        $template->assign(array("SUBNET" => $subnet . "|" . $netmask, "CN" => $subnet, "NETMASK" => $netmask));
/**
 * Adjusts the detection of which networks belong to a user.
 *
 * Users who are a global admin have full capabilities on all networks.
 *
 * @since 1.0.0
 * @access private
 *
 * @param array|null $networks Original array of network IDs or null.
 * @param int        $user_id  User ID to get networks for.
 * @return array|false Array of network IDs or false if no IDs.
 */
function _ga_user_has_networks($networks, $user_id)
{
    if (!is_multinetwork()) {
        return $networks;
    }
    $all_networks = get_networks(array('fields' => 'ids'));
    $user = get_user_by('id', $user_id);
    if ($user->has_cap('manage_networks')) {
        $user_networks = $all_networks;
    } else {
        $user = get_userdata($user_id);
        $user_networks = array();
        foreach ($all_networks as $network_id) {
            $network_admins = get_network_option($network_id, 'site_admins', array());
            if (in_array($user->user_login, $network_admins, true)) {
                $user_networks[] = $network_id;
            }
        }
    }
    if (empty($user_networks)) {
        $user_networks = false;
    }
    return $user_networks;
}
Пример #9
0
<?php

define('SQL_INC', 1);
define('CURR_MENU', 'configs');
define('CURR_SUBMENU', 'configs_dhcpd');
require 'inc/common.inc.php';
check_permissions(CURR_SUBMENU, 1);
if ($_POST['modify'] || $id) {
    check_permissions(CURR_SUBMENU, 2);
    if (!$_POST['confirm'] && $id) {
        $db->sql_query("select configs_dhcpd.id, configs_dhcpd.name, configs_dhcpd.interface, configs_dhcpd.network, configs_dhcpd.gateway, configs_dhcpd.dns1, configs_dhcpd.dns2, configs_dhcpd.nbios1, configs_dhcpd.nbios2, configs_dhcpd.time, configs_dhcpd.ntp, configs_dhcpd.domain from configs_dhcpd where configs_dhcpd.id='{$id}'");
        $result = $db->sql_fetchrow();
    }
    $networks = get_networks();
    $id = $_POST['confirm'] ? addslashes($_POST['id']) : $result['id'];
    $name = $_POST['confirm'] ? addslashes($_POST['name']) : $result['name'];
    $interface = $_POST['confirm'] ? addslashes($_POST['interface']) : $result['interface'];
    $network = $_POST['confirm'] ? addslashes($_POST['network']) : $result['network'];
    $gateway = $_POST['confirm'] ? addslashes($_POST['gateway']) : $result['gateway'];
    $dns1 = $_POST['confirm'] ? addslashes($_POST['dns1']) : $result['dns1'];
    $dns2 = $_POST['confirm'] ? addslashes($_POST['dns2']) : $result['dns2'];
    $nbios1 = $_POST['confirm'] ? addslashes($_POST['nbios1']) : $result['nbios1'];
    $nbios2 = $_POST['confirm'] ? addslashes($_POST['nbios2']) : $result['nbios2'];
    $time = $_POST['confirm'] ? addslashes($_POST['time']) : $result['time'];
    $ntp = $_POST['confirm'] ? addslashes($_POST['ntp']) : $result['ntp'];
    $domain = $_POST['confirm'] ? addslashes($_POST['domain']) : $result['domain'];
    if (!$name) {
        $errors[] = $lang['errors_route_name_empty'];
    } elseif ($db->sql_numrows($db->sql_query("select * from configs_dhcpd where name='{$name}'")) && !$_POST['id']) {
        $errors[] = $lang['errors_route_name_exists'];
    }
    /**
     * Output the delete multiple networks page
     *
     * @since 2.0.0
     */
    private function page_delete_networks()
    {
        // Get posted networks
        $network_id = get_main_network_id();
        $all_networks = isset($_POST['all_networks']) ? array_map('absint', $_POST['all_networks']) : array();
        // Prevent primary network from being deleted
        $all_networks = array_diff($all_networks, array($network_id));
        // Query for networks
        $networks = get_networks(array('network__in' => $all_networks));
        // Bail if no networks
        if (empty($networks)) {
            wp_die(esc_html__('You have selected an invalid network or networks for deletion', 'wp-multi-network'));
        }
        // Ensure each network is valid
        foreach ($networks as $network) {
            if (!get_network($network)) {
                wp_die(esc_html__('You have selected an invalid network for deletion.', 'wp-multi-network'));
            }
        }
        // Query for sites in selected networks
        $sites = get_sites(array('network__in' => $all_networks));
        ?>

		<div class="wrap">
			<h1><?php 
        esc_html_e('Networks', 'wp-multi-network');
        ?>
</h1>
			<h3><?php 
        esc_html_e('Delete Multiple Networks', 'wp-multi-network');
        ?>
</h3>
			<form method="post" action="<?php 
        echo esc_url($this->admin_url());
        ?>
">
				<?php 
        if (!empty($sites)) {
            ?>

					<div class="error inline">
						<h3><?php 
            esc_html_e('You have selected the following networks for deletion', 'wp-multi-network');
            ?>
:</h3>
						<ul>
							<?php 
            foreach ($networks as $deleted_network) {
                ?>
								<li><input type="hidden" name="deleted_networks[]" value="<?php 
                echo esc_attr($deleted_network->id);
                ?>
"><?php 
                echo esc_html($deleted_network->domain . $deleted_network->path);
                ?>
</li>
							<?php 
            }
            ?>
						</ul>
						<p><?php 
            // Messaging
            wp_should_rescue_orphaned_sites() ? esc_html_e('One or more of these networks has existing sites. Deleting these networks will orphan these sites.', 'wp-multi-network') : esc_html_e('One or more of these networks has existing sites. Deleting these networks will permanently delete these sites.', 'wp-multi-network');
            ?>
</p>
						<p>
							<label for="override"><?php 
            esc_html_e('Please confirm that you still want to delete these networks', 'wp-multi-network');
            ?>
:</label>
							<input type="checkbox" name="override" id="override">
						</p>
					</div>

				<?php 
        } else {
            ?>

					<div id="message inline">
						<h3><?php 
            esc_html_e('You have selected the following networks for deletion', 'wp-multi-network');
            ?>
:</h3>
						<ul><?php 
            foreach ($networks as $deleted_network) {
                ?>
<li><input type="hidden" name="deleted_networks[]" value="<?php 
                echo esc_attr($deleted_network->id);
                ?>
"><?php 
                echo esc_html($deleted_network->domain . $deleted_network->path);
                ?>
</li><?php 
            }
            ?>
</ul>
					</div>

				<?php 
        }
        ?>

				<p><?php 
        esc_html_e('Are you sure you want to delete these networks?', 'wp-multi-network');
        ?>
</p>
				<?php 
        wp_nonce_field('edit_network', 'network_edit');
        submit_button(esc_html__('Delete Networks', 'wp-multi-network'), 'primary', 'delete_multiple', false);
        ?>

				<a class="button" href="<?php 
        echo esc_url($this->admin_url());
        ?>
"><?php 
        esc_html_e('Cancel', 'wp-multi-network');
        ?>
</a>
			</form>
		</div>

		<?php 
    }
Пример #11
0
 /**
  * Add a new network
  *
  * @since 1.3
  *
  * @param array $args  {
  *     Array of arguments.
  *     @type string  $domain           Domain name for new network - for VHOST=no,
  *                                     this should be FQDN, otherwise domain only.
  *     @type string  $path             Path to root of network hierarchy - should
  *                                     be '/' unless WP is cohabiting with another
  *                                     product on a domain.
  *     @type string  $site_name        Name of the root blog to be created on
  *                                     the new network.
  *     @type integer $user_id          ID of the user to add as the site owner.
  *                                     Defaults to current user ID.
  *     @type array   $meta             Array of metadata to save to this network.
  *                                     Defaults to array( 'public' => false ).
  *     @type integer $clone_network    ID of network whose networkmeta values are
  *                                     to be copied - default NULL.
  *     @type array   $options_to_clone Override default network meta options to copy
  *                                     when cloning - default NULL.
  * }
  *
  * @return integer ID of newly created network
  */
 function add_network($args = array())
 {
     global $wpdb;
     // Backward compatibility with old method of passing arguments
     if (!is_array($args) || func_num_args() > 1) {
         _deprecated_argument(__METHOD__, '1.7.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'wp-multi-network'), __METHOD__, __FILE__));
         // Juggle function parameters
         $func_args = func_get_args();
         $old_args_keys = array(0 => 'domain', 1 => 'path', 2 => 'site_name', 3 => 'clone_network', 4 => 'options_to_clone');
         // Reset array
         $args = array();
         // Rejig args
         foreach ($old_args_keys as $arg_num => $arg_key) {
             if (isset($func_args[$arg_num])) {
                 $args[$arg_key] = $func_args[$arg_num];
             }
         }
     }
     // Parse args
     $r = wp_parse_args($args, array('domain' => '', 'path' => '/', 'site_name' => __('New Network', 'wp-multi-network'), 'user_id' => get_current_user_id(), 'meta' => array('public' => get_option('blog_public', false)), 'clone_network' => false, 'options_to_clone' => array_keys(network_options_to_copy())));
     // Bail if no user with this ID
     if (empty($r['user_id']) || !get_userdata($r['user_id'])) {
         return new WP_Error('network_user', __('User does not exist.', 'wp-multi-network'));
     }
     // Permissive sanitization for super admin usage
     $r['domain'] = str_replace(' ', '', strtolower($r['domain']));
     $r['path'] = str_replace(' ', '', strtolower($r['path']));
     // Check for existing network
     $networks = get_networks(array('domain' => $r['domain'], 'path' => $r['path'], 'number' => '1'));
     // Bail if network already exists
     if (!empty($networks)) {
         return new WP_Error('network_exists', __('Network already exists.', 'wp-multi-network'));
     }
     // Insert new network
     $wpdb->insert($wpdb->site, array('domain' => $r['domain'], 'path' => $r['path']));
     $new_network_id = $wpdb->insert_id;
     // If network was created, create a blog for it too
     if (!empty($new_network_id)) {
         if (!defined('WP_INSTALLING')) {
             define('WP_INSTALLING', true);
         }
         // Switch to the new network so counts are properly bumped
         switch_to_network($new_network_id);
         // Ensure upload constants are envoked
         ms_upload_constants();
         // Create the site for the root of this network
         $new_blog_id = wpmu_create_blog($r['domain'], $r['path'], $r['site_name'], $r['user_id'], $r['meta'], $new_network_id);
         // Switch back to the current network, to avoid any issues
         restore_current_network();
         // Bail if blog could not be created
         if (is_wp_error($new_blog_id)) {
             return $new_blog_id;
         }
         /**
          * Fix upload_path for main sites on secondary networks
          * This applies only to new installs (WP 3.5+)
          */
         // Switch to network (if set & exists)
         if (defined('SITE_ID_CURRENT_SITE') && get_network(SITE_ID_CURRENT_SITE)) {
             $use_files_rewriting = get_network_option(SITE_ID_CURRENT_SITE, 'ms_files_rewriting');
         } else {
             $use_files_rewriting = get_site_option('ms_files_rewriting');
         }
         global $wp_version;
         // Create the upload_path and upload_url_path values
         if (empty($use_files_rewriting) && version_compare($wp_version, '3.7', '<')) {
             // WP_CONTENT_URL is locked to the current site and can't be overridden,
             //  so we have to replace the hostname the hard way
             $current_siteurl = get_option('siteurl');
             $new_siteurl = untrailingslashit(get_blogaddress_by_id($new_blog_id));
             $upload_url = str_replace($current_siteurl, $new_siteurl, WP_CONTENT_URL);
             $upload_url = $upload_url . '/uploads';
             $upload_dir = WP_CONTENT_DIR;
             if (0 === strpos($upload_dir, ABSPATH)) {
                 $upload_dir = substr($upload_dir, strlen(ABSPATH));
             }
             $upload_dir .= '/uploads';
             if (defined('MULTISITE')) {
                 $ms_dir = '/sites/' . $new_blog_id;
             } else {
                 $ms_dir = '/' . $new_blog_id;
             }
             $upload_dir .= $ms_dir;
             $upload_url .= $ms_dir;
             update_blog_option($new_blog_id, 'upload_path', $upload_dir);
             update_blog_option($new_blog_id, 'upload_url_path', $upload_url);
         }
     }
     // Clone network meta from an existing network.
     //
     // We currently use the _options() API to get cache integration for free,
     // but it may be better to read & write directly to $wpdb->sitemeta.
     if (!empty($r['clone_network']) && get_network($r['clone_network'])) {
         // Temporary array
         $options_cache = array();
         // Old network
         foreach ($r['options_to_clone'] as $option) {
             $options_cache[$option] = get_network_option($r['clone_network'], $option);
         }
         // New network
         foreach ($r['options_to_clone'] as $option) {
             // Skip if option isn't available to copy
             if (!isset($options_cache[$option])) {
                 continue;
             }
             // Fix for bug that prevents writing the ms_files_rewriting
             // value for new networks.
             if ('ms_files_rewriting' === $option) {
                 $wpdb->insert($wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $options_cache[$option]));
             } else {
                 update_network_option($new_network_id, $option, $options_cache[$option]);
             }
         }
     }
     // Clean network cache
     clean_network_cache($new_network_id);
     do_action('add_network', $new_network_id, $r);
     return $new_network_id;
 }