Browser identification is performed by examining the HTTP_USER_AGENT environment variable provided by the web server.
Author: Chuck Hagenbuch (chuck@horde.org)
Author: Jon Parise (jon@horde.org)
Esempio n. 1
0
 /**
  */
 public function match($userAgent = null, $accept = null)
 {
     parent::match($userAgent, $accept);
     try {
         $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook('browser_modify', 'horde', array($this));
     } catch (Horde_Exception_HookNotSet $e) {
     }
 }
Esempio n. 2
0
                $defaultimg .= "blankmovie.png";
                break;
            default:
                $mime = 'image/png';
                $defaultimg .= "blankalbum.png";
                break;
        }
        $image = file_get_contents($defaultimg);
    } else {
        if ($_GET['thumb']) {
            $thumb_data = $art->get_thumb($size);
            $etag .= '-' . $_GET['thumb'];
        }
        $mime = isset($thumb_data['thumb_mime']) ? $thumb_data['thumb_mime'] : $art->raw_mime;
        $image = isset($thumb_data['thumb']) ? $thumb_data['thumb'] : $art->raw;
    }
}
if (!empty($image)) {
    $extension = Art::extension($mime);
    $filename = scrub_out($filename . '.' . $extension);
    // Send the headers and output the image
    $browser = new Horde_Browser();
    if (!empty($etag)) {
        header('ETag: ' . $etag);
        header('Cache-Control: private');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time()));
    }
    header("Access-Control-Allow-Origin: *");
    $browser->downloadHeaders($filename, $mime, true);
    echo $image;
}
Esempio n. 3
0
require_once '../lib/init.php';
if (!Access::check('interface', 100) or AmpConfig::get('demo_mode')) {
    UI::access_denied();
    exit;
}
UI::show_header();
/* Switch on action boys */
switch ($_REQUEST['action']) {
    /* This re-generates the config file comparing
     * /config/ampache.cfg to .cfg.dist
     */
    case 'generate_config':
        ob_end_clean();
        $current = parse_ini_file(AmpConfig::get('prefix') . '/config/ampache.cfg.php');
        $final = generate_config($current);
        $browser = new Horde_Browser();
        $browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, filesize(AmpConfig::get('prefix') . '/config/ampache.cfg.php.dist'));
        echo $final;
        exit;
    case 'reset_db_charset':
        Dba::reset_db_charset();
        show_confirmation(T_('Database Charset Updated'), T_('Your Database and associated tables have been updated to match your currently configured charset'), AmpConfig::get('web_path') . '/admin/system.php?action=show_debug');
        break;
    case 'show_debug':
        $configuration = AmpConfig::get_all();
        if ($_REQUEST['autoupdate'] == 'force') {
            $version = AutoUpdate::get_latest_version(true);
        }
        require_once AmpConfig::get('prefix') . '/templates/show_debug.inc.php';
        break;
    default:
