af5ed85612d29a2d12b129c0f9c3bbd04e42f9e5
[glcas.git] / plugins / admin.php
1 <?php 
2
3 error_log("admin loaded");
4
5 global $URL_HANDLERS;
6 $URL_HANDLERS["admin.*"] = "GLCASAdmin";
7
8 class GLCASAdmin {
9         function __construct($config)
10         {
11                 $this->config = $config;
12                 error_log("constructor for GLCASAdmin");
13                 
14         }
15         
16         function go($url)
17         {
18                 error_log("repo:go called");
19                 
20                 if(isset($_REQUEST["action"])) {
21                         switch($_REQUEST["action"]) {
22                                 case "addrepo":
23                                         GLCASpageBuilder($this,"doAddRepoForm");
24                                         return;
25                                         break;
26                                 case "scanrepo":
27                                         break;
28                         }
29                 }
30                 GLCASpageBuilder($this, "body");
31         }
32         
33         function body($url)
34         {
35                 // for the main admin body, we hae the following components
36                 
37                 // 1. list of currently available repos and stuff
38                 
39                 // 2. way to add a repo direct
40                 
41                 // 3. way to scan for a repo given a url
42                 
43                 // so first, lets do the main body
44                 $this->mainBody($url);
45         }
46         
47         function doAddRepoForm($url)
48         {
49                 $myRep = new GLCASRepo($this->config);
50                 
51                 $wasyum = false;
52                 if($_REQUEST["repotype"] == "yumbase") {
53                         $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"]);
54                         $wasyum = true;
55                 } else if($_REQUEST["repotype"] == "yummirrorlist") {
56                         $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"], true);
57                         $wasyum = true;
58                 } else if($_REQUEST["repotype"] == "apt") {
59                         $glt = $myRep->getRepoDetailsApt($_REQUEST["repourl"]);
60                 }
61                 
62                 
63                 if($wasyum) {
64                         $os = $glt["OS"];
65                         $version = $glt["version"];
66                         $arch = $glt["arch"];
67                         echo "<form method=\"post\" action=\"repoaddreal\">";
68                         echo "OS: <input type=\"text\" name=\"OS\" value=\"$os\"><br>";
69                         echo "Version: <input type=\"text\" name=\"version\" value=\"$version\"><br>";
70                         echo "Architecture: <input type=\"text\" name=\"Architecture\" value=\"$arch\"><br>";
71                         echo "Short URL <input type=\"text\" name=\"shorturl\"><br>";
72                         echo "URL Prefix (blank for none) <input type=\"text\" name=\"shorturl\"><br>";
73                         echo "<input type=\"submit\" name=\"Add\" value=\"add\"><br>";
74                         echo "</form>";
75                 } else {
76                         // apt is much tricker cause one repo can provide multiple versions, OS's and architectures.
77                 }
78         }
79         
80         function mainBody($url)
81         {
82                 // first, list available repos
83                 echo "<h3>Repositories</h3><br><table>";
84                 echo "<tr><th>Name</th><th>Type</th><th>Version</th><th>Browse</th><th>Control</th></tr>";
85                 echo "</table><br><hr>";
86                 
87                 // wrap all this in a table
88                 echo "<table><tr><td valign=\"top\">";
89                 // now, add a repo
90                 echo "<h3>Add A Repo</h3>";
91                 echo "<form method=\"post\" action=\"?action=addrepo\">";
92                 echo "Type <select name=\"repotype\">";
93                         echo "<option value=\"yumbase\">YUM (Base URL)</option>";
94                         echo "<option value=\"yummirrorlist\">YUM (Mirror List)</option>";
95                         echo "<option value=\"apt\">APT</option>";
96                         echo "</select><br>";
97                 echo "URL <input type=\"text\" name=\"repourl\"><br>";
98                 echo "<input type=\"submit\" name=\"Add\" value=\"Add\"><br>";
99                 echo "</form><hr>";
100                 
101                 echo "</td><td valign=\"top\">";
102                 
103                 // now scan for a repo
104                 echo "<h3>Scan For Repos</h3>";
105                 echo "<form method=\"post\" action=\"?action=scanrepo\">";
106                 echo "Hint <select name=\"repohint\">";
107                         echo "<option value=\"fedora\">Fedora</option>";
108                         echo "<option value=\"centos\">Centos</option>";
109                         echo "<option value=\"ubuntu\">Ubuntu</option>";
110                         echo "</select><br>";
111                 echo "URL <input type=\"text\" name=\"repourl\"><br>";
112                 echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
113                 echo "</form>";
114                 
115                 echo "</td></tr></table>";
116         }
117
118         private $config;
119 }
120
121 ?>