function addressbook_init($showerr = true, $onlylocal = false)
{
    global $data_dir, $username, $ldap_server, $address_book_global_filename;
    global $addrbook_dsn, $addrbook_table;
    /* Create a new addressbook object */
    $abook = new AddressBook();
    /*
        Always add a local backend. We use *either* file-based *or* a
        database addressbook. If $addrbook_dsn is set, the database
        backend is used. If not, addressbooks are stores in files.
    */
    if (isset($addrbook_dsn) && !empty($addrbook_dsn)) {
        /* Database */
        if (!isset($addrbook_table) || empty($addrbook_table)) {
            $addrbook_table = 'address';
        }
        $r = $abook->add_backend('database', array('dsn' => $addrbook_dsn, 'owner' => $username, 'table' => $addrbook_table));
        if (!$r && $showerr) {
            echo _("Error initializing addressbook database.");
            exit;
        }
    } else {
        /* File */
        $filename = getHashedFile($username, $data_dir, "{$username}.abook");
        $r = $abook->add_backend('local_file', array('filename' => $filename, 'create' => true));
        if (!$r && $showerr) {
            printf(_("Error opening file %s"), $filename);
            exit;
        }
    }
    /* This would be for the global addressbook */
    if (isset($address_book_global_filename)) {
        $r = $abook->add_backend('global_file');
        if (!$r && $showerr) {
            echo _("Error initializing global addressbook.");
            exit;
        }
    }
    if ($onlylocal) {
        return $abook;
    }
    /* Load configured LDAP servers (if PHP has LDAP support) */
    if (isset($ldap_server) && is_array($ldap_server) && function_exists('ldap_connect')) {
        reset($ldap_server);
        while (list($undef, $param) = each($ldap_server)) {
            if (is_array($param)) {
                $r = $abook->add_backend('ldap_server', $param);
                if (!$r && $showerr) {
                    printf('&nbsp;' . _("Error initializing LDAP server %s:") . "<BR>\n", $param['host']);
                    echo '&nbsp;' . $abook->error;
                    exit;
                }
            }
        }
    }
    /* Return the initialized object */
    return $abook;
}
/**
 * same as delete but does not save calendar
 * saving is done inside event_edit.php
 * @return void
 * @access private
 * @todo code reuse
 */
function update_event($date, $time)
{
    global $calendardata, $username, $data_dir, $year;
    $filename = getHashedFile($username, $data_dir, "{$username}.{$year}.cal");
    $fp = fopen($filename, 'r');
    if ($fp) {
        while ($fdata = fgetcsv($fp, 4096, '|')) {
            if ($fdata[0] == $date && $fdata[1] == $time) {
                // do nothing
            } else {
                $calendardata[$fdata[0]][$fdata[1]] = array('length' => $fdata[2], 'priority' => $fdata[3], 'title' => $fdata[4], 'message' => $fdata[5], 'reminder' => $fdata[6]);
            }
        }
        fclose($fp);
    }
}
<?php

/**
 * sqspell_config.php -- SquirrelSpell Configuration file.
 *
 * Copyright (c) 1999-2006 The SquirrelMail Project Team
 * Licensed under the GNU GPL. For full terms see the file COPYING.
 *
 * @version $Id: sqspell_config.php 10633 2006-02-03 22:27:56Z jervfors $
 * @package plugins
 * @subpackage squirrelspell
 */
require_once SM_PATH . 'functions/prefs.php';
/* Just for poor wretched souls with E_ALL. :) */
global $data_dir;
sqgetGlobalVar('username', $username, SQ_SESSION);
/**
 * Example:
 *
 * $SQSPELL_APP = array( 'English' => 'ispell -a',
 *                     'Spanish' => 'ispell -d spanish -a' );
 * You can replace ispell with aspell keeping the same commandline:
 * $SQSPELL_APP = array( 'English' => 'aspell -a',
 *                     'Spanish' => 'aspell -d spanish -a' );
 */