Esempio n. 4
0
 /**
  * Application bootstrap initialization.
  * Solves chicken-and-egg problem - need a way to init Horde environment
  * from application without an active Horde_Registry object.
  *
  * Page compression will be started (if configured).
  *
  * Global variables defined:
  * <pre>
  *   - $browser: Horde_Browser object
  *   - $cli: Horde_Cli object (if 'cli' is true)
  *   - $conf: Configuration array
  *   - $injector: Horde_Injector object
  *   - $language: Language
  *   - $notification: Horde_Notification object
  *   - $page_output: Horde_PageOutput object
  *   - $prefs: Horde_Prefs object
  *   - $registry: Horde_Registry object
  *   - $session: Horde_Session object
  * </pre>
  *
  * @param string $app  The application to initialize.
  * @param array $args  Optional arguments:
  * <pre>
  *   - admin: (boolean) Require authenticated user to be an admin?
  *            DEFAULT: false
  *   - authentication: (string) The type of authentication to use:
  *     - none: Do not authenticate
  *     - fallback: Attempt to authenticate; if failure, then don't auth
  *                 (@since 2.11.0).
  *     - [DEFAULT]: Authenticate; on no auth redirect to login screen
  *   - cli: (boolean) Initialize a CLI interface. Setting this to true
  *          implicitly sets 'authentication' to 'none' and 'admin' and
  *          'nocompress' to true.
  *          DEFAULT: false
  *   - nocompress: (boolean) If set, the page will not be compressed.
  *                 DEFAULT: false
  *   - nologintasks: (boolean) If set, don't perform logintasks (never
  *                   performed if authentication is 'none').
  *                   DEFAULT: false
  *   - nonotificationinit: (boolean) If set, don't initialize the
  *                         application handlers for the notification
  *                         system (@since 2.12.0).
  *   - permission: (array) The permission required by the user to access
  *                 the page. The first element (REQUIRED) is the permission
  *                 name. The second element (OPTION; defaults to SHOW) is
  *                 the permission level.
  *   - session_cache_limiter: (string) Use this value for the session
  *                            cache limiter.
  *                            DEFAULT: Uses the value in the config.
  *   - session_control: (string) Special session control limitations:
  *     - netscape: TODO; start read/write session
  *     - none: Do not start a session
  *     - readonly: Start session readonly
  *     - [DEFAULT] - Start read/write session
  *   - test: (boolean) Is this the test script? If so, we relax several
  *           sanity checks and don't load things from the cache.
  *           DEFAULT: false
  *   - timezone: (boolean) Set the time zone?
  *               DEFAULT: false
  *   - user_admin: (boolean) Set authentication to an admin user?
  *                 DEFAULT: false
  * </pre>
  *
  * @return Horde_Registry_Application  The application object.
  * @throws Horde_Exception
  */
 public static function appInit($app, array $args = array())
 {
     if (isset($GLOBALS['registry'])) {
         return $GLOBALS['registry']->getApiInstance($app, 'application');
     }
     $args = array_merge(array('admin' => false, 'authentication' => null, 'cli' => null, 'nocompress' => false, 'nologintasks' => false, 'nonotificationinit' => false, 'permission' => false, 'session_cache_limiter' => null, 'session_control' => null, 'timezone' => false, 'user_admin' => null), $args);
     /* CLI initialization. */
     if ($args['cli']) {
         /* Make sure no one runs from the web. */
         if (!Horde_Cli::runningFromCLI()) {
             throw new Horde_Exception(Horde_Core_Translation::t("Script must be run from the command line"));
         }
         /* Load the CLI environment - make sure there's no time limit,
          * init some variables, etc. */
         $GLOBALS['cli'] = Horde_Cli::init();
         $args['nocompress'] = true;
         $args['authentication'] = 'none';
     }
     // For 'fallback' authentication, try authentication first.
     if ($args['authentication'] === 'fallback') {
         $fallback_auth = true;
         $args['authentication'] = null;
     } else {
         $fallback_auth = false;
     }
     // Registry.
     $s_ctrl = 0;
     switch ($args['session_control']) {
         case 'netscape':
             // Chicken/egg: Browser object doesn't exist yet.
             // Can't use Horde_Core_Browser since it depends on registry to be
             // configured.
             $browser = new Horde_Browser();
             if ($browser->isBrowser('mozilla')) {
                 $args['session_cache_limiter'] = 'private, must-revalidate';
             }
             break;
         case 'none':
             $s_ctrl = self::SESSION_NONE;
             break;
         case 'readonly':
             $s_ctrl = self::SESSION_READONLY;
             break;
     }
     $classname = __CLASS__;
     $registry = $GLOBALS['registry'] = new $classname($s_ctrl, $args);
     $registry->initialApp = $app;
     $appob = $registry->getApiInstance($app, 'application');
     $appob->initParams = $args;
     do {
         try {
             $registry->pushApp($app, array('check_perms' => $args['authentication'] != 'none', 'logintasks' => !$args['nologintasks'], 'notransparent' => !empty($args['notransparent'])));
             if ($args['admin'] && !$registry->isAdmin()) {
                 throw new Horde_Exception(Horde_Core_Translation::t("Not an admin"));
             }
             $e = null;
         } catch (Horde_Exception_PushApp $e) {
             if ($fallback_auth) {
                 $registry->authException = $e;
                 $registry->setAuthenticationSetting('none');
                 $args['authentication'] = 'none';
                 $fallback_auth = false;
                 continue;
             }
         }
         break;
     } while (true);
     if (!is_null($e)) {
         $appob->appInitFailure($e);
         switch ($e->getCode()) {
             case self::AUTH_FAILURE:
                 $failure = new Horde_Exception_AuthenticationFailure($e->getMessage());
                 $failure->application = $app;
                 throw $failure;
             case self::NOT_ACTIVE:
                 /* Try redirect to Horde if an app is not active. */
                 if (!$args['cli'] && $app != 'horde') {
                     $GLOBALS['notification']->push($e, 'horde.error');
                     Horde::url($registry->getInitialPage('horde'))->redirect();
                 }
                 /* Shouldn't reach here, but fall back to permission denied
                  * error if we can't even access Horde. */
                 // Fall-through
             /* Shouldn't reach here, but fall back to permission denied
              * error if we can't even access Horde. */
             // Fall-through
             case self::PERMISSION_DENIED:
                 $failure = new Horde_Exception_AuthenticationFailure($e->getMessage(), Horde_Auth::REASON_MESSAGE);
                 $failure->application = $app;
                 throw $failure;
         }
         throw $e;
     }
     if ($args['timezone']) {
         $registry->setTimeZone();
     }
     if (!$args['nocompress']) {
         $GLOBALS['page_output']->startCompression();
     }
     if ($args['user_admin']) {
         if (empty($GLOBALS['conf']['auth']['admins'])) {
             throw new Horde_Exception(Horde_Core_Translation::t("Admin authentication requested, but no admin users defined in configuration."));
         }
         $registry->setAuth(reset($GLOBALS['conf']['auth']['admins']), array(), array('no_convert' => true));
     }
     if ($args['permission']) {
         $admin_opts = array('permission' => $args['permission'][0], 'permlevel' => isset($args['permission'][1]) ? $args['permission'][1] : Horde_Perms::SHOW);
         if (!$registry->isAdmin($admin_opts)) {
             throw new Horde_Exception_PermissionDenied(Horde_Core_Translation::t("Permission denied."));
         }
     }
     return $appob;
 }
