source: ccsweb/trunk/html/configs.php @ 1037

Last change on this file since 1037 was 1037, checked in by mglb1, 7 years ago
  • Always display configuration files after a generation run. If no new revision was generated just show the youngest revision.
  • Fix a minor bug with the title of files displayed in the listing
  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1<?php
2/* Copyright (C) 2006  The University of Waikato
3 *
4 * This file is part of ccsweb - CRCnet Configuration System Web Interface
5 *
6 * Author:       Matt Brown <matt@crc.net.nz>
7 * Version:      $Id$
8 *
9 * ccsweb is free software; you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License version 2 as published by the Free
11 * Software Foundation.
12 *
13 * ccsweb is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * ccsweb; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 */
22require("lib/ccs_init.php");
23
24/* Assign common information */
25$smarty->assign("sheets", array("/css/templateStatus.css", 
26    "/css/configBrowser.css"));
27$smarty->assign("path", explode("/", $_REQUEST["path"]));
28 
29/* Check for template generation requests */
30if (isset($_REQUEST["function"])) {
31    if ($_REQUEST["function"]=="generate") {
32        $rv = do_xmlrpc("generateTemplate", array());
33        header("Location: /configs/status/" . urlencode($rv));
34    } else if ($_REQUEST["function"]=="status") {
35        $key = stripslashes($_REQUEST["statsKey"]);
36        $stats = do_xmlrpc("getTemplateStatus", array($key), $xmlrpconn, 
37            TRUE, FALSE);
38        if (xmlrpc_has_error($stats)) {
39            $smarty->assign("percent", 0);
40            $smarty->assign("statusText", "ERROR: " . 
41                xmlrpc_error_string($stats));   
42            $smarty->assign("error", 1);
43            if (isAjaxRequest()) {
44                display_page("templateStatusUpdate.tpl");
45            } else {
46                display_page("templateStatus.tpl");
47            }
48            exit;
49        }
50        $smarty->assign("stats", $stats);
51        $smarty->assign("statsKey", urlencode($key));
52        $smarty->assign("scripts", array("/js/templateStatus.js"));
53        /* The progress is made up of 50% for the startup phase, which is
54         * controlled by the setupProgress variable. This phase exists until
55         * the generated value goes to > 0. Then the remaining 50% is taken
56         * up by the number of templates have been generated. Once the
57         * finished variable is set to > 0 generation has completed.
58         */
59        $smarty->assign("stats", $stats);
60        $total = $stats["planned"]["total"];
61        if ($stats["generating"] > 0 && $total>0) {
62            $success=0;
63            $fails=0;
64            $errors = array();
65            foreach ($stats["generated"]["hosts"] as $host=>$templates) {
66                foreach ($templates as $name=>$info) {
67                    if ($name == "initiated" || $name=="finished" || 
68                            $name=="error") {
69                        continue;
70                    }
71                    if ($info["error"]=="") {
72                        $success++;
73                    } else {
74                        $fails++;
75                        $errors["hosts/$host/$name"] = $info["error"];
76                    }
77                }
78            }
79            foreach ($stats["generated"]["network"] as $template=>$info) {
80                if ($info["error"]=="") {
81                    $success++;
82                } else {
83                    $fails++;
84                    $errors[$template] = $info["error"];
85                }
86            }
87            $smarty->assign("errors", $errors);
88            $stext = "$success/$total templates generated successfully, " .
89                "$fails failures";
90            if ($stats["finished"] > 0) {
91                $skipped = $total - $success;
92                if ($skipped > 0) {
93                    $stext .= ", $skipped disabled";
94                }
95                $percent = 100;
96                $time = $stats["finished"] - $stats["initiated"];
97                $stext .= sprintf(". Generation took: %0.0f seconds", $time);
98                $smarty->assign("revision", $stats["revision"]);
99                $p = array("inputs");
100                if ($stats["revision"]!=-1) {
101                    if ($stats["revision"] != -1) {
102                        array_push($p, $stats["revision"]);
103                        $smarty->assign("keeprev", 1);
104                    }
105                    $r = do_xmlrpc("viewConfigAtPath", $p);
106                    $smarty->assign("revision", $r[0]);
107                } else {
108                    $r = do_xmlrpc("viewConfigAtPath", $p);
109                }
110                $smarty->assign("path", "inputs");
111                $smarty->assign("entries", $r[1]);
112                   
113            } else {
114                $percent = ((int)((($success+$fails) / $total)*100))/2+50;
115                // Don't let it finish this way, only go to 99% until we
116                // receive the explicit finish notification
117                if ($percent == 100) {
118                    $percent = 99;
119                }
120            }
121        } else {
122            $stext = "Initialising templates...";
123            $percent = $stats["setupProgress"]/2;
124        }
125        $smarty->assign("percent", $percent);
126        $smarty->assign("statusText", $stext);   
127        if (isAjaxRequest()) {
128            display_page("templateStatusUpdate.tpl");
129        } else {
130            display_page("templateStatus.tpl");
131        }
132        exit;
133    }
134}
135
136/* All other requests are to display information on config files */
137
138/* Get the information from the server  */
139$p = array($_REQUEST["path"]);
140if (isset($_REQUEST["rev"]) && $_REQUEST["rev"]!="") {
141    array_push($p, $_REQUEST["rev"]);
142    $smarty->assign("keeprev", 1);
143} else {
144    array_push($p, NULL);
145}
146if (isset($_REQUEST["order"])) {
147    array_push($p, $_REQUEST["order"]);
148    $smarty->assign("order", $_REQUEST["order"]);
149    if (isset($_REQUEST["desc"])) {
150        array_push($p, $_REQUEST["desc"]);
151        $smarty->assign("desc", $_REQUEST["desc"]);
152    } else {
153        $smarty->assign("desc", 0);
154    }
155} else {
156    $smarty->assign("order", "name");
157    $smarty->assign("desc", 0);
158}
159$r = do_xmlrpc("viewConfigAtPath", $p);
160$rev = $r[0];
161$entries = $r[1];
162$smarty->assign("revision", $rev);
163
164if (count($entries)==1 && array_key_exists("contents", $entries[0])) {
165    /* Single File */
166    $smarty->assign("file", $entries[0]);
167    if (isAjaxRequest()) {
168        display_page("configBrowser.tpl");
169    } else {
170        display_page("configBrowserPage.tpl");
171    }
172} else {
173    /* Directory Listing */
174    $smarty->assign("entries", $entries);
175    if (isAjaxRequest()) {
176        display_page("configListing.tpl");
177    } else {
178        display_page("configListingPage.tpl");
179    }
180}
181?>
Note: See TracBrowser for help on using the repository browser.