' : '';
return;
}
$template->assign_block_vars('error', array(
'L_TITLE' => $lang['EM_error_detail'],
'ERROR_MESSAGE' => $message . ' :: ' . FAQ_LINK . $lang['EM_FAQ'] . ' :: ' . REPORT_LINK . $lang['EM_report'] . '')
);
}
// look in the DB to see if we already processed this MOD
function is_unprocessed($db, $mod_title, $mod_version, $phpbb_version)
{
$sql = "SELECT *
FROM " . EASYMOD_TABLE . "
WHERE mod_title = '" . substr($mod_title, 0, 255) . "'
AND mod_version = '" . substr($mod_version, 0, 15) . "'
ORDER BY mod_id DESC";
if ( !($result = $db->sql_query($sql)) || !$db->sql_fetchrow($result) )
{
return true;
}
return false;
}
// parse the MOD file and get properties about it (make sure it really is a MOD too)
function get_mod_properties($file, &$mod_title, &$mod_author_handle, &$mod_author_email, &$mod_author_name, &$mod_author_url, &$mod_description, &$mod_version, &$compliant)
{
global $phpbb_root_path, $script_path;
// used to add a little tolerance on the Author line
$faux_author = false;
$legit_author = false;
// open the file and grab the first line
check_file_scope($file, $phpbb_root_path . $script_path);
$f_mod_script = fopen($file, 'r');
if (!$f_mod_script)
{
return false;
}
$buffer = fgets($f_mod_script, 1024);
// see if it is EMC right away; first line starts with ## on it and contains "easymod"
$compliant = false;
if ((stristr($buffer, 'easymod')) && (substr($buffer,0,2) == '##'))
{
$compliant = true;
}
// loop through file and try to get MOD info; only look at lines starting with ##
$getting_desc = 0;
$first_line = true;
while ( (!feof($f_mod_script)) && ( substr($buffer,0,2) == '##'))
{
// we've already gotten the first line but still need to process it
$buffer = ($first_line) ? $buffer : fgets($f_mod_script, 1024);
$first_line = false;
// check for mod title; allow just "title" if we don't have a title yet
if ((stristr($buffer, 'MOD Title:')) || (($mod_title == '') && (stristr( $buffer, 'Title:'))))
{
$mod_title = htmlspecialchars(trim(substr($buffer, strpos($buffer, ":")+1)));
$getting_desc = 0;
}
// check for author info
else if ( (stristr($buffer, 'MOD Author:')) || (stristr($buffer, 'Author:') ))
{
// if we've already gotten a legit MOD Author, then don't go looking for another
if ($legit_author)
{
continue;
}
// they are using just Author instead of MOD author and we've already gotten a "faux" one; get outta here
else if ((!stristr( $buffer, 'MOD Author:')) && ($faux_author))
{
continue;
}
// again using some variant of "Author" but allow it; we'll only accept the first non-MOD Author entry
else if ((!stristr($buffer, 'MOD Author:')) && (!$faux_author))
{
$faux_author = true;
}
// they are using the proper "MOD Author" label
else
{
$legit_author = true;
}
// init our vars
$mod_author_handle = '';
$mod_author_email = '';
$mod_author_name = '';
$mod_author_url = '';
// trim off the label
$orig = trim(substr($buffer, strpos($buffer, ":")+1));
// get real name + email address
if (strstr($orig, '<'))
{
$left = strpos( $orig, "<")+1;
$len = strpos( $orig, ">") - $left;
$mod_author_email = htmlspecialchars(trim(substr($orig, $left, $len)));
$mod_author_handle = htmlspecialchars(trim(substr($orig, 0, $left-1)));
$mod_author_url = htmlspecialchars(trim(substr($orig, $left + $len +1)));
}
// get handle + web site
if (strstr($orig, '('))
{
$left = strpos( $orig, "(")+1;
$len = strpos( $orig, ")") - $left;
$mod_author_name = htmlspecialchars(trim(substr($orig, $left, $len)));
$mod_author_url = htmlspecialchars(trim(substr($orig, $left + $len +1)));
if ( $mod_author_handle == '')
{
$mod_author_handle = htmlspecialchars(trim(substr($orig, 0, $left-1)));
}
}
// could't get proper format so make it all the handle field
else if ($mod_author_handle == '')
{
$mod_author_handle = htmlspecialchars($orig);
}
// see if we can debork a borked url; if there is "http:" but also spaces, take the chunck without spaces
if ((strstr($mod_author_url, ' ')) && (strstr($mod_author_url, 'http:')))
{
$url_array = explode(' ', $mod_author_url);
$pos_name = '';
// looking for the element that has no http without any spaces; that will be our URL
for ($url=0; $url 0)
{
$new_line = ' ' . trim(substr($buffer, 2));
$mod_description .= htmlspecialchars($new_line);
$getting_desc = ($getting_desc >= 3) ? 0 : $getting_desc + 1;
}
}
fclose($f_mod_script);
// if we have a title and a handle, then that is good enough to call this a MOD (fixed in 0.0.10; used to be name)
if (($mod_title != '') && ($mod_author_handle != ''))
{
return true;
}
else
{
return false;
}
}
// strip the body array of a command down to the minimum
function strip_whitespace($body, $single_line=true)
{
$new_array = array();
$have_line = false;
// rebuild the array and drop the whitespace lines
for ($i=0; $i 0)
{
$new_array[] = $body[$i];
$have_line = true;
}
// empty line so get this out of our body array
else
{
// do nothing
}
}
// the white space is now gone, return the result
return $new_array;
}
// if we encounter an error will modifiying a file then print errors, clean up, and terminate processing if need be
function handle_error( $result, &$file_list, $line, $close_files=false, $find_array=array())
{
global $lang;
// if we are halting the processing then finish writing all files, just to be neat i guess
if (($close_files) && ($result == FIND_FAIL_CRITICAL))
{
// if we failed on an IN-LINE command be sure to write the find_array
if (count($find_array) > 0)
{
write_find_array( $find_array, $file_list);
}
// don't worry if file repro fails since we are halting anyway
complete_file_reproduction( $file_list);
}
// handle warnings and critical errors
$failed_close = false;
if ( $result != OPEN_OK)
{
// loop through all files; print errors; and remove file from our file array
$new_list = array();
for ($err=0; $errerr_msg != '')
{
// if this file through a warning and we aren't halting then close just this file
if (($close_files) && ($result != FIND_FAIL_CRITICAL))
{
$temp_array = array();
$temp_array[] = $file_list[$err];
// if we failed on an IN-LINE command be sure to write the find_array
if (count($find_array) > 0)
{
write_find_array( $find_array, $temp_array);
}
// clean up this file
if (!complete_file_reproduction( $temp_array))
{
// repro failed meaning close failed meaning we now have a show stopping error!
$failed_close = true;
}
}
// show the error(s); do this last in case file repro throw another error
display_error( $file_list[$err]->err_msg . " \n" . $lang['EM_line_num'] . $line);
}
// no error so this file can stay in our file list; ones with errors are removed
else
{
$new_list[] = $file_list[$err];
}
}
$file_list = $new_list;
// if we have a critical error, then we have to halt the processing NOW!
if ( ($result == OPEN_FAIL_CRITICAL) || ($failed_close))
{
return true;
}
}
// no show stopping errors
return false;
}
// look in the config table to get the EM settings
function get_em_settings($filename, $path, $em_pass, $preview = false)
{
global $db, $phpbb_root_path;
//
// grab the EM settings
//
$sql = "SELECT *
FROM " . CONFIG_TABLE . "
WHERE config_name LIKE 'EM_%'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['EM_err_config_info'], '', __LINE__, __FILE__, $sql);
}
// loop through all the settings and assign the EM ones as appropriate
while ($row = $db->sql_fetchrow($result))
{
if ($row['config_name'] == 'EM_read')
{
$read = $row['config_value'];
}
else if ($row['config_name'] == 'EM_write')
{
$write = $row['config_value'];
}
else if ($row['config_name'] == 'EM_move')
{
$move = $row['config_value'];
}
else if ($row['config_name'] == 'EM_ftp_dir')
{
$ftp_dir = $row['config_value'];
}
else if ($row['config_name'] == 'EM_ftp_user')
{
$ftp_user = $row['config_value'];
}
else if ($row['config_name'] == 'EM_ftp_pass')
{
$ftp_pass = crypt_ftp_pass(EM_DECRYPT, $row['config_value'], $em_pass);
}
else if ($row['config_name'] == 'EM_ftp_host')
{
$ftp_host = $row['config_value'];
}
else if ($row['config_name'] == 'EM_ftp_port')
{
$ftp_port = $row['config_value'];
}
else if ($row['config_name'] == 'EM_ftp_type')
{
$ftp_type = $row['config_value'];
}
else if ($row['config_name'] == 'EM_ftp_cache')
{
$ftp_cache = $row['config_value'];
}
}
// if we are in preview mode, then no matter what we will set to display to screen
if ($preview)
{
$write = 'screen';
$move = 'ftpm';
}
// easiest thing to do is return a mod_io object
return new mod_io($filename, $path, $read, $write, $move, $ftp_user, $ftp_pass, $ftp_dir, $ftp_host, $ftp_port, $ftp_type, $ftp_cache);
}
// look in the config table to get the EM Version
function get_em_version()
{
global $db;
// look in db
$sql = "SELECT *
FROM " . CONFIG_TABLE . "
WHERE config_name = 'EM_version'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['EM_err_config_info'], '', __LINE__, __FILE__, $sql);
}
// loop through all the settings and assign the EM ones as appropriate
if ( $row = $db->sql_fetchrow($result))
{
return $row['config_value'];
}
return '';
}
// handle the mode; this is the key to securing EM
$mode = '';
$preview = false;
$get_password = false;
// if mode is passed in a GET, be very suspicious! we don't like it when the user sends us GET vars so make sure they
// are supposed to be
if (isset($HTTP_GET_VARS['mode']))
{
// be very selective about what we allow from GET; the allowed types will also require password auth
$mode = (isset($HTTP_GET_VARS['mode'])) ? stripslashes($HTTP_GET_VARS['mode']) : '';
if ($mode == 'help')
{
$template->set_filenames(array(
'body' => 'admin/mod_help.tpl')
);
$template->assign_vars(array(
'L_TITLE' => $lang['EM_installer_help'])
);
$first_item = true;
foreach( $lang['help'] as $name => $paragraphs )
{
if( $first_item )
{
$first_item = false;
}
else
{
$template->assign_block_vars('helpitem.separator', array());
}
$template->assign_block_vars('helpitem', array(
'TITLE' => $paragraphs[0],
'NAME' => $name
));
for( $i = 1; $i < count($paragraphs); $i++ )
{
$template->assign_block_vars('helpitem.paragraph', array(
'TEXT' => $paragraphs[$i]
));
}
}
$template->pparse('body');
include('page_footer_admin.'.$phpEx);
}
if (($mode == 'install') || ($mode == 'settings') || ($mode == 'history'))
{
$get_password = true;
}
// if we are displaying the file to screen, then get the pw to confirm against
else if (($mode == 'display_file') || ($mode == 'display_backup'))
{
$password = (isset($HTTP_GET_VARS['password'])) ? stripslashes($HTTP_GET_VARS['password']) : '';
$install_file = ( !empty($HTTP_GET_VARS['install_file']) ) ? stripslashes(trim($HTTP_GET_VARS['install_file'])) : '';
$install_path = ( !empty($HTTP_GET_VARS['install_path']) ) ? stripslashes(trim($HTTP_GET_VARS['install_path'])) : '';
// important! we are writing the file output to screen so the PRE tag will format it nicely for us
echo '' . "\n"
. '' . "\n"
. '' . "\n"
. '' . $lang['EM_Title'] . '' . "\n"
. '' . "\n"
. '' . "\n"
. '' . "\n"
. '
';
}
// unexpected mode, someone is trying to circumvent the password! we'll fix 'em ;-)
else
{
// they'll now end up at the password screen instead of whatever they were trying
$mode = 'install';
$get_password = true;
}
}
// get post variables; we trust post variables ;-)
else
{
$mode = ( !empty($HTTP_POST_VARS['mode']) ) ? stripslashes(trim($HTTP_POST_VARS['mode'])) : '';
$password = ( !empty($HTTP_POST_VARS['password']) ) ? stripslashes($HTTP_POST_VARS['password']) : '';
$install_file = ( !empty($HTTP_POST_VARS['install_file']) ) ? stripslashes(trim($HTTP_POST_VARS['install_file'])) : '';
$install_path = ( !empty($HTTP_POST_VARS['install_path']) ) ? stripslashes(trim($HTTP_POST_VARS['install_path'])) : '';
// 0.0.11 preview mode
$preview = (isset($HTTP_POST_VARS['preview'])) ? true : false;
}
// make sure mode is valid; if not then set to default mode and get pw
if (($mode != 'history') && ($mode != 'settings') && ($mode != 'install') &&
($mode != 'display_file') && ($mode != 'download_file') &&
($mode != 'display_backup') && ($mode != 'download_backup') &&
($mode != 'SQL_view') && ($mode != 'SQL_execute') &&
($mode != 'update') && ($mode != 'process') && ($mode != 'post_process') && ($mode != 'diy_process') &&
($mode != 'history_details') && ($mode != 'del_files') && ($mode != 'del_record') && ($mode != 'restore_backups') && ($mode != 'install_lang') && ($mode != 'install_themes') && ($mode != 'uninstall'))
{
$mode = 'install';
$get_password = true;
}
//
// if they are trying to get to the first page, check the pw; after that assume they are validated
//
$pass_message = '';
if ((($mode == 'install') || ($mode == 'settings') || ($mode == 'history') ||
($mode == 'display_file') || ($mode == 'display_backup')) && (!$get_password))
{
// compare passwords and send them back to the password screen if they fail
if (md5($password) !== get_em_pw())
{
$get_password = true;
$pass_message = '' . $lang['EM_err_pw_fail'] . ' ';
}
}
//
// if they are downloading or displaying a file or backup then we need to get setup
//
// downloading a file or a backup from the completed processing screen
if (($mode == 'download_file') || ($mode == 'download_backup'))
{
// they clicked a form button; we need to figure out which one so we know what file they are looking for
$num_files = ( isset($HTTP_POST_VARS['mod_count'])) ? intval($HTTP_POST_VARS['mod_count']) : 0;
// loop through all the submit buttons to see which one was pressed
///////////////////////////////////
///////////////////////////////////
/////////////////////////////////// possible error.... should start at 0? was a 1 before
///////////////////////////////////
///////////////////////////////////
for( $i=0; $i<=$num_files; $i++ )
{
$var_name = 'submitfile' . $i;
// if this is the button that was pressed then we are all set! get the file name
if (isset($HTTP_POST_VARS[$var_name]))
{
$file = (isset($HTTP_POST_VARS['file'.$i])) ? stripslashes($HTTP_POST_VARS['file'.$i]) : '';
break;
}
}
// we'll need to look at the path and filename so split things up
$split = explode('/', $file);
// if a file, then make sure we have the filename correct
if ($mode == 'download_file')
{
// by default the filename sent will match the one in the MOD script
$process_file = (substr($file, 0, 9) == '../../../') ? substr($file, 9) : '';
$orig_file = $process_file;
// handle the special cases of a template file to download; only subSilver will appear in the MOD script
if (($split[3] == 'templates') && ($split[4] != 'subSilver'))
{
$process_file = str_replace( $split[4], 'subSilver', $process_file);
}
// handle the special cases of a language file to download; only english will appear in the MOD script
else if (($split[3] == 'language') && ($split[4] != 'lang_english'))
{
$process_file = str_replace( $split[4], 'lang_english', $process_file);
}
}
// if a backup then we can assume the filename is valid
else
{
$orig_file = $file;
$process_file = (substr($file, 0, 9) == '../../../') ? substr($file, 9) : '';
$process_file = $phpbb_root_path . $process_file;
}
// if there is no file to process then we are in trouble!
if ($process_file == '')
{
message_die(GENERAL_ERROR, $lang['EM_err_no_process_file']);
}
// set up the redirects so we will download a file, the contents of which we will echo out
header('Content-Type: text/x-delimtext; name="' . $split[count($split)-1] . '"');
header('Content-disposition: attachment; filename="' . $split[count($split)-1] . '"');
}
// writing to screen, get set up
else if (($mode == 'display_file') || ($mode == 'display_backup'))
{
// get the file name
$file = (isset($HTTP_GET_VARS['file'])) ? stripslashes($HTTP_GET_VARS['file']) : '';
$split = explode('/', $file);
// if a file, then make sure we have the filename correct
if ($mode == 'display_file')
{
// by default the filename sent will match the one in the MOD script
$process_file = (substr($file, 0, 9) == '../../../') ? substr($file, 9) : '';
$orig_file = $process_file;
// handle the special cases of a template file to display; only subSilver will appear in the MOD script
if (($split[3] == 'templates') && ($split[4] != 'subSilver'))
{
$process_file = str_replace( $split[4], 'subSilver', $process_file);
}
// handle the special cases of a language file to display; only english will appear in the MOD script
else if (($split[3] == 'language') && ($split[4] != 'lang_english'))
{
$process_file = str_replace( $split[4], 'lang_english', $process_file);
}
}
// if a backup then we can assume the filename is valid
else
{
$orig_file = $file;
$process_file = (substr($file, 0, 9) == '../../../') ? substr($file, 9) : '';
$process_file = $phpbb_root_path . $process_file;
}
// if there is no file to process then we are in trouble!
if ( $process_file == '')
{
message_die(GENERAL_ERROR, $lang['EM_err_no_process_file']);
}
}
//
// Show the page header (if we aren't doing the display modes)
//
if (($mode != 'display_file') && ($mode != 'download_file') && ($mode != 'display_backup') && ($mode != 'download_backup'))
{
$template->set_filenames(array(
'mod_header' => 'admin/mod_header.tpl')
);
$template->assign_vars(array(
'L_TITLE' => $lang['EM_Title'],
'L_EM_VERSION' => EASYMOD_VER)
);
$template->pparse('mod_header');
}
//
// password authentication page
//
if ($get_password)
{
// load the password page template
$template->set_filenames(array(
"body" => "admin/mod_login.tpl")
);
$template->assign_vars(array(
'S_ACTION' => append_sid('admin_easymod.' . $phpEx),
'L_ACCESS_WARNING' => $lang['EM_access_warning'],
'L_MESSAGE' => $pass_message,
'L_PASSWORD_TITLE' => $lang['EM_password_title'],
'L_PASSWORD' => $lang['EM_password'],
'L_ACCESS_EM' => $lang['EM_access_EM'],
'MODE' => $mode)
);
}
//
// display the settings page
//
else if ($mode == 'settings')
{
// load the settings page template
$template->set_filenames(array(
"body" => "admin/mod_settings.tpl")
);
$command_file = get_em_settings('6E7574747A79.72756C657321', '', $password);
$select_read = '';
$select_write = '' . "\n";
$select_write .= '' . "\n";
$select_write .= '' . "\n";
$select_write .= '' . "\n";
$select_move = '' . "\n";
$select_move .= '' . "\n";
$select_move .= '' . "\n";
$select_move .= '' . "\n";
$template->assign_vars(array(
'S_ACTION' => append_sid('admin_easymod.' . $phpEx),
'L_SETTINGS' => $lang['EM_settings'],
'L_DESC' => $lang['EM_settings_desc'],
'L_PW_TITLE' => $lang['EM_password_title'],
'L_PW_DESC' => $lang['EM_settings_pw'],
'L_PW_SET' => $lang['EM_password_set'],
'L_PW_CONFIRM' => $lang['EM_password_confirm'],
'L_EM_VERSION' => $lang['EM_easymod_version'],
'L_EMV_DESC' => $lang['EM_emv_description'],
'L_FILE_TITLE' => $lang['EM_file_title'],
'L_FILE_DESC' => $lang['EM_file_desc'],
'L_FILE_READ' => $lang['EM_file_reading'],
'L_FILE_WRITE' => $lang['EM_file_writing'],
'L_FILE_MOVE' => $lang['EM_file_moving'],
'L_FTP_TITLE' => $lang['EM_ftp_title'],
'L_FTP_DESC' => $lang['EM_ftp_desc'],
'L_FTP_DIR' => $lang['EM_ftp_dir'],
'L_FTP_USER' => $lang['EM_ftp_user'],
'L_FTP_PASS' => $lang['EM_ftp_pass'],
'L_FTP_HOST' => $lang['EM_ftp_host'],
'L_FTP_PORT' => $lang['EM_ftp_port'],
'L_FTP_DEBUG' => $lang['EM_ftp_debug'],
'L_FTP_DEBUG_WARN' => $lang['EM_ftp_debug_not'],
'L_FTP_EXT' => $lang['EM_ftp_use_ext'],
'L_FTP_EXT_WARN' => $lang['EM_ftp_ext_not'],
'L_FTP_CACHE' => $lang['EM_ftp_cache'],
'L_SUPPLY_CHANGE' => $lang['EM_supply_on_change'],
'L_YES' => $lang['EM_yes'],
'L_NO' => $lang['EM_no'],
'L_SUBMIT' => $lang['EM_settings_update'],
'EM_PASS' => htmlspecialchars($password),
'EM_VERSION' => get_em_version(),
'SELECT_READ' => $select_read,
'SELECT_WRITE' => $select_write,
'SELECT_MOVE' => $select_move,
'FTP_USER' => $command_file->ftp_user,
'FTP_PASS' => '', // don't send FTP password to page, is unsecure $command_file->ftp_pass,
'FTP_PATH' => $command_file->ftp_path,
'FTP_HOST' => $command_file->ftp_host,
'FTP_PORT' => $command_file->ftp_port,
'FTP_EXT' => ($command_file->ftp_type == 'ext') ? 'checked="checked"' : '',
'FTP_FSOCK' => ($command_file->ftp_type == 'fsock') ? 'checked="checked"' : '',
'FTP_CACHE_YES' => ($command_file->ftp_cache) ? 'checked="checked"' : '',
'FTP_CACHE_NO' => (!$command_file->ftp_cache) ? 'checked="checked"' : '',
'U_HELP' => append_sid('admin_easymod.' . $phpEx . '?mode=help'),
'L_HELP' => $lang['EM_more_info'],
'MODE' => 'update')
);
}
//
// update the EM settings; they already filled out the settings page and hit submit
//
else if ($mode == 'update')
{
// password settings
$em_pass = (isset($HTTP_POST_VARS['em_pass'])) ? stripslashes($HTTP_POST_VARS['em_pass']) : '';
$em_pass_confirm = (isset($HTTP_POST_VARS['em_pass_confirm'])) ? stripslashes($HTTP_POST_VARS['em_pass_confirm']) : '';
$em_version = (isset($HTTP_POST_VARS['em_version'])) ? stripslashes($HTTP_POST_VARS['em_version']) : '';
// file access settings
$read = (isset($HTTP_POST_VARS['sel_read'])) ? stripslashes($HTTP_POST_VARS['sel_read']) : '';
$write = (isset($HTTP_POST_VARS['sel_write'])) ? stripslashes($HTTP_POST_VARS['sel_write']) : '';
$move = (isset($HTTP_POST_VARS['sel_move'])) ? stripslashes($HTTP_POST_VARS['sel_move']) : '';
// ftp settings
$ftp_user = (isset($HTTP_POST_VARS['ftp_user'])) ? stripslashes($HTTP_POST_VARS['ftp_user']) : '';
$ftp_pass = (isset($HTTP_POST_VARS['ftp_pass'])) ? stripslashes($HTTP_POST_VARS['ftp_pass']) : '';
$ftp_host = (isset($HTTP_POST_VARS['ftp_host'])) ? stripslashes($HTTP_POST_VARS['ftp_host']) : '';
$ftp_port = (isset($HTTP_POST_VARS['ftp_port'])) ? intval($HTTP_POST_VARS['ftp_port']) : 0;
$ftp_debug = (isset($HTTP_POST_VARS['ftp_debug'])) ? intval($HTTP_POST_VARS['ftp_debug']) : false;
$ftp_type = (isset($HTTP_POST_VARS['ftp_type'])) ? stripslashes($HTTP_POST_VARS['ftp_type']) : 'fsock';
$ftp_cache = (isset($HTTP_POST_VARS['ftp_cache'])) ? intval($HTTP_POST_VARS['ftp_cache']) : 0;
$ftp_dir = (isset($HTTP_POST_VARS['ftp_dir'])) ? stripslashes($HTTP_POST_VARS['ftp_dir']) : '/';
$ftp_dir == ( $ftp_dir == '') ? '/' : $ftp_dir;
// confirm passwords match and update pw if needed
if ($em_pass === $em_pass_confirm)
{
// update the password; starting with 0.0.11 store as MD5 hash
em_db_update('EM_password', md5($em_pass));
$pass_msg = (empty($em_pass)) ? $lang['EM_pass_disabled'] : $lang['EM_pass_updated'];
$force_ftp_pass = true;
}
// the confirm is empty so they are not trying to update the pw, so don't
else if (empty($em_pass_confirm))
{
$pass_msg = $lang['EM_pass_not_updated'];
$force_ftp_pass = false;
}
// passwords do not match so throw an error
else if ($em_pass !== $em_pass_confirm)
{
message_die(GENERAL_ERROR, $lang['EM_err_set_pw']);
}
// update the settings
em_db_update('EM_read', str_replace("'", "''", $read));
em_db_update('EM_write', str_replace("'", "''", $write));
em_db_update('EM_move', str_replace("'", "''", $move));
em_db_update('EM_ftp_dir', str_replace("'", "''", $ftp_dir));
em_db_update('EM_ftp_user', str_replace("'", "''", $ftp_user));
if ( $force_ftp_pass || !empty($ftp_pass) )
{
// If they are updating the EM password, but they haven't supplied the FTP password, then
// we need the old EM password to decrypt the FTP password so it can be encrypted again
if( empty($ftp_pass) )
{
$ftp_pass = crypt_ftp_pass(EM_DECRYPT, $board_config['EM_ftp_pass'], $password);
}
em_db_update('EM_ftp_pass', str_replace("'", "''", crypt_ftp_pass(EM_ENCRYPT, $ftp_pass, $em_pass)));
}
em_db_update('EM_ftp_host', str_replace("'", "''", $ftp_host));
em_db_update('EM_ftp_port', $ftp_port);
em_db_update('EM_ftp_type', str_replace("'", "''", $ftp_type));
em_db_update('EM_ftp_cache', $ftp_cache);
em_db_update('EM_version', str_replace("'", "''", $em_version));
// Test the FTP connection?
if( $write == 'ftpb' || $move == 'ftpa' )
{
$command_file = get_em_settings('6E7574747A79.72756C657321', '', $password);
$test_report = '';
$test_result = capture_test_ftp($ftp_user, $ftp_pass, $ftp_dir, $ftp_host, $ftp_port, $ftp_debug, $ftp_type, $ftp_cache, $test_report);
$test_report = '
' . $lang['EM_are_you_sure'];
$template->assign_vars(array(
'L_INDEX' => '', // Not really necessary here
'MESSAGE_TITLE' => $lang['EM_restore_backups'],
'MESSAGE_TEXT' => $message,
'L_YES' => $lang['Yes'],
'L_NO' => $lang['No'],
'S_CONFIRM_ACTION' => append_sid('admin_easymod.' . $phpEx),
'S_HIDDEN_FIELDS' => $s_hidden_fields)
);
}
//
// Install MOD on new Languages
//
else if ( $mode == 'install_lang' )
{
// list which languages so user can choose and go through install process
message_die(GENERAL_ERROR, $lang['Coming_soon']);
}
//
// Install MOD on new themes
//
else if ( $mode == 'install_themes' )
{
// list which themes so user can choose and go through install process
message_die(GENERAL_ERROR, $lang['Coming_soon']);
}
//
// uninstall the mod
//
else if ( $mode == 'uninstall' )
{
message_die(GENERAL_MESSAGE, $lang['Coming_soon']);
}
//
// display install MOD page
//
else if ( $mode == 'install')
{
// load the install page template
$template->set_filenames(array(
'body' => 'admin/mod_install.tpl')
);
$template->assign_vars(array(
'L_EM_INTRO' => $lang['EM_Intro'],
'L_UNPROCESSED' => $lang['EM_Unprocessed'],
'L_UNPROCESSED_DESC' => sprintf($lang['EM_unprocessed_mods'], HOW_TO_INSTALL_MODS_URL),
'L_MOD' => $lang['EM_Mod'],
'L_AUTHOR' => $lang['EM_Author'],
'L_SUPPORT' => $lang['EM_support_thread'],
'L_DESCRIPTION' => $lang['EM_Description'],
'L_EMC' => $lang['EM_EMC'],
'L_PROCESS' => $lang['EM_process'],
'L_PREVIEW' => $lang['EM_preview'],
'L_ALL_PROCESSED' => $lang['EM_All_Processed'],
'S_ACTION' => append_sid('admin_easymod.' . $phpEx),
'EM_PASS' => htmlspecialchars($password))
);
$phpbb_version = get_phpbb_version();
if ($phpbb_version == '')
{
message_die(GENERAL_ERROR, $lang['EM_err_phpbb_ver']);
}
// parse the "mods" directory, looking for newly extracted mods, or mod updates
$top_handle = opendir('./mods');
$i = 0;
while (false !== ($dir = readdir($top_handle)))
{
// only want the subdirectories (but not . and ..)
if ( (is_dir('./mods/' . $dir) ) && ($dir != '.') && ($dir != '..'))
{
$path = './mods/' . $dir;
$dir_handle = opendir($path);
// loop through the subdirs, looking for mod files
while (false !== ($file = readdir($dir_handle)))
{
$file_path = $path . '/' . $file;
// make sure it is not a dir, and that it ends with .txt or .mod
if ( !is_dir( $file_path) && ( (eregi(".txt$", $file_path)) || (eregi(".mod$", $file_path))))
{
$mod_title = '';
$mod_author_handle = '';
$mod_author_email = '';
$mod_author_name = '';
$mod_author_url = '';
$mod_description = '';
$mod_version = '';
$compliant = false;
$is_mod = get_mod_properties($file_path, $mod_title, $mod_author_handle, $mod_author_email, $mod_author_name, $mod_author_url, $mod_description, $mod_version, $compliant);
// if it is a MOD and has not been processed yet then add it to the list
if (($is_mod) && ( is_unprocessed( $db, $mod_title, $mod_version, $phpbb_version)))
{
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars('unprocessed', array(
'ROW_CLASS' => $row_class,
'MOD_TITLE' => $mod_title,
'MOD_AUTHOR' => $mod_author_handle,
'MOD_URL' => $mod_author_url,
'MOD_VERSION' => $mod_version,
'MOD_DESC' => $mod_description,
'MOD_EMC' => ($compliant) ? '' : $lang['No'],
'MOD_PATH' => $path . '/',
'MOD_FILE' => $file,
'MOD_FILE_URL' => $path . '/' . $file)
);
$i++;
}
}
}
}
}
// didn't find any MODs we can process
if ( $i == 0 )
{
$template->assign_block_vars('no_unprocessed', array());
}
}
//
// preview the changes EM will be making to files
//
else if ($preview)
{
$files = array();
check_file_scope($install_path . $install_file, $phpbb_root_path . $script_path);
$f_mod_script = fopen($install_path . $install_file, 'r');
while (!feof($f_mod_script))
{
$buffer = fgets($f_mod_script, 4096);
// if the line starts with #, this is either a comment or an action command
// after obtaining the command, skip any comments until we reach the command body
if (($buffer[0] == '#') && ($in_header))
{
// do nothing until we are out of the command header!!
}
// not in a header so this comment is either a random comment or start of a command header
else if ($buffer[0] == '#')
{
// if we find [ and ] and OPEN on this line, then we can be reasonably sure we've got an OPEN command
if ((strstr($buffer, '[')) && (strstr($buffer, ']')) && (strstr($buffer, 'OPEN')))
{
// get us past any remaining # lines
$buffer = fgets($f_mod_script, 4096);
while ($buffer[0] == '#')
{
if ( feof($f_mod_script))
{
break;
}
$buffer = fgets($f_mod_script, 4096);
}
// loop until we get a filename (a non-whitespace line) or the next # line
while (!feof($f_mod_script))
{
// got a line with some text not starting with #, so we're calling this a filename ;)
if ((strlen(trim($buffer)) > 0) && ($buffer[0] != '#'))
{
$files[] = trim($buffer);
break;
}
// we found a # so get us out of here
else if ($buffer[0] == '#')
{
break;
}
$buffer = fgets($f_mod_script, 4096);
}
// if we hit eof, then get us out of here
if (feof($f_mod_script))
{
break;
}
}
}
// not a comment or command so this is the body of the command
else
{
$in_header = false;
}
}
fclose($f_mod_script);
// Show the preview page
$template->set_filenames(array(
'body' => 'admin/mod_preview.tpl')
);
$template->assign_vars(array(
'L_HEADER' => $lang['EM_preview_mode'],
'L_PREVIEW_DESC' => $lang['EM_preview_desc'],
'L_FILENAME' => $lang['EM_preview_filename'],
'L_VIEW' => $lang['EM_preview_view'])
);
// load in the filename and link info
for ($i=0; $iassign_block_vars('files', array(
'NAME' => $files[$i],
'URL' => $link)
);
}
// if there are no files to be modified, then display the message
if ( count($files) == 0)
{
$template->assign_block_vars('nofiles', array(
'L_NO_FILES' => $lang['EM_preview_nofile'])
);
}
}
//
// download or display a backup of the core phpBB file
//
else if (($mode == 'display_backup') || ($mode == 'download_backup'))
{
// open the core file
check_file_scope($process_file, $phpbb_root_path . $script_path, true);
if (!$read_file = fopen($process_file, 'r'))
{
// gotta echo out the message since message_die is not an option
echo sprintf( $lang['EM_err_backup_open'], $process_file) . "\n";
exit;
}
// write out the lines
while (!feof($read_file))
{
$newline = fgets($read_file, 4096);
if ($mode == 'download_backup')
{
echo $newline;
}
else
{
echo htmlspecialchars($newline);
}
}
fclose($read_file);
// finish the PRE formatting tag
if ($mode == 'display_backup')
{
echo "\n\n\n";
}
// done! done! done!
exit;
}
//
// process the MOD script and modify the files
//
else if (($mode == 'process' ) || ($mode == 'display_file') || ($mode == 'download_file'))
{
// 0.0.11 preview mode
$preview = (isset($HTTP_POST_VARS['preview'])) ? 1 : ($mode == 'display_file') ? 1 : 0;
$current_command = '';
$commands = array();
$body = array();
$in_header = false; // in the header of the command (the ## section)
$line_num = 0; // line number in the MOD script we are parsing
$found_file = false; // only for the special cases
//
// open the mod script and load an array with commands to execute
//
check_file_scope($install_path . $install_file, $phpbb_root_path . $script_path);
$f_mod_script = fopen($install_path . $install_file, 'r');
while (!feof($f_mod_script))
{
$buffer = fgets($f_mod_script, 4096);
$line_num++;
// if the line starts with #, this is either a comment or an action command; will also tell us when
// we've hit the last search line of the target content for this command (meaning we've reached the
// next command)
// after obtaining the command, skip any comments until we reach the command body
if (($buffer[0] == '#') && ($in_header))
{
// do nothing until we are out of the command header!!
}
// not in a header so this comment is either a random comment or start of a command header
else if ($buffer[0] == '#')
{
// done with last command now that we've hit a comment (regardless if a new command or just a comment)
if ( $current_command != '')
{
$current_command = '';
}
// if we find [ and ] on this line, then we can be reasonably sure it is an action command
if ((strstr($buffer, '[')) && (strstr($buffer, ']')))
{
//
// we know it's an action, take appropriate steps for the action; see if the current command
// is found on our list; NOTE: since we are using strstr, it is important to keep the
// IN-LINE commands listed before thier similarly named cousins
//
if (strstr($buffer, 'OPEN'))
{
$current_command = 'OPEN';
}
else if (strstr($buffer, 'IN-LINE FIND'))
{
$current_command = 'IN-LINE FIND';
}
else if (strstr($buffer, 'FIND'))
{
$current_command = 'FIND';
}
else if (strstr($buffer, 'IN-LINE AFTER, ADD'))
{
$current_command = 'IN-LINE AFTERADD';
}
else if (strstr($buffer, 'AFTER, ADD'))
{
$current_command = 'AFTERADD';
}
else if (strstr($buffer, 'IN-LINE BEFORE, ADD'))
{
$current_command = 'IN-LINE BEFOREADD';
}
else if (strstr($buffer, 'BEFORE, ADD'))
{
$current_command = 'BEFOREADD';
}
else if (strstr($buffer, 'IN-LINE REPLACE'))
{
$current_command = 'IN-LINE REPLACE';
}
else if (strstr($buffer, 'REPLACE'))
{
$current_command = 'REPLACE';
}
else if (strstr($buffer, 'COPY'))
{
$current_command = 'COPY';
}
else if (strstr($buffer, 'SQL'))
{
$current_command = 'SQL';
}
else if ( strstr($buffer, 'DIY INSTRUCTIONS') )
{
$current_command = 'DIY INSTRUCTIONS';
}
else if ( strstr($buffer, 'INCREMENT') )
{
$current_command = 'INCREMENT';
}
else if (strstr($buffer, 'SAVE/CLOSE'))
{
$current_command = 'CLOSE';
}
// not a known command, let see if it is unrecognized command or just a comment
else
{
$left_bracket = strpos($buffer, '[');
$right_bracket = strpos($buffer, ']');
$left_of_bracket = substr($buffer, 0, $left_bracket);
$right_of_bracket = substr($buffer, $right_bracket);
// if there is no "--" both before and after the brackets, this must be a comment
if (($left_bracket < $right_bracket) && (strstr($left_of_bracket, '--')) && (strstr($right_of_bracket, '--')))
{
$current_command = trim(substr($buffer, $left_bracket+1, (($right_bracket-1)-($left_bracket+1))));
}
}
// handle special cases when we display or download the file; we are looking for the commands
// for one file ONLY, so skip commands until we find the corresponding OPEN
if (($mode == 'display_file') || ($mode == 'download_file'))
{
if ( $current_command != '')
{
// not found found file yet so this is a possible canidate
if ((!$found_file) && ($current_command == 'OPEN'))
{
$in_header = true;
}
// ignore all other commands until we have our file
else if ((!$found_file) && ($current_command != 'OPEN'))
{
$current_command = '';
}
// after found, once we hit another OPEN or the CLOSE, then we are done
else if ((($found_file) && ($current_command == 'OPEN') && (!$in_header)) || ($current_command == 'CLOSE'))
{
$current_command = '';
break;
}
// allow processing of this command
else
{
$in_header = true;
$commands[] = array( 'command' => $current_command, 'line' => $line_num);
$body[] = array();
}
}
}
// normal command processing
else if ( $current_command != '')
{
$in_header = true;
$commands[] = array( 'command' => $current_command, 'line' => $line_num);
$body[] = array();
}
}
}
// not a comment or command so this is the body of the command
else if ( $current_command != '')
{
// handle special cases; make sure this is for the specific file we are looking for
if (($mode == 'display_file') || ($mode == 'download_file'))
{
// not found found file yet so see if this is it
if ((!$found_file) && ($current_command == 'OPEN'))
{
// found the file, excellent!
if (trim($buffer) == $process_file)
{
$commands[] = array( 'command' => $current_command, 'line' => $line_num);
$body[] = array();
$body[ count($body)-1 ][] = $buffer;
$found_file = true;
}
}
// haven't found the file yet, so don't process this command (should never get in here)
else if (!$found_file)
{
$current_command = '';
}
// this command relates to the file we are looking for, so go ahead
else
{
$body[ count($body)-1 ][] = $buffer;
}
$in_header = false;
}
// store this as this body of our command
else
{
$in_header = false;
$body[ count($body)-1 ][] = $buffer;
}
}
}
fclose($f_mod_script);
// load the process mod template unless we are in special case mode
if (($mode != 'display_file') && ($mode != 'download_file'))
{
// set the template
$template->set_filenames(array(
'body' => 'admin/mod_process.tpl')
);
}
$file_list = array();
$search_array = array(); // what we are searching for
$search_fragment = ''; // the IN-LINE FIND fragment we are looking for
$find_array = array(); // contains lines from a FIND which potentially contain our search target
$files_edited = 0;
$num_processed = 0;
$num_unprocessed = 0;
$failed = true;
$exec_close = false; // did we hit the close command?
// grab the EM settings and open the command file
$command_file = get_em_settings('post_process.sh', '', $password, $preview);
// this is really more about moving the other files than is about the command file; establish the FTP connection
// for moving files if necessary
if (!$command_file->modio_prep('move'))
{
$command_file->err_msg = $lang['EM_trace'] . ': main[1]->' . $command_file->err_msg;
message_die(GENERAL_ERROR, '' . $lang['EM_err_critical_error'] . ': ' . $command_file->err_msg . ' ');
}
////////////////////
//////////////////// emcopy - to be fixed and removed in 0.0.11
////////////////////
$display_copy_warning = false;
$display_sql_warning = false;
$sql = array();
//
// now that we have the commands all set let's start to process them
//
// loop through the command and knock 'em out ;-)
for ($i=0; $i' . $lang['EM_err_critical_error'] . "
\n" . $commands[$i]['command'] . $lang['EM_err_no_find'] . " \n" . $lang['EM_line_num'] . $commands[$i]['line']);
break;
}
//
// open phpBB core file
//
if ($commands[$i]['command'] == 'OPEN')
{
// if we were doing an BEFORE or an IN-LINE command we need to write out the find_array
// also, see if we need to write the lines in preview format
if ($i>0)
{
$do_preview = ((strstr($commands[$i-1]['command'], 'IN-LINE') || $commands[$i-1]['command'] == 'INCREMENT') && ($preview)) ? true : false;
}
else
{
$do_preview = false;
}
write_find_array( $find_array, $file_list, $do_preview);
$find_array = array();
// if we already had a file open, close it now
if (!complete_file_reproduction($file_list))
{
// close failed; throw errors and halt
for ($errs=0; $errs' . $lang['EM_err_critical_error'] . "
\n" . $file_list[$errs]->err_msg . " \n" . $lang['EM_line_num'] . $commands[$i]['line']);
}
// halt processing
break;
}
// strip the body of whitespace down and down to a single line
$body[$i] = strip_whitespace($body[$i], true);
// if there is not exactly 1 line then throw a critical error
if ( count($body[$i]) != 1)
{
display_error('' . $lang['EM_err_critical_error'] . "
\n" . $lang['EM_err_comm_open'] . " \n" . $lang['EM_line_num'] . $commands[$i]['line']);
break;
}
// strip off the path and get the file name
$splitarray = explode('/', trim($body[$i][0]));
$filename = $splitarray[count($splitarray)-1];
// now get the path
$path = '';
for ($k=0; $k' . $lang['EM_err_critical_error'] . "
\n" . $lang['EM_err_comm_find'] . " \n" . $lang['EM_line_num'] . $commands[$i]['line']);
break;
}
// do the find and see what happens
$result = perform_find($file_list, $find_array, $search_array);
// display any errors; if it was critical, terminate processing; if warn, remove file from list
// the command will also close the files that we were writing
if (handle_error($result, $file_list, $commands[$i]['line'], true))
{
break;
}
}
//
// write out the find array then write the body
//
else if ($commands[$i]['command'] == 'AFTERADD')
{
$insert_string = '';
for ($j=0; $j>' . $insert_string;
}
// see if we need to write the lines in preview format
$do_preview = ((strstr($commands[$i-1]['command'], 'IN-LINE') || $commands[$i-1]['command'] == 'INCREMENT') && ($preview)) ? true : false;
write_find_array($find_array, $file_list, $do_preview);
write_files($file_list, $insert_string);
// we've written the find array already so we can no longer operate on it
$find_array = array();
}
//
// write the body then write out the find array
//
else if ($commands[$i]['command'] == 'BEFOREADD')
{
$insert_string = '';
for ($j=0; $j>' . $insert_string;
}
write_files($file_list, $insert_string);
// NOTE: since we have not modified the find_array in any way we can still perform operations on it
// so do not write it out
}
//
// write the body then throw out the find array!
//
else if ($commands[$i]['command'] == 'REPLACE')
{
// is this a totally easy command or what!?!?! That's why it is soooo dangerous to use. Another
// mod will never be able to work again if it needs to FIND what we just replaced
// write the replace lines and notice how we never will write the find_array lines
for ($j=0; $j>' . $body[$i][$j]);
}
else
{
write_files($file_list, $body[$i][$j]);
}
}
// we've obliterated the find array already so we can no longer operate on it
$find_array = array();
}
else if ($commands[$i]['command'] == 'INCREMENT')
{
// strip the body of whitespace down and down to a single line
$body[$i] = strip_whitespace($body[$i], true);
// if there is not exactly 1 line then throw a critical error
if (count($body[$i]) != 1)
{
display_error('' . $lang['EM_err_critical_error'] . "
\n" . $commands[$i]['command'] . $lang['EM_err_increment_body'] . " \n" . $lang['EM_line_num'] . $commands[$i]['line']);
break;
}
$inc_data[1] = '{'.$inc_data[1].'}';
$inc_data[2] = isset($inc_data[2]) ? $inc_data[2] : 1;
// perform the increment / throw an error as appropriate
$err_level = FIND_OK;
for ( $file_count = 0; $file_count < count($file_list); $file_count++ )
{
for ( $j = 0; $j < count($find_array); $j++ )
{
$increment_search = ($search_fragment != '') ? $search_fragment : $search_array[$j];
$result = increment_wildcard($inc_data[1], $inc_data[2], $increment_search, $find_array[$file_count][$j]);
if ($result !== false)
{
$find_array[$file_count][$j] = $result;
break;
}
}
if ($j == count($find_array))
{
// halt if this is an english lang file
if (strstr($file_list[$file_count]->path, 'language/lang_english'))
{
$file_list[$file_count]->err_msg = '' . $lang['EM_err_critical_error'] . '
';
$err_level = FIND_FAIL_CRITICAL;
}
// halt if this is a subsilver style file
else if (strstr($file_list[$file_count]->path, 'templates/subSilver'))
{
$file_list[$file_count]->err_msg = '' . $lang['EM_err_critical_error'] . '
';
$err_level = FIND_FAIL_CRITICAL;
}
// if a different lang, then allow to continue processing
else if (strstr($file_list[$file_count]->path, 'language/lang_'))
{
$file_list[$file_count]->err_msg = '' . $lang['EM_err_warning'] . '
';
$err_level = FIND_FAIL_OK;
}
// if a different style file, then allow to continue processing
else if (strstr($file_list[$file_count]->path, 'templates/'))
{
$file_list[$file_count]->err_msg = '' . $lang['EM_err_warning'] . '
';
$err_level = FIND_FAIL_OK;
}
// any other file then halt processing
else
{
$file_list[$file_count]->err_msg = '' . $lang['EM_err_critical_error'] . '
' . htmlspecialchars($search_fragment) . " \n";
}
}
// display any errors; if it was critical, terminate processing; if warn, remove file from list
// the command will also close the files that we were writing
if (handle_error($err_level, $file_list, $commands[$i]['line'], true, $find_array))
{
break;
}
}
//
// IN-LINE commands; perform precision operations on a single line
//
else if (strstr($commands[$i]['command'], 'IN-LINE'))
{
/////////////////////
///////////////////// wasn't there something about not trimming the left side?
/////////////////////
// strip the body of whitespace down and down to a single line
$body[$i] = strip_whitespace($body[$i], true);
// if there is not exactly 1 line then throw a critical error
if (count($body[$i]) != 1)
{
display_error('' . $lang['EM_err_critical_error'] . "
\n" . $commands[$i]['command'] . $lang['EM_err_inline_body'] . " \n" . $lang['EM_line_num'] . $commands[$i]['line']);
break;
}
// if there is no search fragment for an AFTER, BEFORE, or REPLACE then throw a crit error
if (($search_fragment == '') && ($commands[$i]['command'] != 'IN-LINE FIND'))
{
display_error('' . $lang['EM_err_critical_error'] . "
\n" . $commands[$i]['command'] . $lang['EM_err_no_ifind'] . " \n" . $lang['EM_line_num'] .$commands[$i]['line']);
break;
}
// make the actual alteration for after, before, and replace
if ($commands[$i]['command'] == 'IN-LINE AFTERADD')
{
$result = perform_inline_add($find_array, $file_list, $search_fragment, $body[$i][0], 'after');
}
else if ($commands[$i]['command'] == 'IN-LINE BEFOREADD')
{
$result = perform_inline_add($find_array, $file_list, $search_fragment, $body[$i][0], 'before');
}
else if ($commands[$i]['command'] == 'IN-LINE REPLACE')
{
$result = perform_inline_add($find_array, $file_list, $search_fragment, $body[$i][0], 'replace');
}
// strip off white space and get our search fragment (we already know it is not an empty string)
else if ($commands[$i]['command'] == 'IN-LINE FIND')
{
$search_fragment = trim($body[$i][0]);
}
else
{
$bad_command = true;
}
// display any errors; if it was critical, terminate processing; if warn, remove file from list
// the command will also close the files that we were writing
if (handle_error($result, $file_list, $commands[$i]['line'], true, $find_array))
{
break;
}
}
else if ($commands[$i]['command'] == 'SQL')
{
$sql[] = $body[$i];
}
else if ( $commands[$i]['command'] == 'DIY INSTRUCTIONS')
{
$diy[] = $body[$i];
}
//
// setup the copying of files from the mod directory to core directories
//
else if ($commands[$i]['command'] == 'COPY')
{
// strip the body of whitespace lines; allow multiple lines
$body[$i] = strip_whitespace($body[$i], false);
/*
//////////////////////////////////////////////////////////////////////////////
// this COPY command was mostly written by Ptirhiik and integrated by me. It's not perfect yet, and I can't remember why
// since it's been soooooo long since I worked on the dang thing! Will fine tune it later.
//////////////////////////////////////////////////////////////////////////////
////////// yeah.... can't remember what most of these notes mean ;-)
copy to *.*
copy *.*
copy templates/*.* to foo
copy includes/functions?.* to foo
copy templates/subSilver/images/icon*.gif to foo
copy templates/sub* to templates/sav
copy ind*.php to sav*.?u?
copy foo_body.tpl to templates/subSilver/foo_body.tpl
copy foo_body.tpl to templates/subSilver/
copy *.* to templates/subSilver/
want to work:
copy admin_flags.php to admin/admin_flags.php // basic
copy admin_flags.php to admin/admin_flags.php // basic with tabs
copy admin_flags.php to admin/ // to a dir with trailing slash
copy admin_flags.php to admin // to a dir without trailing slash
copy admin_flags.php to admin/*.* // to a dir as *.*
copy admin_flags.?h? to admin // from with ? wildcards
copy admin_flags.* to admin // from with * wildcard
copy a*.* to admin // from with * wildcards
copy *.* to admin // from as *.*
on the bubble:
copy admin_flags.php to admin/* // to a dir as *
copy a*s.* to admin // from with * wildcards
copy templates/sub* to templates/sav // wow!!!
copy ind*.php to sav*.?u? // the heck??
#copy admin_flags.php to admin/
#copy admin_flags.php to admin/*.*
#copy admin_flags.?h? to admin
#copy admin_flags.* to admin
#copy admin_flags.* to admin/
#copy a*.* to admin/
#copy a*.* to admin/xxx // sends files to admin/xxx/ directory
#copy admin_flags.php to admin // careful! Will create a FILE named admin!!
#copy *.* to admin
#copy flags/a*.* to admin
#copy admin_flags.php to admin/* // careful! file named 'admin_flags' w/o .php!
#copy admin_flags.php to admin/*.sfdg
#copy a*s.* to admin
#copy processed/templates/sub* to templates/sav
#copy a*.php to sav*.?u?
*/
// multiple copies : from
$tmp_mult['from_path'] = array();
$tmp_mult['from_file'] = array();
$tmp_mult['to_path'] = array();
$tmp_mult['to_file'] = array();
//
// first pass : split qualified copies from masked copies
//
$bad_copy = false;
for ( $j = 0; $j < count($body[$i]); $j++ )
{
$split_line = array();
// make sure the command is in proper format "copy x to y"
if (!$split_line = copy_check_basic_form($body[$i][$j]))
{
//echo "1 \n";
display_error('' . $lang['EM_err_critical_error'] . "
\n" . $lang['EM_err_copy_format'] . ' ' . trim($body[$i][$j]) . " \n" . $lang['EM_line_num'] .$commands[$i]['line']);
$bad_copy = true;
break;
}
// makes sure the filename+path are ok and do a little formatting
if ((!$targ = copy_check_file(trim( $split_line[1]))) ||
(!$dest = copy_check_file(trim( $split_line[3]))))
{
//echo "2 \n";
display_error('' . $lang['EM_err_critical_error'] . "
\n" . $lang['EM_err_copy_format'] . ' ' . trim($body[$i][$j]) . " \n" . $lang['EM_line_num'] .$commands[$i]['line']);
$bad_copy = true;
break;
}
// final format check, make sure we have a muli dest if we have a multi targ
if ( strstr($targ['file'], '*') || strstr($targ['file'], '?') )
{
// force this to be a multi dest listing if not so already
if ((!strstr( $dest['file'], '*')) && (!strstr( $dest['file'], '?')) )
{
$dest['path'] .= $dest['file'] . '/';
$dest['file'] = '*.*';
}
}
else
{
// check to see if the file exists
if (!file_exists($install_path . $targ['path'] . $targ['file']) )
{
display_error('' . $lang['EM_err_critical_error'] . "
\n" . sprintf($lang['EM_err_comm_copy'], $install_path . $targ['path'], $targ['file']) . ' ' . trim($body[$i][$j]) . " \n" . $lang['EM_line_num'] .$commands[$i]['line']);
$bad_copy = true;
}
}
// store
$tmp_mult['from_path'][] = $targ['path'];
$tmp_mult['from_file'][] = $targ['file'];
$tmp_mult['to_path'][] = $dest['path'];
$tmp_mult['to_file'][] = $dest['file'];
}
// if we failed then halt processing
if ($bad_copy)
{
break;
}
//
// second pass : get the relevant files with the mask
//
for ( $j = 0; $j < count($tmp_mult['from_path']); $j++ )
{
if ($bad_copy)
{
break;
}
$tmp_from_path = $tmp_mult['from_path'][$j];
$tmp_from_file = $tmp_mult['from_file'][$j];
$tmp_to_path = $tmp_mult['to_path'][$j];
$tmp_to_file = $tmp_mult['to_file'][$j];
// from mask
$tmp_all = ($tmp_from_file == '*.*');
$tmp_from_mask = '^' . str_replace(array('*', '?'), array('(.+)', '(.)'), $tmp_from_file . '$');
// to maks
$tmp_to_mask = $tmp_to_file;
$tmp_pos = strrpos($tmp_to_mask, '.');
if ( $tmp_pos === false )
{
$tmp_to_ext = '';
$tmp_to_base = $tmp_to_file;
}
else
{
$tmp_to_ext = substr($tmp_to_file, $tmp_pos+1);
$tmp_to_base = substr($tmp_to_file, 0, $tmp_pos);
}
// stack of subdirs
$tmp_dirs_from = array();
$tmp_dirs_to = array();
// init with the asked dir
array_push($tmp_dirs_from, $tmp_from_path);
array_push($tmp_dirs_to, $tmp_to_path);
// let's go
$first_pass = true;
while ( !empty($tmp_dirs_from) )
{
// get the dir
$tmp_from_dir = array_pop($tmp_dirs_from);
$tmp_to_dir = array_pop($tmp_dirs_to);
// we are no more on the main dir, so accept all files and sub dirs
if ( !$first_pass )
{
$tmp_all = true;
}
$first_pass = false;
// another one bites the dust
if (!$tmp_handle = @opendir($install_path . $tmp_from_dir) )
{
//echo "3 [$install_path][$tmp_from_dir] \n";
display_error('' . $lang['EM_err_critical_error'] . "
\n" . $lang['EM_err_copy_format'] . ' ' . trim($body[$i][$j]) . " \n" . $lang['EM_line_num'] .$commands[$i]['line']);
$bad_copy = true;
break;
}
while ( $tmp_file = readdir($tmp_handle) )
{
// don't take care of . & ..
if ( in_array($tmp_file, array('.', '..')) )
{
continue;
}
// check if relevant name
else if ( !$tmp_all && !ereg($tmp_from_mask, $tmp_file) )
{
continue;
}
// if we keep the full name or are in sub-dirs, don't bother to filter the dest mask
$tmp_to_file = $tmp_file;
if ( !$tmp_all )
{
// split in basename + ext
$tmp_pos = strrpos($tmp_file, '.');
$tmp_from_ext = '';
$tmp_from_base = $tmp_file;
if ( $tmp_pos)
{
$tmp_from_ext = substr($tmp_file, $tmp_pos+1);
$tmp_from_base = substr($tmp_file, 0, $tmp_pos);
}
$w_base = process_file_split($tmp_to_base, $tmp_from_base);
$w_ext = process_file_split($tmp_to_ext, $tmp_from_ext);
// get the final result
$tmp_to_file = $w_base . ( empty($w_ext) ? '' : '.' . $w_ext );
}
// if we are on a dir, push it
if ( is_dir($install_path . $tmp_from_dir . $tmp_file) )
{
array_push($tmp_dirs_from, $tmp_from_dir . $tmp_file . '/');
array_push($tmp_dirs_to, $tmp_to_dir . $tmp_to_file . '/');
}
// we are on a file
else
{
$final = array();
$final = final_formatting($tmp_to_dir, $tmp_to_file, $tmp_from_dir, $tmp_file);
for ($x=0; $xmodio_mkdirs_copy( $final[$x]['to_path']);
$command_file->afile[] = 'copy ' . $final[$x]['from_path'] . $final[$x]['from_file'] . ' ../../../' . $final[$x]['to_path'] . $final[$x]['to_file'];
//echo 'copy ' . $final[$x]['from_path'] . $final[$x]['from_file'] . ' ../../../' . $final[$x]['to_path'] . $final[$x]['to_file'] . " \n";
}
}
}
}
}
// if we failed then halt processing
if ($bad_copy)
{
break;
}
}
//
// we are done! close up shop and stop processing
//
else if ($commands[$i]['command'] == 'CLOSE')
{
// if we haven't dumped the find_array, then do it now
if (count($find_array) != 0)
{
// also, see if we need to write the lines in preview format
$do_preview = ((strstr($commands[$i-1]['command'], 'IN-LINE') || $commands[$i-1]['command'] == 'INCREMENT') && ($preview)) ? true : false;
write_find_array($find_array, $file_list, $do_preview);
$find_array = array();
}
// if we have a file open, close it now
if (!complete_file_reproduction( $file_list))
{
// close failed; throw errors and halt
for ($errs=0; $errs' . $lang['EM_err_critical_error'] . "
\n" . $file_list[$errs]->err_msg . " \n" . $lang['EM_line_num'] . $commands[$i]['line']);
}
// halt processing
break;
}
$body[$i] = array();
$failed = false;
$exec_close = true;
}
else
{
$bad_command = true;
}
//
// where unloved commands go ;-)
//
if ($bad_command)
{
$processed = false;
$num_unprocessed++;
if ($mode == 'process')
{
display_unprocessed_line($commands[$i], $body[$i]);
}
}
// we processed the command, increase our count and display command info on screen
if (($processed) && ($mode == 'process'))
{
$num_processed++;
display_line( $commands[$i], $body[$i]);
}
}
// close the ftp connection
$command_file->modio_cleanup('move');
//
// we will now finish up the download or display file if that's what we're doing
//
if (($mode == 'display_file') || ($mode == 'download_file'))
{
// if we have a file open, close it now
if (!$exec_close)
{
// if we haven't dumped the find_array, then do it now
if (count($find_array) != 0)
{
// also, see if we need to write the lines in preview format
$do_preview = ((strstr($commands[$i-1]['command'], 'IN-LINE') || $commands[$i-1]['command'] == 'INCREMENT') && ($preview)) ? true : false;
write_find_array($find_array, $file_list, $do_preview);
}
// not likely a close error will be thrown
complete_file_reproduction($file_list);
}
// make sure we have the right file
for ($file=0; $filepath . $file_list[$file]->filename))
{
continue;
}
// write out the lines
$preview_display = false;
$preview_count = count($file_list[$file]->afile);
for ($i=0; $i<$preview_count; $i++)
{
// writing to file, so do NOT use htmlspecial chars
if ($mode == 'download_file')
{
echo $file_list[$file]->afile[$i];
}
// writing to screen so you damn well better use htmlspecial chars!
else
{
// if we encountered a line with the designated EM preview symbol then make it stand out
if (substr($file_list[$file]->afile[$i], 0, 4) == 'EM>>')
{
// the first line of a preview display, being bolding
if (!$preview_display)
{
echo '
' . htmlspecialchars(substr($file_list[$file]->afile[$i], 4));
}
// special case: the very last line of the file, end the bolding
else if ($i == ($preview_count-1))
{
echo htmlspecialchars(substr($file_list[$file]->afile[$i], 4));
}
// a middle line of the preview display, just print the line
else
{
echo htmlspecialchars(substr($file_list[$file]->afile[$i], 4));
}
$preview_display = true;
}
// first line following a preview display line, end the bolding and then carry on
else if ($preview_display)
{
echo '
' . htmlspecialchars($file_list[$file]->afile[$i]);
$preview_display = false;
}
// normal line
else
{
echo htmlspecialchars($file_list[$file]->afile[$i]);
}
}
}
// finish the html tag
if ($mode == 'display_file')
{
echo "