@($f = fopen($outfile, "w")); if (!$f) { print "Problem: Could not write to {$outfile} - maybe it's running?\n"; exit; } fwrite($f, $stub); fclose($f); print "\n"; while (list(, $file) = each($includefiles)) { $sourcefile = $file[0]; $file = $file[1]; if ($file != "") { $embedfile = str_replace('/', '\\', $file); if (strpos($file, '.php') > -1 & !$option_noencode) { print "Encoding and embedding {$file}\n"; $encdata = mmcache_encode($sourcefile); $data = "<?mmcache_load(\"{$encdata}\");?>"; res_set($outfile, "PHP", $embedfile, $data); } else { print "Embedding {$file}\n"; $data = file_get_contents($sourcefile); res_set($outfile, "PHP", $embedfile, $data); } } } res_set($outfile, "PHP", "MAIN", $mainfile); $extension_loadlist = array(); if (count($extensions) > 0) { while (list(, $file) = each($extensions)) { $extension_file = $file; if (!file_exists($extension_file)) {
function mmcache_encode_file($src, $out, $f, $c, $web) { if (empty($out)) { echo "\n// {$src}\n"; } $prefix = ""; $cmp = mmcache_encode($src, $prefix); if (empty($cmp)) { mmcache_error("Can't compile file \"{$src}\"", $web); if ($f) { if ($c && !empty($out)) { if ($web) { global $web_error; if (!empty($web_error)) { echo "<font color=\"#ff0000\">{$web_error}</font><br>\n"; flush(); $web_error = ""; } } mmcache_copy_file($src, $out, $f, $web); } } else { if (!$web) { exit; } } } else { $cmp = $prefix . '<?php if (!is_callable("mmcache_load") && !@dl((PHP_OS=="WINNT"||PHP_OS=="WIN32")?"TurckLoader.dll":"TurckLoader.so")) { die("This PHP script has been encoded with Turck MMcache, to run it you must install <a href=\\"http://turck-mmcache.sourceforge.net/\\">Turck MMCache or Turck Loader</a>");} return mmcache_load(\'' . $cmp . "');?>\n"; if (!empty($out)) { if (!$f && file_exists($out)) { mmcache_error("Can't create output file \"{$out}\" (already exists)", $web); } else { $file = @fopen($out, "wb"); if (!$file) { mmcache_error("Can't open output file \"{$out}\"", $web); } else { fwrite($file, $cmp); unset($cmp); fclose($file); $stat = stat($src); chmod($out, $stat['mode']); if ($web) { echo "<font color=\"#00aa00\">Encoding: \"{$src}\" -> \"{$out}\"</font><br>\n"; } } } } else { if ($web) { echo "<pre>" . htmlspecialchars($cmp) . "</pre>\n"; } else { echo $cmp; } unset($cmp); } } }
function wurfl_file_parse($wurfl_file, $patch_file = '') { //global $wurfl, $pwurple_stat, $check_patch_params, $checkpatch_result; $wurfl = array(); $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($xml_parser, "pwurple_start_element", "pwurple_end_element"); xml_set_character_data_handler($xml_parser, "characterData"); if (!file_exists($wurfl_file)) { pwurple_log('parse', $wurfl_file . " does not exist"); return false; } if (!($fp = fopen($wurfl_file, "r"))) { pwurple_log('ERROR parse', "could not open XML input"); return false; } //$count = 0; while ($data = fread($fp, 4096)) { //$count++; if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } //if ( $count > 30 ) //return; } fclose($fp); xml_parser_free($xml_parser); pwurple_log('INFO', 'WURFL Parsing done'); pwurple_log('INFO', "Patchfile = {$patch_file}"); $check_patch_params = false; if ($patch_file && file_exists($patch_file) && is_file($patch_file)) { pwurple_log('parse', "Trying to load XML patch file: " . $patch_file); $check_patch_params = true; $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($xml_parser, "pwurple_start_element", "pwurple_end_element"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($patch_file, "r"))) { pwurple_log('parse', "could not open XML patch file: " . $patch_file); } pwurple_log('parse', "Loaded, now parsing"); while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } fclose($fp); xml_parser_free($xml_parser); // logging? $checkpatch_result['device']['id'] } else { if (defined('WURFL_PATCH_FILE') && !file_exists($patch_file)) { pwurple_log('parse', $patch_file . " does not exist"); } else { pwurple_log('parse', "No XML patch file defined"); } } //reset($wurfl); //echo "<pre>"; //print_r($wurfl); //echo "</pre>"; reset($wurfl); $devices = $wurfl["devices"]; // I check if var_export loses any empty key, in this case I force the generic // device. if (var_export_bug()) { $pwurple_agents['generic'] = 'generic'; } foreach ($devices as $one) { $pwurple_agents[$one['user_agent']] = $one['id']; } reset($wurfl); reset($pwurple_agents); if (WURFL_USE_CACHE) { if (defined("WURFL_AGENT2ID_FILE") && file_exists(WURFL_AGENT2ID_FILE) && !is_writeable(WURFL_AGENT2ID_FILE)) { pwurple_log('parse', "ERROR: Unable to remove " . WURFL_AGENT2ID_FILE); //die ('Unable to remove '.WURFL_AGENT2ID_FILE); return; } if (isset($pwurple_stat)) { $cache_stat = $pwurple_stat; } else { $cache_stat = $pwurple_stat = filemtime(WURFL_FILE); if (defined('WURFL_PATCH_FILE') && file_exists(WURFL_PATCH_FILE)) { $patch_stat = filemtime(WURFL_PATCH_FILE); if ($patch_stat > $pwurple_stat) { // if the patch file is newer than the WURFL I set pwurple_stat to that time $pwurple_stat = $patch_stat; } } } if (WURFL_USE_MULTICACHE) { // If using Multicache remove old cache files $pwurple_temp_devices = $wurfl['devices']; $wurfl['devices'] = array(); //Attempt to remove all existing multicache files if (defined("MULTICACHE_DIR") && is_dir(MULTICACHE_DIR) && !is_writeable(MULTICACHE_DIR)) { pwurple_log('parse', "ERROR: Unable to remove files from" . MULTICACHE_DIR); return; } // Get all the agent file names in the multicache directory. Use // glob if available if (function_exists('glob')) { $filelist = glob(MULTICACHE_DIR . "/*" . MULTICACHE_SUFFIX); } else { if ($dh = @opendir(MULTICACHE_DIR)) { $filelist = array(); while (false !== ($file = @readdir($dh))) { $filename = MULTICACHE_DIR . "/{$file}"; if (is_file($filename)) { $filelist[] = $filename; } } @closedir($dh); } } foreach ($filelist as $filename) { @unlink($filename); } } $php_version = PHP_VERSION; list($php_main_version, $php_subversion, $php_subsubversion) = explode('.', $php_version); $fp_cache = fopen(CACHE_FILE, "w"); fwrite($fp_cache, "<?php\n"); // it seems until PHP 4.3.2 var_export had a problem with apostrophes in array keys if ($php_main_version > 4 || $php_main_version == 4 && $php_subversion > 3 || $php_main_version == 4 && $php_subversion == 3 && $php_subsubversion > 2) { if (!WURFL_USE_MULTICACHE) { $pwurple_to_file = var_export($wurfl, true); } $pwurple_agents_to_file = var_export($pwurple_agents, true); $cache_stat_to_file = var_export($cache_stat, true); fwrite($fp_cache, "\$cache_stat={$cache_stat_to_file};\n"); if (!WURFL_USE_MULTICACHE) { fwrite($fp_cache, "\$wurfl={$pwurple_to_file};\n"); } fwrite($fp_cache, "\$pwurple_agents={$pwurple_agents_to_file};\n"); } else { if (!WURFL_USE_MULTICACHE) { $pwurple_to_file = urlencode(serialize($wurfl)); } $pwurple_agents_to_file = urlencode(serialize($pwurple_agents)); $cache_stat_to_file = urlencode(serialize($cache_stat)); fwrite($fp_cache, "\$cache_stat=unserialize(urldecode(\"" . $cache_stat_to_file . "\"));\n"); if (!WURFL_USE_MULTICACHE) { fwrite($fp_cache, "\$wurfl=unserialize(urldecode(\"" . $pwurple_to_file . "\"));\n"); } fwrite($fp_cache, "\$pwurple_agents=unserialize(urldecode(\"" . $pwurple_agents_to_file . "\"));\n"); } fwrite($fp_cache, "?>\n"); fclose($fp_cache); if (defined("WURFL_AGENT2ID_FILE") && file_exists(WURFL_AGENT2ID_FILE)) { @unlink(WURFL_AGENT2ID_FILE); } if (WURFL_USE_MULTICACHE) { // Return the capabilities to the wurfl structure $wurfl['devices'] =& $pwurple_temp_devices; // Write multicache files if (@FORCED_UPDATE === true) { $path = MULTICACHE_TMP_DIR; } else { $path = MULTICACHE_DIR; } if (!is_dir($path)) { @mkdir($path); } foreach ($pwurple_temp_devices as $id => $capabilities) { $fname = urlencode($id); $varname = addcslashes($id, "'\\"); $fp_cache = fopen($path . "/{$fname}" . MULTICACHE_SUFFIX, 'w'); fwrite($fp_cache, "<?php\n"); if ($php_main_version == 4 && $php_subversion > 2 || $php_main_version > 4) { $pwurple_to_file = var_export($capabilities, true); fwrite($fp_cache, "\$_cached_devices['{$varname}']={$pwurple_to_file};\n"); } else { $pwurple_to_file = urlencode(serialize($capabilities)); fwrite($fp_cache, "\$_cached_devices['{$varname}']=unserialize(urldecode(\"" . $pwurple_to_file . "\"));\n"); } fwrite($fp_cache, "?>\n"); fclose($fp_cache); } } // It's probably not really worth encoding cache.php if you're using Multicache if (0 && function_exists('mmcache_encode')) { $empty = ''; set_time_limit(60); $to_file = mmcache_encode(CACHE_FILE, $empty); $to_file = '<?php if (!is_callable("mmcache_load") && !@dl((PHP_OS=="WINNT"||PHP_OS=="WIN32")?"TurckLoader.dll":"TurckLoader.so")) { die("This PHP script has been encoded with Turck MMcache, to run it you must install <a href=\\"http://turck-mmcache.sourceforge.net/\\">Turck MMCache or Turck Loader</a>");} return mmcache_load(\'' . $to_file . "');?>\n"; $fp_cache = fopen(CACHE_FILE, "wb"); fwrite($fp_cache, $to_file); fclose($fp_cache); } } else { $cache_stat = 0; } return array($cache_stat, $wurfl, $pwurple_agents); }
function _MmCacheEncodeString($string) { if (empty($string)) { return false; } // create temporary file name $tmp_name = tempnam("/tmp", "mmcache_encode_"); // attempt to open the file for writing if (!($fp = fopen($tmp_name, 'wb'))) { return false; } // write our string to the file if (!fwrite($fp, $string, strlen($string))) { @fclose($fp); // remove our temporary file @unlink($tmp_name); return false; } // close the file @fclose($fp); // use mmcache to encode the file $encoded_contents = mmcache_encode($tmp_name); // remove our temporary file @unlink($tmp_name); if (!empty($encoded_contents)) { return $encoded_contents; } else { return false; } }