summaryrefslogtreecommitdiff
path: root/buildmaster/log.php
blob: 6235b06b9fc7310b4e36119611b9edaecd662394 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
require_once "../init.php";
require_once BASE . "/lib/mysql.php";


  $filter = "";
  if (array_key_exists("show", $_GET) &&
    ($_GET["show"] == "ssh")) {
    $to_show = "ssh";
    $columns = array(
      "date" => "`ssh_log`.`date`",
      "duration" => "`ssh_log`.`duration`",
      "exit code" => "`ssh_log`.`exit_code`",
      "build slave" => "`build_slaves`.`name`",
      "action" => "`ssh_log`.`action`",
      "parameters" => "`ssh_log`.`parameters`"
    );
    $join = " LEFT" . mysql_join_ssh_log_build_slaves();
    if (array_key_exists("action", $_GET))
      $filter .= " AND `ssh_log`.`action` LIKE from_base64(\"" . base64_encode($_GET["action"] . "%") . "\")";
    if (array_key_exists("parameters", $_GET))
      $filter .= " AND `ssh_log`.`parameters` LIKE from_base64(\"" . base64_encode($_GET["parameters"] . "%") . "\")";
    if (array_key_exists("slave", $_GET))
      $filter .= " AND `build_slaves`.`name` LIKE from_base64(\"" . base64_encode($_GET["slave"] . "%") . "\")";
  } elseif (array_key_exists("show", $_GET) &&
    ($_GET["show"] == "command")) {
    $to_show = "command";
    $columns = array(
      "date" => "`command_log`.`date`",
      "command" => "`command_log`.`command`",
      "parameters" => "`command_log`.`parameters`",
      "shell" => "IF(`command_log`.`shell`,1,0)"
    );
    $join = '';
    if (array_key_exists("command", $_GET))
      $filter .= " AND `command_log`.`command` LIKE from_base64(\"" . base64_encode($_GET["command"]) . "\")";
    if (array_key_exists("shell", $_GET)) {
      $filter .= " AND";
      if (!$_GET["shell"])
        $filter .= " NOT";
      $filter .= " `command_log`.`shell`";
    }
  } else {
    $to_show = "email";
    $columns = array(
      "date" => "`email_log`.`date`",
      "action" => "`email_actions`.`name`",
      "count" => "`email_log`.`count`",
      "success" => "`email_log`.`success`",
      "person" => "`persons`.`name`",
      "comment" => "`email_log`.`comment`"
    );
    $join =
      " LEFT" . mysql_join_email_log_email_actions() .
      " LEFT JOIN (" .
        "`gpg_keys`" .
        mysql_join_gpg_keys_persons() .
      ") ON `email_log`.`gpg_key`=`gpg_keys`.`id`";
  }

  if (array_key_exists("from", $_GET))
    $min_time = $_GET["from"];
  elseif ($to_show == "email")
    $min_time = "1 00:00:00";
  else
    $min_time = "00:42:00";

  $query = "SELECT ";
  foreach ($columns as $name => $column)
    $query .= $column . " AS `".$name."`,";

  $query = substr($query,0,-1);
  $query .= " FROM `" . $to_show . "_log`" . $join .
    " WHERE TIMEDIFF((" .
  // NOW() is wrong here - due to differing time zones O.o
      "SELECT MAX(`l`.`date`) FROM `" . $to_show . "_log` AS `l`" .
    "),`" . $to_show . "_log`.`date`) < from_base64(\"" . base64_encode( $min_time ) . "\")" .
    $filter .
    " ORDER BY `" . $to_show . "_log`.`date` DESC";

  $result = mysql_run_query($query);

?>
<html>
  <head>
    <title><?php print $to_show; ?>-log</title>
    <link rel="stylesheet" type="text/css" href="/static/style.css">
  </head>
  <body>
    <table>
      <tr>
<?php
  foreach ($columns as $label => $column) {
    print "        <th>\n";
    print "          " . $label . "\n";
    print "        </th>\n";
  }
?>
      </tr>
<?php

  while ($row = $result -> fetch_assoc()) {
    print "      <tr>\n";
    foreach ($row as $val) {
      print "      <td>\n";
      print "        ";
      if (array_key_exists('exit code', $row)) {
        print "<font color=\"";
        switch ($row['exit code']) {
          case 0:
            print "#008000";
            break;
          default:
            print "#800000";
            break;
        };
        print "\">";
      }
      print $val;
      if (array_key_exists('exit code', $row)) {
        print "</font>";
      }
      print "\n";
      print "      </td>\n";
    }
    print "      </tr>\n";
  }

?>
    </table>
  </body>
</html>