|
| 1 | +<?php require '../config.php'; ?> |
| 2 | +<?php loadClass('Helper')->authPage(); ?> |
| 3 | +<?php |
| 4 | +// TODO: This is currently a temporary hack to talk to supervisor on the HTTPD server |
| 5 | +function run_supervisor_command($command) { |
| 6 | + $supervisor_config_file = '/tmp/supervisorctl.conf'; |
| 7 | + $port = getenv('SVCTL_LISTEN_PORT'); |
| 8 | + $user = getenv('SVCTL_USER'); |
| 9 | + $pass = getenv('SVCTL_PASS'); |
| 10 | + |
| 11 | + $content = "[supervisorctl]\n"; |
| 12 | + $content .= "serverurl=http://httpd:" . $port . "\n"; |
| 13 | + $content .= "username=" . $user . "\n"; |
| 14 | + $content .= "password=" . $pass . "\n"; |
| 15 | + |
| 16 | + $fp = fopen($supervisor_config_file, 'w'); |
| 17 | + fwrite($fp, $content); |
| 18 | + fclose($fp); |
| 19 | + |
| 20 | + return loadClass('Helper')->exec('supervisorctl -c ' . $supervisor_config_file . ' ' . $command); |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +?> |
| 25 | +<?php if ( isset($_POST['watcherd']) && $_POST['watcherd'] == 'reload' ) { |
| 26 | + run_supervisor_command('restart watcherd'); |
| 27 | + sleep(1); |
| 28 | + loadClass('Helper')->redirect('/cnc.php'); |
| 29 | +} |
| 30 | +?> |
| 31 | +<!DOCTYPE html> |
| 32 | +<html lang="en"> |
| 33 | + <head> |
| 34 | + <?php echo loadClass('Html')->getHead(true); ?> |
| 35 | + </head> |
| 36 | + |
| 37 | + <body> |
| 38 | + <?php echo loadClass('Html')->getNavbar(); ?> |
| 39 | + |
| 40 | + <div class="container"> |
| 41 | + <h1>Command & Control</h1> |
| 42 | + <br/> |
| 43 | + <br/> |
| 44 | + |
| 45 | + <div class="row"> |
| 46 | + <div class="col-md-12"> |
| 47 | + |
| 48 | + <?php |
| 49 | + $status_w = run_supervisor_command('status watcherd'); |
| 50 | + $status_h = run_supervisor_command('status httpd'); |
| 51 | + |
| 52 | + $words = preg_split("/\s+/", $status_w); |
| 53 | + $data_w = array( |
| 54 | + 'name' => isset($words[0]) ? $words[0] : '', |
| 55 | + 'state' => isset($words[1]) ? $words[1] : '', |
| 56 | + 'pid' => isset($words[3]) ? preg_replace('/,$/', '', $words[3]) : '', |
| 57 | + 'uptime' => isset($words[5]) ? $words[5] : '', |
| 58 | + ); |
| 59 | + $words = preg_split("/\s+/", $status_h); |
| 60 | + $data_h = array( |
| 61 | + 'name' => isset($words[0]) ? $words[0] : '', |
| 62 | + 'state' => isset($words[1]) ? $words[1] : '', |
| 63 | + 'pid' => isset($words[3]) ? preg_replace('/,$/', '', $words[3]) : '', |
| 64 | + 'uptime' => isset($words[5]) ? $words[5] : '', |
| 65 | + ); |
| 66 | + ?> |
| 67 | + <h3>Daemon overview</h3><br/> |
| 68 | + <p>If you made a change to any vhost settings, you can trigger a manual reload here.</p> |
| 69 | + <table class="table table-striped"> |
| 70 | + <thead class="thead-inverse"> |
| 71 | + <tr> |
| 72 | + <th>Daemon</th> |
| 73 | + <th>Status</th> |
| 74 | + <th>Pid</th> |
| 75 | + <th>Uptime</th> |
| 76 | + <th>Action</th> |
| 77 | + </tr> |
| 78 | + </thead> |
| 79 | + <tbody> |
| 80 | + <tr> |
| 81 | + <td><?php echo $data_w['name']; ?></td> |
| 82 | + <td><?php echo $data_w['state']; ?></td> |
| 83 | + <td><?php echo $data_w['pid']; ?></td> |
| 84 | + <td><?php echo $data_w['uptime']; ?></td> |
| 85 | + <td><form method="post"><button type="submit" name="watcherd" value="reload" class="btn btn-primary">Reload</button></form></td> |
| 86 | + </tr> |
| 87 | + <tr> |
| 88 | + <td><?php echo $data_h['name']; ?></td> |
| 89 | + <td><?php echo $data_h['state']; ?></td> |
| 90 | + <td><?php echo $data_h['pid']; ?></td> |
| 91 | + <td><?php echo $data_h['uptime']; ?></td> |
| 92 | + <td></td> |
| 93 | + </tr> |
| 94 | + </tbody> |
| 95 | + </table> |
| 96 | + <br/> |
| 97 | + <br/> |
| 98 | + |
| 99 | + <h3>watcherd stderr</h3> |
| 100 | + <br/> |
| 101 | + <?php |
| 102 | + $output = run_supervisor_command('tail -1000000 watcherd stderr'); |
| 103 | + echo '<pre>'; |
| 104 | + foreach(preg_split("/((\r?\n)|(\r\n?))/", $output) as $line) { |
| 105 | + if ( strpos($line, "[ERR]") !== false ) { |
| 106 | + echo '<span style="color: #ff0000">' . $line . '</span>'; |
| 107 | + } else if ( strpos($line, "[emerg]") !== false ) { |
| 108 | + echo '<span style="color: #ff0000">' . $line . '</span>'; |
| 109 | + } else if ( strpos($line, "Syntax error") !== false ) { |
| 110 | + echo '<span style="color: #ff0000">' . $line . '</span>'; |
| 111 | + } else if ( strpos($line, "[WARN]") !== false ) { |
| 112 | + echo '<span style="color: #ccaa00">' . $line . '</span>'; |
| 113 | + } else { |
| 114 | + echo $line; |
| 115 | + } |
| 116 | + echo "\n"; |
| 117 | + } |
| 118 | + echo '</pre>'; |
| 119 | + ?> |
| 120 | + <h3>watcherd stdout</h3> |
| 121 | + <br/> |
| 122 | + <?php |
| 123 | + $output = run_supervisor_command('tail -1000000 watcherd'); |
| 124 | + echo '<pre>'; |
| 125 | + foreach(preg_split("/((\r?\n)|(\r\n?))/", $output) as $line) { |
| 126 | + $pos_info = strpos($line, "[INFO]"); |
| 127 | + $pos_ok = strpos($line, "[OK]"); |
| 128 | + if ( $pos_ok !== false ) { |
| 129 | + echo '<span style="color: #669a00"><strong>' . $line . '</strong></span>'; |
| 130 | + } else if ( $pos_info !== false && $pos_info == 0 ) { |
| 131 | + echo '<span style="color: #0088cd">' . $line . '</span>'; |
| 132 | + } else { |
| 133 | + echo $line; |
| 134 | + } |
| 135 | + echo "\n"; |
| 136 | + } |
| 137 | + echo '</pre>'; |
| 138 | + ?> |
| 139 | + |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + |
| 143 | + </div><!-- /.container --> |
| 144 | + |
| 145 | + <?php echo loadClass('Html')->getFooter(); ?> |
| 146 | + <script> |
| 147 | + $(function() { |
| 148 | + $('.subject').click(function() { |
| 149 | + const id = ($(this).attr('id')); |
| 150 | + const row = $('#mail-'+id); |
| 151 | + row.toggle(); |
| 152 | + |
| 153 | + const bodyElement = row.find('.email-body')[0]; |
| 154 | + if(bodyElement.shadowRoot !== null){ |
| 155 | + // We've already fetched the message content. |
| 156 | + return; |
| 157 | + } |
| 158 | + |
| 159 | + bodyElement.attachShadow({ mode: 'open' }); |
| 160 | + bodyElement.shadowRoot.innerHTML = 'Loading...'; |
| 161 | + |
| 162 | + $.get('?get-body=' + id, function(response){ |
| 163 | + response = JSON.parse(response); |
| 164 | + row.find('.raw-email-body').html(response.raw); |
| 165 | + |
| 166 | + const body = response.body; |
| 167 | + if(body === null){ |
| 168 | + row.find('.alert').show(); |
| 169 | + } |
| 170 | + else{ |
| 171 | + bodyElement.shadowRoot.innerHTML = body; |
| 172 | + } |
| 173 | + }) |
| 174 | + }) |
| 175 | + // Handler for .ready() called. |
| 176 | + }); |
| 177 | + </script> |
| 178 | + </body> |
| 179 | +</html> |
0 commit comments