summaryrefslogtreecommitdiff
path: root/portal/admin/frontends.php
blob: bf052839314dac2e14a97549062c11cf0d6b5ed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

//
// Frontend mirror management
//
// $Id$
//
class Admin_Frontends extends Admin_BasePage {
    function __construct() {
        $this->content_template = 'admin/frontends.html';
    }

    function Render() {
        if ($_POST['op'] == 'syncreq') 
            return $this->NewSyncRequest();

        $this->tpl->setVariable('now', date('c', time()));
        $st = @stat('/tmp/.website_update.lck');
        if (!$st) {
            $this->tpl->setVariable('updstatus', 'No update currently running');
        }
        else {
            $this->tpl->setVariable('updstatus', 'Update has been running since ' . date('c',$st['mtime']) . ' (' . $this->formattime(time()-$st['mtime']) . ').');
        }
        $rs = $this->pg_query("SELECT t,docs,ftp,requestby,completed,completed-t FROM sync_request ORDER BY t DESC LIMIT 15");
        for ($i = 0, $rows = pg_num_rows($rs); $i < $rows; $i++) {
            $this->tpl->setVariable('request_time', pg_fetch_result($rs, $i, 0));
            $this->tpl->setVariable('request_by', pg_fetch_result($rs, $i, 3));
            $this->tpl->setVariable('request_complete', pg_fetch_result($rs ,$i,4));
            $this->tpl->setVariable('request_elapsed', pg_fetch_result($rs, $i, 5));
            $p = '';
            if (pg_fetch_result($rs, $i, 1) == 1) $p .= 'Docs included<br>';
            if (pg_fetch_result($rs, $i, 2) == 1) $p .= 'Ftp included<br>';
            $this->tpl->setVariable('request_params', $p);
            $this->tpl->parse('requests_loop');
        }

        $rs = $this->pg_query("SELECT t AS log_t,op AS log_op,node AS log_node,start AS log_start,t-start AS log_elapsed FROM sync_log ORDER BY t DESC LIMIT 50");
        for ($i = 0, $rows = pg_num_rows($rs); $i < $rows; $i++) {
            $this->tpl->setVariable(pg_fetch_assoc($rs, $i));
            $this->tpl->parse('log_loop');
        }
    }

    function NewSyncRequest() {
        $ftp = isset($_POST['ftp'])?1:0;
        $docs = isset($_POST['docs'])?1:0;

        $rs = $this->pg_query_params('INSERT INTO sync_request (t,docs,ftp,requestby) VALUES ($1, $2, $3, $4)', array(
            $_POST['when'],
            $docs,
            $ftp,
            $_SERVER['PHP_AUTH_USER']
        ));
        if (!$rs) 
            throw new Exception("Database update failed");

        header('Location: frontends.php');
        exit(0);
    }

    function formattime($t) {
        $s = '';
        if ($t > 3600) {
            $s = intval($t/3600) . ' hours ';
            $t = intval($t%3600);
        }
        if ($t > 60) {
            $s .= intval($t/60) . ' minutes ';
            $t = intval($t%60);
        }
        $s .= $t . ' seconds';
        return $s;
    }
}
?>