Esempio n. 1
0
 /** Is the graph available.  (Are all Dependency available,
  * are all preconditions in the statistics class available, etc.) Always
  * returns true unless overriden by the child class
  * @param &$errormsg Optionnal error message returned by the class
  * @return true or false */
 public function isAvailable(&$errormsg = null)
 {
     $retval = false;
     if (Dependency::check("Image_Graph", $errormsg)) {
         require_once "Image/Graph.php";
         $retval = true;
     }
     return $retval;
 }
Esempio n. 2
0
 /**
  * Constructor.
  *
  * @return void
  */
 public function __construct()
 {
     // Check if PEAR::HTML_Safe is available
     if (Dependency::check("HTML_Safe")) {
         // Load PEAR::HTML_Safe
         require_once 'HTML/Safe.php';
         // Enabled PEAR::HTML_Safe support
         $this->isHtmlSafeEnabled = true;
         // Create a PEAR::HTML_Safe object
         $this->_HtmlSafe = new HTML_Safe();
         // Define list of dangerous tags
         $this->_HtmlSafe->deleteTags = $this->getDeleteTags();
         // Define list of dangerous tags
         $this->_HtmlSafe->deleteTagsContent = $this->getDeleteTagsContent();
         // Define list of dangerous attributes
         $this->_HtmlSafe->attributes = $this->getAttributes();
     }
 }
Esempio n. 3
0
 /**
  * Validates the uploaded file and return a boolean to tell if valid
  * This method should be overridden when you need to write special validation scripts
  *
  * @param string path to input file
  * @param string path to output file (by ref.), making sure you create a struct that matches the $_FILES[][] format
  *
  * @return boolean
  */
 protected function validateUploadedFile($input, &$output)
 {
     $errmsg = null;
     // Only if GD is available, resize to max size
     if (Dependency::check("gd", $errmsg)) {
         // Extract image metadata
         list($width_orig, $height_orig, $type, $attr) = getimagesize($input['tmp_name']);
         // Check if it busts the max size
         if ($width_orig > $this->getMaxDisplayWidth() || $height_orig > $this->getMaxDisplayHeight()) {
             // Init with max values
             $width = $this->getMaxDisplayWidth();
             $height = $this->getMaxDisplayHeight();
             // Compute ratios
             $ratio_orig = $width_orig / $height_orig;
             if ($this->getMaxDisplayWidth() / $this->getMaxDisplayHeight() > $ratio_orig) {
                 $width = $height * $ratio_orig;
             } else {
                 $height = $width / $ratio_orig;
             }
             // Resample
             $image_p = imagecreatetruecolor($width, $height);
             $image = imagecreatefromstring(file_get_contents($input['tmp_name']));
             if (!$image) {
                 pretty_print_r(gd_info());
                 throw new Exception(_("Unable to process image (GD probably doesn't have support for it enabled)"));
             } else {
                 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
             }
             // Build output metadata struct
             $output = array();
             $output['tmp_name'] = tempnam("/tmp", session_id());
             $output['type'] = "image/png";
             $output['name'] = $input['name'];
             // Output PNG at full compression (no artefact)
             imagepng($image_p, $output['tmp_name'], 9);
             // Write new file size
             $output['size'] = filesize($output['tmp_name']);
         }
     }
     return true;
 }
