$value) { $output_indexed[] = json_encode($value); $output_associative[] = json_encode($key) . ':' . json_encode($value); if ($output_index_count !== NULL && $output_index_count++ !== $key) { $output_index_count = NULL; } } if ($output_index_count !== NULL) { return '[' . implode(',', $output_indexed) . ']'; } else { return '{' . implode(',', $output_associative) . '}'; } default: return ''; // Not supported } } } function delete_files($path, $del_dir = FALSE, $level = 0) { // Trim the trailing slash $path = rtrim($path, DIRECTORY_SEPARATOR); if ( ! $current_dir = @opendir($path)) { return FALSE; } while (FALSE !== ($filename = @readdir($current_dir))) { if ($filename != "." and $filename != "..") { if (is_dir($path.DIRECTORY_SEPARATOR.$filename)) { // Ignore empty folders if (substr($filename, 0, 1) != '.') { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1); } } else { unlink($path.DIRECTORY_SEPARATOR.$filename); } } } @closedir($current_dir); if ($del_dir == TRUE AND $level > 0) { return @rmdir($path); } return TRUE; } function download($f, $to, $test = false) { $error = false; if (in_array('curl', get_loaded_extensions())) { $cp = curl_init($f); $fp = fopen($to, "w+"); if (!$fp) { curl_close($cp); $error = 'perms'; } else { curl_setopt($cp, CURLOPT_FILE, $fp); curl_setopt($cp, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($cp, CURLOPT_FOLLOWLOCATION, true); curl_setopt($cp, CURLOPT_SSL_VERIFYPEER, false); if (curl_exec($cp) === false) { fclose($fp); @unlink($to); $error = curl_error($cp); } else { fclose($fp); } curl_close($cp); } } else { $error = 'extensions'; } return array( file_exists($to) && filesize($to) > 0, $error); } function extract_callback($p_event, &$p_header) { $current_dir = dirname(__FILE__); $current_perms = substr(sprintf('%o', fileperms($current_dir)), -4); if ($current_perms < 755) { $current_perms = '0755'; } chmod($current_dir . DIRECTORY_SEPARATOR . $p_header['filename'], octdec($current_perms)); return 1; } if (isset($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], '/json') === 0) { die(json_encode(array('success' => true))); } if ($_POST) { if (isset($_POST['database_check'])) { $host = urldecode($_POST['host']); $user = urldecode($_POST['user']); $password = urldecode($_POST['password']); $name = urldecode($_POST['name']); $tmp_table = urldecode($_POST['prefix']) . 'applications'; $db_error = false; $create = $alter = false; $data = array(); if (function_exists('mysqli_connect') && strpos($host, ':') === false) { $data['driver'] = 'mysqli'; $host_bits = explode(':', $host); if (count($host_bits)) { $host = $host_bits[0]; if (is_numeric($host_bits[1])) { $host = urldecode($_POST['host']); $socket = null; } else { $socket = $host_bits[1]; } } else { $socket = null; } $link = mysqli_connect($host, $user, $password, $name, null, $socket); if (!$link) { $data['error'] = mysqli_connect_error(); $link = mysqli_connect('localhost', $user, $password, $name); if ($link) { $host = 'localhost'; unset($data['error']); } } if ($link) { $info = mysqli_get_server_info($link); $create = mysqli_query($link, "CREATE TABLE $tmp_table (a INT)"); if ($create) { $alter = mysqli_query($link, "ALTER TABLE $tmp_table ADD b INT(10)"); if (!$alter) { $db_error = mysqli_error($link); } } else { $db_error = mysqli_error($link); } if ($create && !mysqli_query($link, "DROP TABLE $tmp_table")) { $db_error = mysqli_error($link); } } } else if (function_exists('mysql_connect')) { $data['driver'] = 'mysql'; $link = mysql_connect($host, $user, $password); if (!$link) { $data['error'] = mysql_error($link); $link = mysql_connect('localhost', $user, $password); if ($link) { $host = 'localhost'; unset($data['error']); } } if ($link && !mysql_select_db($name, $link)) { $data['error'] = mysql_error($link); } else { $info = mysql_get_server_info(); $create = mysql_query("CREATE TABLE $tmp_table (a INT)"); if ($create) { $alter = mysql_query("ALTER TABLE $tmp_table ADD b INT(10)"); if (!$alter) { $db_error = mysql_error($link); } } else { $db_error = mysql_error($link); } if ($create && !mysql_query("DROP TABLE $tmp_table")) { $db_error = mysql_error($link); } } } else { $data['error'] = 'Koken requires the mysql client library (not mysqli) in order to connect via socket.'; } if (isset($info)) { // Strip a-log and other stuff from end of MySQL version info $info = preg_replace('/[a-z\-]/', '', $info); if (version_compare($info, '4.1.0', '<')) { $data['error'] = "Koken requires MySQL 4.1 or higher. You're server is running MySQL $info. Contact your host to see if a more up to date version is available."; } else if ($db_error) { if (strpos($db_error, 'already exists') !== -1) { $data['error'] = "This database already contains an installation of Koken. If you'd like to install another copy in this database, click the \"Advanced options\" link below and change the table prefix."; } else { $data['error'] = 'This MySQL user has insufficient permissions. Koken requires SELECT, UPDATE, CREATE, DELETE, ALTER and DROP permissions on this database. MySQL returned this error: ' . $db_error; } } } $data['host'] = $host; } else if ($_POST['server_test']) { $current_dir = dirname(__FILE__); $writable = is_writable($current_dir) && is_writable(__FILE__); list($download, $download_error) = download('https://s3.amazonaws.com/install.koken.me/releases/pclzip.lib.txt', 'pclzip.lib.php'); $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $imagick = in_array('imagick', get_loaded_extensions()) && class_exists('Imagick'); $php = $connection = $permissions = $im = $browser = array( 'warn' => array(), 'fail' => array() ); if (!$has_json) { $php['fail'][] = 'Koken requires that PHP be built with the JSON extension. Contact your host or system administrator for help with installing the JSON extension.'; } if (version_compare(PHP_VERSION, '5.3.0', '<')) { $php['fail'][] = "Koken requires PHP 5.3.0 or higher. Your server is running " . PHP_VERSION . '.'; } // Safe mode completely removed in PHP 5.4, so only check PHP installs earlier than that. if (version_compare(PHP_VERSION, '5.4.0', '<') && (ini_get('safe_mode') === true || ini_get('safe_mode') === 1 || ini_get('safe_mode') === '1' || strtolower(ini_get('safe_mode')) === 'on')) { $php['fail'][] = "Koken is incompatible with PHP's safe_mode. Ask your host or system administrator to disable safe_mode in PHP's configuration."; } if (!function_exists('gzopen')) { $php['fail'][] = 'Koken requires zlib library support in PHP to be enabled before installing. Check with your web host or system administrator for more information.'; } if ( strpos($ua, 'msie') !== false || strpos($ua, 'internet explorer') !== false) { $browser['fail'][] = 'The Koken beta does not currently support Internet Explorer. Please use Chrome, Safari or Firefox.'; } if (!in_array('mysql', get_loaded_extensions()) && !in_array('mysqli', get_loaded_extensions())) { $php['fail'][] = 'Koken requires either the mysql or mysqli PHP extension to be installed and enabled.'; } if (isset($_SERVER['ACCESS_DOMAIN']) && strpos($_SERVER['ACCESS_DOMAIN'], 'gridserver.com') !== false && getenv('FCGI_ROLE')) { $htaccess = << 0) { if (!$writable || (!$download && $download_error === 'perms')) { $permissions['fail'][] = 'This directory does not have the necessary permissions to perform the install. Set the permissions on the koken folder and the koken/index.php file to 777.'; } else if (!$download && $download_error === 'extensions') { $php['fail'][] = 'Koken requires the cURL extension to be enabled in PHP. Consult with your host and modify your server configuration to enable the cURL extension.'; } else if (!$download) { $connection['fail'][] = 'Koken cannot download the necessary files from install.koken.me. Check with your host to see if they are limiting outgoing connections and if so, have them open a path to install.koken.me.' . ( $download_error ? " Error: $download_error" : '' ); } } if (count($php['fail']) > 0) { $permissions['warn'][] = 'Permissions can not be tested until the above PHP requirements are met.'; $connection['warn'][] = 'Connections can not be tested until the above PHP requirements are met.'; } $disabled_functions = explode(',', str_replace(' ', '', ini_get('disable_functions'))); if (ini_get('suhosin.executor.func.blacklist')) { $disabled_functions = array_merge($disabled_functions, explode(',', str_replace(' ', '', ini_get('suhosin.executor.func.blacklist')))); } if (!$imagick && (!is_callable('exec') || in_array('exec', $disabled_functions))) { if (in_array('gd', get_loaded_extensions())) { $magick_path = 'gd'; } else { $im['fail'][] = "Koken requires either the GD library, the 'imagick' PECL extension, ImageMagick, or GraphicsMagick in order to process images. Ask your host to enable one of those options before continuing installation."; } } else if (!$imagick) { $common_magick_paths = array( '$PATH', '/usr/bin', '/usr/local/bin', '/usr/local/sbin', '/bin', '/opt/local/bin', '/opt/ImageMagick/bin', '/usr/local/ImageMagick/bin' ); if (isset($_POST['custom_magick_path']) && !empty($_POST['custom_magick_path'])) { $common_magick_paths[] = $_POST['custom_magick_path']; } $magick_path = false; $magicks = array(); $gmagick_path = false; $gmagicks = array(); foreach($common_magick_paths as $path) { if ($path === '$PATH') { $path = 'convert'; } else if (!preg_match("/\/convert$/", $path) && strpos('\\', $path) === false) { $path = rtrim($path, '/') . '/convert'; } $out = ''; exec($path . ' -version', $out); $test = $out[0]; if (!empty($test) && preg_match('/\d+\.\d+\.\d+/', $test, $matches)) { $magicks[] = array('path' => $path, 'version' => $matches[0]); } $gpath = str_replace('convert', 'gm convert', str_replace('ImageMagick', 'GraphicsMagick', $path)); exec($gpath . ' -version', $gout); $gtest = $gout[0]; if (!empty($gtest) && preg_match('/\d+\.\d+\.\d+/', $gtest, $gmatches)) { $gmagicks[] = array('path' => $gpath, 'version' => $gmatches[0]); } } if (empty($magicks) && empty($gmagicks)) { if (in_array('gd', get_loaded_extensions())) { $magick_path = 'gd'; } else { $im['fail'][] = 'Koken cannot locate the GD, ImageMagick, or GraphicsMagick library on your server.

