generic ssh
[configmanager.git] / lib / www.php
1 <?php
2
3
4 // some global menu stuff
5 $MENUS["home"]["url"] = "?action=home";
6 $MENUS["home"]["name"] = "Home";
7 $MENUS["hosts"]["url"] = "?action=hosts";
8 $MENUS["hosts"]["name"] = "Hosts";
9 $MENUS["add"]["url"] = "?action=addhost";
10 $MENUS["add"]["name"] = "Add Host";
11 $MENUS["config"]["url"] = "?action=config";
12 $MENUS["config"]["name"] = "Configure";
13
14 $FUNCTIONS["config"] = "www_configure";
15 $FUNCTIONS["addhost"] = "www_addhost";
16 $FUNCTIONS["addhostnext"] = "www_addHostStageTwo";
17 $FUNCTIONS["addhostthree"] = "www_addHostStageThree";
18
19
20 function www_header()
21 {
22         ?>
23 <html>
24 <title>Network Config Manager</title>
25 <body>
26         <?php
27 }
28
29 function www_pageLayout()
30 {
31         ?>
32 <table>
33 <tr><td colspan="2"><h1>Network Config Manager</h1></td></tr>
34 <tr valign="top"><td><?php www_menu() ?></td><td><?php www_body() ?></td></tr>
35 </table>
36         
37         <?php 
38 }
39
40 function www_footer()
41 {
42         ?>
43 <br><font size="-1"><i>Copyright 2003-2011, Paul J Robinson</i></font><br>
44 </body>
45 </html>
46         <?php 
47 }
48
49 function www_menu()
50 {
51         global $MENUS;
52         foreach($MENUS as $menuitems) {
53                 $url = $menuitems["url"];
54                 $name = $menuitems["name"];
55                 echo "<a href=\"$url\">$name</a><br>";
56         }
57 }
58
59 function www_body()
60 {
61         global $FUNCTIONS;
62         
63         $called = false;
64         if(isset($_REQUEST["action"])) {
65                 $req = $_REQUEST["action"];
66                 if(isset($FUNCTIONS["$req"])) {
67                         $func = $FUNCTIONS["$req"];
68                         if(function_exists($func)) {
69                                 $func();
70                                 return true;
71                         }
72                 }
73         }
74         
75         $db = db_getDB();
76         
77         // here we do the normal body, whatever that
78         // we'll list the hosts, the size of the current config and
79         // the last time it was updated, plus the number of versions
80         
81 }
82
83 function www_hostTypesDropDown()
84 {
85         global $HOST_TYPE;
86         
87         foreach($HOST_TYPE as $tloop => $types) {
88                 $typename = $types["name"];
89                 $typever = $tloop;
90                 echo "<option value=\"$typever\">$typename</option>";
91         }
92 }
93
94 function www_addhost()
95 {
96         ?>
97 <form method="post" action="?action=addhostnext">
98 <table>
99 <tr><td>Name</td><td><input type="text" name="cname"></td></tr>
100 <tr><td>Hostname/IP Address</td><td><input type="text" name="hname"></td></tr>
101 <tr><td>Host Type</td><td><select name="hosttype"><?php www_hostTypesDropDown() ?></select></td></tr>
102 </table>
103 <input type="submit" value="Next" name="Next">
104 </form>
105         <?php
106 }
107
108 function www_addHostStageTwo()
109 {
110         global $HOST_TYPE;
111         if(isset($_REQUEST["hosttype"])) {
112                 $htype = $_REQUEST["hosttype"];
113                 $func = $HOST_TYPE["$htype"]["configform"];
114                 if(function_exists($func)) {
115                         echo "<form method=\"post\" action=\"?action=addhostthree&hosttype=$htype\">";
116                         $func();
117                         echo "<input type=\"submit\" value=\"Add\" name=\"Add\">";
118                 } else echo "would call $func for $htype but it doesnt exist\n";
119         }
120 }
121
122 function www_addHostStageThree()
123 {
124         global $HOST_TYPE;
125         if(isset($_REQUEST["hosttype"])) {
126                 $htype = $_REQUEST["htype"];
127                 $func = $HOST_TYPE["$htype"]["postfunction"];
128                 if(function_exists($func)) {
129                         $func();
130                 } else echo "would call $func for $htype but it doesnt exist\n";
131         }
132         
133 }
134 ?>