Esempio n. 4
0
 /**
  * This method contains the interface to add an additional element to a
  * content object.  (For example, a new string in a Langstring)
  * It is called when getNewContentUI has only a single possible object type.
  * It may also be called by the object getAdminUI to avoid code duplication.
  *
  * @param string $contentId      The id of the (possibly not yet created) content object.
  *
  * @param string $userData=null Array of contextual data optionally sent by displayAdminUI(),
  *  and only understood by the class (or subclasses) where getNewUI() is defined.
  *  The function must still function if none of it is present.
  *
  * @return HTML markup or false.  False means that this object does not support this interface.
  */
 public static function getNewUI($contentId, $userData = null)
 {
     $html = '';
     $locale = LocaleList::GetDefault();
     !empty($userData['typeInterface']) ? $typeInterface = $userData['typeInterface'] : ($typeInterface = null);
     $html .= "<div class='admin_element_data'>\n";
     $html .= _("Language") . ": " . LocaleList::GenererFormSelect($locale, "langstrings_" . $contentId . "_substring_new_language", null, TRUE);
     if (Dependency::check("FCKeditor")) {
         // Load FCKeditor class
         require_once 'lib/FCKeditor/fckeditor.php';
         $_FCKeditor = new FCKeditor('langstrings_' . $contentId . '_substring_new_string');
         $_FCKeditor->BasePath = SYSTEM_PATH . "lib/FCKeditor/";
         $_FCKeditor->Config["CustomConfigurationsPath"] = BASE_URL_PATH . "js/HTMLeditor.js";
         $_FCKeditor->Config["AutoDetectLanguage"] = false;
         $_FCKeditor->Config["DefaultLanguage"] = substr(Locale::getCurrentLocale()->getId(), 0, 2);
         $_FCKeditor->Config["StylesXmlPath"] = BASE_URL_PATH . "templates/HTMLeditor/css/" . substr(Locale::getCurrentLocale()->getId(), 0, 2) . ".xml";
         $_FCKeditor->Config["TemplatesXmlPath"] = BASE_URL_PATH . "templates/HTMLeditor/templates/" . substr(Locale::getCurrentLocale()->getId(), 0, 2) . ".xml";
         $_FCKeditor->ToolbarSet = "WiFiDOG";
         $_FCKeditor->Value = "";
         if ($typeInterface == 'LARGE') {
             $_FCKeditor->Height = 400;
         } else {
             $_FCKeditor->Height = 200;
         }
         $_FCKeditor->Width = 386;
         $html .= $_FCKeditor->CreateHtml();
     } else {
         $html .= "<textarea name='langstrings_{$contentId}_substring_new_string' class='textarea' cols='60' rows='3'></textarea>";
     }
     $html .= "</div>\n";
     $html .= "<div class='admin_element_tools'>\n";
     $html .= "<input type='submit' class='submit' name='langstrings_" . $contentId . "_add_new_entry' value='" . _("Add new string") . "'>";
     $html .= "</div>\n";
     return $html;
 }
Esempio n. 5
0
        $ui->displayError($e->getMessage());
        exit;
    }
} else {
    $ui = MainUI::getObject();
    $ui->displayError(_("No user id specified!"));
    exit;
}
// Init ALL smarty SWITCH values
$smarty->assign('sectionMAINCONTENT', false);
/*
 * Render output
 */
$ui = MainUI::getObject();
$ui->setTitle(_("User profile"));
if (Dependency::check('php-openid')) {
    require_once 'classes/OpenIdServerWifidog.php';
    $ui->appendHtmlHeadContent("<link rel='openid.server' href='" . OpenIdServerWifidog::getOpenIdServerUrl() . "' />");
}
$ui->setPageName('profile');
//$ui->addContent('left_area_middle', $tool_html);
/*
 * Main content
 */
$welcome_msg = sprintf("<span>%s</span> <em>%s</em>", _("User profile for"), $profile_user->getUsername());
$ui->addContent('page_header', "<h1>{$welcome_msg}</h1>");
if (!empty($profile)) {
    $main_area_middle_html = "";
    $main_area_middle_html .= $profile->getUserUI();
    $ui->addContent('main_area_middle', $main_area_middle_html);
}
Esempio n. 6
0
 /**
  * Return if PEAR::Cache_Lite is available and caching has been enabled.
  *
  * @return bool Caching enabled or disabled.
  */
 private function _cachingEnabled()
 {
     // Init values.
     $_doCache = false;
     // Check if PEAR::Cache_Lite is available.
     if (defined("USE_CACHE_LITE") && USE_CACHE_LITE == true && Dependency::check("Cache")) {
         // Check if caching has been enabled in config.php or local.config.php.
         $_doCache = true;
     }
     return $_doCache;
 }