We looked for ImageMagick and GraphicsMagick in the following locations: ' . join(', ', $common_magick_paths) . '.

Ask your host for the path to ImageMagick or GraphicsMagick on your server and enter it below.'; } } else { function top_magick_lib($arr) { $top = array_shift($arr); foreach($arr as $m) { if (version_compare($m['version'], $top['version']) > 0) { $top = $m; } } return $top; } $top_im = top_magick_lib($magicks); $top_gm = top_magick_lib($gmagicks); if (substr($top_im['version'], 0, 1) === '6') { $magick_path = $top_im['path']; } else if (substr($top_gm['version'], 2, 3) >= 3) { $magick_path = $top_gm['path']; } else { if (in_array('gd', get_loaded_extensions())) { $magick_path = 'gd'; } else { $im['fail'][] = 'The version of ImageMagick or GraphicsMagick on your server is not compatible with Koken.
Koken requires ImageMagick 6+ or GraphicsMagick 1.3+.
Ask your host for the path to a newer version of ImageMagick or GraphicsMagick and enter it below or enable the PHP GD library and restart the installation.'; } } } } if ($imagick) { $magick_path = 'imagick'; } if (isset($magick_path)) { $im['path'] = $magick_path; } $loopback = array( 'warn' => array(), 'fail' => array() ); if ($download_error === 'extensions') { $loopback['warn'][] = 'Loopback connections cannot be tested until cURL is enabled.'; } else { $loopback_test = koken_http_get('/json'); $loopback_result = $loopback_test && isset($loopback_test['success']) && $loopback_test['success'] === true; if (!$loopback_result) { $use_host_header_loopback = true; $loopback_test = koken_http_get('/json', $use_host_header_loopback); $loopback_result = $loopback_test && isset($loopback_test['success']) && $loopback_test['success'] === true; } if ($loopback_result) { $suhosin = min(ini_get('suhosin.get.max_name_length'), ini_get('suhosin.request.max_varname_length')); if ($suhosin && $suhosin < 256) { $loopback_long_test = koken_http_get('/json/one:two/three:four/five:six/seven:eight/fill:up/space:true/limit:1000/order_by:some_column_name/include_empty:maybe/order_direction:desc/types:everything/page:100/token:123456789abcdefghijklmnop', $use_host_header_loopback); $loopback_long_result = $loopback_long_test && isset($loopback_long_test['success']) && $loopback_long_test['success'] === true; if (!$loopback_long_result) { $loopback['fail'][] = "Your installation of PHP is running the Suhosin security extension. The current settings for that extension conflict with Koken's functionality. Add the following lines to your php.ini file (your host may need to help you do this).