Esempio n. 5
0
    // FIXME: why are these separate?
    // Remove the media votes if this is a democratic song
    if ($demo_id && isset($democratic)) {
        $democratic->delete_from_oid($oid, $type);
    }
    debug_event('play', "Media {$media->file} ({$media->title}) does not have a valid filename specified", 2);
    header('HTTP/1.1 404 Invalid media, file not found or file unreadable');
    exit;
}
// don't abort the script if user skips this media because we need to update now_playing
ignore_user_abort(true);
// Format the media name
$media_name = $media->get_stream_name() . "." . $media->type;
header('Access-Control-Allow-Origin: *');
// Generate browser class for sending headers
$browser = new Horde_Browser();
/* If they are just trying to download make sure they have rights
 * and then present them with the download file
 */
if ($_GET['action'] == 'download' and AmpConfig::get('download')) {
    debug_event('play', 'Downloading file...', 5);
    // STUPID IE
    $media_name = str_replace(array('?', '/', '\\'), "_", $media->f_file);
    $browser->downloadHeaders($media_name, $media->mime, false, $media->size);
    $fp = fopen(Core::conv_lc_file($media->file), 'rb');
    $bytesStreamed = 0;
    if (!is_resource($fp)) {
        debug_event('Play', "Error: Unable to open {$media->file} for downloading", '2');
        exit;
    }
    if (!$share_id) {
Esempio n. 6
0
/**
 * install_create_config
 *
 * Attempts to write out the config file or offer it as a download.
 */
function install_create_config($download = false)
{
    $config_file = AmpConfig::get('prefix') . '/config/ampache.cfg.php';
    /* Attempt to make DB connection */
    Dba::dbh();
    $params = AmpConfig::get_all();
    if (empty($params['database_username']) || empty($params['database_password']) && strpos($params['database_hostname'], '/') !== 0) {
        Error::add('general', T_("Invalid configuration settings"));
        return false;
    }
    // Connect to the DB
    if (!Dba::check_database()) {
        Error::add('general', T_("Database Connection Failed Check Hostname, Username and Password"));
        return false;
    }
    $final = generate_config($params);
    // Make sure the directory is writable OR the empty config file is
    if (!$download) {
        if (!check_config_writable()) {
            Error::add('general', T_('Config file is not writable'));
            return false;
        } else {
            // Given that $final is > 0, we can ignore lazy comparison problems
            if (!file_put_contents($config_file, $final)) {
                Error::add('general', T_('Error writing config file'));
                return false;
            }
        }
    } else {
        $browser = new Horde_Browser();
        $browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, strlen($final));
        echo $final;
        exit;
    }
    return true;
}
Esempio n. 7
0
File: Base.php Progetto: horde/horde
 /**
  * Takes all necessary actions for the given import step, parameters and
  * form values and returns the next necessary step.
  *
  * @param integer $action  The current step. One of the IMPORT_* constants.
  * @param array $param     An associative array containing needed
  *                         parameters for the current step.
  *
  * @return mixed  Either the next step as an integer constant or imported
  *                data set after the final step.
  * @throws Horde_Data_Exception
  */
 public function nextStep($action, array $param = array())
 {
     /* First step. */
     if (is_null($action)) {
         return Horde_Data::IMPORT_FILE;
     }
     switch ($action) {
         case Horde_Data::IMPORT_FILE:
             if (!isset($this->_browser)) {
                 throw new LogicException('Missing browser parameter.');
             }
             /* Sanitize uploaded file. */
             try {
                 $this->_browser->wasFileUploaded('import_file', $param['file_types'][$this->_vars->import_format]);
             } catch (Horde_Exception $e) {
                 throw new Horde_Data_Exception($e);
             }
             if ($_FILES['import_file']['size'] <= 0) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("The file contained no data."));
             }
             $this->storage->set('format', $this->_vars->import_format);
             break;
         case Horde_Data::IMPORT_MAPPED:
             if (!$this->_vars->dataKeys || !$this->_vars->appKeys) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("You didn\\'t map any fields from the imported file to the corresponding fields."));
             }
             $dataKeys = explode("\t", $this->_vars->dataKeys);
             $appKeys = explode("\t", $this->_vars->appKeys);
             $dates = $map = array();
             if (!($import_data = $this->storage->get('data'))) {
                 $import_data = array();
             }
             foreach ($appKeys as $key => $app) {
                 $map[$dataKeys[$key]] = $app;
                 if (isset($param['time_fields']) && isset($param['time_fields'][$app])) {
                     $dates[$dataKeys[$key]]['type'] = $param['time_fields'][$app];
                     $dates[$dataKeys[$key]]['values'] = array();
                     $i = 0;
                     /* Build an example array of up to 10 date/time fields. */
                     while ($i < count($import_data) && count($dates[$dataKeys[$key]]['values']) < 10) {
                         if (!empty($import_data[$i][$dataKeys[$key]])) {
                             $dates[$dataKeys[$key]]['values'][] = $import_data[$i][$dataKeys[$key]];
                         }
                         ++$i;
                     }
                 }
             }
             $this->storage->set('map', $map);
             if (count($dates) > 0) {
                 foreach ($dates as $key => $data) {
                     if (count($data['values'])) {
                         $this->storage->set('dates', $dates);
                         return Horde_Data::IMPORT_DATETIME;
                     }
                 }
             }
             return $this->nextStep(Horde_Data::IMPORT_DATA, $param);
         case Horde_Data::IMPORT_DATETIME:
         case Horde_Data::IMPORT_DATA:
             if ($action == Horde_Data::IMPORT_DATETIME) {
                 $params = array('delimiter' => $this->_vars->delimiter, 'format' => $this->_vars->format, 'order' => $this->_vars->order, 'day_delimiter' => $this->_vars->day_delimiter, 'day_format' => $this->_vars->day_format, 'time_delimiter' => $this->_vars->time_delimiter, 'time_format' => $this->_vars->time_format);
             }
             if (!$this->storage->exists('data')) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("The uploaded data was lost since the previous step."));
             }
             /* Build the result data set as an associative array. */
             $data = array();
             $data_map = $this->storage->get('map');
             foreach ($this->storage->get('data') as $row) {
                 $data_row = array();
                 foreach ($row as $key => $val) {
                     if (isset($data_map[$key])) {
                         $mapped_key = $data_map[$key];
                         if ($action == Horde_Data::IMPORT_DATETIME && !empty($val) && isset($param['time_fields']) && isset($param['time_fields'][$mapped_key])) {
                             $val = $this->_mapDate($val, $param['time_fields'][$mapped_key], $params, $key);
                         }
                         $data_row[$mapped_key] = $val;
                     }
                 }
                 $data[] = $data_row;
             }
             return $data;
     }
 }
Esempio n. 8
0
 public function prepare_media($media)
 {
     $client = $this->createClient();
     if ($client != null) {
         set_time_limit(0);
         // Generate browser class for sending headers
         $browser = new Horde_Browser();
         $media_name = $media->f_artist_full . " - " . $media->title . "." . $media->type;
         $browser->downloadHeaders($media_name, $media->mime, false, $media->size);
         $file = $this->get_rel_path($media->file);
         $output = fopen('php://output', 'w');
         $metadata = $client->getFile($file, $output);
         if ($metadata == null) {
             debug_event('play', 'File not found on Dropbox: ' . $file, 5);
         }
         fclose($output);
     }
     return null;
 }
Esempio n. 9
0
 /**
  * ungimp_ie
  *
  * This function sets the cache limiting to public if you are running
  * some flavor of IE and not using HTTPS.
  */
 public static function ungimp_ie()
 {
     // If no https, no ungimpage required
     if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'on') {
         return true;
     }
     $browser = new Horde_Browser();
     if ($browser->isBrowser('msie')) {
         session_cache_limiter('public');
     }
     return true;
 }