Esempio n. 7
0
 /**
  * Attempts to login a user against the authentication source
  *
  * If successfull, returns a User object
  *
  * @param string $username A valid identifying token for the source. Not
  *                         necessarily unique.
  * @param string $password Clear text password.
  * @param string $errmsg   Reference of error message
  *
  * @return object The actual User object if login was successfull, false
  *                otherwise.
  */
 public function login($username, $password, &$errmsg = null)
 {
     $db = AbstractDb::getObject();
     // Init values
     $retval = false;
     $username = $db->EscapeString($username);
     $password = $db->EscapeString($password);
     // Check if php-ldap extension is loaded
     if (Dependency::check("ldap", $errmsg)) {
         if ($this->checkLdapUser($username, $password, $this->mldap_hostname, $this->mldap_o, $this->mldap_filter, $errmsg)) {
             //LDAP Authentication Successful
             $sql = "SELECT user_id, pass FROM users WHERE (username='******') AND account_origin='" . $this->getNetwork()->getId() . "'";
             $db->ExecSqlUniqueRes($sql, $user_info, false);
             if ($user_info != null) {
                 $user = User::getObject($user_info['user_id']);
                 if ($user->isUserValid($errmsg)) {
                     $retval = $user;
                     User::setCurrentUser($user);
                     $errmsg = _("Login successfull");
                 } else {
                     $retval = false;
                     //Error already been set
                 }
             } else {
                 $user = User::createUser(get_guid(), $username, $this->getNetwork(), "", "");
                 $retval =& $user;
                 $user->setAccountStatus(ACCOUNT_STATUS_ALLOWED);
                 $errmsg = _("Login successfull");
             }
         } else {
             $retval = false;
             //Error already been set
         }
     }
     User::setCurrentUser($retval);
     return $retval;
 }
 /**
  * Final update and stop accounting
  *
  * @param string $conn_id The connection id (the token id) for the
  *                        connection to work on
  * @param string $errmsg  Reference of error message
  *
  * @return bool Returns whether successful or not
  */
 function acctStop($conn_id, &$errmsg = null)
 {
     // Call parent method
     parent::acctStop($conn_id);
     $db = AbstractDb::getObject();
     // Init values
     $info = null;
     $conn_id = $db->escapeString($conn_id);
     if (Dependency::check("Auth_RADIUS", $errmsg)) {
         $db->execSqlUniqueRes("SELECT CURRENT_TIMESTAMP, *, CASE WHEN ((CURRENT_TIMESTAMP - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id={$conn_id}", $info, false);
         // RADIUS accounting stop
         // Session is completely based on Database time
         $session_time = strtotime($info['now']) - strtotime($info['timestamp_in']);
         $radius_acct = new Auth_RADIUS_Acct_Stop();
         $radius_acct->addServer($this->mRadius_hostname, $this->mRadius_acct_port, $this->mRadius_secret_key);
         // Specify the user for which accounting will be done
         $radius_acct->username = $info['username'];
         $racct->session_time = $session_time;
         // Set the session ID to the generated token
         $radius_acct->session_id = $info['token'];
         $status = $radius_acct->start();
         if (PEAR::isError($status)) {
             $errmsg = "Could not initiate PEAR RADIUS class.";
             return false;
         }
         // Cause of session termination
         $radius_acct->putAttribute(RADIUS_ACCT_TERMINATE_CAUSE, RADIUS_TERM_SESSION_TIMEOUT);
         $result = $radius_acct->send();
         if (PEAR::isError($result)) {
             $errmsg = "Could not send accounting request to RADIUS server.";
             return false;
         } else {
             if ($result !== true) {
                 $radius_acct->close();
                 $errmsg = "Accounting request rejected by RADIUS server.";
                 return false;
             }
         }
         $radius_acct->close();
         return true;
     } else {
         return false;
     }
 }
