ccHost has detected \'../cc-host-db.php\' exists. Please move this file out of the way before proceeding with visiting your current URL/path for successful installation. '); } chdir('..'); if( !empty($_REQUEST['rewritehelp']) ) get_rewrite_help(); $step = empty($_REQUEST['step']) ? '1' : $_REQUEST['step']; if( intval($step) == 4 ) { // we have to login before headers are sent do_login(); } $install_title = 'ccHost Installation'; include( dirname(__FILE__) . '/cc-install-head.php'); $stepfunc = 'step_' . $step; $stepfunc(); print(''); function step_1() { $v = split('\.',phpversion()); if( intval($v[0]) < 4 ) { $vmsg = "
It doesn't look like you're running on PHP 4, you can't run ccHost until you upgrade."; } else { $vmsg = "It looks like you're running on a supported version of PHP"; } $id3suggest = $_SERVER['DOCUMENT_ROOT'] . '/getid3'; include( dirname(__FILE__) . '/cc-install-intro.php' ); } function step_1a() { ?>

A Warning

If you have a previous installation of ccHost and you use the same database name as that previous installation, this installation script with completely and totally destroy all previous data in that database. All records of uploads and configuation will be wiped completely out.

If you're OK with that then continue...

We Ask, You Answer'); $v = get_default_values(); $f = get_install_fields($v); print_install_form($f); } function step_3() { $f = array(); $errs = ''; $ok = verify_fields($f,$errs); $ok = $ok && install_htaccess($f,$errs); $ok = $ok && install_db_config($f,$errs); $ok = $ok && install_tables($f,$errs); if( !$ok ) { print_install_form($f,$errs); return; } step_3a(); } function do_login() { cc_host_incs(); require_once( 'cchost_lib/cc-login.php' ); list($user,$pw) = CCDatabase::QueryRow('SELECT user_name,user_password FROM cc_tbl_user WHERE user_id=1',false); $lapi = new CCLogin(); $lapi->_create_login_cookie(1,$user,$pw); } function cc_host_incs() { require_once('cc-host-db.php'); require_once('cchost_lib/cc-defines.php'); require_once('cchost_lib/cc-debug.php'); require_once('cchost_lib/cc-database.php'); require_once('cchost_lib/cc-table.php'); require_once('cchost_lib/cc-config.php'); require_once('cchost_lib/cc-util.php'); if( !function_exists('gettext') ) require_once('cchost_lib/ccextras/cc-no-gettext.inc'); // ugh, ccextras } function step_4() { cc_host_incs(); $configs =& CCConfigs::GetTable(); $settings = $configs->GetConfig('settings'); $config = $configs->GetConfig('config'); $admins = split(',',$settings['admins']); $admin = $admins[0]; $ttags = $configs->GetConfig('ttag'); $root_url = $ttags['root-url']; $perms = sprintf( '%04o', $config['file-perms'] ); $rnum = rand(); $login_url = $root_url; // home page will redirect to login $html =<<Securing the Site

You must rename the /ccadmin subdirectory to anything else. ccHost won't run until you do this.

In addition it is highly recommended that you change access permissions in order to secure the site from unauthorized usage.

For example from a Unix/Linux command line you do both operations with these commands from the root of your cchost installation:

    mv ccadmin ccadmin-$rnum
    chmod 700 ccadmin-$rnum
    

For Unix/Linux In order to facilitate an easy installation, ccHost is initially configured with $perms as the default mask used when creating configuration, cache, media content and other files. You can change this in 'Global Settings' once you've logged in as administrator.

For Unix/Linux installations you should further read ccHost File Access Policy and Troubleshooting

Go forth...

If you've done those steps you can browse to $login_url (log in as "$admin" if not already) and continue with the installation.

EOF; print($html); } function step_3a() { $v['file_uploads']['v'] = ini_get('file_uploads'); $v['file_uploads']['s'] = 'On (1)'; $v['file_uploads']['m'] = 'This is required to be On to allow uploads'; $v['file_uploads']['k'] = ($v['file_uploads']['v'] && ($v['file_uploads']['v'] != 'Off')); $v['file_uploads']['i'] = ' '; $v['upload_max_filesize']['v'] = ini_get('upload_max_filesize'); $v['upload_max_filesize']['s'] = '10M'; $v['upload_max_filesize']['m'] = 'Determines the overall maximum file upload size. (Typical MP3 song is encoded at 1M per minute.)'; preg_match('/([0-9]*)/',$v['upload_max_filesize']['v'],$m); $i = intval($m[1]); $v['upload_max_filesize']['i'] = $i; $v['upload_max_filesize']['k'] = $i < 10 ? false : true; $v['post_max_size']['v'] = ini_get('post_max_size'); $v['post_max_size']['s'] = '10M'; $v['post_max_size']['m'] = 'Determines the maximum file upload size from an HTML form.'; preg_match('/([0-9]*)/',$v['post_max_size']['v'],$m); $i = intval($m[1]); $v['post_max_size']['k'] = $i < 10 ? false : true; $v['post_max_size']['i'] = $i; $v['memory_limit']['v'] = ini_get('memory_limit'); $v['memory_limit']['s'] = '25'; if( $v['memory_limit']['v'] ) { $v['memory_limit']['m'] = 'Dealing with large file can consume a lot of memory, being too stingy can have adverse affects.'; preg_match('/([0-9]*)/',$v['memory_limit']['v'],$m); $i = intval($m[1]); $v['memory_limit']['k'] = $i < 25 ? false : true; $v['memory_limit']['i'] = $i; } else { $v['memory_limit']['m'] = 'It looks as though your installation of PHP is not compiled to use this setting.'; $v['memory_limit']['k'] = 1; $v['memory_limit']['i'] = ''; } $v['max_execution_time']['v'] = ini_get('max_execution_time'); $v['max_execution_time']['s'] = '120'; $v['max_execution_time']['m'] = 'Number of seconds a script will execute before aborting. You have to allow for users who upload large files over slow connections.'; $i = intval($v['max_execution_time']['v']); $v['max_execution_time']['i'] = $i; $v['max_execution_time']['k'] = $i < 120 ? false : true; $v['max_input_time']['v'] = ini_get('max_input_time'); $v['max_input_time']['s'] = '-1'; $v['max_input_time']['m'] = 'Number of seconds a form\'s script will execute before aborting. You have to allow for users who upload large files over slow connections. (setting to -1 allows unlimited time)'; $i = intval($v['max_input_time']['v']); $v['max_input_time']['i'] = $i; $v['max_input_time']['k'] = ($i > -1) && ($i < 120) ? false : true; ?>

Setting up your PHP environment

There are several things you should know about uploading files to a PHP environment.

The default settings for a PHP install may not be the ideal. A list of all PHP settings, where they can be changed and what version they apply to can be found here.

Below are some settings you should be aware of. You might want to print or save this page for future reference.

$ini_location."; } else { $inimsg = 'These can be updated in your php.ini file; on gentoo this is located at: /etc/php/apache2-php4/php.ini'; } $inimsg =<<$inimsg

If you do not have access to the global php.ini you can create one with just these settings and place in them $local_ini

EOF; print $inimsg; ?> $d ) { $html .= "
Setting NameDescriptionCurrent
Value
Suggested
Value
$n{$d['m']}

You're almost done, there's one more step...

"); return true; } $msg = "You already have an existing .htaccess file. 'Pretty URLs' has been disabled. You may enable it later in ccHost.
"; print($msg); $f['pretty_urls']['v'] = ""; } else { $fh = @fopen($fname,'w+'); if( !$fh ) { $err = "Could not open a .htaccess file for writing in ccHost directory."; $f['pretty_urls']['v'] = ""; } else { if( fwrite($fh,$text) === false ) { $err = "Could not write to .htaccess file in ccHost directory. Please make sure the directory is writable and try again."; $f['pretty_urls']['v'] = ""; } fclose($fh); if( empty($err) ) { chmod($fname, 0777); // cc_default_file_perms()); print(".htaccess written for Pretty URLs
"); } } } return( empty($err) ); } function install_tables(&$f,&$errs) { cc_host_incs(); require_once( 'cchost_lib/cc-pools.php' ); require_once( dirname(__FILE__) . '/cc-install-db.php'); require_once( 'cchost_lib/cc-lics-install.php'); CCDebug::Enable(true) ; $local_base_dir = $f['localdir']['v']; install_local_files($local_base_dir); print "Local files installed to {$local_base_dir}/*
"; if( !cc_install_tables($f,$errs,$local_base_dir) ) return(false); print "Created tables
"; cc_install_licenses(); print "Licenses installed
"; $pw = md5( $f['pw']['v'] ); $user = $f['admin']['v']; $date = date('Y-m-d H:i:00'); $email = $f['admin-email']['v']; $sql =<<"; return( true ); } function install_local_files($local_dir) { foreach( array( 'content', $local_dir, $local_dir . '/pages', $local_dir . '/skins', $local_dir . '/images', $local_dir . '/skins/extras', $local_dir . '/dataviews', $local_dir . '/lib', $local_dir . '/temp', ) as $locdir ) { // is it right to disable warning here? if( !@mkdir( $locdir ) ) { if( !file_exists($locdir) ) { print("error with making: $locdir
"); exit; } chmod( $locdir, 0777 ); } } $htaccess =<< order deny,allow deny from all EOF; $f = fopen( $local_dir . '/temp/.htaccess', 'w' ); fwrite($f,$htaccess); fclose($f); docopy( 'home.php', $local_dir, 'pages'); docopy( 'news.php', $local_dir, 'pages'); docopy( 'welcome.php', $local_dir, 'pages'); docopy( 'DEBUG.php', $local_dir, 'lib'); docopy( 'extras_links.tpl', $local_dir, 'skins/extras'); docopy( 'person.png', $local_dir, 'images'); docopy( 'submit-remix.gif', $local_dir, 'images'); docopy( 'submit-sample.gif', $local_dir, 'images'); docopy( 'submit-original.gif', $local_dir, 'images'); docopy( 'error-msg.txt', $local_dir, ''); docopy( 'disabled-msg.txt', $local_dir, ''); } function docopy($file,$local_dir,$subdir,$do_chmod=true) { $src = dirname( __FILE__ ) . '/' . $file; if( $subdir ) $local_dir .= '/' . $subdir; $dest = $local_dir . '/' . $file; if( file_exists($src) && !file_exists($dest) ) { copy( $src, $dest); if( $do_chmod ) chmod( $dest, 0777 ); } } function clean_post() { if( get_magic_quotes_gpc() == 1 ) { $keys = array_keys($_POST); $c = count($keys); for( $i = 0; $i < $c; $i++ ) $_POST[$keys[$i]] = trim(stripslashes( $_POST[$keys[$i]] )); } } function verify_fields(&$f,&$errs) { clean_post(); $f = get_install_fields($_POST); $ok = true; foreach( $f as $id => $data ) { if( empty($f[$id]['v']) && $f[$id]['q'] ) { $ok = false; $f[$id]['e'] = 'Must be filled in:'; } } verify_password($f,$ok); verify_mysql($f,$ok); verify_getid3($f,$ok); verify_localdirs($f,$ok); $f['rooturl']['v'] = empty($f['rooturl']['v']) ? '' : check_dir($f['rooturl']['v'], true); $f['getid3']['v'] = empty($f['getid3']['v']) ? '' : check_dir($f['getid3']['v'], false); $f['logfile_dir']['v'] = empty($f['logfile_dir']['v']) ? '' : check_dir($f['logfile_dir']['v'], true); if( !$ok ) $errs = 'There were problems, please correct them below'; return($ok); } function verify_localdirs(&$f,&$ok) { $local_dir = $f['localdir']['v']; if( !file_exists($local_dir) ) { if( !@mkdir( $local_dir ) ) { $f['localdir']['e'] = 'Error creating directory'; $ok = false; return; } } if( !@chmod( $local_dir, 0777 ) ) { $f['localdir']['e'] = 'Error changing permissions'; $ok = false; return; } $writable = is_writeable($local_dir); if( $writable ) { $rand = $local_dir . '/test_' . rand(); $fh = @fopen($rand,'w'); if( $fh ) { if( !@fwrite($fh,'hello') ) { $writable = false; } fclose($fh); if( !@chmod( $rand, 0777 ) ) { $f['localdir']['e'] = 'Error changing file permissions'; $ok = false; } unlink($rand); } else { $writable = false; } } if( $ok && !$writable ) { $f['localdir']['e'] = 'Error: could not write to directory'; $ok = false; } } function verify_password(&$f,&$ok) { $value = $f['pw']['v']; if( strlen($value) < 5 ) { $f['pw']['e'] = "Must be at least 5 characters"; $ok = false; } if( preg_match('/[^A-Za-z0-9]/', $value) ) { $f['pw']['e'] = "Must letters or numbers"; $ok = false; } } function verify_getid3(&$f,&$ok) { if( !empty($f['getid3']['v'] ) ) { $dir = check_dir($f['getid3']['v'],false); if( !file_exists($dir) ) { $ok = false; $f['getid3']['e'] = "GetID3 directory ($dir) does not exist"; } elseif( !file_exists( $dir . '/getid3.php' ) ) { $f['getid3']['e'] = "Can't find getid3.php in " . $dir; } } } function verify_mysql(&$f, &$ok) { $link = 0; if( !empty($f['dbuser']['v'] ) && !empty($f['dbpw']['v']) ) { if( !function_exists('mysql_connect') ) { $url = "http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.php5"; $f['database']['e'] = "MySQL does not seem to be installed into PHP
The problem might be related to". " this, or you might need to enable it as an extension in your settings file, php.ini"; $ok = false; } else { $link = @mysql_connect( $f['dbserver']['v'], $f['dbuser']['v'], $f['dbpw']['v'] ); if( !$link ) { $f['dbuser']['e'] = 'MySQL Error: ' . mysql_error() . " for CONNECT"; $ok = false; } } } if( $link && !empty($f['database']['v']) ) { if( !@mysql_select_db($f['database']['v']) ) { $f['database']['e'] = "MySQL Error: " . mysql_error() . " for SELECT"; $ok = false; } else { if( !mysql_query("CREATE TABLE table_test ( test_column int(1) )") ) { $ok = false; $f['database']['e'] = "MySQL Error: " . mysql_error() . " for CREATE."; } else { $table_ok = false; $qr = mysql_query("SHOW TABLES"); $row = mysql_fetch_row($qr); if( !empty($row[0]) ) { $qr = mysql_query("DESCRIBE table_test"); $row = mysql_fetch_row($qr); $ok = $table_ok = $row[0] == 'test_column'; } if( !$table_ok ) { $f['database']['e'] = "Error creating tables: " . mysql_error(); } mysql_query("DROP TABLE table_test"); } } } if( $link ) @mysql_close($link); } function check_dir($dir,$slash_required) { $dir = str_replace('\\','/',$dir); if( preg_match('#^(.*)/$#',$dir,$m) ) { if( $slash_required ) return($dir); return( $m[1] ); } if( $slash_required ) return( $dir . '/' ); return( $dir ); } function get_default_values() { $v['getid3'] = route_around('getid3'); if( !file_exists($v['getid3'] . '/getid3.php') ) if( file_exists($v['getid3'] . '/getid3/getid3.php') ) $v['getid3'] .= '/getid3'; $v['sitename'] = 'ccHost - ' . $_SERVER['HTTP_HOST']; $v['cookiedom'] = ''; $v['rooturl'] = 'http://' . $_SERVER['HTTP_HOST'] . get_script_base(); $v['dbserver'] = 'localhost'; $v['admin'] = 'admin'; $v['site-description'] = 'Download, Sample, Cut-up, Share.'; $v['localdir'] = get_local_base_dir(); return($v); } function get_script_base() { $me = $_SERVER['REQUEST_URI']; if( !empty($me) ) { if( preg_match( '%^(.+/)[^/]+/(\?.*)?$%', $me, $m ) ) { $base = $m[1]; } } if( empty($base) ) $base = '/'; return $base; } function get_php_ini_location() { ob_start(); phpinfo(); $info = ob_get_contents(); ob_end_clean(); preg_match( '#(?:>|=> )+([^\s]+php\.ini)#', $info, $m ); if( !empty($m[1]) ) return $m[1]; return ''; } function get_cchost_local_root() { $dir = dirname(dirname(__FILE__)); return $dir; } function get_local_base_dir() { $short_name = ''; if( !empty($_SERVER['HTTP_HOST']) && ($_SERVER['HTTP_HOST'] != 'localhost') && preg_match( '#^([^\.]+)\.?([^\.]+)?#', $_SERVER['HTTP_HOST'], $m ) ) { $short_name = $m[1] == 'www' ? (empty($m[2]) ? $m[0] : $m[2]) : $m[1]; } else { $short_name = 'local'; } $short_name .= '_files'; $i = 0; $short_base = $short_name; while( file_exists($short_name) ) { $short_name = $short_base . ++$i; } return $short_name; } function get_rewrite_help() { $sbase = get_script_base(); $local_root = get_cchost_local_root(); $pretty_help =<< All ccHost URLs look something like:
http://example.com/cchost/?ccm=/media/people/rejon
The '?ccm=/' in the middle of that is considered 'ugly.' The 'pretty' version would like:
http://example.com/cchost/media/people/rejon
If you are running on Apache you can use Rewrite rules ('pretty URLs') to have that. If you enable Rewrite rules we will try to write the file $local_root/.htaccess and include the following lines:
RewriteEngine On RewriteBase $sbase RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ {$sbase}index.php?ccm=/$1 [L,QSA]
Optionally if you have access to your global Apache configuration files you can add the following instead:
<Directory "$local_root"> RewriteEngine On RewriteBase $sbase RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ {$sbase}index.php?ccm=/$1 [L,QSA] </Directory>
This method is preferred for performance reasons but you'll need to restart Apache in order for this version to take effect. EOF; print $pretty_help; exit; } function get_install_fields($values) { $sbase = get_script_base(); $local_root = get_cchost_local_root(); // n - Name // t - Input type (see print_install_form()) // e - Error (filled in at _POST) // v - Value // q - Required (1 = yes, 0 = no) // h - Help hint $f = array( 'sitename' => array( 'n' => 'Site Name', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 0, 'h' => 'The name of your site' ), 'site-description' => array( 'n' => 'Site Description', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 0, 'h' => 'A short tag-line for the site' ), 'rooturl' => array( 'n' => 'Root URL', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 1, 'h' => 'The URL of your main installation' ), 'localdir' => array( 'n' => 'Your files root', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 1, 'h' => 'Directory where we put files specific to your site.' ), 'pretty_urls' => array( 'n' => 'Use \'pretty URLs\'', 'e' => '', 't' => 'checkbox', 'v' => '' , 'q' => 0, 'h' => "What's this?" ), 'admin' => array( 'n' => 'Admin name', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 1, 'h' => 'A ccHost account will be created with this name' ), 'pw' => array( 'n' => 'Admin password', 'e' => '', 't' => 'password', 'v' => '' , 'q' => 1, 'h' => '(Remember this, you\'ll need it. Must be at least 5 characters long, letters and numbers only.)' ), 'admin-email' => array( 'n' => 'Site email', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 1, 'h' => 'Default return address when ccHost sends email ' ), 'database' => array( 'n' => 'Database name', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 1, 'h' => 'Name of the mySQL database to use (this must exist already)' ), 'dbuser' => array( 'n' => 'Database user', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 1, 'h' => 'mySQL account name to use to access the database' ), 'dbpw' => array( 'n' => 'Database password', 'e' => '', 't' => 'password', 'v' => '' , 'q' => 1, 'h' => 'Password for the mySQL database account ' ), 'dbserver' => array( 'n' => 'Database server', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 1, 'h' => 'Almost always \'localhost\' unless your hosting service told you otherwise' ), 'logfile_dir' => array( 'n' => 'Path to ccHost logfiles', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 0, 'h' => 'Where should ccHost write log files to? (e.g. \'/var/log/cchost\') - This directory MUST exists.' ), 'getid3' => array( 'n' => 'Path to GetID3', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 0, 'h' => "Root directory of GetID3 Library (the one with " . "getid3.php in it, e.g. '$local_root/getid3/getid3')" ), 'cookiedom' => array( 'n' => 'Cookie Domain', 'e' => '', 't' => 'text', 'v' => '' , 'q' => 0, 'h' => 'Leaving this blank is fine (and even necessary in many configurations)'), ); foreach($values as $n => $v ) { $f[$n]['v'] = $v; } return($f); } function print_install_form($f,$err='') { $fields = ''; foreach( $f as $id => $data ) { if( $data['t'] == 'static' ) { $fields .= "". "{$data['v']}\n"; continue; } $required = $data['q'] ? '*' : ''; if( $data['e'] ) $fields .= "{$data['e']}\n"; $fields .= "$required{$data['n']}:
{$data['h']}
". " $fields
Fields marked '*' are required
END; print($html); } function install_db_config($f,&$err) { $varname = "\$CC_DB_CONFIG"; $text = " '{$f['database']['v']}', 'db-server' => '{$f['dbserver']['v']}', 'db-user' => '{$f['dbuser']['v']}', 'db-password' => '{$f['dbpw']['v']}', ); END; $text .= "?>"; $err = ''; $fname = 'cc-host-db.php'; $fh = @fopen($fname,'w+'); if( !$fh ) { $err = "Could not open a configuration file for writing in ccHost directory. Please make sure the directory is writable and try again."; } else { if( fwrite($fh,$text) === false ) { $err = "Could not write to configuration file in ccHost directory. Please make sure the directory is writable and try again."; } fclose($fh); } if( !$err ) { chmod($fname, 0777); // cc_default_file_perms()); print("Database config written
"); } return( empty($err) ); } function route_around($dir) { if( file_exists($dir) ) return($dir); if( file_exists( '../' . $dir ) ) return( realpath( '../' . $dir ) ); if( file_exists( '../../' . $dir ) ) return( realpath( '../../' . $dir ) ); return( null ); } ?>