Changeset 1316

Show
Ignore:
Timestamp:
01/06/08 19:25:20 (5 years ago)
Author:
benoitg
Message:
  • Some more work on the permission system. At long last, close #358
Location:
trunk/wifidog-auth
Files:
16 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1315 r1316  
    11# $Id$ 
     22008-01-06 Benoit Grégoire  <bock@step.polymtl.ca> 
     3        * Some more work on the permission system.  At long last, close #358 
     4         
    252008-01-05 Benoit Grégoire  <bock@step.polymtl.ca> 
    36        * French translation update from Frederic Sheedy (sheedf@gmail.com).  Closes #411 
  • trunk/wifidog-auth/sql/dump_initial_data_postgres.sh

    r1250 r1316  
    1414echo "INSERT INTO virtual_hosts (virtual_host_id, hostname, default_network) VALUES ('DEFAULT_VHOST', 'localhost', 'default-network');"; 
    1515echo "INSERT INTO server (server_id, default_virtual_host) VALUES ('SERVER_ID', 'DEFAULT_VHOST');"; 
    16 echo "INSERT into roles (role_id, stakeholder_type_id) VALUES ('SERVER_SYSADMIN', 'Server');"; 
    17 echo "INSERT into roles (role_id, stakeholder_type_id) VALUES ('NETWORK_SYSADMIN', 'Network');"; 
     16echo "INSERT into roles (role_id, stakeholder_type_id) VALUES ('SERVER_OWNER', 'Server');"; 
     17echo "INSERT into roles (role_id, stakeholder_type_id) VALUES ('NETWORK_OWNER', 'Network');"; 
    1818 
    1919pg_dump -a -D --username=wifidog -t schema_info 
  • trunk/wifidog-auth/wifidog/admin/generic_object_admin.php

    r1268 r1316  
    262262switch ($_REQUEST['action']) { 
    263263    case "list" : 
    264         $hasCreateNewObjectUI = true; 
    265  
     264        $userData = null; 
     265        $disableCreateNewButton = false; 
    266266        switch ($_REQUEST['object_class']) { 
    267267            case "Content" : 
     
    271271                $displayEditButton = false; 
    272272                break; 
    273  
    274273            case "Node" : 
    275                 $newLongText = $addLongText; 
    276274                $userData['typeInterface'] = "table"; 
    277                 $objectSelector = Node :: getSelectUI('object_id', $userData); 
    278275                $displayEditButton = false; 
    279                 break; 
    280             case "ProfileTemplate" : 
    281                 $hasCreateNewObjectUI = false; 
    282  
     276            case "Network" : 
     277                $disableCreateNewButton = true; 
    283278            default : 
    284279                $newLongText = $addLongText; 
     
    286281                $_REQUEST['object_class'], 
    287282                'getSelectUI' 
    288         ), 'object_id'); 
     283                ), 'object_id' 
     284                , $userData); 
    289285                break; 
    290  
    291         } 
    292  
    293         if($hasCreateNewObjectUI == true) { 
     286        } 
     287 
     288        if($disableCreateNewButton == false && method_exists($_REQUEST['object_class'],'getCreateNewObjectUI')) { 
    294289            $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>"; 
    295290            $html .= "<input type='hidden' name='object_class' value='$class'>"; 
    296291            $html .= "<input type='hidden' name='action' value='new_ui'>"; 
    297             $html .= "<input type='submit' name='new_submit' value='$newLongText'>\n"; 
    298             $html .= '</form>'; 
    299         } else { 
    300             $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>"; 
    301             $html .= "<input type='hidden' name='object_class' value='$class'>"; 
    302             $html .= "<input type='hidden' name='action' value='new'>"; 
    303292            $html .= "<input type='submit' name='new_submit' value='$newLongText'>\n"; 
    304293            $html .= '</form>'; 
     
    353342                $class, 
    354343                'getCreateNewObjectUI' 
    355         )); 
     344                )); 
    356345                $html .= "<input type='hidden' name='action' value='process_new_ui'>"; 
    357346                $html .= "<input type=submit name='new_ui_submit' value='$newText'>"; 
  • trunk/wifidog-auth/wifidog/classes/Dependency.php

    r1313 r1316  
    4646 */ 
    4747 
    48  // Detect Gettext support 
    49  if (!function_exists('gettext')) { 
    50      /** 
    51       * Load Locale class if Gettext support is not available 
    52       */ 
    53       require_once ('classes/Locale.php'); 
    54  } 
    55  
    56  require_once ('classes/Utils.php'); 
    57   
    58         define('OPENID_PATH', WIFIDOG_ABS_FILE_PATH.'lib/php-openid-2.0.0-rc2/'); 
    59         define('SMARTY_PATH', WIFIDOG_ABS_FILE_PATH.'lib/Smarty-2.6.18/libs/');         
    60  /** 
    61   * This class checks the existence of components required by WiFiDog. 
    62   * Note that it implicitely depends on the defines in include/path_defines_base.php 
    63   * 
    64   * @package    WiFiDogAuthServer 
    65   * @author     Philippe April 
    66   * @author     Max Horváth <max.horvath@freenet.de> 
    67   * @author     Benoit Grégoire <bock@step.polymtl.ca> 
    68   * @copyright  2005-2007 Philippe April 
    69   * @copyright  2005-2007 Max Horváth, Horvath Web Consulting 
    70   * @copyright  2006-2007 Benoit Grégoire, Technologies Coeus inc. 
    71   */ 
    72   class Dependency 
    73   { 
    74       /** 
    75        * An array of components used by WiFiDog 
    76        * The main array key is the EXACT name name of the dependency.  Do NOT translate it or blindly change it; 
    77        *   It is used in the code if various ways, for example to detect PHP or PEAR modules  
    78        * Documentation of the various array keys:   
    79        * 'mandatory' => Optional.  Set to true if the dependency absolutely required for basic operation of an auth server 
    80        * 'type' => Mandatory.  The type of Dependency.  Currently, allowed values are:  
    81            *    "phpExtension":  Standard PHP extension  
    82            *    "peclStandard":  Standard (in the PECL reposidory) PECL PHP module 
    83            *    "peclStandard":  PEAR PHP module in the standard PEAR repository or in a custom channel 
    84            *    "pearCustom":   PEAR-compatible tarball 
    85            *    "localLib": Custom PHP extension, to be downloaded and installed in wifidog/lib 
    86            * 'detectFiles' => Mandatory for most type of dependencies, the relative path to the file that must exist for the dependency to be considered present. 
    87            *                                    The path is relative to the PHP path, or wifidog/lib depending on the type of install 
    88            * 'description' => Description of the dependency, and what it's used for in wifidog 
    89            * 'website' => URL to the dependency's official website 
    90        * 'installSourceUrl' => For localLib and pearCustom dependency, the URL where the dependency can be downloaded. 
    91        *                                                For pearStandard, either the required alpha or beta name like "Image_Canvas-alpha" or the fulle channel URL like: "channel://pear.php.net/Image_graph-0.7.2" ( normally not used for dependencies in standard pear repositories) 
    92        * 'installMethod' => For localLib, the protocol to be used to download and install the dependency.  Currently, allowed values are: 
    93        *        'tarball': Decompress a tarball in wifidog/lib 
    94        * 'installDestination' => For localLib, the path, relative to wifidog/lib where the dependency should be installed 
    95        * 'filename' => temp download filename if sourceurl does not meet preg requirements. 
    96        *  
    97        * @var array 
    98        */ 
    99  
    100        private static $_components = array( 
    101        /* PHP extensions (mandatory) */ 
     48// Detect Gettext support 
     49if (!function_exists('gettext')) { 
     50    /** 
     51     * Load Locale class if Gettext support is not available 
     52     */ 
     53    require_once ('classes/Locale.php'); 
     54} 
     55 
     56require_once ('classes/Utils.php'); 
     57 
     58define('OPENID_PATH', WIFIDOG_ABS_FILE_PATH.'lib/php-openid-2.0.0-rc2/'); 
     59define('SMARTY_PATH', WIFIDOG_ABS_FILE_PATH.'lib/Smarty-2.6.18/libs/'); 
     60/** 
     61 * This class checks the existence of components required by WiFiDog. 
     62 * Note that it implicitely depends on the defines in include/path_defines_base.php 
     63 * 
     64 * @package    WiFiDogAuthServer 
     65 * @author     Philippe April 
     66 * @author     Max Horváth <max.horvath@freenet.de> 
     67 * @author     Benoit Grégoire <bock@step.polymtl.ca> 
     68 * @copyright  2005-2007 Philippe April 
     69 * @copyright  2005-2007 Max Horváth, Horvath Web Consulting 
     70 * @copyright  2006-2007 Benoit Grégoire, Technologies Coeus inc. 
     71 */ 
     72class Dependency 
     73{ 
     74    /** 
     75     * An array of components used by WiFiDog 
     76     * The main array key is the EXACT name name of the dependency.  Do NOT translate it or blindly change it; 
     77     *   It is used in the code if various ways, for example to detect PHP or PEAR modules 
     78     * Documentation of the various array keys: 
     79     * 'mandatory' => Optional.  Set to true if the dependency absolutely required for basic operation of an auth server 
     80     * 'type' => Mandatory.  The type of Dependency.  Currently, allowed values are: 
     81     *  "phpExtension":  Standard PHP extension 
     82     *  "peclStandard":  Standard (in the PECL reposidory) PECL PHP module 
     83     *  "peclStandard":  PEAR PHP module in the standard PEAR repository or in a custom channel 
     84     *  "pearCustom":   PEAR-compatible tarball 
     85     *  "localLib": Custom PHP extension, to be downloaded and installed in wifidog/lib 
     86     * 'detectFiles' => Mandatory for most type of dependencies, the relative path to the file that must exist for the dependency to be considered present. 
     87     *                                  The path is relative to the PHP path, or wifidog/lib depending on the type of install 
     88     * 'description' => Description of the dependency, and what it's used for in wifidog 
     89     * 'website' => URL to the dependency's official website 
     90     * 'installSourceUrl' => For localLib and pearCustom dependency, the URL where the dependency can be downloaded. 
     91     *                                          For pearStandard, either the required alpha or beta name like "Image_Canvas-alpha" or the fulle channel URL like: "channel://pear.php.net/Image_graph-0.7.2" ( normally not used for dependencies in standard pear repositories) 
     92     * 'installMethod' => For localLib, the protocol to be used to download and install the dependency.  Currently, allowed values are: 
     93     *  'tarball': Decompress a tarball in wifidog/lib 
     94     * 'installDestination' => For localLib, the path, relative to wifidog/lib where the dependency should be installed 
     95     * 'filename' => temp download filename if sourceurl does not meet preg requirements. 
     96     * 
     97     * @var array 
     98     */ 
     99 
     100    private static $_components = array( 
     101    /* PHP extensions (mandatory) */ 
    102102       'mbstring' => array ( 
    103103       'mandatory' => true, 
     
    125125       'installDestination' => "/" 
    126126       ), 
    127        
     127 
    128128       /* PHP extensions (optional) */ 
    129129       "simplepie" => array ( 
     
    145145       'installMethod' => "tarball", 
    146146       'installDestination' => "/" 
    147         ), 
     147       ), 
    148148       'feedpressreview' => array ( 
    149149       "type" => "localLib", 
     
    154154       'installMethod' => "svn", 
    155155       'installDestination' => "feedpressreview" 
    156         ), 
     156       ), 
    157157       'gettext' => array ( 
    158158       "type" => "phpExtension", 
     
    215215       'installDestination' => "/", 
    216216       ), 
    217         
     217         
    218218       "FPDF" => array ( 
    219219       "type" => "localLib", 
     
    296296        * Object cache for the object factory (getObject()) 
    297297        */ 
    298         private static $instanceArray = array(); 
    299  
    300         private $_id; 
    301  
    302         /** 
    303          * Constructor 
    304          */ 
    305          private function __construct($component) { 
    306              $this->_id = $component; 
    307          } 
    308  
    309          /** 
    310           * Get the entire array of Dependency 
    311           * 
    312           * @return boolean Returns whether the file has been found or not. 
    313           */ 
    314           public static function getDependencies() 
    315           { 
    316               $retval = array(); 
    317  
    318               foreach (self::$_components as $component_key=>$component_info) { 
    319                   $retval[] = self::getObject($component_key); 
    320               } 
    321  
    322               return $retval; 
    323           } 
    324  
    325           /** Use PHP internal functions to execute a command 
    326            Â @return: Return value of the command*/ 
    327           function execVerbose($command, & $output, & $return_var, &$errMsg = null) { 
    328               $errMsg .= "Executing: $command <br/>"; 
    329               exec($command.'  2>&1', $output, $return_var); 
    330               if ($return_var != 0) 
    331               $errMsg .= "<p style='color:red'><em>Error:</em>  Command did not complete successfully  (returned $return_var): <br/>\n"; 
    332               else 
    333               $errMsg .= "<p style='color:green'><em>Command completed successfully</em>  (returned $return_var): <br/>\n"; 
    334  
    335               if (($return_var != 0) && $output) { 
    336                   foreach ($output as $output_line) 
    337                   $errMsg .= " $output_line <br/>\n"; 
    338               } 
    339               $errMsg .= "</p>\n"; 
    340               return $return_var; 
    341           } 
    342  
    343           /** 
    344            * Checks if a file exists, including checking in the include path 
    345            * 
    346            * @param string $file Path or name of a file 
    347            * 
    348            * @return boolean Returns whether the file has been found or not. 
    349            * 
    350            * @author Aidan Lister <aidan@php.net> 
    351            * @link http://aidanlister.com/repos/v/function.file_exists_incpath.php 
    352            */ 
    353            public static function file_exists_incpath($file) 
    354            { 
    355                $_paths = explode(PATH_SEPARATOR, get_include_path()); 
    356  
    357                foreach ($_paths as $_path) { 
    358                    // Formulate the absolute path 
    359                    $_fullPath = $_path . DIRECTORY_SEPARATOR . $file; 
    360  
    361                    // Check it 
    362                    if (file_exists($_fullPath)) { 
    363                        return $_fullPath; 
     298       private static $instanceArray = array(); 
     299 
     300       private $_id; 
     301 
     302       /** 
     303        * Constructor 
     304        */ 
     305       private function __construct($component) { 
     306           $this->_id = $component; 
     307       } 
     308 
     309       /** 
     310        * Get the entire array of Dependency 
     311        * 
     312        * @return boolean Returns whether the file has been found or not. 
     313        */ 
     314       public static function getDependencies() 
     315       { 
     316           $retval = array(); 
     317 
     318           foreach (self::$_components as $component_key=>$component_info) { 
     319               $retval[] = self::getObject($component_key); 
     320           } 
     321 
     322           return $retval; 
     323       } 
     324 
     325       /** Use PHP internal functions to execute a command 
     326         @return: Return value of the command*/ 
     327       function execVerbose($command, & $output, & $return_var, &$errMsg = null) { 
     328           $errMsg .= "Executing: $command <br/>"; 
     329           exec($command.'  2>&1', $output, $return_var); 
     330           if ($return_var != 0) 
     331           $errMsg .= "<p style='color:red'><em>Error:</em>  Command did not complete successfully  (returned $return_var): <br/>\n"; 
     332           else 
     333           $errMsg .= "<p style='color:green'><em>Command completed successfully</em>  (returned $return_var): <br/>\n"; 
     334 
     335           if (($return_var != 0) && $output) { 
     336               foreach ($output as $output_line) 
     337               $errMsg .= " $output_line <br/>\n"; 
     338           } 
     339           $errMsg .= "</p>\n"; 
     340           return $return_var; 
     341       } 
     342 
     343       /** 
     344        * Checks if a file exists, including checking in the include path 
     345        * 
     346        * @param string $file Path or name of a file 
     347        * 
     348        * @return boolean Returns whether the file has been found or not. 
     349        * 
     350        * @author Aidan Lister <aidan@php.net> 
     351        * @link http://aidanlister.com/repos/v/function.file_exists_incpath.php 
     352        */ 
     353       public static function file_exists_incpath($file) 
     354       { 
     355           $_paths = explode(PATH_SEPARATOR, get_include_path()); 
     356 
     357           foreach ($_paths as $_path) { 
     358               // Formulate the absolute path 
     359               $_fullPath = $_path . DIRECTORY_SEPARATOR . $file; 
     360 
     361               // Check it 
     362               if (file_exists($_fullPath)) { 
     363                   return $_fullPath; 
     364               } 
     365           } 
     366 
     367           return false; 
     368       } 
     369 
     370       /** 
     371        * Checks if a component is available. 
     372        * 
     373        * This function checks, if a specific component is available to be used 
     374        * by Wifidog. 
     375        * 
     376        * @param string $component Name of component to be checked. 
     377        * @param string $errmsg    Reference of a string which would contain an 
     378        *                          error message. 
     379        * 
     380        * @return boolean Returns whether the component has been found or not. 
     381        */ 
     382       public static function check($component, &$errmsg = null) 
     383       { 
     384           // Init values 
     385           $returnValue = false; 
     386 
     387           // Check, if the requested component can be found. 
     388           if (isset(self::$_components[$component])) { 
     389               // What are we checking for? 
     390               if (self::$_components[$component]["type"] == "phpExtension" || self::$_components[$component]["type"] == "peclStandard") { 
     391                   // Warning: extension_loaded(string) is case sensitive 
     392                   $returnValue = extension_loaded($component); 
     393               } 
     394               else if (self::$_components[$component]["type"] == "localLib") { 
     395                   if (is_array(self::$_components[$component]["detectFiles"])) { 
     396                       $_singleReturns = true; 
     397                       foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { 
     398                           $filePath = WIFIDOG_ABS_FILE_PATH . $_fileNames; 
     399 
     400                           if (!file_exists($filePath)) { 
     401                               echo "TEST"; 
     402                               $_singleReturns = false; 
     403                               // The component has NOT been found. Return error message. 
     404                               $errmsg .= sprintf(_("File %s not found"), $filePath); 
     405                               break; 
     406                           } 
     407                       } 
     408 
     409                       $returnValue = $_singleReturns; 
     410                   } 
     411                   else { 
     412                       $filePath = WIFIDOG_ABS_FILE_PATH . self::$_components[$component]["detectFiles"]; 
     413 
     414                       if (file_exists($filePath)) { 
     415                           // The component has been found. 
     416                           $returnValue = true; 
     417                       } 
     418                       else { 
     419                           // The component has NOT been found. Return error message. 
     420                           $errmsg .= sprintf(_("File %s not found"), $filePath); 
     421                       } 
    364422                   } 
    365423               } 
    366  
    367                return false; 
    368            } 
    369  
    370            /** 
    371             * Checks if a component is available. 
    372             * 
    373             * This function checks, if a specific component is available to be used 
    374             * by Wifidog. 
    375             * 
    376             * @param string $component Name of component to be checked. 
    377             * @param string $errmsg    Reference of a string which would contain an 
    378             *                          error message. 
    379             * 
    380             * @return boolean Returns whether the component has been found or not. 
    381             */ 
    382             public static function check($component, &$errmsg = null) 
    383             { 
    384                 // Init values 
    385                 $returnValue = false; 
    386  
    387                 // Check, if the requested component can be found. 
    388                 if (isset(self::$_components[$component])) { 
    389                     // What are we checking for? 
    390                     if (self::$_components[$component]["type"] == "phpExtension" || self::$_components[$component]["type"] == "peclStandard") { 
    391                         // Warning: extension_loaded(string) is case sensitive 
    392                         $returnValue = extension_loaded($component); 
    393                     } 
    394                     else if (self::$_components[$component]["type"] == "localLib") { 
    395                         if (is_array(self::$_components[$component]["detectFiles"])) { 
    396                             $_singleReturns = true; 
    397                             foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { 
    398                                 $filePath = WIFIDOG_ABS_FILE_PATH . $_fileNames; 
    399  
    400                                 if (!file_exists($filePath)) { 
    401                                     echo "TEST"; 
    402                                     $_singleReturns = false; 
    403                                     // The component has NOT been found. Return error message. 
    404                                     $errmsg .= sprintf(_("File %s not found"), $filePath); 
    405                                     break; 
    406                                 } 
    407                             } 
    408  
    409                             $returnValue = $_singleReturns; 
    410                         } 
    411                         else { 
    412                             $filePath = WIFIDOG_ABS_FILE_PATH . self::$_components[$component]["detectFiles"]; 
    413  
    414                             if (file_exists($filePath)) { 
    415                                 // The component has been found. 
    416                                 $returnValue = true; 
    417                             } 
    418                             else { 
    419                                 // The component has NOT been found. Return error message. 
    420                                 $errmsg .= sprintf(_("File %s not found"), $filePath); 
    421                             } 
    422                         } 
    423                     } 
    424                     else if (self::$_components[$component]["type"] == "pearStandard" || self::$_components[$component]["type"] == "pearCustom") { 
    425                         if (is_array(self::$_components[$component]["detectFiles"])) { 
    426                             $_singleReturns = true; 
    427  
    428                             foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { 
    429                                 // We need to use a custom file_exists to also check in the include path 
    430                                 if (!self::file_exists_incpath($_fileNames)) { 
    431                                     $_singleReturns = false; 
    432  
    433                                     // The component has NOT been found. Return error message. 
    434                                     $errmsg .= sprintf(_("File %s not found in %s"), $_fileNames, get_include_path()); 
    435                                 } 
    436                             } 
    437  
    438                             $returnValue = $_singleReturns; 
    439                         } else { 
    440                             // We need to use a custom file_exists to also check in the include path 
    441                             if (self::file_exists_incpath(self::$_components[$component]["detectFiles"])) { 
    442                                 // The component has been found. 
    443                                 $returnValue = true; 
    444                             } 
    445                             else { 
    446  
    447                                 // The component has NOT been found. Return error message. 
    448                                 $errmsg .= sprintf(_("File %s not found in %s"), self::$_components[$component]["detectFiles"], get_include_path()); 
    449                             } 
    450                         } 
    451                     } 
    452                     else { 
    453                         throw new Exception(sprintf("Unknown component type: %s", self::$_components[$component]["type"])); 
    454                     } 
    455                 } else { 
    456                     // The requested component has not been defined in this class. 
    457                     throw new Exception("Component not found"); 
    458                 } 
    459  
    460                 return $returnValue; 
    461             } 
    462  
    463                        /** 
    464             * Checks if one of the mandatory components is missing. 
    465             * 
    466             * @param string $errmsg    Reference of a string which would contain an 
    467             *                          error message. 
    468             * 
    469             * @return boolean Returns false if any components are missing. 
    470             */ 
    471             public static function checkMandatoryComponents(&$errmsg = null) 
    472             { 
    473                 // Init values 
    474                 $returnValue = true; 
    475 $components = self::getDependencies(); 
    476 foreach($components as $component) { 
    477     if($component->isMandatory()) { 
    478         $returnValue &= self::check($component->getId(), $errmsg); 
    479     } 
    480 } 
    481  
    482                 return $returnValue; 
    483             } 
     424               else if (self::$_components[$component]["type"] == "pearStandard" || self::$_components[$component]["type"] == "pearCustom") { 
     425                   if (is_array(self::$_components[$component]["detectFiles"])) { 
     426                       $_singleReturns = true; 
     427 
     428                       foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { 
     429                           // We need to use a custom file_exists to also check in the include path 
     430                           if (!self::file_exists_incpath($_fileNames)) { 
     431                               $_singleReturns = false; 
     432 
     433                               // The component has NOT been found. Return error message. 
     434                               $errmsg .= sprintf(_("File %s not found in %s"), $_fileNames, get_include_path()); 
     435                           } 
     436                       } 
     437 
     438                       $returnValue = $_singleReturns; 
     439                   } else { 
     440                       // We need to use a custom file_exists to also check in the include path 
     441                       if (self::file_exists_incpath(self::$_components[$component]["detectFiles"])) { 
     442                           // The component has been found. 
     443                           $returnValue = true; 
     444                       } 
     445                       else { 
     446 
     447                           // The component has NOT been found. Return error message. 
     448                           $errmsg .= sprintf(_("File %s not found in %s"), self::$_components[$component]["detectFiles"], get_include_path()); 
     449                       } 
     450                   } 
     451               } 
     452               else { 
     453                   throw new Exception(sprintf("Unknown component type: %s", self::$_components[$component]["type"])); 
     454               } 
     455           } else { 
     456               // The requested component has not been defined in this class. 
     457               throw new Exception("Component not found"); 
     458           } 
     459 
     460           return $returnValue; 
     461       } 
     462 
     463       /** 
     464        * Checks if one of the mandatory components is missing. 
     465        * 
     466        * @param string $errmsg    Reference of a string which would contain an 
     467        *                          error message. 
     468        * 
     469        * @return boolean Returns false if any components are missing. 
     470        */ 
     471       public static function checkMandatoryComponents(&$errmsg = null) 
     472       { 
     473           // Init values 
     474           $returnValue = true; 
     475           $components = self::getDependencies(); 
     476           foreach($components as $component) { 
     477               if($component->isMandatory()) { 
     478                   $returnValue &= self::check($component->getId(), $errmsg); 
     479               } 
     480           } 
     481 
     482           return $returnValue; 
     483       } 
     484 
     485       /** Use PHP internal functions to download a file */ 
     486       static public function downloadFile($remoteURL, $localPath) { 
     487           set_time_limit(1500); // 25 minutes timeout 
     488           return copy($remoteURL, $localPath); 
     489       } 
     490       /** 
     491        * Get a UI to install the component 
     492        * 
     493        * @return html markup. 
     494        */ 
     495       public function getInstallUI() 
     496       { 
     497           // Init values 
     498           $html = false; 
     499 
     500           // Check, if the requested component can be found. 
     501           if (self::check($this->getId())) { 
     502               //Component already installed 
     503           } 
     504           else { 
     505               // What are we checking for? 
     506               $type = $this->getType(); 
     507               switch ($type) { 
     508                   case "phpExtension": 
     509                       $html .= sprintf(_("To install this standard PHP extension, look for a package with a similar name in your distribution's package manager.  Ex: For Debian based distributions, you may try 'sudo apt-get install php5-%s'"), $this->getId()); 
     510 
     511                       break; 
     512                   case "localLib": 
     513                       if($this->getInstallSourceUrl()) { 
     514                           $name = $this->getId().'_install'; 
     515                           $value = sprintf(_("Install %s"), $this->getId()); 
     516                           $html .= sprintf("<input type='submit' name='%s' value='%s'/>", $name, $value); 
     517 
     518                       } 
     519                       else { 
     520                           $html .= sprintf(_("Sorry, i couldn't find the source for %s in installSourceUrl"), 
     521                           $this->getId()); 
     522                       } 
     523                       break; 
     524                         
     525                         
     526                   case "pearStandard": 
     527                       if($this->getInstallSourceUrl()) { 
     528                           $installSource=$this->getInstallSourceUrl(); 
     529                       } 
     530                       else { 
     531                           $installSource=$this->getId(); 
     532                       } 
     533                       $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pear install --onlyreqdeps %s'"), $installSource); 
     534                       break; 
     535                         
     536                         
     537                   case "peclStandard": 
     538                       if($this->getInstallSourceUrl()) { 
     539                           $installSource=$this->getInstallSourceUrl(); 
     540                       } 
     541                       else { 
     542                           $installSource=$this->getId(); 
     543                       } 
     544                       $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pecl install %s'"), $installSource); 
     545                       break; 
     546                         
     547                         
     548                   case "pearCustom": 
     549                       if($this->getInstallSourceUrl()) { 
     550                           $installSource=$this->getInstallSourceUrl(); 
     551                       } 
     552                       else { 
     553                           $installSource=sprintf(_("url_to_the_tarball (Sorry, i couldn't find the source for %s in installSourceUrl)"), $this->getId()); 
     554                       } 
     555                       $html .= sprintf(_("To install this custom PEAR extension, use 'sudo pear install %s'"), $installSource); 
     556                       break; 
     557                         
     558                         
     559                   default: 
     560                       $html .= sprintf(_("Sorry, I don't know how to install a %s extension"), $type); 
     561               } 
     562           } 
     563           return $html; 
     564       } 
     565 
     566       /** 
     567        * Get a UI to install the component 
     568        * 
     569        * @return true if something was processed. 
     570        */ 
     571       public function processInstallUI(&$errMsg=null) 
     572       { 
     573 
     574           $retval = false; 
     575           $name = $this->getId().'_install'; 
     576           if(!empty($_REQUEST[$name])) 
     577           { 
     578               $this->install($errMsg); 
     579           } 
    484580             
    485             /** Use PHP internal functions to download a file */ 
    486             static public function downloadFile($remoteURL, $localPath) { 
    487                 set_time_limit(1500); // 25 minutes timeout 
    488                 return copy($remoteURL, $localPath); 
    489             } 
    490             /** 
    491              * Get a UI to install the component 
    492              * 
    493              * @return html markup. 
    494              */ 
    495              public function getInstallUI() 
    496              { 
    497                  // Init values 
    498                  $html = false; 
    499  
    500                  // Check, if the requested component can be found. 
    501                  if (self::check($this->getId())) { 
    502                      //Component already installed 
    503                  } 
    504                  else { 
    505                      // What are we checking for? 
    506                      $type = $this->getType(); 
    507                      switch ($type) { 
    508                          case "phpExtension": 
    509                              $html .= sprintf(_("To install this standard PHP extension, look for a package with a similar name in your distribution's package manager.  Ex: For Debian based distributions, you may try 'sudo apt-get install php5-%s'"), $this->getId()); 
    510  
    511                              break; 
    512                          case "localLib": 
    513                              if($this->getInstallSourceUrl()) { 
    514                                  $name = $this->getId().'_install'; 
    515                                  $value = sprintf(_("Install %s"), $this->getId()); 
    516                                  $html .= sprintf("<input type='submit' name='%s' value='%s'/>", $name, $value); 
    517                                                        
    518                              } 
    519                              else { 
    520                                  $html .= sprintf(_("Sorry, i couldn't find the source for %s in installSourceUrl"), 
    521                                  $this->getId()); 
    522                              } 
    523                              break; 
    524                               
    525                               
    526                              case "pearStandard": 
    527                              if($this->getInstallSourceUrl()) { 
    528                                  $installSource=$this->getInstallSourceUrl(); 
    529                              } 
    530                              else { 
    531                                  $installSource=$this->getId(); 
    532                              } 
    533                              $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pear install --onlyreqdeps %s'"), $installSource); 
    534                              break; 
    535                               
    536                                   
    537                          case "peclStandard": 
    538                              if($this->getInstallSourceUrl()) { 
    539                                  $installSource=$this->getInstallSourceUrl(); 
    540                              } 
    541                              else { 
    542                                  $installSource=$this->getId(); 
    543                              } 
    544                              $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pecl install %s'"), $installSource); 
    545                              break; 
    546                               
    547                                   
    548                          case "pearCustom": 
    549                              if($this->getInstallSourceUrl()) { 
    550                                  $installSource=$this->getInstallSourceUrl(); 
    551                              } 
    552                              else { 
    553                              $installSource=sprintf(_("url_to_the_tarball (Sorry, i couldn't find the source for %s in installSourceUrl)"), $this->getId()); 
    554                              } 
    555                              $html .= sprintf(_("To install this custom PEAR extension, use 'sudo pear install %s'"), $installSource); 
    556                              break; 
    557                               
    558                               
    559                          default: 
    560                              $html .= sprintf(_("Sorry, I don't know how to install a %s extension"), $type); 
    561                      } 
    562                  } 
    563                  return $html; 
    564              } 
    565  
    566              /** 
    567               * Get a UI to install the component 
    568               * 
    569               * @return true if something was processed. 
    570               */ 
    571               public function processInstallUI(&$errMsg=null) 
    572               { 
    573  
    574                   $retval = false; 
    575                   $name = $this->getId().'_install'; 
    576                   if(!empty($_REQUEST[$name])) 
    577                   { 
    578                       $this->install($errMsg); 
    579                   } 
    580                     
    581                   return $retval; 
    582               } 
    583               /** 
    584                * Retreives the id of the object 
    585                * 
    586                * @return The id, a string 
    587                */ 
    588                public function getId() { 
    589                    return $this->_id; 
     581           return $retval; 
     582       } 
     583       /** 
     584        * Retreives the id of the object 
     585        * 
     586        * @return The id, a string 
     587        */ 
     588       public function getId() { 
     589           return $this->_id; 
     590       } 
     591 
     592       /** 
     593        * Get an instance of the object 
     594        * 
     595        * @param string $id The object id 
     596        * 
     597        * @return mixed The Content object, or null if there was an error 
     598        *               (an exception is also thrown) 
     599        * 
     600        * @see GenericObject 
     601        * @static 
     602        * @access public 
     603        */ 
     604       public static function &getObject($id) 
     605       { 
     606           if(!isset(self::$instanceArray[$id])) { 
     607               self::$instanceArray[$id] = new self($id); 
     608           } 
     609 
     610           return self::$instanceArray[$id]; 
     611       } 
     612 
     613       /** 
     614        * Get website URL for the dependency (if available) 
     615        * 
     616        * @return URL or null 
     617        */ 
     618       public function getWebsiteURL() 
     619       { 
     620           $retval = null; 
     621 
     622           if(self::$_components[$this->_id]["type"] == "phpExtension") { 
     623               $retval = "http://www.php.net/" . $this->_id . "/"; 
     624           } else if(self::$_components[$this->_id]["type"] == "pearStandard") { 
     625               $retval = "http://pear.php.net/package/" . $this->_id . "/"; 
     626           } else if(self::$_components[$this->_id]["type"] == "peclStandard") { 
     627               $retval = "http://pecl.php.net/package/" . $this->_id . "/"; 
     628           } else { 
     629               if(!empty(self::$_components[$this->_id]['website'])) { 
     630                   $retval = self::$_components[$this->_id]['website']; 
    590631               } 
    591  
    592                /** 
    593                 * Get an instance of the object 
    594                 * 
    595                 * @param string $id The object id 
    596                 * 
    597                 * @return mixed The Content object, or null if there was an error 
    598                 *               (an exception is also thrown) 
    599                 * 
    600                 * @see GenericObject 
    601                 * @static 
    602                 * @access public 
    603                 */ 
    604                 public static function &getObject($id) 
    605                 { 
    606                     if(!isset(self::$instanceArray[$id])) { 
    607                         self::$instanceArray[$id] = new self($id); 
    608                     } 
    609  
    610                     return self::$instanceArray[$id]; 
    611                 } 
    612  
    613                 /** 
    614                  * Get website URL for the dependency (if available) 
    615                  * 
    616                  * @return URL or null 
    617                  */ 
    618                  public function getWebsiteURL() 
    619                  { 
    620                      $retval = null; 
    621  
    622                      if(self::$_components[$this->_id]["type"] == "phpExtension") { 
    623                          $retval = "http://www.php.net/" . $this->_id . "/"; 
    624                      } else if(self::$_components[$this->_id]["type"] == "pearStandard") { 
    625                          $retval = "http://pear.php.net/package/" . $this->_id . "/"; 
    626                      } else if(self::$_components[$this->_id]["type"] == "peclStandard") { 
    627                          $retval = "http://pecl.php.net/package/" . $this->_id . "/"; 
    628                      } else { 
    629                          if(!empty(self::$_components[$this->_id]['website'])) { 
    630                              $retval = self::$_components[$this->_id]['website']; 
    631                          } 
    632                      } 
    633  
    634                      return $retval; 
    635                  } 
    636  
    637                  /** 
    638                   * Get the description of the dependency (if available) 
    639                   * 
    640                   * @return String or null 
    641                   */ 
    642                   public function getDescription() 
    643                   { 
    644                       $retval = null; 
    645  
    646                       if(!empty(self::$_components[$this->_id]['description'])) { 
    647                           $retval = self::$_components[$this->_id]['description']; 
    648                       } 
    649  
    650                       return $retval; 
    651                   } 
    652                    
    653  
    654                   /** 
    655                    * Get the source URL where the package can be downloaded.  It's meaning depends on the install method (for example, it may be a svn source) 
    656                    * 
    657                    * @return String or null 
    658                    */ 
    659                    public function getInstallSourceUrl() 
    660                    { 
    661                        $retval = null; 
    662                        if(!empty(self::$_components[$this->_id]['installSourceUrl'])) { 
    663                            $retval = self::$_components[$this->_id]['installSourceUrl']; 
    664                        } 
    665                        return $retval; 
    666                    } 
    667                    /** 
    668                     * Get the install method for this dependency (only for those that can be directly installed by the auth server)                  * 
    669                     * @return String or null 
    670                     */ 
    671                     public function getInstallMethod() 
    672                     { 
    673                         $retval = null; 
    674                         if(!empty(self::$_components[$this->_id]['installMethod'])) { 
    675                             $retval = self::$_components[$this->_id]['installMethod']; 
    676                         } 
    677                         return $retval; 
    678                     } 
    679  
    680                     /** 
    681                      * Get the install destination.  Interpretation depends on the install method.  Usisally the parameter to be passed to tar or SVN                 * 
    682                      * @return String or null 
    683                      */ 
    684                      public function getInstallDestination() 
    685                      { 
    686                          $retval = null; 
    687                          if(!empty(self::$_components[$this->_id]['installDestination'])) { 
    688                              $retval = self::$_components[$this->_id]['installDestination']; 
    689                          } 
    690                          return $retval; 
    691                      } 
    692                      /** 
    693                       * Get the type of the dependency 
    694                       * 
    695                       * @return String 
    696                       */ 
    697                       public function getType() 
    698                       { 
    699                           return self::$_components[$this->_id]['type']; 
    700                       } 
    701  
    702                       /** 
    703                        * Get the type of the dependency 
    704                        * 
    705                        * @return String 
    706                        */ 
    707                        public function isMandatory() 
    708                        { 
    709                            $retval = null; 
    710  
    711                            if(!empty(self::$_components[$this->_id]['mandatory'])) { 
    712                                $retval = true; 
    713                            } 
    714  
    715                            return $retval; 
    716                        } 
    717  
    718                        public function install(&$errorMsg = null){ 
    719                            $installSourceUrl = $this->getInstallSourceUrl(); 
    720                            $installDestinationPathOrig = $this->getInstallDestination(); 
    721                            if(!$installSourceUrl || !$installDestinationPathOrig) { 
    722                                $errorMsg .= "<em style=\"color:red\">Error:</em>Either the install source or destination path is missing<br/>\n"; 
     632           } 
     633 
     634           return $retval; 
     635       } 
     636 
     637       /** 
     638        * Get the description of the dependency (if available) 
     639        * 
     640        * @return String or null 
     641        */ 
     642       public function getDescription() 
     643       { 
     644           $retval = null; 
     645 
     646           if(!empty(self::$_components[$this->_id]['description'])) { 
     647               $retval = self::$_components[$this->_id]['description']; 
     648           } 
     649 
     650           return $retval; 
     651       } 
     652 
     653 
     654       /** 
     655        * Get the source URL where the package can be downloaded.  It's meaning depends on the install method (for example, it may be a svn source) 
     656        * 
     657        * @return String or null 
     658        */ 
     659       public function getInstallSourceUrl() 
     660       { 
     661           $retval = null; 
     662           if(!empty(self::$_components[$this->_id]['installSourceUrl'])) { 
     663               $retval = self::$_components[$this->_id]['installSourceUrl']; 
     664           } 
     665           return $retval; 
     666       } 
     667       /** 
     668        * Get the install method for this dependency (only for those that can be directly installed by the auth server)                  * 
     669        * @return String or null 
     670        */ 
     671       public function getInstallMethod() 
     672       { 
     673           $retval = null; 
     674           if(!empty(self::$_components[$this->_id]['installMethod'])) { 
     675               $retval = self::$_components[$this->_id]['installMethod']; 
     676           } 
     677           return $retval; 
     678       } 
     679 
     680       /** 
     681        * Get the install destination.  Interpretation depends on the install method.  Usisally the parameter to be passed to tar or SVN                 * 
     682        * @return String or null 
     683        */ 
     684       public function getInstallDestination() 
     685       { 
     686           $retval = null; 
     687           if(!empty(self::$_components[$this->_id]['installDestination'])) { 
     688               $retval = self::$_components[$this->_id]['installDestination']; 
     689           } 
     690           return $retval; 
     691       } 
     692       /** 
     693        * Get the type of the dependency 
     694        * 
     695        * @return String 
     696        */ 
     697       public function getType() 
     698       { 
     699           return self::$_components[$this->_id]['type']; 
     700       } 
     701 
     702       /** 
     703        * Get the type of the dependency 
     704        * 
     705        * @return String 
     706        */ 
     707       public function isMandatory() 
     708       { 
     709           $retval = null; 
     710 
     711           if(!empty(self::$_components[$this->_id]['mandatory'])) { 
     712               $retval = true; 
     713           } 
     714 
     715           return $retval; 
     716       } 
     717 
     718       public function install(&$errorMsg = null){ 
     719           $installSourceUrl = $this->getInstallSourceUrl(); 
     720           $installDestinationPathOrig = $this->getInstallDestination(); 
     721           if(!$installSourceUrl || !$installDestinationPathOrig) { 
     722               $errorMsg .= "<em style=\"color:red\">Error:</em>Either the install source or destination path is missing<br/>\n"; 
     723           } 
     724           else { 
     725               $installDestinationPath = WIFIDOG_ABS_FILE_PATH . "lib/" .$installDestinationPathOrig; 
     726               $installMethod = $this->getInstallMethod(); 
     727               switch($installMethod) { 
     728                   case "svn": 
     729                       self::execVerbose("svn co ".escapeshellarg($installSourceUrl)." ".escapeshellarg      ($installDestinationPath), $output, $return, $errorMsg); 
     730 
     731 
     732                       break; 
     733 
     734                   case "tarball": 
     735                       $downloadPath = WIFIDOG_ABS_FILE_PATH . "tmp/"; 
     736                       chdir($downloadPath); 
     737                       if(!empty(self::$_components[$this->_id]['filename'])) { 
     738                           $filename = self::$_components[$this->_id]['filename']; 
     739                       } 
     740                       else { 
     741                           $filename_array = preg_split("/\//", $installSourceUrl); 
     742                           $filename = array_pop($filename_array); 
     743                       } 
     744 
     745 
     746                       if (!file_exists($downloadPath . $filename)){ 
     747                           $errorMsg .= "Downloading tarball ($installSourceUrl) : "; 
     748                           //execVerbose("wget \"$phlickr_full_url\" 2>&1", $output, $return); 
     749                           self::downloadFile($installSourceUrl, $downloadPath . $filename); 
     750 
     751                           if (!file_exists($downloadPath . $filename)) { # Error occured, print output of wget 
     752                               $errorMsg .= sprintf("<em style=\"color:red\">Error:</em> Unable to download $installSourceUrl to $destinationPath<br/>\n"); 
     753                               return false; 
    723754                           } 
    724755                           else { 
    725                                $installDestinationPath = WIFIDOG_ABS_FILE_PATH . "lib/" .$installDestinationPathOrig; 
    726                                $installMethod = $this->getInstallMethod(); 
    727                                switch($installMethod) { 
    728                                    case "svn": 
    729                                        self::execVerbose("svn co ".escapeshellarg($installSourceUrl)." ".escapeshellarg      ($installDestinationPath), $output, $return, $errorMsg); 
    730  
    731  
    732                                        break; 
    733  
    734                                    case "tarball": 
    735                                        $downloadPath = WIFIDOG_ABS_FILE_PATH . "tmp/"; 
    736                                        chdir($downloadPath); 
    737                                         if(!empty(self::$_components[$this->_id]['filename'])) { 
    738                                             $filename = self::$_components[$this->_id]['filename']; 
    739                                         } 
    740                                         else { 
    741                                             $filename_array = preg_split("/\//", $installSourceUrl); 
    742                                             $filename = array_pop($filename_array); 
    743                                         } 
    744  
    745  
    746                                        if (!file_exists($downloadPath . $filename)){ 
    747                                            $errorMsg .= "Downloading tarball ($installSourceUrl) : "; 
    748                                            //execVerbose("wget \"$phlickr_full_url\" 2>&1", $output, $return); 
    749                                            self::downloadFile($installSourceUrl, $downloadPath . $filename); 
    750  
    751                                            if (!file_exists($downloadPath . $filename)) { # Error occured, print output of wget 
    752                                                $errorMsg .= sprintf("<em style=\"color:red\">Error:</em> Unable to download $installSourceUrl to $destinationPath<br/>\n"); 
    753                                                return false; 
    754                                            } 
    755                                            else { 
    756                                                $errorMsg .= "OK<br/>"; 
    757                                            } 
    758                                        } 
    759                                        else { 
    760                                            $errorMsg .= "Tarball $filename already present<br/>\n"; 
    761                                        } 
    762                                        chdir($installDestinationPath); 
    763                                        //pretty_print_r($installDestinationPath); 
    764                                        if(preg_match("/(.tgz$)|(.tar.gz$)/",$filename)) { 
    765                                            $errorMsg .= "Archive is in gzip format<br/>"; 
    766                                            $params = "-zxf"; 
    767                                        } 
    768                                        else if(preg_match("/\.bz2$/",$filename)) { 
    769                                            $errorMsg .= "Archive is in bz2 format<br/>"; 
    770                                                                                       $params = "-jxf"; 
    771                                        } 
    772                                        else { 
    773                                            $errorMsg .= "Unable to determine the archive format from the filemname<br/>"; 
    774                                            return; 
    775                                        } 
    776                                        $errorMsg .= "Uncompressing : "; 
    777                                        $execRetval = self::execVerbose("tar $params ".$downloadPath . $filename, $output, $return, $errorMsg); 
    778                                        if($execRetval==0) { 
    779                                            $errorMsg .= "OK<br/>"; 
    780                                        } 
    781                                        else { 
    782                                            $errorMsg .= "<em style=\"color:red\">Decompression failed</em><br/>"; 
    783                                            return; 
    784                                        } 
    785                                        break; 
    786                                    default: 
    787                                        $errorMsg .= "Unknown install method $installMethod<br/>"; 
    788                                }//End switch 
     756                               $errorMsg .= "OK<br/>"; 
    789757                           } 
    790758                       } 
    791  
    792  
    793   } 
    794  
    795   /* 
    796    * Local variables: 
    797    * tab-width: 4 
    798    * c-basic-offset: 4 
    799    * c-hanging-comment-ender-p: nil 
    800    * End: 
    801    */ 
     759                       else { 
     760                           $errorMsg .= "Tarball $filename already present<br/>\n"; 
     761                       } 
     762                       chdir($installDestinationPath); 
     763                       //pretty_print_r($installDestinationPath); 
     764                       if(preg_match("/(.tgz$)|(.tar.gz$)/",$filename)) { 
     765                           $errorMsg .= "Archive is in gzip format<br/>"; 
     766                           $params = "-zxf"; 
     767                       } 
     768                       else if(preg_match("/\.bz2$/",$filename)) { 
     769                           $errorMsg .= "Archive is in bz2 format<br/>"; 
     770                           $params = "-jxf"; 
     771                       } 
     772                       else { 
     773                           $errorMsg .= "Unable to determine the archive format from the filemname<br/>"; 
     774                           return; 
     775                       } 
     776                       $errorMsg .= "Uncompressing : "; 
     777                       $execRetval = self::execVerbose("tar $params ".$downloadPath . $filename, $output, $return, $errorMsg); 
     778                       if($execRetval==0) { 
     779                           $errorMsg .= "OK<br/>"; 
     780                       } 
     781                       else { 
     782                           $errorMsg .= "<em style=\"color:red\">Decompression failed</em><br/>"; 
     783                           return; 
     784                       } 
     785                       break; 
     786                   default: 
     787                       $errorMsg .= "Unknown install method $installMethod<br/>"; 
     788               }//End switch 
     789           } 
     790       } 
     791 
     792 
     793} 
     794 
     795/* 
     796 * Local variables: 
     797 * tab-width: 4 
     798 * c-basic-offset: 4 
     799 * c-hanging-comment-ender-p: nil 
     800 * End: 
     801 */ 
  • trunk/wifidog-auth/wifidog/classes/Network.php

    r1312 r1316  
    5454require_once('classes/Cache.php'); 
    5555require_once('classes/ThemePack.php'); 
    56  
     56require_once('classes/Security.php'); 
    5757 
    5858/** 
     
    190190        } 
    191191        $object = self::getObject($network_id); 
     192        require_once('classes/Stakeholder.php'); 
     193        Stakeholder::add(null, Role::getObject('NETWORK_OWNER'), $object); 
    192194        return $object; 
    193  
    194     } 
    195  
    196      /** 
     195    } 
     196 
     197    /** 
    197198     * Get an interface to pick an object of this class 
    198199     * 
     
    221222     *                                     programmer to recognise it's 
    222223     *                                     generated html form 
    223      *  
     224     * 
    224225     * @param string $userData=null Array of contextual data optionally sent to the method. 
    225226     *  The function must still function if none of it is present. 
     
    239240        //pretty_print_r($userData); 
    240241        !empty($userData['preSelectedObject'])?$selected_id=$userData['preSelectedObject']->getId():$selected_id=self::getDefaultNetwork()->getId(); 
    241                 !empty($userData['additionalWhere'])?$additional_where=$userData['additionalWhere']:$additional_where=null; 
    242                 !empty($userData['allowEmpty'])?$allow_empty=$userData['allowEmpty']:$allow_empty=false; 
    243                  
     242        !empty($userData['additionalWhere'])?$additional_where=$userData['additionalWhere']:$additional_where=null; 
     243        !empty($userData['allowEmpty'])?$allow_empty=$userData['allowEmpty']:$allow_empty=false; 
     244 
    244245        $db = AbstractDb::getObject(); 
    245246        $sql = "SELECT network_id, name FROM networks WHERE 1=1 $additional_where"; 
     
    333334 
    334335            if ($network_id) { 
    335                 try { 
    336                     if (!User::getCurrentUser()->DEPRECATEDisSuperAdmin()) { 
    337                         throw new Exception(_("Access denied")); 
    338                     } 
    339                 } catch (Exception $e) { 
    340                     $ui = MainUI::getObject(); 
    341                     $ui->displayError($e->getMessage(), false); 
    342                     exit; 
    343                 } 
    344  
     336                Security::requirePermission(Permission::P('SERVER_PERM_ADD_NEW_NETWORK'), Server::getServer()); 
    345337                $retval = self::createNewObject($network_id); 
    346338            } 
     
    963955    public function setGisLocation($pt) 
    964956    { 
    965             $retval=false; 
     957        $retval=false; 
    966958        $db = AbstractDb::getObject(); 
    967959 
     
    973965            if (!empty ($lat) && !empty ($long) && !empty ($alt)) { 
    974966                $db->execSqlUpdate("UPDATE networks SET gmaps_initial_latitude = $lat, gmaps_initial_longitude = $long, gmaps_initial_zoom_level = $alt WHERE network_id = '{$this->getId()}'"); 
    975             $retval=true; 
     967                $retval=true; 
    976968            } 
    977969            else { 
     
    14131405 
    14141406    /** 
    1415      * Does the user have admin access to this network? 
    1416      * 
    1417      * @return bool true our false 
    1418      * 
    1419      * @access public 
    1420      */ 
    1421     public function DEPRECATEDhasAdminAccess(User $user) 
    1422     { 
    1423  
    1424         $db = AbstractDb::getObject(); 
    1425  
    1426         // Init values 
    1427         $row = null; 
    1428         $retval = false; 
    1429  
    1430         if ($user != null) { 
    1431                 if ($user->DEPRECATEDisSuperAdmin()) { 
    1432                     $retval = true; 
    1433                 } 
    1434         } 
    1435  
    1436         return $retval; 
    1437     } 
    1438  
    1439     /** 
    14401407     * Get an array of all Content linked to the network 
    14411408     * 
     
    14811448    public function getAdminUI() 
    14821449    { 
     1450        Security::requirePermission(Permission::P('NETWORK_PERM_EDIT_NETWORK_CONFIG'), $this); 
    14831451        require_once('classes/InterfaceElements.php'); 
    14841452        // Init values 
     
    16691637            $html .= InterfaceElements::generateAdminSectionContainer("network_gis_data", _("GIS data"), implode(null, $html_network_gis_data)); 
    16701638        } 
    1671          
     1639 
    16721640        // Profile templates 
    16731641        $title = _("Network profile templates"); 
     
    16911659    public function processAdminUI() 
    16921660    { 
    1693         $user = User::getCurrentUser(); 
    1694  
    1695         if (!$this->DEPRECATEDhasAdminAccess($user)) { 
    1696             throw new Exception(_('Access denied!')); 
    1697         } 
     1661        Security::requirePermission(Permission::P('NETWORK_PERM_EDIT_NETWORK_CONFIG'), $this); 
    16981662 
    16991663        // Content management 
     
    17591723        $name = "network_".$this->getId()."_allow_custom_portal_redirect"; 
    17601724        $this->setCustomPortalRedirectAllowed(empty ($_REQUEST[$name]) ? false : true); 
    1761          
     1725 
    17621726        // Access rights 
    1763             require_once('classes/Stakeholder.php'); 
     1727        require_once('classes/Stakeholder.php'); 
    17641728        Stakeholder::processAssignStakeholdersUI($this, $errMsg); 
    17651729        if(!empty($errMsg)) { 
    1766         echo $errMsg; 
    1767         } 
    1768          
     1730            echo $errMsg; 
     1731        } 
     1732 
    17691733        // GIS data 
    17701734        if (defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED == true) { 
     
    17771741            $this->setGisMapType($_REQUEST[$name]); 
    17781742        } 
    1779          
     1743 
    17801744        // Profile templates 
    17811745        $name = "network_".$this->_id."_profile_templates"; 
     
    18921856        // Init values 
    18931857        $retval = false; 
    1894  
    1895         $user = User :: getCurrentUser(); 
    1896         if (!$user->DEPRECATEDisSuperAdmin()) { 
    1897             $errmsg = _('Access denied (must have super admin access)'); 
     1858        Security::requirePermission(Permission::P('NETWORK_PERM_DELETE_NETWORK'), $this); 
     1859        if ($this->isDefaultNetwork() === true) { 
     1860            $errmsg = _('Cannot delete default network, create another one and select it before you remove this one.'); 
    18981861        } else { 
    1899             if ($this->isDefaultNetwork() === true) { 
    1900                 $errmsg = _('Cannot delete default network, create another one and select it before remove this one.'); 
     1862            $db = AbstractDb::getObject(); 
     1863            $id = $db->escapeString($this->getId()); 
     1864            if (!$db->execSqlUpdate("DELETE FROM networks WHERE network_id='{$id}'", false)) { 
     1865                $errmsg = _('Could not delete network!'); 
    19011866            } else { 
    1902                 $db = AbstractDb::getObject(); 
    1903                 $id = $db->escapeString($this->getId()); 
    1904                 if (!$db->execSqlUpdate("DELETE FROM networks WHERE network_id='{$id}'", false)) { 
    1905                     $errmsg = _('Could not delete network!'); 
    1906                 } else { 
    1907                     $retval = true; 
    1908                 } 
    1909             } 
    1910         } 
     1867                $retval = true; 
     1868            } 
     1869        } 
     1870 
    19111871 
    19121872        return $retval; 
     
    19251885        $this->__construct($this->_id); 
    19261886    } 
    1927      
     1887 
    19281888    /** Menu hook function */ 
    19291889    static public function hookMenu() { 
    19301890        $items = array(); 
    1931         if($networks = Security::getObjectsWithPermission(Permission::P('NETWORK_PERM_EDIT_NETWORK_CONFIG'))) 
    1932         { 
    1933                     foreach ($networks as $networkId => $network) { 
     1891        if($networks = Security::getObjectsWithPermission(Permission::P('NETWORK_PERM_EDIT_NETWORK_CONFIG'))) { 
     1892            foreach ($networks as $networkId => $network) { 
    19341893                $items[] = array('path' => 'network/network_'.$networkId.'edit', 
    19351894                'title' => sprintf(_("Edit %s"), $network->getName()), 
     
    19381897            } 
    19391898        } 
    1940                 $items[] = array('path' => 'network', 
     1899        if(Security::hasPermission(Permission::P('SERVER_PERM_ADD_NEW_NETWORK'), Server::getServer())){ 
     1900            $items[] = array('path' => 'network/network_add_new', 
     1901                'title' => sprintf(_("Add a new network on this server")), 
     1902                'url' => BASE_URL_PATH.htmlspecialchars("admin/generic_object_admin.php?object_class=Network&action=new_ui") 
     1903            ); 
     1904        } 
     1905        $items[] = array('path' => 'network', 
    19411906                'title' => _('Network administration'), 
    19421907                'type' => MENU_ITEM_GROUPING); 
    1943              
    1944             return $items;  
    1945         } 
    1946      
     1908        return $items; 
     1909    } 
     1910 
    19471911    /** 
    19481912     * Assigns values about network to be processed by the Smarty engine. 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r1312 r1316  
    458458 
    459459        if ($network) { 
    460             try { 
    461                 if (!$network->DEPRECATEDhasAdminAccess(User :: getCurrentUser())) { 
    462                     throw new Exception(_("Access denied")); 
    463                 } 
    464             } catch (Exception $e) { 
    465                 $ui = MainUI::getObject(); 
    466                 $ui->displayError($e->getMessage(), false); 
    467                 exit; 
    468             } 
    469  
     460            Security::requirePermission(Permission::P('NETWORK_PERM_ADD_NEW_NODE'), $network); 
    470461            $retval = self::createNewObject($gw_id, $network); 
    471462        } 
     
    16321623            } 
    16331624        } 
     1625            if(Security::hasPermission(Permission::P('NETWORK_PERM_ADD_NEW_NODE'))){ 
     1626            $items[] = array('path' => 'node/node_add_new', 
     1627                'title' => sprintf(_("Add a new node")), 
     1628                'url' => BASE_URL_PATH.htmlspecialchars("admin/generic_object_admin.php?object_class=Node&action=new_ui") 
     1629            ); 
     1630        } 
    16341631        $items[] = array('path' => 'node', 
    16351632        'title' => _('Node administration'), 
  • trunk/wifidog-auth/wifidog/classes/NodeLists/NodeListHTML.php

    r1253 r1316  
    162162        // Init ALL smarty values 
    163163        $this->_smarty->assign('DEPRECATEDisSuperAdmin', false); 
    164         $this->_smarty->assign('DEPRECATEDisOwner', false); 
    165164        $this->_smarty->assign('GMapsEnabled', false); 
    166165        $this->_smarty->assign('nodes', array()); 
     
    176175         */ 
    177176        $this->_smarty->assign('DEPRECATEDisSuperAdmin', $this->_currentUser && $this->_currentUser->DEPRECATEDisSuperAdmin()); 
    178         $this->_smarty->assign('DEPRECATEDisOwner', $this->_currentUser && $this->_currentUser->DEPRECATEDisOwner()); 
    179177 
    180178        if (defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED == true) { 
  • trunk/wifidog-auth/wifidog/classes/Permission.php

    r1249 r1316  
    8686            $PERMISSIONS['NETWORK_PERM_EDIT_ANY_USER'] = array(_("User is allowed to edit any user for this network"), StakeholderType::Network, true); 
    8787            $PERMISSIONS['NETWORK_PERM_EDIT_NETWORK_CONFIG'] = array(_("User is allowed to edit the configuration of this network"), StakeholderType::Network, true); 
     88            $PERMISSIONS['NETWORK_PERM_DELETE_NETWORK'] = array(_("User is allowed to delete this network"), StakeholderType::Network, true); 
    8889            $PERMISSIONS['NETWORK_PERM_VIEW_STATISTICS'] = array(_("User is allowed to view all statistics for this network"), StakeholderType::Network, true); 
    8990            $PERMISSIONS['NETWORK_PERM_EDIT_ANY_NODE_CONFIG'] = array(_("User is allowed to edit any configuration of any node on the network"), StakeholderType::Network, true); 
    90  
     91            $PERMISSIONS['NETWORK_PERM_ADD_NEW_NODE'] = array(_("User is allowed to create a new Node on this network"), StakeholderType::Server, true); 
     92             
    9193            $PERMISSIONS['SERVER_PERM_EDIT_ROLES'] = array(_("User is allowed to edit user role definitions"), StakeholderType::Server, true); 
    9294            $PERMISSIONS['SERVER_PERM_EDIT_ANY_VIRTUAL_HOST'] = array(_("User is allowed to edit any virtual host definition"), StakeholderType::Server, true); 
     
    9597            $PERMISSIONS['SERVER_PERM_EDIT_CONTENT_TYPE_FILTERS'] = array(_("User is allowed to edit the content type filters on the network"), StakeholderType::Server, true); 
    9698            $PERMISSIONS['SERVER_PERM_EDIT_CONTENT_LIBRARY'] = array(_("User is allowed to create reusable content"), StakeholderType::Server, true); 
    97  
     99            $PERMISSIONS['SERVER_PERM_ADD_NEW_NETWORK'] = array(_("User is allowed to create a new Network on this server"), StakeholderType::Server, true); 
     100             
    98101            $PERMISSIONS['NODE_PERM_EDIT_GATEWAY_ID'] = array(_("User is allowed to change the gateway id of this node"), StakeholderType::Node, false); 
    99102            $PERMISSIONS['NODE_PERM_EDIT_CONFIG'] = array(_("TEMPORARY:  User is allowed to edit general configuration for this node.  This will be replaced with more granular permissions in the future"), StakeholderType::Node, false); 
     
    172175 
    173176    /** Instantiate a user object 
    174      * @param $id The user id of the requested user 
     177     * @param $id The id of the requested permission 
    175178     * @return a Permission object, or null if there was an error 
    176179     */ 
     
    183186    } 
    184187    /** Shorthand for getObject 
    185      * @param $id The user id of the requested user 
     188     * @param $id The id of the requested permission 
    186189     * @return a Permission object, or null if there was an error 
    187190     */ 
  • trunk/wifidog-auth/wifidog/classes/Role.php

    r1308 r1316  
    228228        // Init values 
    229229        $html = ''; 
    230  
    231  
    232  
    233  
    234230        $name = "new_role_stakeholder_type"; 
    235231        $stakeholderTypeSelect = StakeholderType::getSelectUI($name); 
  • trunk/wifidog-auth/wifidog/classes/Security.php

    r1301 r1316  
    237237    } 
    238238 
    239     /* Check if the current user has the requested role on the target object 
     239    /* Check if the current user has the requested role on the target object.  Be carefull, all access control logic should be based on permissions, nor roles, UNLESS the role is a system role.  Typically OBJECTTYPE_OWNER, which implies that the stakeholder can assign other roles to that object. (and nothing else)  
    240240     * @param role The role object to check 
    241241     * @param $targetObject The Object on which the permssion applies (Network, Server, etc.) 
  • trunk/wifidog-auth/wifidog/classes/Stakeholder.php

    r1299 r1316  
    4848require_once('classes/Session.php'); 
    4949require_once('classes/User.php'); 
     50require_once('classes/Role.php'); 
    5051 
    5152/** 
     
    103104        return $html; 
    104105    } 
     106 
     107    /** 
     108     * Process the interface to assign stakeholders to objects 
     109     * @param &$errMsg An error message will be appended to this is the username is not empty, but the user doesn't exist. 
     110     * 
     111     * @return null 
     112     * 
     113     * @param $targetObject The Object on which the permssion applies (Network, Server, etc.) 
     114     */ 
     115    static public function add($user=null, Role $role, $targetObject) 
     116    { 
     117        $db = AbstractDb::getObject(); 
     118        $object_id = $db->escapeString($targetObject->getId()); 
     119        $object_class = get_class($targetObject); 
     120        $table = strtolower($object_class).'_stakeholders'; 
     121        if(!$user) { 
     122            $user = User::getCurrentUser(); 
     123        } 
     124          
     125        if(Security::hasRole($role, $targetObject, $user)){ 
     126            throw new Exception(_("User %s already has role %s for this object"), $user->getUsername(), $role->getId()); 
     127        } 
     128        else {// the user doesn't already have that role 
     129            $sql = "INSERT INTO $table (object_id, user_id, role_id) VALUES ('$object_id', '{$user->getId()}', '{$role->getId()}');"; 
     130            $db->execSqlUpdate($sql, false); 
     131        } 
     132    } 
    105133    /** 
    106134     * Process the interface to assign stakeholders to objects 
     
    113141    static public function processAssignStakeholdersUI($targetObject, &$errMsg) 
    114142    { 
    115         require_once('classes/Role.php'); 
    116143        $db = AbstractDb::getObject(); 
    117144        $object_id = $db->escapeString($targetObject->getId()); 
     
    132159            } 
    133160        } 
    134                     $stakeholder_rows = null; 
    135             $sql = "SELECT * FROM $table JOIN roles USING (role_id) WHERE object_id = '$object_id';"; 
    136             $db->execSql($sql, $stakeholder_rows, false); 
    137             if($stakeholder_rows) { 
    138                 foreach ($stakeholder_rows as $stakeholder_row) { 
    139                     $user = User::getObject($stakeholder_row['user_id']); 
    140                     $name = $object_id . "_stakeholder_" . $stakeholder_row['user_id'] . "_". $stakeholder_row['role_id'] . "_remove"; 
    141                     if(!empty($_REQUEST[$name])) { 
    142                         $userIdStr=$db->escapeString($stakeholder_row['user_id']); 
    143                         $roleIdStr=$db->escapeString($stakeholder_row['role_id']); 
    144                         $sql = "DELETE FROM $table WHERE object_id='$object_id' AND user_id='$userIdStr' AND role_id = '$roleIdStr';"; 
    145                         $db->execSqlUpdate($sql, false); 
    146                     } 
     161        $stakeholder_rows = null; 
     162        $sql = "SELECT * FROM $table JOIN roles USING (role_id) WHERE object_id = '$object_id';"; 
     163        $db->execSql($sql, $stakeholder_rows, false); 
     164        if($stakeholder_rows) { 
     165            foreach ($stakeholder_rows as $stakeholder_row) { 
     166                $user = User::getObject($stakeholder_row['user_id']); 
     167                $name = $object_id . "_stakeholder_" . $stakeholder_row['user_id'] . "_". $stakeholder_row['role_id'] . "_remove"; 
     168                if(!empty($_REQUEST[$name])) { 
     169                    $userIdStr=$db->escapeString($stakeholder_row['user_id']); 
     170                    $roleIdStr=$db->escapeString($stakeholder_row['role_id']); 
     171                    $sql = "DELETE FROM $table WHERE object_id='$object_id' AND user_id='$userIdStr' AND role_id = '$roleIdStr';"; 
     172                    $db->execSqlUpdate($sql, false); 
    147173                } 
    148174            } 
    149          
     175        } 
     176 
    150177        return null; 
    151178    } 
  • trunk/wifidog-auth/wifidog/classes/Statistics.php

    r1292 r1316  
    375375            throw new Exception(_('Access denied!')); 
    376376        } else 
    377         if ((!$user->DEPRECATEDisSuperAdmin() && !$user->DEPRECATEDisOwner())) { 
     377        if ((!$user->DEPRECATEDisSuperAdmin())) { 
    378378            throw new Exception(_('Access denied!')); 
    379379        } 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r1304 r1316  
    506506    } 
    507507 
    508     /** 
    509      * Tells if the current user is owner of at least one hotspot. 
    510      */ 
    511     public function DEPRECATEDisOwner() { 
    512         $db = AbstractDb::getObject(); 
    513         $db->execSql("SELECT * FROM node_stakeholders WHERE role_id = 'NODE_OWNER' AND user_id='{$this->getId()}'", $row, false); 
    514         if ($row != null) 
    515         return true; 
    516         return false; 
    517  
    518     } 
    519  
    520508    /** Is this user the Splash Only User() */ 
    521509    public function isSplashOnlyUser() { 
     
    746734        $userPreferencesItems = array(); 
    747735        $finalHtml = ''; 
    748         if($this->getNetwork()->DEPRECATEDhasAdminAccess($currentUser)) { 
     736        if(Security::hasPermission(Permission::P('NETWORK_PERM_VIEW_STATISTICS'), $this->getNetwork())) { 
    749737            /* Statistics */ 
    750738            $content = "<a href='".BASE_SSL_PATH."admin/stats.php?Statistics=".$this->getNetwork()->getId()."&distinguish_users_by=user_id&stats_selected_users=".$this->getUsername()."&UserReport=on&user_id=".$this->getId()."&action=generate'>"._("Get user statistics")."</a>\n"; 
     
    762750        } 
    763751 
    764         if (($this == $currentUser && !$this->isSplashOnlyUser() )|| $this->getNetwork()->DEPRECATEDhasAdminAccess($currentUser)) { 
     752        if (($this == $currentUser && !$this->isSplashOnlyUser() )|| Security::hasPermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) { 
    765753            /* Username */ 
    766754            $title = _("Username"); 
     
    826814        $db = AbstractDb::getObject(); 
    827815        $currentUser = self :: getCurrentUser(); 
    828         if ($this->getNetwork()->DEPRECATEDhasAdminAccess($currentUser)) { 
     816        if (Security::hasPermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) { 
    829817            /* Account status */ 
    830818            $name = "user_" . $this->getId() . "_accountstatus"; 
     
    833821        } 
    834822 
    835         if ($this == $currentUser || $this->getNetwork()->DEPRECATEDhasAdminAccess($currentUser)) { 
     823        if ($this == $currentUser || Security::requirePermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) { 
    836824            /* Username */ 
    837825            $name = "user_" . $this->getId() . "_username"; 
     
    986974        $smarty->assign('userIsValid', $user && !$user->isSplashOnlyUser() ? true : false); 
    987975        $smarty->assign('userDEPRECATEDisSuperAdmin', $user && $user->DEPRECATEDisSuperAdmin()); 
    988         $smarty->assign('userIsANodeOwner', $user && $user->DEPRECATEDisOwner()); 
    989976 
    990977        if (isset ($_REQUEST['debug_request']) && ($user && $user->DEPRECATEDisSuperAdmin())) { 
  • trunk/wifidog-auth/wifidog/hotspots_map.php

    r1249 r1316  
    7878// Init ALL smarty values 
    7979$smarty->assign('DEPRECATEDisSuperAdmin', false); 
    80 $smarty->assign('DEPRECATEDisOwner', false); 
    8180$smarty->assign('selectNetworkUI', null); 
    8281 
     
    8988 */ 
    9089$smarty->assign('DEPRECATEDisSuperAdmin', $currentUser && $currentUser->DEPRECATEDisSuperAdmin()); 
    91 $smarty->assign('DEPRECATEDisOwner', $currentUser && $currentUser->DEPRECATEDisOwner()); 
    9290 
    9391/* 
  • trunk/wifidog-auth/wifidog/include/schema_validate.php

    r1289 r1316  
    4848 * Define current database schema version 
    4949 */ 
    50 define('REQUIRED_SCHEMA_VERSION', 57); 
     50define('REQUIRED_SCHEMA_VERSION', 58); 
    5151/** Used to test a new shecma version before modyfying the database */ 
    5252define('SCHEMA_UPDATE_TEST_MODE', false); 
     
    7373    if (empty ($row)) { 
    7474        echo "<html><body>"; 
    75                       echo "<h1>" . _("I am unable to retrieve the schema version. Either the wifidog database hasn't been created yet, the postgresql server is down, or pg_hba.conf does not allow your web server to connect to the wifidog database.") . "</h1>"; 
    76          
     75        echo "<h1>" . _("I am unable to retrieve the schema version. Either the wifidog database hasn't been created yet, the postgresql server is down, or pg_hba.conf does not allow your web server to connect to the wifidog database.") . "</h1>"; 
     76 
    7777        echo "<h2>" . _("Try running the") . " <a href='" . BASE_URL_PATH . "install.php'>" . _("installation script") . "</a>.</h2>\n"; 
    7878        echo "</html></body>"; 
     
    570570                if ($ownersRow != null) { 
    571571                    foreach ($ownersRow as $owner_row) { 
    572                     $sql .= "INSERT INTO content_has_owners (content_id, user_id) VALUES ('$content_id', '" . $owner_row['user_id'] . "');\n"; 
     572                        $sql .= "INSERT INTO content_has_owners (content_id, user_id) VALUES ('$content_id', '" . $owner_row['user_id'] . "');\n"; 
    573573                    } 
    574574                } 
     
    755755                if ($ownersRow != null) { 
    756756                    foreach ($ownersRow as $owner_row) { 
    757                     $sql .= "INSERT INTO content_has_owners (content_id, user_id) VALUES ('$content_id', '" . $owner_row['user_id'] . "');\n"; 
     757                        $sql .= "INSERT INTO content_has_owners (content_id, user_id) VALUES ('$content_id', '" . $owner_row['user_id'] . "');\n"; 
    758758                    } 
    759759                } 
     
    12711271 
    12721272    } 
    1273      $new_schema_version = 55; 
    1274      if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
    1275      printUpdateVersion($new_schema_version); 
    1276      $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1273    $new_schema_version = 55; 
     1274    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1275        printUpdateVersion($new_schema_version); 
     1276        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
    12771277        $sql .= "ALTER TABLE nodes ADD COLUMN last_heartbeat_sys_uptime INTEGER;\n";//68 years of uptime should be enough for anybody ;) 
    12781278        $sql .= "ALTER TABLE nodes ALTER COLUMN last_heartbeat_sys_uptime SET DEFAULT NULL;\n"; 
     
    12831283        $sql .= "ALTER TABLE nodes ADD COLUMN last_heartbeat_sys_load real;\n"; 
    12841284        $sql .= "ALTER TABLE nodes ALTER COLUMN last_heartbeat_sys_load SET DEFAULT NULL;\n"; 
    1285      } 
     1285    } 
    12861286      
    1287      $new_schema_version = 56; 
    1288      if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
    1289      printUpdateVersion($new_schema_version); 
    1290      $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1287    $new_schema_version = 56; 
     1288    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1289        printUpdateVersion($new_schema_version); 
     1290        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
    12911291        $sql .= "CREATE INDEX idx_connections_timestamp_in ON connections (timestamp_in);\n"; 
    1292      } 
    1293  
    1294      $new_schema_version = 57; 
    1295      if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
    1296      printUpdateVersion($new_schema_version); 
    1297      $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1292    } 
     1293 
     1294    $new_schema_version = 57; 
     1295    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1296        printUpdateVersion($new_schema_version); 
     1297        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
    12981298        $sql .= "ALTER TABLE users ADD COLUMN open_id_url text;\n"; 
    12991299        $sql .= "CREATE INDEX idx_users_topen_id_url ON users (open_id_url);\n"; 
    1300      } 
     1300    } 
     1301 
     1302    $new_schema_version = 58; 
     1303    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1304        printUpdateVersion($new_schema_version); 
     1305        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1306        $sql .= "ALTER TABLE network_stakeholders ADD CONSTRAINT fk_roles FOREIGN KEY (role_id) REFERENCES roles (role_id) ON UPDATE CASCADE ON DELETE CASCADE;\n"; 
     1307        $sql .= "ALTER TABLE node_stakeholders ADD CONSTRAINT fk_roles FOREIGN KEY (role_id) REFERENCES roles (role_id) ON UPDATE CASCADE ON DELETE CASCADE;\n"; 
     1308        $sql .= "ALTER TABLE server_stakeholders ADD CONSTRAINT fk_roles FOREIGN KEY (role_id) REFERENCES roles (role_id) ON UPDATE CASCADE ON DELETE CASCADE;\n"; 
     1309        $sql .= "UPDATE roles SET role_id='SERVER_OWNER', is_system_role=true WHERE role_id='SERVER_SYSADMIN';\n"; 
     1310        $sql .= "UPDATE roles SET role_id='NETWORK_OWNER', is_system_role=true WHERE role_id='NETWORK_SYSADMIN';\n"; 
     1311        $sql .= "UPDATE roles SET is_system_role=true WHERE role_id='NODE_OWNER';\n"; 
     1312        $sql .= "INSERT into roles (role_id, stakeholder_type_id, is_system_role) VALUES ('CONTENT_OWNER', 'Content', true);\n"; 
     1313    } 
     1314 
    13011315    /* 
    13021316     $new_schema_version = ; 
  • trunk/wifidog-auth/wifidog/install.php

    r1313 r1316  
    837837 
    838838            # Add user to admin table, hide his username and set his account status to 1 (allowed) 
    839             $sql = "INSERT INTO server_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'SERVER_SYSADMIN', 'SERVER_ID');\n"; 
    840             $sql .= "INSERT INTO network_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'NETWORK_SYSADMIN', 'default-network');\n"; 
     839            $sql = "INSERT INTO server_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'SERVER_OWNER', 'SERVER_ID');\n"; 
     840            $sql .= "INSERT INTO network_stakeholders (user_id, role_id, object_id) VALUES ('$user_id', 'NETWORK_OWNER', 'default-network');\n"; 
    841841            $sql .= "UPDATE users SET account_status='1' WHERE user_id='$user_id'"; 
    842842            $result = pg_query($connection, $sql);