Esempio n. 9
0
 /** Retreives the admin interface of this object.
  * @return The HTML fragment for this interface, or null.
  * If it returns null, this object does not support new object creation */
 public static function getAdminUIStatic($userData = null)
 {
     $html = '';
     /* PHP version check */
     $okMsg = '<td ALIGN="CENTER" STYLE="background:lime;">OK</td>';
     $errorMsg = '<td ALIGN="CENTER" STYLE="background:red;">ERROR</td>';
     $warningMsg = '<td ALIGN="CENTER" STYLE="background:yellow;">Warning</td>';
     $html .= "<table BORDER=\"1\">";
     /* PHP version check */
     $requiredPHPVersion = '5.0';
     $phpVersion = phpversion();
     $html .= "<tr><td>PHP</td>";
     if (version_compare($phpVersion, $requiredPHPVersion, ">=")) {
         $html .= "{$okMsg}<td>{$phpVersion}</td>";
         // Version 5.0.0 or later
     } else {
         $html .= "{$errorMsg}<td>" . sprintf(_("Version %s needed"), $requiredPHPVersion) . "</td>";
         // Version < 5.0.0
         $userData['error'] = 1;
     }
     $html .= "</tr>";
     if (function_exists('pg_version')) {
         //Be carefull, postgres version check will also fail if there wasn't a db connexion yet.
         $pgVersionArray = @pg_version();
         $pgVersionArray ? $pgVersion = $pgVersionArray['server'] : ($pgVersion = null);
         if ($pgVersion) {
             $postgresRecommendedVersion = '8.0';
             $postgresRequiredVersion = '7.4';
             $html .= "<tr><td>PostgreSQL</td>";
             if (version_compare($pgVersion, $postgresRecommendedVersion, ">=")) {
                 $html .= "{$okMsg}<td>{$pgVersion}</td>";
                 // Version 5.0.0 or later
             } else {
                 if (version_compare($pgVersion, $postgresRequiredVersion, ">=")) {
                     $html .= "{$warningMsg}<td>" . sprintf(_("%s may work, but version %s is recommended"), $pgVersion, $postgresRecommendedVersion) . "</td>";
                     // Version < 5.0.0
                 } else {
                     $html .= "{$errorMsg}<td>" . sprintf(_("%s is too old, version %s needed"), $pgVersion, $postgresRecommendedVersion) . "</td>";
                     // Version < 5.0.0
                     $userData['error'] = 1;
                 }
             }
             $html .= "</tr>";
         }
     }
     $html .= "</table>";
     $components = Dependency::getDependencies();
     $html .= "<table BORDER=\"1\">\n";
     $html .= "<tr><th>" . _("Component") . '<br/>' . _("Click for the component's website") . "</th>\n";
     $html .= "<th>" . _("Type") . "</th>\n";
     $html .= "<th>" . _("Status") . "</th>\n";
     $html .= "<th>" . _("Information") . "</th>\n";
     $html .= "</tr>\n";
     $even_odd = "odd";
     foreach ($components as $dependency) {
         $even_odd = 'odd' != $even_odd ? 'odd' : 'even';
         $html .= "<tr class=" . $even_odd . ">\n";
         $websiteUrl = $dependency->getWebsiteURL();
         $component_key = $dependency->getId();
         $description = $dependency->getDescription();
         $mandatory = $dependency->isMandatory();
         $type = $dependency->getType();
         if ($websiteUrl) {
             $html .= "<td><A HREF=\"{$websiteUrl}\">{$component_key}</A></td>\n";
         } else {
             $html .= "<td>{$component_key}</td>\n";
         }
         $html .= "<td>{$type}</td>\n";
         $instalMessage = null;
         $dependency->processInstallUI($instalMessage);
         $message = null;
         $available = Dependency::check($component_key, $message);
         if ($available) {
             $html .= "{$okMsg}\n";
         } else {
             if ($mandatory) {
                 $html .= "{$errorMsg}\n";
                 $error = 1;
             } else {
                 $html .= "{$warningMsg}\n";
             }
         }
         $html .= "<td>\n";
         $html .= "<em>" . _("Description") . ":</em> {$description}<br/>\n";
         if ($instalMessage) {
             $html .= "<em>" . _("Install message") . ":</em> {$instalMessage}<br/>\n";
         }
         if ($message) {
             $html .= "<em>" . _("Detection message") . ":</em> {$message}<br/>\n";
         }
         if (!$available) {
             $html .= "<em>" . _("To install") . ":</em> " . $dependency->getInstallUI() . "<br/>\n";
         }
         $html .= "</td></tr>\n";
     }
     $html .= "</table>\n";
     return $html;
 }
