Permalink
Browse files

adds support for several rabbitmq servers

  • Loading branch information...
1 parent ba48f97 commit a1727b0fb5449e1a8dcef59c848c6870b6ba4707 @videlalvaro videlalvaro committed May 19, 2010
Showing with 60 additions and 6 deletions.
  1. +14 −2 config/config.php.sample
  2. +8 −0 controllers/servers.php
  3. +14 −0 lib/helpers.php
  4. +17 −3 views/layout.html.php
  5. +7 −1 web/index.php
View
@@ -1,4 +1,16 @@
<?php
-define('RABBITMQ_HOST', 'rabbit@127.0.0.1');
-define('RABBITMQ_COOKIE', 'COOKIE_HERE');
+$RABBIT_SERVERS = array(
+ array(
+ 'host' => 'rabbit@10.20.0.1',
+ 'cookie' => 'COOKIE_HERE'
+ ),
+ array(
+ 'host' => 'rabbit@10.20.0.2',
+ 'cookie' => 'COOKIE_HERE'
+ ),
+ array(
+ 'host' => 'rabbit@10.20.0.3',
+ 'cookie' => 'COOKIE_HERE'
+ )
+ );
View
@@ -0,0 +1,8 @@
+<?php
+
+function switch_server()
+{
+ $server = isset($_POST['server_id']) ? (int) $_POST['server_id'] : 0;
+ $_SESSION['server_id'] = $server;
+ header("Location: " . $_SERVER['HTTP_REFERER']);
+}
View
@@ -0,0 +1,14 @@
+<?php
+
+function init_servers_config()
+{
+ include_once(__DIR__ . '/../config/config.php');
+ set('RABBIT_SERVERS', $RABBIT_SERVERS);
+ define('RABBITMQ_HOST', $RABBIT_SERVERS[get_server_id()]['host']);
+ define('RABBITMQ_COOKIE', $RABBIT_SERVERS[get_server_id()]['cookie']);
+}
+
+function get_server_id()
+{
+ return isset($_SESSION['server_id']) ? $_SESSION['server_id'] : 0;
+}
View
@@ -26,19 +26,33 @@ function delete_vhost(vhost, vhostEl){
</head>
<body>
<div id="page">
- <h1 id="top"><a href="/"><img src="/img/rabbitmqlogonostrap.png" /></a><a href="/">Administration Console</a></h1>
+ <h1 id="top">
+ <form id="server_form" action="/switch_server" method="POST" accept-charset="utf-8">
+ <select id='server_id' name='server_id' change="" style="float:right">
+ <?php foreach($RABBIT_SERVERS as $k => $server): ?>
+ <option value="<?php echo $k; ?>" <?php echo (get_server_id() == $k) ? 'selected="true"' : ''; ?>><?php echo $server['host']; ?></option>
+ <?php endforeach; ?>
+ </select>
+ </form>
+ <script type="text/javascript" charset="utf-8">
+ $('#server_id').change(function() {
+ $('#server_form').submit();
+ });
+ </script>
+ <a href="/"><img src="/img/rabbitmqlogonostrap.png" /></a><a href="/">Administration Console</a>
+ </h1>
<ul id="menu">
<li><a href="/">Vhosts</a></li>
<li><a href="/list_users">Users</a></li>
<li><a href="/list_connections">Connections</a></li>
<li><a href="/list_channels">Channels</a></li>
</ul>
<div id="content">
- <?php echo $content; ?>
+ <?php echo $content; ?>
</div>
<div class="clear">
<!---->
</div>
</div>
</body>
-</html>
+</html>
View
@@ -1,10 +1,14 @@
<?php
+session_start();
+
require_once(__DIR__ . '/../lib/vendor/limonade/lib/limonade.php');
-require_once(__DIR__ . '/../config/config.php');
+require_once(__DIR__ . '/../lib/helpers.php');
function configure()
{
+ init_servers_config();
+
option('env', ENV_DEVELOPMENT);
option('limonade_dir', __DIR__ . '/../lib/vendor/limonade/lib');
option('lib_dir', __DIR__ . '/../lib');
@@ -17,6 +21,8 @@ function before($route)
layout('layout.html.php');
}
+dispatch_post('/switch_server', 'switch_server');
+
dispatch('/', 'list_vhosts');
dispatch('/vhost_permissions/:vhost', 'list_vhost_permissions');
dispatch('/add_vhost', 'add_vhost_form');

0 comments on commit a1727b0

Please sign in to comment.