root/branches/networkfusion/wifidog-auth/wifidog/admin/generic_object_admin.php @ 1388

Revision 1388, 18.2 KB (checked in by networkfusion, 5 years ago)

* Added MAC Banning UI, Network Permission and SQL Schema Update.
The SQL for controlling access still needs to be written.
See http://dev.wifidog.org/wiki/doc/developer/MACBlacklisting for more details.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3
4/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
5
6// +-------------------------------------------------------------------+
7// | WiFiDog Authentication Server                                     |
8// | =============================                                     |
9// |                                                                   |
10// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
11// | portal suite.                                                     |
12// +-------------------------------------------------------------------+
13// | PHP version 5 required.                                           |
14// +-------------------------------------------------------------------+
15// | Homepage:     http://www.wifidog.org/                             |
16// | Source Forge: http://sourceforge.net/projects/wifidog/            |
17// +-------------------------------------------------------------------+
18// | This program is free software; you can redistribute it and/or     |
19// | modify it under the terms of the GNU General Public License as    |
20// | published by the Free Software Foundation; either version 2 of    |
21// | the License, or (at your option) any later version.               |
22// |                                                                   |
23// | This program is distributed in the hope that it will be useful,   |
24// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
25// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
26// | GNU General Public License for more details.                      |
27// |                                                                   |
28// | You should have received a copy of the GNU General Public License |
29// | along with this program; if not, contact:                         |
30// |                                                                   |
31// | Free Software Foundation           Voice:  +1-617-542-5942        |
32// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
33// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
34// |                                                                   |
35// +-------------------------------------------------------------------+
36
37/**
38 * A simple interface to edit any object that implements the GenericObject
39 * interface.
40 *
41 * The php file takes the following params:
42 * - $_REQUEST['action']: new, edit, delete, preview, process_new_ui, new_ui
43 *  (also   save, but not meant for calling from outside this file)
44 * - $_REQUEST ['object_id']: The id of the object ot be edited
45 * - $_REQUEST ['object_class']: The class name of the object ot be edited
46 * - $_REQUEST ['node_id']: In preview mode, the current node to simulate
47 *  display
48 * -$_REQUEST  ['debug']: If present and non empty, the $_REQUEST variables will
49 * be displayed
50 *
51 * @package    WiFiDogAuthServer
52 * @author     Benoit Grégoire <bock@step.polymtl.ca>
53 * @copyright  2005-2006 Benoit Grégoire, Technologies Coeus inc.
54 * @version    Subversion $Id$
55 * @link       http://www.wifidog.org/
56 */
57
58/**
59 * Load common include file
60 */
61require_once ('admin_common.php');
62
63require_once ('classes/GenericObject.php');
64require_once ('classes/MainUI.php');
65
66
67// Init values
68$ui = MainUI :: getObject();
69$html = "";
70$errmsg = "";
71$common_input = "";
72$displayEditButton = true;
73$displayShowAllButton = false;
74$supportsPreview = true;
75$supportsDeletion = true;
76/*
77 * Check for the object class to use
78 */
79if (empty ($_REQUEST['object_class'])) {
80    echo "<div class='errormsg'>" . _("Sorry, the 'object_class' parameter must be specified") . "</div>\n";
81    exit;
82} else {
83    $class = $_REQUEST['object_class'];
84
85    //For some reason, we can't use the || operator here (probably a PHP bug)
86    if(!@include_once("classes/{$class}.php")) {
87        if(!@include_once("classes/Content/{$class}/{$class}.php")) {
88            throw new Exception(sprintf("Unable to include the class for %s",  $class));
89        }
90    }
91}
92// Init text values
93$createText = sprintf(_("Create %s"), $_REQUEST['object_class']);
94$addText = sprintf(_("Add %s"), $_REQUEST['object_class']);
95$createLongText = sprintf(_("Create a new %s"), $_REQUEST['object_class']);
96$addLongText = sprintf(_("Add a new %s"), $_REQUEST['object_class']);
97$listAllText = sprintf(_("Show all %s"), $_REQUEST['object_class']);
98$listPersistantText = sprintf(_("Show only persistant %s"), $_REQUEST['object_class']);
99$editText = sprintf(_("Edit %s"), $_REQUEST['object_class']);
100
101$newText = $createText;
102$newLongText = $createLongText;
103
104$objectClass = $_REQUEST['object_class'];
105$objectId = "none";
106if (!empty($_REQUEST['object_id'])) { $objectId = $_REQUEST['object_id']; }
107
108
109/*
110 * Check for debugging requests
111 */
112//$_REQUEST['debug']=true;
113if (!empty ($_REQUEST['debug'])) {
114    echo "<pre>";
115    print_r($_REQUEST);
116    echo "</pre>";
117}
118
119/*
120 * Check for action requests
121 */
122if (!isset ($_REQUEST['action'])) {
123    $_REQUEST['action'] = "";
124}
125
126if (!isset ($_REQUEST['action_delete'])) {
127    $_REQUEST['action_delete'] = "";
128}
129
130/*
131 * Pre-process action requests (load required objects)
132 */
133switch ($_REQUEST['action']) {
134    case "new" :
135        $object = call_user_func(array (
136        $class,
137        'createNewObject'
138        ));
139        $_REQUEST['action'] = 'edit';
140        break;
141
142    case "process_new_ui" :
143        $object = call_user_func(array (
144        $class,
145        'processCreateNewObjectUI'
146        ));
147
148        if (!$object) {
149            echo "<div class='errormsg'>" . _("Sorry, the object couldn't be created.  You probably didn't fill the form properly") . "</div>\n";
150            exit;
151        }
152
153        $_REQUEST['action'] = 'edit';
154        break;
155
156    case "list" :
157    case "new_ui" :
158        // No need for an object
159        break;
160
161    default :
162        $object = call_user_func(array (
163        $class,
164        'getObject'
165        ), $objectId);
166        break;
167}
168
169/*
170 * Process action requests (saving, previewing and deleting)
171 */
172switch ($_REQUEST['action']) {
173    case "save" :
174        $object->processAdminUI();
175        $_REQUEST['action'] = 'edit';
176        break;
177
178    case "preview" :
179        if (empty ($_REQUEST['node_id'])) {
180            $node_id = null;
181            $node = null;
182        } else {
183            $node_id = $_REQUEST['node_id'];
184            $node = Node :: getObject($node_id);
185            Node :: setCurrentNode($node);
186
187            $html .= "<h1>" . _("Showing preview as it would appear at ") . $node->getName() . "</h1><br><br>";
188        }
189
190        if (!empty ($_REQUEST['debug'])) {
191            $common_input .= "<input type='hidden' name='debug' value='true'>";
192        }
193
194        $common_input .= "<input type='hidden' name='object_id' value='" . $object->GetId() . "'>";
195        $common_input .= "<input type='hidden' name='object_class' value='" . get_class($object) . "'>";
196        $common_input .= "<input type='hidden' name='node_id' value='" . $node_id . "'>";
197
198        $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' target='_top' method='post'>";
199        $html .= $common_input;
200
201        $name = "node_id";
202        $html .= _("Node");
203        $html .= ": ";
204        $html .= Node :: getSelectUI($name);
205
206        if (method_exists($object, "getUserUI")) {
207            $ui->addContent('main_area_middle', $object, 1);
208        }
209
210        $html .= "<input type='hidden' name='action' value='preview'>";
211        $html .= "<input type='submit' name='preview_submit' value='" . _("Preview") . " " . get_class($object) . "'>";
212        $html .= '</form>';
213
214        $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>";
215        $html .= $common_input;
216        $html .= "<input type='hidden' name='action' value='edit'>";
217        $html .= "<input type=submit name='edit_submit' value='" . _("Edit") . " " . get_class($object) . "'>";
218        $html .= '</form>';
219        break;
220
221    case "delete" :
222        // Gets called only if no JavaScript was enabled in the browser
223        if ($object->delete($errmsg) == true) {
224            $html .= "<div class='successmsg'>" . _("Object successfully deleted") . "</div>";
225        } else {
226            $html .= "<div class='errormsg'>" . _("Deletion failed, error was: ") . "<br />$errmsg</div>";
227            $_REQUEST['action'] = 'edit';
228        }
229        break;
230
231    default :
232        // Do nothing
233        break;
234}
235
236/*
237 * Process action requests (deleting with enabled JavaScript)
238 */
239switch ($_REQUEST['action_delete']) {
240    case "delete" :
241        // First save the object so we can catch any "persistent content" changes
242        $object->processAdminUI();
243
244        // Now try to delete the content
245        if ($object->delete($errmsg) == true) {
246            $html .= "<div class='successmsg'>" . _("Object successfully deleted") . "</div>";
247            $_REQUEST['action'] = "";
248        } else {
249            $html .= "<div class='errormsg'>" . _("Deletion failed, error was: ") . "<br />$errmsg</div>";
250            $_REQUEST['action'] = 'edit';
251        }
252        break;
253
254    default :
255        // Do nothing
256        break;
257}
258
259/*
260 * Process action requests (list and new_ui and edit)
261 */
262switch ($_REQUEST['action']) {
263    case "list" :
264        $userData = null;
265        $disableCreateNewButton = false;
266        switch ($_REQUEST['object_class']) {
267            case "Content" :
268                $displayShowAllButton = true;
269                ((isset ($_REQUEST['display_content']) && $_REQUEST['display_content'] == "all_content") ? $sql_additional_where = null : $sql_additional_where = " AND is_persistent=TRUE ");
270                $objectSelector = Content :: getSelectExistingContentUI('object_id', $sql_additional_where, null, "creation_timestamp DESC, content_type", "table");
271                $displayEditButton = false;
272                break;
273            case "Node" :
274                $userData['typeInterface'] = "table";
275                $displayEditButton = false;
276            default :
277                $newLongText = $addLongText;
278                $objectSelector = call_user_func(array (
279                $_REQUEST['object_class'],
280                'getSelectUI'
281                ), 'object_id'
282                , $userData);
283                break;
284        }
285
286        if ($displayShowAllButton) {
287            $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>";
288            $html .= "<input type='hidden' name='object_class' value='$class'>";
289            $html .= "<input type='hidden' name='action' value='list'>\n";
290
291            if (isset ($_REQUEST['display_content']) && $_REQUEST['display_content'] == "all_content") {
292                $html .= "<input type='submit' name='list_submit' value='$listPersistantText'>\n";
293            } else {
294                $html .= "<input type='hidden' name='display_content' value='all_content'>\n";
295                $html .= "<input type='submit' name='list_submit' value='$listAllText'>\n";
296            }
297
298            $html .= '</form>';
299        }
300
301        if ($objectSelector != "") {
302            if ($displayEditButton) {
303                $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>";
304                $html .= "<input type='hidden' name='object_class' value='$class'>";
305                $html .= "<input type='hidden' name='action' value='edit'>";
306                $html .= $objectSelector;
307                $html .= "<input type='submit' name='edit_submit' value='$editText'>\n";
308                $html .= '</form>';
309            } else {
310                $html .= $objectSelector;
311            }
312        }
313       
314        if($disableCreateNewButton == false 
315        && method_exists($_REQUEST['object_class'],'getCreateNewObjectUI') 
316        && null != $newUi = call_user_func(array ($_REQUEST['object_class'], 'getCreateNewObjectUI'))) {
317            $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>\n";
318            $html .= "<input type='hidden' name='object_class' value='$class'>\n";
319            $html .= $newUi;
320            $html .= "<input type='hidden' name='action' value='process_new_ui'>\n";
321            $html .= "<input type='submit' name='new_submit' value='$newLongText'>\n";
322            $html .= "</form>\n";
323        }
324        break;
325
326            case "new_ui" :
327                switch ($_REQUEST['object_class']) {
328                    case "Node" :
329                    case "Server" :
330                    case "Content" :
331                    case "ContentTypeFilter" :
332                    case "ProfileTemplate" :
333                        $newText = $addText;
334                        break;
335
336                    default :
337                        break;
338                }
339
340                $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>";
341                $html .= "<input type='hidden' name='object_class' value='$class'>";
342                $html .= call_user_func(array (
343                $class,
344                'getCreateNewObjectUI'
345                ));
346                $html .= "<input type='hidden' name='action' value='process_new_ui'>";
347                $html .= "<input type=submit name='new_ui_submit' value='$newText'>";
348                $html .= '</form>';
349                break;
350
351                    case "edit" :
352                        // Process preview abilities
353                        switch ($_REQUEST['object_class']) {
354                            case "Network" :
355                            case "Mac" :
356                            case "Server" :
357                            case "User" :
358                            case "ContentTypeFilter" :
359                            case "ProfileTemplate" :
360                                $supportsPreview = false;
361                                break;
362
363                            default :
364                                break;
365                        }
366
367                        // Process deletion abilities
368                        switch ($_REQUEST['object_class']) {
369                            case "User" :
370                                $supportsDeletion = false;
371                                break;
372                            case "Network" :
373                            case "Mac" :
374                            case "Node" :
375                            case "Server" :
376                            case "ProfileTemplate" :
377                            case "ContentTypeFilter" :
378                                break;
379
380                            default :
381                                break;
382                        }
383
384                        if (!$object) {
385                            echo "<div class='errormsg'>" . _("Sorry, the 'object_id' parameter must be specified") . "</div>";
386                            exit;
387                        }
388
389                        if (!empty ($_REQUEST['debug'])) {
390                            $common_input .= "<input type='hidden' name='debug' value='true'>";
391                        }
392
393                        $common_input .= "<input type='hidden' name='object_id' value='" . $object->getId() . "'>";
394                        $common_input .= "<input type='hidden' name='object_class' value='" . get_class($object) . "'>";
395
396                        $html .= "<form name='generic_object_form' enctype='multipart/form-data' action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>";
397                        $html .= $common_input;
398                        $html .= $object->getAdminUI();
399                        $html .= "<div class='generic_object_admin_edit'>";
400                        $html .= "<input type='hidden' name='action' value='save'>";
401                        $html .= "<input type='submit' class='submit' name='save_submit' value='" . _("Save") . " " . get_class($object) . "'>";
402
403                        if ($supportsDeletion) {
404                            $html .= "<script type='text/javascript'>";
405                            $html .= "document.write(\"<input type='hidden' name='action_delete' value='no' id='form_action_delete' />\");";
406                            $html .= "document.write(\"<input type='submit' class='submit' name='action_delete_submit' onmouseup='document.getElementById(\\\"form_action_delete\\\").value = \\\"delete\\\"' onkeyup='document.getElementById(\\\"form_action_delete\\\").value = \\\"delete\\\"' value='" . _("Delete") . " " . get_class($object) . "' />\");";
407                            $html .= "</script>";
408                        }
409
410                        $html .= '</form>';
411
412                        if ($supportsPreview) {
413                            $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' target='_blank' method='post'>";
414                            $html .= $common_input;
415                            $html .= "<input type='hidden' name='action' value='preview'>";
416                            $html .= "<input type='submit' class='submit' name='preview_submit' value='" . _("Preview") . " " . get_class($object) . "'>";
417                            $html .= '</form>';
418                        }
419
420                        // Display delete button (without check for unchecked persitant switch) only if JavaScript has been disabled
421                        if ($supportsDeletion) {
422                            $html .= "<noscript>";
423                            $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>";
424                            $html .= $common_input;
425                            $html .= "<input type='hidden' name='action' value='delete'>";
426                            $html .= "<input type='submit' class='submit'  name='delete_submit' value='" . _("Delete") . " " . get_class($object) . "'>";
427                            $html .= '</form>';
428                            $html .= "</noscript>";
429                        }
430
431                        $html .= "<div class='clearbr'></div>";
432                        $html .= "</div>";
433                        break;
434
435                            default :
436                                // Do nothing
437                                break;
438}
439
440/*
441 * Define JavaScripts
442 */
443
444$_htmlHeader = "<script type='text/javascript' src='" . BASE_SSL_PATH . "js/interface.js'></script>";
445$_htmlHeader .= "<script type='text/javascript' src='" . BASE_SSL_PATH . "js/interface.js'></script>";
446
447/*
448 * Render output
449 */
450
451$ui->setTitle(_("Generic object editor") . " (" .  $objectClass . ": " . $objectId . ")");
452$ui->appendHtmlHeadContent($_htmlHeader);
453$ui->addContent('main_area_middle', "<div>" . $html . "</div>");
454$ui->display();
455
456/*
457 * Local variables:
458 * tab-width: 4
459 * c-basic-offset: 4
460 * c-hanging-comment-ender-p: nil
461 * End:
462 */
463?>
Note: See TracBrowser for help on using the browser.