Changeset 554

Show
Ignore:
Timestamp:
04/19/05 17:04:33 (8 years ago)
Author:
benoitg
Message:

2005-04-19 Benoit Gr�goire <bock@…>

  • Working (beta...) content manager and portal.
  • Add content preview mode
Location:
trunk/wifidog-auth
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r553 r554  
     12005-04-19 Benoit Grégoire  <bock@step.polymtl.ca> 
     2        * Working (beta...) content manager and portal. 
     3        * Add content preview mode 
     4         
    152005-04-18 Benoit Grégoire  <bock@step.polymtl.ca> 
    26        * Hotspot and network content association, continue access control work. 
  • trunk/wifidog-auth/wifidog/admin/generic_object_admin.php

    r553 r554  
    2323/**@file generic_object_admin.php 
    2424 * A simple interface to edit any object that implements the GenericObject interface.  The php file takes the following params: 
    25  * $_REQUEST['action']: new, edit, delete (also save, but not meant for calling from outside this file) 
     25 * $_REQUEST['action']: new, edit, delete, preview (also save, but not meant for calling from outside this file) 
    2626 * $_REQUEST['object_id']:  The id of the object ot be edited 
    2727 * $_REQUEST['object_class']:  The class name of the object ot be edited 
     28 * $_REQUEST['node_id']: In preview mode, the current node to simulate display 
    2829 * $_REQUEST['debug']:  If present and non empty, the $_REQUEST variables will be displayed 
    2930 * @author Copyright (C) 2005 Benoit Grégoire <bock@step.polymtl.ca>, 
     
    106107        $html .= '</form>'; 
    107108         
     109                $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>"; 
     110                $html .= $common_input; 
     111        $html .= "<input type='hidden' name='action' value='preview'>\n"; 
     112        $html .= "<input type=submit name='preview_submit' value='"._("Preview")." ".get_class($object)."'>\n"; 
     113        $html .= '</form>'; 
     114         
    108115        $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>"; 
    109116$html .= $common_input; 
     
    113120} 
    114121 
     122 
     123if ($_REQUEST['action'] == 'preview') 
     124{ 
     125        if(empty($_REQUEST['node_id'])) 
     126        { 
     127                $node_id = null; 
     128                $node = null; 
     129        } 
     130        else 
     131        { 
     132        $node_id = $_REQUEST['node_id']; 
     133        $node= Node::getObject($node_id); 
     134        Node::setCurrentNode($node); 
     135        } 
     136$common_input = ''; 
     137        if(!empty($_REQUEST['debug'])) 
     138        { 
     139        $common_input .= "<input type=submit name='debug' value='true'>\n"; 
     140        } 
     141                $common_input .= "<input type='hidden' name='object_id' value='".$object->GetId()."'>\n"; 
     142        $common_input .= "<input type='hidden' name='object_class' value='".get_class($object)."'>\n"; 
     143                $common_input .= "<input type='hidden' name='node_id' value='".$node_id."'>\n"; 
     144                 
     145        $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>"; 
     146$html .= $common_input; 
     147 
     148                $name = "node_id"; 
     149                $html .= Node :: getSelectNodeUI($name); 
     150                 
     151        $html .= $object->getUserUI(); 
     152        $html .= "<input type='hidden' name='action' value='preview'>\n"; 
     153        $html .= "<input type=submit name='preview_submit' value='"._("Preview")." ".get_class($object)."'>\n"; 
     154        $html .= '</form>'; 
     155         
     156        $html .= "<form action='".GENERIC_OBJECT_ADMIN_ABS_HREF."' method='post'>"; 
     157$html .= $common_input; 
     158        $html .= "<input type='hidden' name='action' value='edit'>\n"; 
     159        $html .= "<input type=submit name='edit_submit' value='"._("Edit")." ".get_class($object)."'>\n"; 
     160        $html .= '</form>'; 
     161} 
     162 
    115163echo $html; 
    116164$smarty->display("templates/footer.html"); 
  • trunk/wifidog-auth/wifidog/classes/Network.php

    r553 r554  
    4141        { 
    4242                return new self($id); 
     43        } 
     44 
     45        /** Get the current network for which the portal is displayed or to which a user is physically connected. 
     46         * @param $real_network_only true or false.  If true, the real physical network where the user is connected is returned, and the node set by setCurrentNode is ignored. 
     47         * @return a Node object, or null if it can't be found. 
     48         */ 
     49        static function getCurrentNetwork($real_network_only = false) 
     50        { 
     51                                global $AUTH_SOURCE_ARRAY; 
     52                $keys = array_keys ( $AUTH_SOURCE_ARRAY); 
     53                 
     54                return new self($keys[0]); 
    4355        } 
    4456 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r553 r554  
    11<?php 
     2 
    23 
    34/********************************************************************\ 
     
    3031        private $mRow; 
    3132        private $id; 
     33        private static $current_node_id = null; 
    3234 
    3335        /** Instantiate a node object  
     
    4244        } 
    4345 
     46        /** Get the current node for which the portal is displayed or to which a user is physically connected. 
     47         * @param $real_node_only true or false.  If true, the real physical node where the user is connected is returned, and the node set by setCurrentNode is ignored. 
     48         * @return a Node object, or null if it can't be found. 
     49         */ 
     50        static function getCurrentNode($real_node_only = false) 
     51        { 
     52                $object = null; 
     53                if (self :: $current_node_id != null && $real_node_only == false) 
     54                { 
     55                        $object = new self(self :: $current_node_id); 
     56                } 
     57                else 
     58                { 
     59                        $object = getCurrentRealNode(); 
     60                } 
     61                return $object; 
     62        } 
     63 
     64        /** Set the current node where the user is to be considered connected to.  (For portal and content display purpuses, among other. 
     65         * @param $node Node.  The new current node. 
     66         * @return true  */ 
     67        static function setCurrentNode(Node $node) 
     68        { 
     69                self :: $current_node_id = $node->GetId(); 
     70                return true; 
     71        } 
     72 
     73        /** Get the current node to which a user is physically connected, if any.  This is done by an IP adress lookup against the last reported IP adress of the node 
     74         * @param        * @return a Node object, or null if it can't be found. 
     75         */ 
     76        public function getCurrentRealNode() 
     77        { 
     78                global $db; 
     79                $retval = null; 
     80                $sql = "SELECT node_id, last_heartbeat_ip from nodes WHERE last_heartbeat_ip='$_SERVER[REMOTE_ADDR]'"; 
     81                $db->ExecSql($sql, $node_rows, false); 
     82                $num_match = count($node_rows); 
     83                if ($num_match == 0) 
     84                { 
     85                        // User is not physically connected to a node 
     86                        $retval = null; 
     87                } 
     88                else 
     89                        if ($num_match = 1) 
     90                        { 
     91                                // Only a single node matches, the user is presumed to be there 
     92                                $retval = new self($node_rows[0]['node_id']); 
     93                        } 
     94                        else 
     95                        { 
     96                                /* We have more than one node matching the IP (the nodes are behind the same NAT). 
     97                                 * We will try to discriminate by finding which node the user last authenticated against. 
     98                                 * If the IP matches, we can be pretty certain the user is there.  
     99                                 */ 
     100                                $retval = null; 
     101                                $current_user = User :: getCurrentUser(); 
     102                                if ($current_user != null) 
     103                                { 
     104                                        $current_user_id = $current_user->getId(); 
     105                                        $_SERVER['REMOTE_ADDR']; 
     106                                        $sql = "SELECT node_id, last_heartbeat_ip from connections NATURAL JOIN nodes WHERE user_id='$current_user_id' ORDER BY last_updated DESC "; 
     107                                        $db->ExecSql($sql, $node_rows, false); 
     108                                        $node_row = $node_rows[0]; 
     109                                        if($node_row!=null && $node_row['last_heartbeat_ip']==$_SERVER['REMOTE_ADDR']) 
     110                                        { 
     111                                                $retval = new self($node_row['node_id']); 
     112                                        } 
     113                                } 
     114                        } 
     115return $retval; 
     116        } 
     117 
    44118        public function delete(& $errmsg) 
    45119        { 
    46                 $retval=false; 
    47                 $user = User::getCurrentUser(); 
    48                 if($this->isOwner($user)||$user->isSuperAdmin()) 
    49                 { 
    50                         $errmsg=_('Access denied!'); 
     120                $retval = false; 
     121                $user = User :: getCurrentUser(); 
     122                if ($this->isOwner($user) || $user->isSuperAdmin()) 
     123                { 
     124                        $errmsg = _('Access denied!'); 
    51125                } 
    52126                global $db; 
     
    54128                if (!$db->ExecSqlUpdate("DELETE FROM nodes WHERE node_id='{$this->$id}'", false)) 
    55129                { 
    56                         $errmsg=_('Could not delete node!');} 
    57                         else 
    58                         { 
    59                                 $retval=true; 
    60                         } 
    61 return $retval; 
     130                        $errmsg = _('Could not delete node!'); 
     131                } 
     132                else 
     133                { 
     134                        $retval = true; 
     135                } 
     136                return $retval; 
    62137        } 
    63138 
     
    123198        * @return html markup 
    124199        */ 
    125         public static function getSelectNodeUI($user_prefix, $sql_additional_where=null) 
     200        public static function getSelectNodeUI($user_prefix, $sql_additional_where = null) 
    126201        { 
    127202                global $db; 
     
    290365                return $html; 
    291366        } 
    292          
     367 
    293368        /** Process admin interface of this object. 
    294369        */ 
    295370        public function processAdminUI() 
    296371        { 
    297                 if($this->isOwner($user)||$user->isSuperAdmin()) 
     372                $user = User::getCurrentUser(); 
     373                if (!$this->isOwner($user) || !$user->isSuperAdmin()) 
    298374                { 
    299375                        throw new Exception(_('Access denied!')); 
     
    317393                } 
    318394        } 
    319          
    320 /** Add content to this node */ 
     395 
     396        /** Add content to this node */ 
    321397        public function addContent(Content $content) 
    322398        { 
    323399                global $db; 
    324                 $content_id=$db->EscapeString($content->getId()); 
     400                $content_id = $db->EscapeString($content->getId()); 
    325401                $sql = "INSERT INTO node_has_content (node_id, content_id) VALUES ('$this->id','$content_id')"; 
    326402                $db->ExecSqlUpdate($sql, false); 
    327403        } 
    328          
    329 /** Remove content from this node */ 
     404 
     405        /** Remove content from this node */ 
    330406        public function removeContent(Content $content) 
    331407        { 
    332408                global $db; 
    333                 $content_id=$db->EscapeString($content->getId()); 
     409                $content_id = $db->EscapeString($content->getId()); 
    334410                $sql = "DELETE FROM node_has_content WHERE node_id='$this->id' AND content_id='$content_id'"; 
    335411                $db->ExecSqlUpdate($sql, false); 
    336412        } 
    337          
     413 
    338414        /**Get an array of all Content linked to this node 
    339415        * @return an array of Content or an empty arrray */ 
  • trunk/wifidog-auth/wifidog/config.php

    r545 r554  
    77 * 
    88 *     $Log$ 
     9 *     Revision 1.32  2005/04/19 21:02:40  benoitg 
     10 *     2005-04-19 Benoit Gr�goire  <bock@step.polymtl.ca> 
     11 *      * Working (beta...) content manager and portal. 
     12 *      * Add content preview mode 
     13 * 
    914 *     Revision 1.31  2005/04/14 15:12:35  benoitg 
    1015 *     2005-04-14 Benoit Gr�goire  <bock@step.polymtl.ca> 
     
    214219define('STYLESHEET_NAME', 'stylesheet.css'); 
    215220define('LOGIN_PAGE_NAME', 'login.html'); 
    216 define('PORTAL_PAGE_NAME', 'portal.html'); 
     221define('PORTAL_PAGE_NAME', 'portal.html');/**< @deprecated version - 19-Apr-2005*/ 
    217222define('PAGE_HEADER_NAME', 'header.html'); 
    218223define('PAGE_FOOTER_NAME', 'footer.html'); 
  • trunk/wifidog-auth/wifidog/local_content/default/stylesheet.css

    r553 r554  
    209209 
    210210.list_ui_container{ display: inline; } 
     211 
     212/* Portal */ 
     213 
     214#portal_container { 
     215margin: 3px;} 
     216 
     217.portal_network_section {/*background-color:    #FBFBFF;/*lighter blue*/ 
     218margin: 3px;} 
     219.portal_node_section {/*background-color:       #FBFBFF;/*lighter blue*/ 
     220margin: 3px;} 
     221.portal_user_section {/*background-color:       #FBFBFF;/*lighter blue*/ 
     222margin: 3px;} 
     223 
     224.portal_section_logo{ 
     225float: right; 
     226clear: right; 
     227 padding: 2px; 
     228max-height: 100px; 
     229max-width: 100px; 
     230} 
     231 
    211232{/literal} 
  • trunk/wifidog-auth/wifidog/portal/index.php

    r553 r554  
    3232    garbage_collect(); 
    3333} 
     34$node = Node::getObject($_REQUEST['gw_id']); 
    3435 
    35 if (!isset($_REQUEST['gw_id'])) { 
     36if ($node==null) { 
    3637    $smarty->display("templates/message_unknown_hotspot.html"); 
    3738    exit; 
    3839} 
     40$node_id=$node->getId(); 
     41$portal_template = $node_id . ".html"; 
    3942 
    40 $portal_template = $_REQUEST['gw_id'] . ".html"; 
    41 $node_id = $db->EscapeString($_REQUEST['gw_id']); 
    42  
    43 $node = Node::getObject($node_id); 
    4443if ($node == null) { 
    4544    $smarty->assign("gw_id", $_REQUEST['gw_id']); 
     
    4847} 
    4948 
     49Node::setCurrentNode($node); 
     50 
    5051$smarty->assign('hotspot_name', $node->getName()); 
    51 $hotspot_rss_url = $node->getRSSURL(); 
     52$node_name= $node->getName(); 
    5253 
    5354/* Find out who is online */ 
    5455$smarty->assign("online_users", $node->getOnlineUsers()); 
    5556 
    56 if (RSS_SUPPORT) { 
    57     //      $old_error_level = error_reporting(E_ERROR); 
    58     define('MAGPIE_DIR', BASEPATH.MAGPIE_REL_PATH); 
    59     //    require_once(MAGPIE_DIR.'rss_fetch.inc'); 
    60     //    define('MAGPIE_DEBUG', 0); 
    61     require_once BASEPATH.'classes/RssPressReview.inc'; 
    62     $press_review=new RssPressReview; 
    63     $tokens = "/[\s,]+/"; 
    64     $network_rss_sources = NETWORK_RSS_URL; 
    65     $network_rss_html = null; 
    66     if(!empty($network_rss_sources)) 
    67       { 
    68  
    69         $extract_array=null; 
    70         $extract_array = preg_split($tokens, $network_rss_sources); 
    71         //print_r($extract_array); 
    72         foreach($extract_array as $source) 
    73           { 
    74             $network_rss_sources_array[] = array('url' => $source, 'default_publication_interval' => 7*24*3600); 
    75           } 
    76         $network_rss_html=$press_review->get_rss_html($network_rss_sources_array, 5); 
    77       } 
    78                       
    79     $hotspot_rss_html=null; 
    80     if(!empty($hotspot_rss_url)) 
    81       { 
    82         $extract_array=null; 
    83         $extract_array = preg_split($tokens, $hotspot_rss_url); 
    84         //print_r($extract_array); 
    85         foreach($extract_array as $source) 
    86           { 
    87             $hotspot_rss_sources_array[] = array('url' => $source, 'default_publication_interval' => 7*24*3600); 
    88           } 
    89         $hotspot_rss_html=$press_review->get_rss_html($hotspot_rss_sources_array, 5);      
    90       } 
    91     /** 
    92      @return the generated html or the error message or an empty string if called without a URL. 
    93     */ 
    94     function generate_rss_html ( $url ) { 
    95       $rss_html=''; 
    96       if(!empty($url)) 
    97         { 
    98           $rss = fetch_rss( $url ); 
    99           $rss_html=''; 
    100           if ( !$rss ) 
    101             { 
    102               $rss_html .= _("Error: ") . magpie_error() ; 
    103             } 
    104           else  
    105             { 
    106               //$rss->show_channel(); 
    107               //$rss->show_list(); 
    108               $rss_html .= "<p>"._('Channel: ') . $rss->channel['title'] . "</p>\n"; 
    109               $rss_html .= "<ul>\n"; 
    110               foreach ($rss->items as $item) 
    111                 { 
    112                   //echo '<pre>'; print_r($item);       echo '</pre>'; 
    113                   $href = $item['link']; 
    114                   $title = $item['title']; 
    115                   $summary =  $item['summary'];  
    116                   $rss_html .= "<li><emp><a href=$href>$title</a></emp> $summary</li>\n"; 
    117                 } 
    118               $rss_html .= "</ul>\n"; 
    119             } 
    120         } 
    121       return $rss_html; 
    122     } 
    123  
    124  
    125     //$network_rss_html=generate_rss_html(NETWORK_RSS_URL);     
    126     //echo $networkrss_html; 
    127     $smarty->assign("network_rss_html", $network_rss_html); 
    128  
    129      
    130     //$hotspot_rss_html=generate_rss_html($hotspot_rss_url);     
    131     //echo $hotspot_rss_html; 
    132     $smarty->assign("hotspot_rss_html", $hotspot_rss_html); 
    133     //   error_reporting($old_error_level); 
    134 } 
    13557 
    13658if (isset($session)) { 
    13759    $smarty->assign("original_url_requested", $session->get(SESS_ORIGINAL_URL_VAR)); 
    13860} 
     61        $hotspot_network_name=HOTSPOT_NETWORK_NAME; 
     62        $hotspot_network_url=HOTSPOT_NETWORK_URL; 
     63        $network_logo_url=COMMON_CONTENT_URL.NETWORK_LOGO_NAME; 
     64        $network_logo_banner_url=COMMON_CONTENT_URL.NETWORK_LOGO_BANNER_NAME; 
     65 
     66     $hotspot_logo_url= find_local_content_url(HOTSPOT_LOGO_NAME); 
     67     $hotspot_logo_banner_url=find_local_content_url(HOTSPOT_LOGO_BANNER_NAME); 
     68 
    13969 
    14070$smarty->display(DEFAULT_CONTENT_SMARTY_PATH."header.html"); 
     71$html=''; 
     72$html .= "<div id='portal_container'>\n"; 
    14173 
     74/* Network section */ 
     75$html .= "<div class='portal_network_section'>\n"; 
     76$html .= "<a href='{$hotspot_network_url}'><img class='portal_section_logo' src='{$network_logo_banner_url}' alt='{$hotspot_network_name} logo' border='0'></a>\n"; 
     77$html .= "Content from \"<a href='{$hotspot_network_url}'>{$hotspot_network_name}</a>\"\n"; 
     78$contents = Network::getCurrentNetwork()->getAllContent(); 
     79foreach ($contents as $content) 
     80{ 
     81        $html .= $content->getUserUI(); 
     82} 
     83$html .= "</div>\n"; 
     84 
     85/* Node section */ 
     86$html .= "<div class='portal_node_section'>\n"; 
     87$html .= "<img class='portal_section_logo' src='{$hotspot_logo_url}' alt=''>\n"; 
     88$html .= "Content from \"<a href='{$hotspot_logo_url}'>{$node_name}</a>\"\n"; 
     89$contents = $node->getAllContent(); 
     90foreach ($contents as $content) 
     91{ 
     92        $html .= $content->getUserUI(); 
     93} 
     94$html .= "</div>\n"; 
     95 
     96/* User section */ 
     97$html .= "<div class='portal_user_section'>\n"; 
     98$html .= _("My content")."\n"; 
     99$html .= "</div>\n"; 
     100$html .= "</div>\n"; /* end portal_container */ 
     101                echo $html; 
    142102/* If we have local content, display it. Otherwise, display default */ 
    143 if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.PORTAL_PAGE_NAME)) { 
     103/*if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.PORTAL_PAGE_NAME)) { 
    144104    $smarty->assign("local_content_path", NODE_CONTENT_SMARTY_PATH); 
    145105    $smarty->display(NODE_CONTENT_SMARTY_PATH.PORTAL_PAGE_NAME); 
     
    148108    $smarty->display(DEFAULT_CONTENT_SMARTY_PATH.PORTAL_PAGE_NAME); 
    149109} 
     110*/ 
    150111 
    151112$smarty->display(DEFAULT_CONTENT_SMARTY_PATH."footer.html");