$SQSPELL_APP = array('English' => 'ispell -a', 'Spanish' => 'ispell -d spanish -a');
$SQSPELL_APP_DEFAULT = 'English';
$SQSPELL_WORDS_FILE = getHashedFile($username, $data_dir, "{$username}.words");
$SQSPELL_EREG = 'ereg';
/**
 * Get the signature.
 */
function getSig($data_dir, $username, $number)
{
    $filename = getHashedFile($username, $data_dir, "{$username}.si{$number}");
    $sig = '';
    if (file_exists($filename)) {
        /* Open the file, or else display an error to the user. */
        if (!($file = @fopen($filename, 'r'))) {
            logout_error(sprintf(_("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename));
            exit;
        }
        while (!feof($file)) {
            $sig .= fgets($file, 1024);
        }
        fclose($file);
    }
    return $sig;
}
/**
   Create and initialize an addressbook object.
   Returns the created object
*/
function addressbook_init($showerr = true, $onlylocal = false)
{
    global $data_dir, $username, $color, $ldap_server, $address_book_global_filename;
    global $addrbook_dsn, $addrbook_table;
    // Shared file based address book globals
    global $abook_global_file, $abook_global_file_writeable, $abook_global_file_listing;
    // Shared DB based address book globals
    global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
    // Record size restriction in file based address books
    global $abook_file_line_length;
    /* Create a new addressbook object */
    $abook = new AddressBook();
    /* Create empty error message */
    $abook_init_error = '';
    /*
        Always add a local backend. We use *either* file-based *or* a
        database addressbook. If $addrbook_dsn is set, the database
        backend is used. If not, addressbooks are stores in files.
    */
    if (isset($addrbook_dsn) && !empty($addrbook_dsn)) {
        /* Database */
        if (!isset($addrbook_table) || empty($addrbook_table)) {
            $addrbook_table = 'address';
        }
        $r = $abook->add_backend('database', array('dsn' => $addrbook_dsn, 'owner' => $username, 'table' => $addrbook_table));
        if (!$r && $showerr) {
            $abook_init_error .= _("Error initializing address book database.") . ' ' . $abook->error;
        }
    } else {
        /* File */
        $filename = getHashedFile($username, $data_dir, "{$username}.abook");
        $r = $abook->add_backend('local_file', array('filename' => $filename, 'line_length' => $abook_file_line_length, 'create' => true));
        if (!$r && $showerr) {
            $abook_init_error .= sprintf(_("Error opening file %s"), $filename);
        }
    }
    /* This would be for the global addressbook */
    if (isset($abook_global_file) && isset($abook_global_file_writeable) && trim($abook_global_file) != '') {
        // Detect place of address book
        if (!preg_match("/[\\/\\\\]/", $abook_global_file)) {
            /* no path chars, address book stored in data directory
             * make sure that there is a slash between data directory
             * and address book file name
             */
            $abook_global_filename = $data_dir . (substr($data_dir, -1) != '/' ? '/' : '') . $abook_global_file;
        } elseif (preg_match("/^\\/|\\w:/", $abook_global_file)) {
            // full path is set in options (starts with slash or x:)
            $abook_global_filename = $abook_global_file;
        } else {
            $abook_global_filename = SM_PATH . $abook_global_file;
        }
        $r = $abook->add_backend('local_file', array('filename' => $abook_global_filename, 'name' => _("Global address book"), 'detect_writeable' => false, 'line_length' => $abook_file_line_length, 'writeable' => $abook_global_file_writeable, 'listing' => $abook_global_file_listing));
        if (!$r && $showerr) {
            if ($abook_init_error != '') {
                $abook_init_error .= "\n";
            }
            $abook_init_error .= _("Error initializing global address book.") . "\n" . $abook->error;
        }
    }
    /* Load global addressbook from SQL if configured */
    if (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) {
        /* Database configured */
        if (!isset($addrbook_global_table) || empty($addrbook_global_table)) {
            $addrbook_global_table = 'global_abook';
        }
        $r = $abook->add_backend('database', array('dsn' => $addrbook_global_dsn, 'owner' => 'global', 'name' => _("Global address book"), 'writeable' => $addrbook_global_writeable, 'listing' => $addrbook_global_listing, 'table' => $addrbook_global_table));
        if (!$r && $showerr) {
            if ($abook_init_error != '') {
                $abook_init_error .= "\n";
            }
            $abook_init_error .= _("Error initializing global address book.") . "\n" . $abook->error;
        }
    }
    /*
     * hook allows to include different address book backends.
     * plugins should extract $abook and $r from arguments
     * and use same add_backend commands as above functions.
     * @since 1.5.1 and 1.4.5
     */
    $hookReturn = do_hook('abook_init', $abook, $r);
    $abook = $hookReturn[1];
    $r = $hookReturn[2];
    if (!$onlylocal) {
        /* Load configured LDAP servers (if PHP has LDAP support) */
        if (isset($ldap_server) && is_array($ldap_server) && function_exists('ldap_connect')) {
            reset($ldap_server);
            while (list($undef, $param) = each($ldap_server)) {
                if (is_array($param)) {
                    $r = $abook->add_backend('ldap_server', $param);
                    if (!$r && $showerr) {
                        if ($abook_init_error != '') {
                            $abook_init_error .= "\n";
                        }
                        $abook_init_error .= sprintf(_("Error initializing LDAP server %s:") . "\n", $param['host']);
                        $abook_init_error .= $abook->error;
                    }
                }
            }
        }
    }
    // end of remote abook backends init
    /**
     * display address book init errors.
     */
    if ($abook_init_error != '' && $showerr) {
        $abook_init_error = htmlspecialchars($abook_init_error);
        error_box($abook_init_error, $color);
    }
    /* Return the initialized object */
    return $abook;
}
/**
 * Create and initialize an addressbook object.
 * @param boolean $showerr display any address book init errors. html page header
 * must be created before calling addressbook_init() with $showerr enabled.
 * @param boolean $onlylocal enable only local address book backends. Should 
 *  be used when code does not need access to remote backends. Backends
 *  that provide read only address books with limited listing options can be
 *  tagged as remote.
 * @return object address book object.
 */
function addressbook_init($showerr = true, $onlylocal = false)
{
    global $data_dir, $username, $ldap_server, $address_book_global_filename;
    global $addrbook_dsn, $addrbook_table;
    global $abook_global_file, $abook_global_file_writeable, $abook_global_file_listing;
    global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
    global $abook_file_line_length;
    /* Create a new addressbook object */
    $abook = new AddressBook();
    /* Create empty error message */
    $abook_init_error = '';
    /*
        Always add a local backend. We use *either* file-based *or* a
        database addressbook. If $addrbook_dsn is set, the database
        backend is used. If not, addressbooks are stores in files.
    */
    if (isset($addrbook_dsn) && !empty($addrbook_dsn)) {
        /* Database */
        if (!isset($addrbook_table) || empty($addrbook_table)) {
            $addrbook_table = 'address';
        }
        $r = $abook->add_backend('database', array('dsn' => $addrbook_dsn, 'owner' => $username, 'table' => $addrbook_table));
        if (!$r && $showerr) {
            $abook_init_error .= _("Error initializing address book database.") . "\n" . $abook->error;
        }
    } else {
        /* File */
        $filename = getHashedFile($username, $data_dir, "{$username}.abook");
        $r = $abook->add_backend('local_file', array('filename' => $filename, 'umask' => 077, 'line_length' => $abook_file_line_length, 'create' => true));
        if (!$r && $showerr) {
            // no need to use $abook->error, because message explains error.
            $abook_init_error .= sprintf(_("Error opening file %s"), $filename);
        }
    }
    /* Global file based addressbook */
    if (isset($abook_global_file) && isset($abook_global_file_writeable) && isset($abook_global_file_listing) && trim($abook_global_file) != '') {
        // Detect place of address book
        if (!preg_match("/[\\/\\\\]/", $abook_global_file)) {
            /* no path chars, address book stored in data directory
             * make sure that there is a slash between data directory
             * and address book file name
             */
            $abook_global_filename = $data_dir . (substr($data_dir, -1) != '/' ? '/' : '') . $abook_global_file;
        } elseif (preg_match("/^\\/|\\w:/", $abook_global_file)) {
            // full path is set in options (starts with slash or x:)
            $abook_global_filename = $abook_global_file;
        } else {
            $abook_global_filename = SM_PATH . $abook_global_file;
        }
        $r = $abook->add_backend('local_file', array('filename' => $abook_global_filename, 'name' => _("Global Address Book"), 'detect_writeable' => false, 'line_length' => $abook_file_line_length, 'writeable' => $abook_global_file_writeable, 'listing' => $abook_global_file_listing));
        /* global abook init error is not fatal. add error message and continue */
        if (!$r && $showerr) {
            if ($abook_init_error != '') {
                $abook_init_error .= "\n";
            }
            $abook_init_error .= _("Error initializing global address book.") . "\n" . $abook->error;
        }
    }
    /* Load global addressbook from SQL if configured */
    if (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) {
        /* Database configured */
        if (!isset($addrbook_global_table) || empty($addrbook_global_table)) {
            $addrbook_global_table = 'global_abook';
        }
        $r = $abook->add_backend('database', array('dsn' => $addrbook_global_dsn, 'owner' => 'global', 'name' => _("Global Address Book"), 'writeable' => $addrbook_global_writeable, 'listing' => $addrbook_global_listing, 'table' => $addrbook_global_table));
        /* global abook init error is not fatal. add error message and continue */
        if (!$r && $showerr) {
            if ($abook_init_error != '') {
                $abook_init_error .= "\n";
            }
            $abook_init_error .= _("Error initializing global address book.") . "\n" . $abook->error;
        }
    }
    /*
     * hook allows to include different address book backends.
     * plugins should extract $abook and $r from arguments
     * and use same add_backend commands as above functions.
     * Since 1.5.2 hook sends third ($onlylocal) argument to address book
     * plugins in order to allow detection of local address book init.
     * @since 1.5.1 and 1.4.5
     * Since 1.5.2, the plugin arguments are passed inside an array
     * and by reference, so plugins hooking in here need to accept arguments
     * in an array and change those values as needed instead of returning
     * the changed values.
     */
    $temp = array(&$abook, &$r, &$onlylocal);
    do_hook('abook_init', $temp);
    if (!$r && $showerr) {
        if ($abook_init_error != '') {
            $abook_init_error .= "\n";
        }
        $abook_init_error .= _("Error initializing other address books.") . "\n" . $abook->error;
    }
    /* Load configured LDAP servers (if PHP has LDAP support) */
    if (isset($ldap_server) && is_array($ldap_server)) {
        reset($ldap_server);
        while (list($undef, $param) = each($ldap_server)) {
            if (!is_array($param)) {
                continue;
            }
            /* if onlylocal is true, we only add writeable ldap servers */
            if ($onlylocal && (!isset($param['writeable']) || $param['writeable'] != true)) {
                continue;
            }
            $r = $abook->add_backend('ldap_server', $param);
            if (!$r && $showerr) {
                if ($abook_init_error != '') {
                    $abook_init_error .= "\n";
                }
                $abook_init_error .= sprintf(_("Error initializing LDAP server %s:"), $param['host']) . "\n";
                $abook_init_error .= $abook->error;
            }
        }
    }
    // end of ldap server init
    /**
     * display address book init errors.
     */
    if ($abook_init_error != '' && $showerr) {
        error_box(nl2br(sm_encode_html_special_chars($abook_init_error)));
    }
    /* Return the initialized object */
    return $abook;
}
/**
   Create and initialize an addressbook object.
   Returns the created object
*/
function addressbook_init($showerr = true, $onlylocal = false)
{
    global $data_dir, $username, $ldap_server, $address_book_global_filename;
    global $addrbook_dsn, $addrbook_table;
    global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
    /* Create a new addressbook object */
    $abook = new AddressBook();
    /*
        Always add a local backend. We use *either* file-based *or* a
        database addressbook. If $addrbook_dsn is set, the database
        backend is used. If not, addressbooks are stores in files.
    */
    if (isset($addrbook_dsn) && !empty($addrbook_dsn)) {
        /* Database */
        if (!isset($addrbook_table) || empty($addrbook_table)) {
            $addrbook_table = 'address';
        }
        $r = $abook->add_backend('database', array('dsn' => $addrbook_dsn, 'owner' => $username, 'table' => $addrbook_table));
        if (!$r && $showerr) {
            echo _("Error initializing addressbook database.");
            exit;
        }
    } else {
        /* File */
        $filename = getHashedFile($username, $data_dir, "{$username}.abook");
        $r = $abook->add_backend('local_file', array('filename' => $filename, 'create' => true));
        if (!$r && $showerr) {
            printf(_("Error opening file %s"), $filename);
            exit;
        }
    }
    /* This would be for the global addressbook */
    if (isset($address_book_global_filename)) {
        $r = $abook->add_backend('global_file');
        if (!$r && $showerr) {
            echo _("Error initializing global addressbook.");
            exit;
        }
    }
    /* Load global addressbook from SQL if configured */
    if (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) {
        /* Database configured */
        if (!isset($addrbook_global_table) || empty($addrbook_global_table)) {
            $addrbook_global_table = 'global_abook';
        }
        $r = $abook->add_backend('database', array('dsn' => $addrbook_global_dsn, 'owner' => 'global', 'name' => _("Global address book"), 'writeable' => $addrbook_global_writeable, 'listing' => $addrbook_global_listing, 'table' => $addrbook_global_table));
    }
    /*
     * hook allows to include different address book backends.
     * plugins should extract $abook and $r from arguments
     * and use same add_backend commands as above functions.
     */
    $hookReturn = do_hook('abook_init', $abook, $r);
    $abook = $hookReturn[1];
    $r = $hookReturn[2];
    if ($onlylocal) {
        return $abook;
    }
    /* Load configured LDAP servers (if PHP has LDAP support) */
    if (isset($ldap_server) && is_array($ldap_server) && function_exists('ldap_connect')) {
        reset($ldap_server);
        while (list($undef, $param) = each($ldap_server)) {
            if (is_array($param)) {
                $r = $abook->add_backend('ldap_server', $param);
                if (!$r && $showerr) {
                    printf('&nbsp;' . _("Error initializing LDAP server %s:") . "<br />\n", $param['host']);
                    echo '&nbsp;' . $abook->error;
                    exit;
                }
            }
        }
    }
    /* Return the initialized object */
    return $abook;
}
Exemple #8
0
/**
 * Save newmail plugin settings
 */
function newmail_sav_function()
{
    global $data_dir, $username, $_FILES, $newmail_uploadsounds;
    if (sqgetGlobalVar('submit_newmail', $submit, SQ_POST)) {
        $media_enable = '';
        $media_popup = '';
        $media_recent = '';
        $media_changetitle = '';
        $media_sel = '';
        $popup_width = '';
        $popup_height = '';
        sqgetGlobalVar('media_enable', $media_enable, SQ_POST);
        sqgetGlobalVar('media_popup', $media_popup, SQ_POST);
        sqgetGlobalVar('media_recent', $media_recent, SQ_POST);
        sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
        sqgetGlobalVar('popup_width', $popup_width, SQ_POST);
        sqgetGlobalVar('popup_height', $popup_height, SQ_POST);
        // sanitize height and width
        $popup_width = (int) $popup_width;
        if ($popup_width <= 0) {
            $popup_width = 200;
        }
        $popup_height = (int) $popup_height;
        if ($popup_height <= 0) {
            $popup_height = 130;
        }
        setPref($data_dir, $username, 'newmail_enable', $media_enable);
        setPref($data_dir, $username, 'newmail_popup', $media_popup);
        setPref($data_dir, $username, 'newmail_recent', $media_recent);
        setPref($data_dir, $username, 'newmail_changetitle', $media_changetitle);
        setPref($data_dir, $username, 'newmail_popup_width', $popup_width);
        setPref($data_dir, $username, 'newmail_popup_height', $popup_height);
        if (sqgetGlobalVar('newmail_unseen_notify', $newmail_unseen_notify, SQ_POST)) {
            $newmail_unseen_notify = (int) $newmail_unseen_notify;
            setPref($data_dir, $username, 'newmail_unseen_notify', $newmail_unseen_notify);
        }
        if (sqgetGlobalVar('media_sel', $media_sel, SQ_POST) && $media_sel == '(none)') {
            removePref($data_dir, $username, 'newmail_media');
        } else {
            setPref($data_dir, $username, 'newmail_media', $media_sel);
        }
        // process uploaded file
        if ($newmail_uploadsounds && isset($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['tmp_name'] != '') {
            // set temp file and get media file name
            $newmail_tempmedia = getHashedDir($username, $data_dir) . "/{$username}.tempsound";
            $newmail_mediafile = getHashedFile($username, $data_dir, $username . '.sound');
            if (move_uploaded_file($_FILES['media_file']['tmp_name'], $newmail_tempmedia)) {
                // new media file is in $newmail_tempmedia
                if (file_exists($newmail_mediafile)) {
                    unlink($newmail_mediafile);
                }
                if (!rename($newmail_tempmedia, $newmail_mediafile)) {
                    // remove (userfile), if file rename fails
                    removePref($data_dir, $username, 'newmail_media');
                } else {
                    // store media type
                    if (isset($_FILES['media_file']['type']) && isset($_FILES['media_file']['name'])) {
                        setPref($data_dir, $username, 'newmail_userfile_type', newmail_get_mediatype($_FILES['media_file']['type'], $_FILES['media_file']['name']));
                    } else {
                        removePref($data_dir, $username, 'newmail_userfile_type');
                    }
                    // store file name
                    if (isset($_FILES['media_file']['name'])) {
                        setPref($data_dir, $username, 'newmail_userfile_name', basename($_FILES['media_file']['name']));
                    } else {
                        setPref($data_dir, $username, 'newmail_userfile_name', 'mediafile.unknown');
                    }
                }
            }
        }
    }
}
Exemple #9
0
 * @package plugins
 * @subpackage newmail
 */
/**
 * Path for SquirrelMail required files.
 * @ignore
 */
require '../../include/init.php';
/** Load plugin functions */
include_once SM_PATH . 'plugins/newmail/functions.php';
sqgetGlobalVar('username', $username, SQ_SESSION);
global $data_dir;
$media = getPref($data_dir, $username, 'newmail_media', '(none)');
// get other prefs
$newmail_userfile_type = getPref($data_dir, $username, 'newmail_userfile_type', false);
$newmail_userfile_location = getHashedFile($username, $data_dir, $username . '.sound');
if ($newmail_uploadsounds && $newmail_userfile_type != false && file_exists($newmail_userfile_location)) {
    // open media file
    $newmail_userfile_handle = fopen($newmail_userfile_location, 'rb');
    if ($newmail_userfile_handle) {
        $newmail_userfile_filesize = filesize($newmail_userfile_location);
        $newmail_userfile_contents = fread($newmail_userfile_handle, $newmail_userfile_filesize);
        fclose($newmail_userfile_handle);
        // user prefs use only integer values to store file type
        switch ($newmail_userfile_type) {
            case SM_NEWMAIL_FILETYPE_WAV:
                // wav file
                $newmail_userfile_contenttype = 'audio/x-wav';
                break;
            case SM_NEWMAIL_FILETYPE_MP3:
                // mp3 file