Skip to content
Snippets Groups Projects
Commit a9c854ff authored by Joe Oblivian's avatar Joe Oblivian Committed by agata
Browse files

added the mapping file

parent 748d89cc
Branches
Tags
1 merge request!3Noblogs 5.4
<?php
// wp-nginx-map.php
//
// Stampa una mappa delle assegnazioni blog -> backend, per NGINX.
// Load wordpress api.
define('WP_CACHE',false);
require_once('/opt/noblogs/www/wp-load.php');
// Return all blogs.
function get_blogs() {
global $wpdb;
$sql = "SELECT blog_id, domain FROM $wpdb->blogs WHERE deleted = 0 AND archived = '0' ORDER BY domain ASC";
$result = $wpdb->get_results($sql);
return ($result);
}
function printline($s) {
echo $s . "\n";
}
function backend_to_http_endpoint($backend) {
if (substr($backend, 0, 8) != 'backend_') {
error_log('diamine, di questo backend non so che farmene: ' . $backend);
return 'localhost:82';
}
$id = substr($backend, 8);
return '172.16.1.' . $id . ':82';
}
// Print the blog -> backend map.
function generate_map() {
global $wpdb;
$wpdb_hash = &$wpdb->hash_map;
$blogs = get_blogs();
printline('map $http_host $backend_noblogs {');
printline(' default http://localhost:82;');
foreach ($blogs as $blog) {
$blog_id = $blog->blog_id;
$backend_id = $wpdb_hash->lookup($blog_id);
$backend_http = backend_to_http_endpoint($backend_id);
printline(' ' . $blog->domain . ' http://' . $backend_http . ';');
}
printline('}');
}
generate_map();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment