Subversion Repositories travelsized

Rev

Rev 450 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?PHP
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of Travelsized CMS
 *              A content management system with modules, based on wiki syntax
 *
 * Author: Dan Jensen <admin@leinir.dk>
 * Copyright 2003/2004
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License is available at: http://www.gnu.org/copyleft/
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


$page_author = $creator_name;
$page_author_email = $creator_email;
$page_menu = 1;
$page_date = formatTime( time() );
$page_title = i18n("System options");

/**
 * Function by greg _at_ rhythmicdesign d.o.t com in the PHP manual
 */

function recurse_chown_chgrp($mypath, $uid, $gid)
{
        $d = opendir ($mypath) ;
        while(($file = readdir($d)) !== false)
        {
                if ($file != "." && $file != "..")
                {
                        $typepath = $mypath . "/" . $file;
       
                        //print $typepath. " : " . filetype ($typepath). "<BR>" ;
                        if (filetype ($typepath) == 'dir')
                                recurse_chown_chgrp ($typepath, $uid, $gid);
                       
                        chown($typepath, $uid);
                        chgrp($typepath, $gid);
                }
        }

}

function chmodRecursive($mypath, $filePermission, $dirPermission)
{
        $d = opendir( $mypath );
        while( ( $file = readdir( $d ) ) !== false )
        {
                if( $file != "." && $file != ".." )
                {
                        $typepath = $mypath . "/" . $file;
       
                        //print $typepath. " : " . filetype ($typepath). "<BR>" ;
                        if (filetype ($typepath) == 'dir')
                        {
                                chmod( $typepath, $dirPermission );
                                chmodRecursive( $typepath, $filePermission, $dirPermission );
                        }
                        else
                                chmod( $typepath, $filePermission );
                }
        }

}

function systemOptionsLockdownUnlock()
{
        global $systemOptions, $setup_folder;
       
        if( $systemOptions["locked"] == 1 )
        {
                $filePermission = 0600;
                $dirPermission = 0700;
        }
        else
        {
                $filePermission = 0666;
                $dirPermission = 0777;
        }
       
        // Fix ownership
        recurse_chown_chgrp( $setup_folder, posix_getuid(), posix_getgid() );
       
        // Fix permissions
        chmodRecursive( $setup_folder, $filePermission, $dirPermission );
}

function saveSystemOptions()
{
        global $setup_folder, $systemOptions;
       
        if( file_exists( "$setup_folder/systemOptions.php" ) )
                unlink( "$setup_folder/systemOptions.php" );
       
        fileSave( "$setup_folder/systemOptions.php", array_export( $systemOptions, "systemOptions" ) );
}

if( ! isAllowed("global_admin") )
        $page_content = loginform($language, globalIDtoURL( "setup/options" ), $auth_messages);
else
{
        // System options
       
        $systemOptionsPanel = new optionsPanel( "options" );
       
        $systemOptionsPanel->addOption(
                        i18n("Locked down"),
                        i18n("Check this to lock the system down. This is the default option. If you unlock the system, it means that everybody on the server can view the files. Locked down gives only owner read/write rights, while unlocked means that the files are read and write enabled for all. Use this for site migration and emergencies only!"),
                        $systemOptions["locked"],
                        "locked",
                        "checkbox"
                        );
        $systemOptionsPanel->addOption(
                        i18n("Default time format"),
                        i18n("The format used by Travelsized to format dates, if the user has not set one manually. Set this using the format found in ##0##date section of the PHP manual##1##", array( "<a href=\"http://php.net/date\" target=\"_top\">", "</a>" ) ),
                        $systemOptions["timeformat"],
                        "timeformat",
                        "text"
                        );
        $systemOptionsPanel->addOption(
                        i18n("Enable pretty URLs"),
                        i18n("Use pretty URLs for links on the website"),
                        $systemOptions["rewrite"],
                        "rewrite",
                        "checkbox"
                        );
        $systemOptionsPanel->addOption(
                        i18n("Human readable URLs"),
                        i18n("If using pretty URLs, the addresses will be shown with their full human readable name in stead of the page ID."),
                        $systemOptions["humanurls"],
                        "humanurls",
                        "checkbox"
                        );
        $systemOptionsPanel->addOption(
                        i18n("Hide external link hint"),
                        i18n("Hide the hint image normally shown on external links"),
                        $systemOptions["hideexternalhint"],
                        "hideexternalhint",
                        "checkbox"
                        );
        $systemOptionsPanel->addOption(
                        i18n("Permission messages"),
                        i18n("Show a message describing why a user is unable to perform a certain action."),
                        $systemOptions["permissionmessages"],
                        "permissionmessages",
                        "checkbox"
                        );
       
        if( ini_get( "safe_mode" ) == true )
        {
                $systemOptionsPanel->addHeader( i18n("FTP Account (required for PHP Safe Mode)"), "ftp_stuff" );
               
                $systemOptionsPanel->addOption(
                                i18n("Host name"),
                                i18n("The host name for the FTP server. For example ftp.myhost.com or web3.somewhere.com"),
                                $systemOptions["ftp_host"],
                                "ftp_host",
                                "text"
                                );

                $systemOptionsPanel->addOption(
                                i18n("Port"),
                                i18n("The port used to connect to the ftp server. Normally this will be 21"),
                                $systemOptions["ftp_port"],
                                "ftp_port",
                                "text"
                                );

                $systemOptionsPanel->addOption(
                                i18n("Home directory"),
                                i18n("Where is Travelsized placed on the FTP server? This must be the absolute path. For example /home/user/public_html/some.org/ or /sites/www.somewhere.com/"),
                                $systemOptions["ftp_dir"],
                                "ftp_dir",
                                "text"
                                );

                $systemOptionsPanel->addOption(
                                i18n("Username"),
                                i18n("The username for the ftp server"),
                                $systemOptions["ftp_user"],
                                "ftp_user",
                                "text"
                                );

                $systemOptionsPanel->addOption(
                                i18n("Password"),
                                i18n("The password for the ftp server"),
                                $systemOptions["ftp_password"],
                                "ftp_password",
                                "password"
                                );
        }
       
        if( $systemOptionsPanel->submitted )
        {
                $newLocked = $systemOptionsPanel->getValue("locked") ? 1 : 0;
                $systemOptions["timeformat"] = $systemOptionsPanel->getValue("timeformat");
                $systemOptions["rewrite"] = $systemOptionsPanel->getValue("rewrite") ? 1 : 0;
                $systemOptions["humanurls"] = $systemOptionsPanel->getValue("humanurls") ? 1 : 0;
                $systemOptions["hideexternalhint"] = $systemOptionsPanel->getValue("hideexternalhint") ? 1 : 0;
                $systemOptions["permissionmessages"] = $systemOptionsPanel->getValue("permissionmessages") ? 1 : 0;
               
                $systemOptions["ftp_host"] = $systemOptionsPanel->getValue("ftp_host");
                $systemOptions["ftp_port"] = ((int)$systemOptionsPanel->getValue("ftp_port") == 0) ? 21 : (int)$systemOptionsPanel->getValue("ftp_port");
                $systemOptions["ftp_dir"] = $systemOptionsPanel->getValue("ftp_dir");
                $systemOptions["ftp_user"] = $systemOptionsPanel->getValue("ftp_user");
                $systemOptions["ftp_password"] = $systemOptionsPanel->getValue("ftp_password");
               
                saveSystemOptions();
               
                if( $systemOptions["locked"] != $newLocked )
                {
                        $systemOptions["locked"] = $newLocked;
                        saveSystemOptions();
                        systemOptionsLockdownUnlock();
                }
               
        }

        $setupPage = new setupPage;
        $setupPage->addBreadcrumb( i18n("System options"), globalIDtoURL( "setup/options" ) );
        $setupPage->contents =  $systemOptionsPanel->render();
        $page_content = "<form action=\"" . thisPageURL() . "\" method=\"POST\">" . $setupPage->render() . "</form>";
}
?>