Esempio n. 10
0
 protected function __construct($content_id)
 {
     // Init values
     $errmsg = "";
     $row = null;
     parent::__construct($content_id);
     if (Dependency::check("Phlickr", $errmsg) && Dependency::check('curl', $errmsg)) {
         // Defined globals
         $db = AbstractDb::getObject();
         // Load Phlickr classes
         require_once "Phlickr/Api.php";
         require_once "Phlickr/User.php";
         require_once "Phlickr/Group.php";
         $content_id = $db->escapeString($content_id);
         $sql = "SELECT *, EXTRACT(EPOCH FROM AGE(CURRENT_TIMESTAMP, cache_update_timestamp)) as cache_age FROM content_flickr_photostream WHERE flickr_photostream_id='{$content_id}'";
         $db->execSqlUniqueRes($sql, $row, false);
         if ($row == null) {
             /*Since the parent Content exists, the necessary data in content_group had not yet been created */
             $sql = "INSERT INTO content_flickr_photostream (flickr_photostream_id, preferred_size) VALUES ('{$content_id}', '" . self::SIZE_SMALL_240x180 . "')";
             $db->execSqlUpdate($sql, false);
             $sql = "SELECT * FROM content_flickr_photostream WHERE flickr_photostream_id='{$content_id}'";
             $db->execSqlUniqueRes($sql, $row, false);
             if ($row == null) {
                 throw new Exception(_("The content with the following id could not be found in the database: ") . $content_id);
             }
         }
         $this->flickr_photostream_row = $row;
         $this->flickr_api = null;
         $this->mBd =& $db;
         $this->_PhlickrAvailable = true;
     }
 }
Esempio n. 11
0
if ($network or NodeList::getAllowsNullNetwork($format)) {
    // Init node list type
    $nodeList = NodeList::getObject($format, $network);
    /**
     * XSLT support for Hotspot status page
     * ====================================
     *
     * If you want to enable XSLT support for the Hotspot status page enable this
     * value.
     *
     * Enabling it will let you you display hostpot status in any format.
     * http://server_ip/hotspot_status.php?format=XML&xslt=http://xslt_server/xslt/wifidog_status.xsl
     */
    // If a XSL transform stylesheet has been specified, try to use it.
    if ($format == "XML" && !empty($_REQUEST['xslt'])) {
        if (Dependency::check("xsl")) {
            // Load the XSLT
            if (($xslt_dom = @DomDocument::load(trim($_REQUEST['xslt']))) === false) {
                echo sprintf("Unable to load XSTL : %s", $_REQUEST['xslt']);
            } else {
                $xslt_proc = new XSLTProcessor();
                $xslt_proc->importStyleSheet($xslt_dom);
                // Prepare HTML
                header("Content-Type: text/html; charset=UTF-8");
                echo $xslt_proc->transformToXML($nodeList->getOutput(true));
            }
        } else {
            $dep = Dependency::getObject("xsl");
            echo sprintf("Missing dependency: %s: %s", $dep->getId(), $dep->getDescription());
        }
    } else {