suhosin.get.max_name_length=256
suhosin.request.max_varname_length=256
"; } } } else { $loopback['fail'][] = 'Loopback connection failed. Your server must be configured to make requests to its own IP address over HTTP. Contact your host and ask them to enable "loopback connections" to resolve this issue.'; } } header('Content-type: application/json'); die(json_encode( array( 'php' => $php, 'permissions' => $permissions, 'connection' => $connection, 'im' => $im, 'browser' => $browser, 'loopback' => $loopback, 'loopback_host_header' => $use_host_header_loopback ) )); } else { if (download('https://s3.amazonaws.com/install.koken.me/releases/latest.zip', 'core.zip')) { require('pclzip.lib.php'); // Work around issue with mbstring.func_overload = 2 if ((ini_get('mbstring.func_overload') & 2) && function_exists('mb_internal_encoding')) { $previous_encoding = mb_internal_encoding(); mb_internal_encoding('ISO-8859-1'); } unlink('index.php'); $archive = new PclZip('core.zip'); $archive->extract(PCLZIP_CB_POST_EXTRACT, 'extract_callback'); $storage = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR; chdir($storage); $zip = 'elementary.zip'; download('https://koken-store.s3.amazonaws.com/plugins/be1cb2d9-ed05-2d81-85b4-23282832eb84.zip', $zip); $theme_zip = new PclZip($zip); $theme_zip->extract(PCLZIP_CB_POST_EXTRACT, 'extract_callback'); rename('be1cb2d9-ed05-2d81-85b4-23282832eb84', 'elementary'); unlink($zip); chdir(dirname(__FILE__)); unlink('pclzip.lib.php'); unlink('core.zip'); $db_name = urldecode($_POST['name']); $db_username = urldecode($_POST['user']); $db_password = str_replace("'", "\\'", urldecode($_POST['password'])); $db_prefix = urldecode($_POST['prefix']); $conf = << '{$_POST['driver']}', 'hostname' => '{$_POST['host']}', 'database' => '$db_name', 'username' => '$db_username', 'password' => '$db_password', 'prefix' => '$db_prefix', 'socket' => '' ); OUT; if (file_put_contents('storage/configuration/database.php', $conf)) { $data['success'] = true; } else { // TODO: Fail } if ($_POST['loopback_host_header']) { file_put_contents('storage/configuration/user_setup.php', "\n\n\t// Enable loopback connection workaround. Added automatically by Koken installer\n\tdefine('LOOPBACK_HOST_HEADER', true);", FILE_APPEND); } } else { $data['error'] = 'Permissions'; } } header('Content-type: application/json'); die( json_encode($data) ); exit; } ?> Koken - Setup

Server test

Testing your server for compatibility. Please wait...

By installing this application you agree to our
License Agreement and Privacy Policy.

Setup user

This will be the administrator for this installation.

Connect to database

Enter your MySQL database information.

Download and install

Ready to download and setup Koken. Click the button below to begin.
This should only take a few minutes.

Set timezone

We guessed your timezone. Edit if necessary.

Keep in touch

Our email newsletter contains the latest news, announcements and special offers.
Keep in touch by adding your email address below.

  

Installing...

Fetching the latest version of Koken. Please wait...

Installation complete

All done. Click the button below to start using Koken.