$now_timeout = $db->getOne("select @@wait_timeout"); logThis('Wait Timeout after change ***** ' . $now_timeout, $path); } //// END UPGRADE UPGRADEWIZARD /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// //// MAKE SURE PATCH IS COMPATIBLE if (is_file("{$unzip_dir}/manifest.php")) { // provides $manifest array include "{$unzip_dir}/manifest.php"; if (!isset($manifest)) { fwrite(STDERR, "\nThe patch did not contain a proper manifest.php file. Cannot continue.\n\n"); exit(1); } else { copy("{$unzip_dir}/manifest.php", $sugar_config['upload_dir'] . "/upgrades/patch/{$zip_from_dir}-manifest.php"); $error = validate_manifest($manifest); if (!empty($error)) { $error = strip_tags(br2nl($error)); fwrite(STDERR, "\n{$error}\n\nFAILURE\n"); exit(1); } } } else { fwrite(STDERR, "\nThe patch did not contain a proper manifest.php file. Cannot continue.\n\n"); exit(1); } $ce_to_pro_ent = isset($manifest['name']) && ($manifest['name'] == 'SugarCE to SugarPro' || $manifest['name'] == 'SugarCE to SugarEnt' || $manifest['name'] == 'SugarCE to SugarCorp' || $manifest['name'] == 'SugarCE to SugarUlt'); $_SESSION['upgrade_from_flavor'] = $manifest['name']; global $sugar_config; global $sugar_version; global $sugar_flavor;
function langPackUnpack($unpack_type = 'langpack', $full_file = '') { global $sugar_config; global $base_upgrade_dir; global $base_tmp_upgrade_dir; $manifest = array(); if (!empty($full_file)) { $tempFile = $full_file; $base_filename = urldecode($tempFile); $base_filename = preg_replace("#\\\\#", "/", $base_filename); $base_filename = basename($base_filename); } else { $tempFile = getcwd() . '/' . $sugar_config['upload_dir'] . $_FILES['language_pack']['name']; $base_filename = $_FILES['language_pack']['name']; } $manifest_file = extractManifest($tempFile, $base_tmp_upgrade_dir); if ($unpack_type == 'module') { $license_file = extractFile($tempFile, 'LICENSE.txt', $base_tmp_upgrade_dir); } if (is_file($manifest_file)) { if ($unpack_type == 'module' && is_file($license_file)) { copy($license_file, getcwd() . '/' . $sugar_config['upload_dir'] . 'upgrades/' . $unpack_type . '/' . remove_file_extension($base_filename) . "-license.txt"); } copy($manifest_file, getcwd() . '/' . $sugar_config['upload_dir'] . 'upgrades/' . $unpack_type . '/' . remove_file_extension($base_filename) . "-manifest.php"); require_once $manifest_file; validate_manifest($manifest); $upgrade_zip_type = $manifest['type']; // exclude the bad permutations /*if($upgrade_zip_type != "langpack") { unlinkTempFiles($manifest_file, $tempFile); die( "You can only upload module packs, theme packs, and language packs on this page." ); }*/ //$base_filename = urldecode( $_REQUEST['language_pack_escaped'] ); $base_filename = preg_replace("#\\\\#", "/", $base_filename); $base_filename = basename($base_filename); mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}"); $target_path = getcwd() . "/{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}"; $target_manifest = remove_file_extension($target_path) . "-manifest.php"; if (isset($manifest['icon']) && $manifest['icon'] != "") { $icon_location = extractFile($tempFile, $manifest['icon'], $base_tmp_upgrade_dir); $path_parts = pathinfo($icon_location); copy($icon_location, remove_file_extension($target_path) . "-icon." . $path_parts['extension']); } // move file from cache/upload to cache/upload/langpack if (copy($tempFile, $target_path)) { copy($manifest_file, $target_manifest); unlink($tempFile); // remove tempFile return "The file {$base_filename} has been uploaded.<br>\n"; } else { unlinkTempFiles($manifest_file, $tempFile); return "There was an error uploading the file, please try again!<br>\n"; } } else { die("The zip file is missing a manifest.php file. Cannot proceed."); } unlinkTempFiles($manifest_file, ''); }
function langPackUnpack($unpack_type, $full_file) { global $sugar_config; global $base_upgrade_dir; global $base_tmp_upgrade_dir; $manifest = array(); if (!empty($full_file)) { $base_filename = pathinfo(urldecode($full_file), PATHINFO_FILENAME); } else { return "Empty filename supplied"; } $manifest_file = extractManifest($full_file, $base_tmp_upgrade_dir); if ($unpack_type == 'module') { $license_file = extractFile($full_file, 'LICENSE.txt', $base_tmp_upgrade_dir); } if (is_file($manifest_file)) { if ($unpack_type == 'module' && is_file($license_file)) { copy($license_file, $base_upgrade_dir . '/' . $unpack_type . '/' . $base_filename . "-license.txt"); } copy($manifest_file, $base_upgrade_dir . '/' . $unpack_type . '/' . $base_filename . "-manifest.php"); require_once $manifest_file; validate_manifest($manifest); $upgrade_zip_type = $manifest['type']; mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}"); $target_path = "{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}"; $target_manifest = $target_path . "-manifest.php"; if (isset($manifest['icon']) && $manifest['icon'] != "") { $icon_location = extractFile($full_file, $manifest['icon'], $base_tmp_upgrade_dir); $path_parts = pathinfo($icon_location); copy($icon_location, $target_path . "-icon." . $path_parts['extension']); } // move file from uploads to cache // FIXME: where should it be? if (copy($full_file, $target_path . ".zip")) { copy($manifest_file, $target_manifest); unlink($full_file); // remove tempFile return "The file {$base_filename} has been uploaded.<br>\n"; } else { unlinkTempFiles($manifest_file, $full_file); return "There was an error uploading the file, please try again!<br>\n"; } } else { die("The zip file is missing a manifest.php file. Cannot proceed."); } unlinkTempFiles($manifest_file, ''); }
} } } if ($perform) { $manifest_file = extractManifest($tempFile); if (is_file($manifest_file)) { //SCAN THE MANIFEST FILE TO MAKE SURE NO COPIES OR ANYTHING ARE HAPPENING IN IT $ms = new ModuleScanner(); $fileIssues = $ms->scanFile($manifest_file); if (!empty($fileIssues)) { echo '<h2>' . $mod_strings['ML_MANIFEST_ISSUE'] . '</h2><br>'; $ms->displayIssues(); die; } require_once $manifest_file; validate_manifest($manifest); $upgrade_zip_type = $manifest['type']; // exclude the bad permutations if ($view == "module") { if ($upgrade_zip_type != "module" && $upgrade_zip_type != "theme" && $upgrade_zip_type != "langpack") { unlinkTempFiles(); die($mod_strings['ERR_UW_NOT_ACCEPTIBLE_TYPE']); } } elseif ($view == "default") { if ($upgrade_zip_type != "patch") { unlinkTempFiles(); die($mod_strings['ERR_UW_ONLY_PATCHES']); } } $base_filename = pathinfo($tempFile, PATHINFO_BASENAME); mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}");
} else { if (!file_exists(FORUM_ROOT . 'extensions/' . $entry . '/manifest.xml')) { $forum_page['ext_error'][] = '<div class="ext-error databox db' . ++$forum_page['item_num'] . '">' . "\n\t\t\t\t" . '<h3 class="legend"><span>' . sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)) . '<span></h3>' . "\n\t\t\t\t" . '<p>' . $lang_admin_ext['Missing manifest'] . '</p>' . "\n\t\t\t" . '</div>'; ++$num_failed; continue; } } // Parse manifest.xml into an array $ext_data = is_readable(FORUM_ROOT . 'extensions/' . $entry . '/manifest.xml') ? xml_to_array(file_get_contents(FORUM_ROOT . 'extensions/' . $entry . '/manifest.xml')) : ''; if (empty($ext_data)) { $forum_page['ext_error'][] = '<div class="ext-error databox db' . ++$forum_page['item_num'] . '">' . "\n\t\t\t\t" . '<h3 class="legend"><span>' . sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)) . '<span></h3>' . "\n\t\t\t\t" . '<p>' . $lang_admin_ext['Failed parse manifest'] . '</p>' . "\n\t\t\t" . '</div>'; ++$num_failed; continue; } // Validate manifest $errors = validate_manifest($ext_data, $entry); if (!empty($errors)) { $forum_page['ext_error'][] = '<div class="ext-error databox db' . ++$forum_page['item_num'] . '">' . "\n\t\t\t\t" . '<h3 class="legend"><span>' . sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)) . '</span></h3>' . "\n\t\t\t\t" . '<p>' . implode(' ', $errors) . '</p>' . "\n\t\t\t" . '</div>'; ++$num_failed; } else { if (!array_key_exists($entry, $inst_exts) || version_compare($inst_exts[$entry]['version'], $ext_data['extension']['version'], '!=')) { $forum_page['ext_item'][] = '<div class="ct-box info-box extension available">' . "\n\t\t\t" . '<h3 class="ct-legend hn">' . forum_htmlencode($ext_data['extension']['title']) . ' <em>' . $ext_data['extension']['version'] . '</em></h3>' . "\n\t\t\t" . '<ul class="data-list">' . "\n\t\t\t\t" . '<li><span>' . sprintf($lang_admin_ext['Extension by'], forum_htmlencode($ext_data['extension']['author'])) . '</span></li>' . ($ext_data['extension']['description'] != '' ? "\n\t\t\t\t" . '<li><span>' . forum_htmlencode($ext_data['extension']['description']) . '</span></li>' : '') . "\n\t\t\t" . '</ul>' . "\n\t\t\t" . '<p class="options"><span class="first-item"><a href="' . $base_url . '/admin/extensions.php?install=' . urlencode($entry) . '">' . (isset($inst_exts[$entry]['version']) ? $lang_admin_ext['Upgrade extension'] : $lang_admin_ext['Install extension']) . '</a></span></p>' . "\n\t\t" . '</div>'; ++$num_exts; } } } } $d->close(); ($hook = get_hook('aex_section_install_pre_display_available_ext_list')) ? eval($hook) : null; if ($num_exts) { echo "\t\t" . implode("\n\t\t", $forum_page['ext_item']) . "\n";
</div> </fieldset> <br /> <input type="hidden" name="the_ext_file" value="<?php echo $_GET['edit']; ?> " /> <input type="submit" name="edit_ext" value="<?php echo SAVE_BUTTON; ?> " /> </div> <?php } elseif (isset($_GET['edit_free']) && is_writable(OPENLD_ROOT . 'extensions/' . $_GET['edit_free'] . '/extension.xml')) { $ext_data = xml_to_array(@file_get_contents(OPENLD_ROOT . 'extensions/' . $_GET['edit_free'] . '/extension.xml')); $manifest_errors = validate_manifest($ext_data, $_GET['edit_free']); $_ext_doc = fopen(OPENLD_ROOT . 'extensions/' . $_GET['edit_free'] . '/extension.xml', 'r'); $_ext_raw = fread($_ext_doc, filesize(OPENLD_ROOT . 'extensions/' . $_GET['edit_free'] . '/extension.xml')); fclose($_ext_doc); ?> <div class="adformpanel"> <fieldset id="admin-welcome"> <legend> <span> <?php echo EDIT_LABEL; ?> : <?php echo $_GET['edit_free']; ?> </span>
function install_extension($folder_name) { global $db, $settings; $id = preg_replace('/[^a-zA-Z_]/', '', $folder_name); // Parse extension.xml into an array and validate it $ext_data = xml_to_array(@file_get_contents(OPENLD_ROOT . 'extensions/' . $id . '/extension.xml')); $errors = validate_manifest($ext_data, $id); if (!empty($errors)) { error(var_export($errors, true), __FILE__, __LINE__); } $new_uninstall_code = isset($ext_data['extension']['uninstall']) && trim($ext_data['extension']['uninstall']) != '' ? '\'' . $db->escape(trim($ext_data['extension']['uninstall'])) . '\'' : 'NULL'; // Is this a fresh install or an upgrade? $query = array('SELECT' => 'version', 'FROM' => 'extensions', 'WHERE' => 'id="' . $db->escape($id) . '"'); ($hook = get_hook('functions_install_extension_sql_select_extensions')) ? eval($hook) : null; $result = $db->query_build($query) or error('Unable to fetch extension', __FILE__, __LINE__); if ($db->num_rows($result)) { // $cur_version will be available to the extension install routine (to facilitate extension upgrades) $cur_version = $db->result($result); // Run the author supplied install code if (isset($ext_data['extension']['install']) && trim($ext_data['extension']['install']) != '') { eval($ext_data['extension']['install']); } $query = array('UPDATE ' => 'extensions', 'SET' => 'title="' . $db->escape($ext_data['extension']['title']) . '", version="' . $db->escape($ext_data['extension']['version']) . '", description="' . $db->escape($ext_data['extension']['description']) . '", author="' . $db->escape($ext_data['extension']['author']) . '", uninstall=' . $new_uninstall_code, 'WHERE' => 'extension_id="' . $db->escape($id) . '"'); ($hook = get_hook('functions_install_extension_sql_update_extensions')) ? eval($hook) : null; $db->query_build($query) or error('Unable to update extension', __FILE__, __LINE__); $query = array('DELETE' => 'extension_hooks', 'WHERE' => 'extension_id="' . $db->escape($id) . '"'); ($hook = get_hook('functions_install_extension_sql_update_extension_hooks')) ? eval($hook) : null; $db->query_build($query) or error('Unable to delete extension hooks', __FILE__, __LINE__); } else { // Run the author supplied install code if (isset($ext_data['extension']['install']) && trim($ext_data['extension']['install']) != '') { eval($ext_data['extension']['install']); } $query = array('INSERT' => 'id, title, version, description, author, uninstall', 'INTO' => 'extensions', 'VALUES' => '"' . $db->escape($ext_data['extension']['id']) . '", "' . $db->escape($ext_data['extension']['title']) . '", "' . $db->escape($ext_data['extension']['version']) . '", "' . $db->escape($ext_data['extension']['description']) . '", "' . $db->escape($ext_data['extension']['author']) . '", ' . $new_uninstall_code); //Room for possible extension hook $db->query_build($query) or error('Unable to create extension', __FILE__, __LINE__); } // Now insert the hooks $hooks = $ext_data['extension']['hooks']['hook']; if (!is_array(current($hooks))) { $hooks = array($hooks); } foreach ($hooks as $hook) { $query = array('INSERT' => 'id, extension_id, code, installed', 'INTO' => 'extension_hooks', 'VALUES' => '"' . $db->escape(trim($hook['attributes']['id'])) . '", "' . $db->escape($id) . '", "' . $db->escape(trim($hook['content'])) . '", ' . time()); ($hook = get_hook('functions_install_extension_sql_insert_extension_hooks')) ? eval($hook) : null; $db->query_build($query) or error('Unable to create extension hook', __FILE__, __LINE__); } generate_hooks_cache(); }
function get_ext_title($ext_file) { $ext_data = xml_to_array(@file_get_contents(OPENLD_ROOT . 'extensions/' . $ext_file . '/extension.xml')); $manifest_errors = validate_manifest($ext_data, $ext_file); return empty($manifest_errors) ? openld_htmlspecialchars($ext_data['extension']['title']) : $ext_file; }