Exemplo n.º 1
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        $user->add_lang('install');
        $this->tpl_name = 'acp_update';
        $this->page_title = 'ACP_VERSION_CHECK';
        // Get current and latest version
        $errstr = '';
        $errno = 0;
        $info = get_remote_file('www.phpbb.com', '/updatecheck', defined('PHPBB_QA') ? '30x_qa.txt' : '30x.txt', $errstr, $errno);
        if ($info === false) {
            trigger_error($errstr, E_USER_WARNING);
        }
        $info = explode("\n", $info);
        $latest_version = trim($info[0]);
        $announcement_url = trim($info[1]);
        $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update');
        // Determine automatic update...
        $sql = 'SELECT config_value
			FROM ' . CONFIG_TABLE . "\n\t\t\tWHERE config_name = 'version_update_from'";
        $result = $db->sql_query($sql);
        $version_update_from = (string) $db->sql_fetchfield('config_value');
        $db->sql_freeresult($result);
        $current_version = !empty($version_update_from) ? $version_update_from : $config['version'];
        $up_to_date_automatic = version_compare(str_replace('rc', 'RC', strtolower($current_version)), str_replace('rc', 'RC', strtolower($latest_version)), '<') ? false : true;
        $up_to_date = version_compare(str_replace('rc', 'RC', strtolower($config['version'])), str_replace('rc', 'RC', strtolower($latest_version)), '<') ? false : true;
        $template->assign_vars(array('S_UP_TO_DATE' => $up_to_date, 'S_UP_TO_DATE_AUTO' => $up_to_date_automatic, 'S_VERSION_CHECK' => true, 'U_ACTION' => $this->u_action, 'LATEST_VERSION' => $latest_version, 'CURRENT_VERSION' => $config['version'], 'AUTO_VERSION' => $version_update_from, 'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $announcement_url, $update_link)));
    }
 function main($id, $mode)
 {
     global $user, $template;
     global $phpbb_admin_path, $phpEx;
     $phpbb_root_path = '';
     // mpv fix?
     $phpEx = '';
     // mpv fix?
     $this->tpl_name = 'acp_version_check';
     $this->page_title = 'ACP_MOD_VERSION_CHECK';
     // load version files
     $class_functions = array();
     $mod_directory = $phpbb_admin_path . 'mods/';
     $dh = @opendir($mod_directory);
     if (!$dh) {
         trigger_error('NO_ACCESS_MODS_DIRECTORY');
     }
     while (($file = readdir($dh)) !== false) {
         if (preg_match('/^(.+)_version.' . $phpEx . '$/', $file)) {
             include $phpbb_root_path . $mod_directory . $file . $phpEx;
             $class_name = substr($file, 0, -(strlen($phpEx) + 1));
             $class_functions[] = call_user_func(array($class_name, 'version'));
         }
     }
     closedir($dh);
     foreach ($class_functions as $var) {
         // Get current and latest version
         $errstr = '';
         $errno = 0;
         $mod_version = $user->lang['NO_INFO'];
         $data = array('title' => $var['title'], 'description' => $user->lang['NO_INFO'], 'download' => $user->lang['NO_INFO'], 'announcement' => $user->lang['NO_INFO']);
         $file = get_remote_file($var['file'][0], '/' . $var['file'][1], $var['file'][2], $errstr, $errno);
         if ($file) {
             if (version_compare(PHP_VERSION, '5.0.0', '<')) {
                 $row = array();
                 $data_array = $this->setup_array($file);
                 $row = $data_array['mods'][$var['tag']];
                 $mod_version = $row['mod_version'];
                 $mod_version = $mod_version['major'] . '.' . $mod_version['minor'] . '.' . $mod_version['revision'] . $mod_version['release'];
                 $data = array('title' => $row['title'], 'description' => $row['description'], 'download' => $row['download'], 'announcement' => $row['announcement']);
             } else {
                 // let's not stop the page from loading if a mod author messed up their mod check file
                 // also take care of one of the easiest ways to mess up an xml file: "&"
                 $mod = @simplexml_load_string(str_replace('&', '&amp;', $file));
                 if (isset($mod->{$var}['tag'])) {
                     $row = $mod->{$var}['tag'];
                     $mod_version = $row->mod_version->major . '.' . $row->mod_version->minor . '.' . $row->mod_version->revision . $row->mod_version->release;
                     $data = array('title' => $row->title, 'description' => $row->description, 'download' => $row->download, 'announcement' => $row->announcement);
                 }
             }
         }
         // remove spaces from the version in the mod file stored locally
         $version = str_replace(' ', '', $var['version']);
         $version_compare = version_compare($version, $mod_version, '<') ? false : true;
         $template->assign_block_vars('mods', array('ANNOUNCEMENT' => $data['announcement'], 'AUTHOR' => $var['author'], 'CURRENT_VERSION' => $version, 'DESCRIPTION' => $data['description'], 'DOWNLOAD' => $data['download'], 'LATEST_VERSION' => $mod_version, 'TITLE' => $data['title'], 'UP_TO_DATE' => sprintf(!$version_compare ? $user->lang['NOT_UP_TO_DATE'] : $user->lang['UP_TO_DATE'], $data['title']), 'S_UP_TO_DATE' => $version_compare, 'U_AUTHOR' => 'http://www.phpbb.com/community/memberlist.php?mode=viewprofile&un=' . $var['author']));
     }
 }
Exemplo n.º 3
0
 public function __construct()
 {
     global $db, $template, $user;
     global $quickinstall_path, $phpbb_root_path, $phpEx, $config, $qi_config;
     if ($qi_config['version_check']) {
         // we use this for get_remote_file()
         include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
         // Get current and latest version
         $errstr = '';
         $errno = 0;
         $info = get_remote_file('phpbbmodders.net', '/files/updatecheck', 'quickinstall.txt', $errstr, $errno);
         if ($info !== false) {
             list($latest_version, $announcement_url) = explode("\n", $info);
             $up_to_date = version_compare(str_replace('rc', 'RC', strtolower($qi_config['qi_version'])), str_replace('rc', 'RC', strtolower($latest_version)), '<') ? false : true;
             $template->assign_vars(array('UP_TO_DATE' => $up_to_date, 'L_UPDATE' => sprintf($user->lang['UPDATE_TO'], $announcement_url, $latest_version)));
         }
     }
     $changelog_file = $quickinstall_path . 'changelog.xml';
     if ($use_changelog = file_exists($changelog_file)) {
         // let's get the changelog :)
         $automod_path = '';
         if (file_exists($quickinstall_path . 'sources/automod/includes')) {
             // Let's assume they copied the contents.
             $automod_path = $quickinstall_path . 'sources/automod/';
         } else {
             if (file_exists($quickinstall_path . 'sources/automod/root/includes')) {
                 // They copied to complete root to automod instead of its contents.
                 $automod_path = $quickinstall_path . 'sources/automod/root/';
             } else {
                 if (file_exists($quickinstall_path . 'sources/automod/upload/includes')) {
                     // They copied to complete upload directory to automod instead of its contents.
                     $automod_path = $quickinstall_path . 'sources/automod/upload/';
                 } else {
                     trigger_error($user->lang['NO_AUTOMOD']);
                 }
             }
         }
         include $automod_path . 'includes/mod_parser.' . $phpEx;
         $xml_parser = new xml_array();
         $data = $xml_parser->parse($changelog_file, file_get_contents($changelog_file));
         foreach ($data[0]['children']['ENTRY'] as &$entry) {
             list($year, $month, $day) = explode('-', $entry['children']['DATE'][0]['data']);
             $template->assign_block_vars('history', array('DATE' => qi::format_date(mktime(null, null, null, intval($month), intval($day), intval($year)), 'Y-m-d'), 'VERSION' => $entry['children']['VERSION'][0]['data']));
             foreach ($entry['children']['CHANGELOG'][0]['children']['CHANGE'] as &$change) {
                 $template->assign_block_vars('history.changelog', array('CHANGE' => htmlspecialchars($change['data'])));
             }
         }
     }
     $template->assign_vars(array('S_IN_INSTALL' => false, 'S_IN_SETTINGS' => false, 'S_ALLOW_VERSION_CHECK' => $qi_config['version_check'], 'S_ALLOW_CHANGELOG' => $use_changelog, 'PAGE_MAIN' => false));
     // Output page
     qi::page_header($user->lang['QI_ABOUT'], $user->lang['QI_ABOUT_ABOUT']);
     $template->set_filenames(array('body' => 'about_body.html'));
     qi::page_footer();
 }
Exemplo n.º 4
0
function scrape($url, $infohash = '')
{
    global $TABLE_PREFIX;
    if (isset($url)) {
        $extannunce = str_replace('announce', 'scrape', urldecode($url));
        if ($infohash != '') {
            $ihash = array();
            $ihash = explode('\',\'', $infohash);
            $info_hash = '';
            foreach ($ihash as $myihash) {
                $info_hash .= '&info_hash=' . escapeURL($myihash);
            }
            $info_hash = substr($info_hash, 1);
            $stream = get_remote_file($extannunce . '?' . $info_hash);
        } else {
            $stream = get_remote_file($extannunce);
        }
        $stream = trim(stristr($stream, 'd5:files'));
        if (strpos($stream, 'd5:files') === false) {
            $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash == '' ? '' : ' AND info_hash IN ("' . $infohash . '")'));
            write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (not connectable)', '');
            return;
        }
        $array = BDecode($stream);
        if (!isset($array) || $array == false || !isset($array['files'])) {
            $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash == '' ? '' : ' AND info_hash IN ("' . $infohash . '")'));
            write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (not bencode data)', '');
            return;
        }
        $files = $array['files'];
        if (!is_array($files)) {
            $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash = '' ? '' : ' AND info_hash IN ("' . $infohash . '")'));
            write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (probably deleted torrent(s))', '');
            return;
        }
        foreach ($files as $hash => $data) {
            $seeders = $data['complete'];
            $leechers = $data['incomplete'];
            $completed = isset($data['downloaded']) ? $data['downloaded'] : 0;
            $torrenthash = bin2hex(stripslashes($hash));
            $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW(), lastsuccess=NOW(), seeds=' . $seeders . ', leechers=' . $leechers . ', finished=' . $completed . ' WHERE announce_url = "' . $url . '"' . ($hash == '' ? '' : ' AND info_hash="' . $torrenthash . '";'));
            if (mysql_affected_rows() == 1) {
                write_log('SUCCESS update external torrent from ' . $url . ' tracker (infohash: ' . $torrenthash . ')', '');
            }
        }
    }
}
Exemplo n.º 5
0
 public function test_version_phpbb_com()
 {
     $hostname = 'version.phpbb.com';
     if (!phpbb_checkdnsrr($hostname, 'A')) {
         $this->markTestSkipped(sprintf('Could not find a DNS record for hostname %s. ' . 'Assuming network is down.', $hostname));
     }
     $errstr = $errno = null;
     $file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno);
     $this->assertNotEquals(0, strlen($file), 'Failed asserting that the response is not empty.');
     $this->assertSame('', $errstr, 'Failed asserting that the error string is empty.');
     $this->assertSame(0, $errno, 'Failed asserting that the error number is 0 (i.e. no error occurred).');
     $lines = explode("\n", $file);
     $this->assertGreaterThanOrEqual(2, sizeof($lines), 'Failed asserting that the version file has at least two lines.');
     $this->assertStringStartsWith('3.', $lines[0], "Failed asserting that the first line of the version file starts with '3.'");
     $this->assertNotSame(false, filter_var($lines[1], FILTER_VALIDATE_URL), 'Failed asserting that the second line of the version file is a valid URL.');
     $this->assertContains('http', $lines[1]);
     $this->assertContains('phpbb.com', $lines[1], '', true);
 }
 /**
  * A copy of Handyman` s MOD version check, to view it on the gallery overview
  */
 public static function check($return_version = false)
 {
     global $user, $template;
     global $phpbb_admin_path, $phpEx;
     if (!function_exists('get_remote_file')) {
         global $phpbb_root_path;
         include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
     }
     if (!$phpbb_admin_path || !is_dir($phpbb_admin_path)) {
         global $phpbb_root_path;
         $phpbb_admin_path = $phpbb_root_path . 'adm/';
     }
     // load version files
     $class_functions = array();
     include $phpbb_admin_path . 'mods/phpbb_gallery_version.' . $phpEx;
     $class_name = 'phpbb_gallery_version';
     $var = call_user_func(array($class_name, 'version'));
     // Get current and latest version
     $errstr = '';
     $errno = 0;
     $mod_version = '0.0.0';
     if (!$return_version) {
         $mod_version = $user->lang['NO_INFO'];
         $data = array('title' => $var['title'], 'description' => $user->lang['NO_INFO'], 'download' => $user->lang['NO_INFO'], 'announcement' => $user->lang['NO_INFO']);
     }
     $file = get_remote_file($var['file'][0], '/' . $var['file'][1], $var['file'][2], $errstr, $errno);
     if ($file) {
         // let's not stop the page from loading if a mod author messed up their mod check file
         // also take care of one of the easiest ways to mess up an xml file: "&"
         $mod = @simplexml_load_string(str_replace('&', '&amp;', $file));
         if (isset($mod->{$var}['tag'])) {
             $row = $mod->{$var}['tag'];
             $mod_version = $row->mod_version->major . '.' . $row->mod_version->minor . '.' . $row->mod_version->revision . $row->mod_version->release;
             $data = array('title' => $row->title, 'description' => $row->description, 'download' => $row->download, 'announcement' => $row->announcement);
         }
     }
     // remove spaces from the version in the mod file stored locally
     $version = str_replace(' ', '', $var['version']);
     if ($return_version) {
         return $mod_version;
     }
     $version_compare = version_compare($version, $mod_version, '<') ? false : true;
     $template->assign_block_vars('mods', array('ANNOUNCEMENT' => $data['announcement'], 'AUTHOR' => $var['author'], 'CURRENT_VERSION' => $version, 'DESCRIPTION' => $data['description'], 'DOWNLOAD' => $data['download'], 'LATEST_VERSION' => $mod_version, 'TITLE' => $data['title'], 'UP_TO_DATE' => sprintf(!$version_compare ? $user->lang['NOT_UP_TO_DATE'] : $user->lang['UP_TO_DATE'], $data['title']), 'S_UP_TO_DATE' => $version_compare, 'U_AUTHOR' => 'http://www.phpbb.com/community/memberlist.php?mode=viewprofile&un=' . $var['author']));
 }
Exemplo n.º 7
0
 public function check_version()
 {
     global $db, $template;
     $url = 'phpbbireland.com';
     $sub = 'kiss2/updates';
     $file = 'portal.xml';
     $errstr = '';
     $errno = 0;
     $data = array();
     $data_read = get_remote_file($url, '/' . $sub, $file, $errstr, $errno);
     $mod = @simplexml_load_string(str_replace('&', '&amp;', $data_read));
     if (isset($mod->version_check)) {
         $row = $mod->version_check;
         $version = $row->version->major[0] . '.' . $row->version->minor[0] . '.' . $row->version->revision[0];
         $data = array('title' => $row->title[0], 'description' => $row->description[0], 'download' => $row->download, 'announcement' => $row->announcement, 'version' => $version);
         return $data;
     }
     return null;
 }
 public function fetch_gravatar()
 {
     $gravatar_url = $this->generate_gravatar_url();
     $gravatar_data = get_remote_file($gravatar_url, 10, FALSE, 2);
     if (!empty($gravatar_data) && !empty($gravatar_data['content'])) {
         try {
             $tmpfname = tempnam("/tmp", "GRAVATAR-" . md5($this->get_user_email()));
             $handle = @fopen($tmpfname, "w");
             if ($handle !== FALSE) {
                 fwrite($handle, $gravatar_data['content']);
                 fclose($handle);
                 $this->save_gravatar($tmpfname);
             } else {
                 throw new Exception("Fancy_gravatar: can not open temporary file for writing.");
             }
         } catch (Exception $exception) {
             if (!empty($tmpfname) && file_exists($tmpfname)) {
                 unlink($tmpfname);
             }
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Obtains the latest version information
  * @param string    $current_version    version information
  * @param int       $ttl             Cache version information for $ttl seconds. Defaults to 86400 (24 hours).
  * 
  * @return bool       false on failure.
  **/
 function shareon_version_compare($current_version = '', $version_up_to_date = true, $ttl = 86400)
 {
     global $cache, $template;
     $info = $cache->get('shareon_versioncheck');
     if ($info === false) {
         $errstr = '';
         $errno = 0;
         $info = get_remote_file('www.suportephpbb.com.br', '/shareon', 'shareon.txt', $errstr, $errno);
         if ($info === false) {
             $template->assign_var('S_VERSIONCHECK_FAIL', true);
             $cache->destroy('shareon_versioncheck');
         }
     }
     if ($info !== false) {
         $cache->put('shareon_versioncheck', $info, $ttl);
         $latest_version_info = explode("\n", $info);
         $latest_version = strtolower(trim($latest_version_info[0]));
         $current_version = strtolower(trim($current_version));
         $version_up_to_date = version_compare($current_version, $latest_version, '<') ? false : true;
         $template->assign_vars(array('U_VERSIONCHECK' => $version_up_to_date ? false : $latest_version_info[1], 'S_VERSIONOLD' => $current_version, 'S_VERSIONNEW' => $version_up_to_date ? false : $latest_version_info[0]));
     }
     return $version_up_to_date;
 }
Exemplo n.º 10
0
    /**
     * Get remote file
     */
    function get_file($mode)
    {
        global $user, $db;
        $errstr = '';
        $errno = 0;
        switch ($mode) {
            case 'version_info':
                global $phpbb_root_path, $phpEx;
                $info = get_remote_file('www.phpbbgarage.com', '/updatecheck', '30x.txt', $errstr, $errno);
                if ($info !== false) {
                    $info = explode("\n", $info);
                    $info = trim($info[0]);
                }
                if ($this->test_update !== false) {
                    $info = $this->test_update;
                }
                // If info is false the fsockopen function may not be working. Instead get the latest version from our update file (and pray it is up-to-date)
                if ($info === false) {
                    $update_info = array();
                    include $phpbb_root_path . 'garage/install/update/index.php';
                    $info = empty($update_info) || !is_array($update_info) ? false : $update_info;
                    if ($info !== false) {
                        $info = !empty($info['version']['to']) ? trim($info['version']['to']) : false;
                    }
                }
                break;
            case 'install_info':
                global $phpbb_root_path, $phpEx;
                $install_info = array();
                include $phpbb_root_path . 'garage/install/install/index.php';
                //Handle the installed & supported style themes
                $sql = 'SELECT *
					FROM ' . STYLES_THEME_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    //Check For Imageset Data To Load
                    if (file_exists($phpbb_root_path . "garage/install/install/styles/{$row['theme_path']}/theme/index." . $phpEx)) {
                        $theme_info = array();
                        include $phpbb_root_path . "garage/install/install/styles/{$row['theme_path']}/theme/index." . $phpEx;
                        $install_info['files'] = array_merge($install_info['files'], $theme_info['files']);
                    }
                }
                $db->sql_freeresult($result);
                //Handle the installed & supported style template
                $sql = 'SELECT *
					FROM ' . STYLES_TEMPLATE_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    //Check For Imageset Data To Load
                    if (file_exists($phpbb_root_path . "garage/install/install/styles/{$row['template_path']}/template/index." . $phpEx)) {
                        $template_info = array();
                        include $phpbb_root_path . "garage/install/install/styles/{$row['template_path']}/template/index." . $phpEx;
                        $install_info['files'] = array_merge($install_info['files'], $template_info['files']);
                    }
                }
                $db->sql_freeresult($result);
                //Handle the installed & supported style imagesets
                $sql = 'SELECT *
					FROM ' . STYLES_IMAGESET_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    //Check For Imageset Data To Load
                    if (file_exists($phpbb_root_path . "garage/install/install/styles/{$row['imageset_name']}/imageset/index." . $phpEx)) {
                        $imageset_info = array();
                        include $phpbb_root_path . "garage/install/install/styles/{$row['imageset_name']}/imageset/index." . $phpEx;
                        $install_info['files'] = array_merge($install_info['files'], $imageset_info['files']);
                    }
                    //Check For All Installed Languages
                    $sql = 'SELECT *
					FROM ' . LANG_TABLE;
                    $lresult = $db->sql_query($sql);
                    while ($lrow = $db->sql_fetchrow($lresult)) {
                        //Check For Imageset Data To Load
                        if (file_exists($phpbb_root_path . "garage/install/install/styles/{$row['imageset_name']}/imageset/{$lrow['lang_dir']}/index." . $phpEx)) {
                            $imageset_info = array();
                            include $phpbb_root_path . "garage/install/install/styles/{$row['imageset_name']}/imageset/{$lrow['lang_dir']}/index." . $phpEx;
                            $install_info['files'] = array_merge($install_info['files'], $imageset_info['files']);
                        }
                    }
                    $db->sql_freeresult($lresult);
                }
                $db->sql_freeresult($result);
                $info = empty($install_info) || !is_array($install_info) ? false : $install_info;
                $errstr = $info === false ? $user->lang['WRONG_INFO_FILE_FORMAT'] : '';
                if ($info !== false) {
                    // Adjust the update info file to hold some specific style-related information
                    $info['custom'] = array();
                    /*
                    					// Get custom installed styles...
                    					$sql = 'SELECT template_name, template_path
                    						FROM ' . STYLES_TEMPLATE_TABLE . "
                    						WHERE LOWER(template_name) NOT IN ('subsilver2', 'prosilver')";
                    					$result = $db->sql_query($sql);
                    
                    					$templates = array();
                    					while ($row = $db->sql_fetchrow($result))
                    					{
                    						$templates[] = $row;
                    					}
                    					$db->sql_freeresult($result);
                    
                    					if (sizeof($templates))
                    					{
                    						foreach ($info['files'] as $filename)
                    						{
                    							// Template update?
                    							if (strpos(strtolower($filename), 'styles/prosilver/template/') === 0)
                    							{
                    								foreach ($templates as $row)
                    								{
                    									$info['custom'][$filename][] = str_replace('/prosilver/', '/' . $row['template_path'] . '/', $filename);
                    								}
                    							}
                    						}
                    					}
                    */
                }
                break;
            default:
                trigger_error('Mode for getting remote file not specified', E_USER_ERROR);
                break;
        }
        if ($info === false) {
            trigger_error($errstr, E_USER_ERROR);
        }
        return $info;
    }
function get_remote_file($url, $timeout, $head_only = false, $max_redirects = 10)
{
    $result = null;
    $parsed_url = parse_url($url);
    $allow_url_fopen = strtolower(@ini_get('allow_url_fopen'));
    // Quite unlikely that this will be allowed on a shared host, but it can't hurt
    if (function_exists('ini_set')) {
        @ini_set('default_socket_timeout', $timeout);
    }
    // If we have cURL, we might as well use it
    if (function_exists('curl_init')) {
        // Setup the transfer
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_NOBODY, $head_only);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_USERAGENT, 'PunBB');
        // Grab the page
        $content = @curl_exec($ch);
        $responce_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        // Process 301/302 redirect
        if ($content !== false && ($responce_code == '301' || $responce_code == '302') && $max_redirects > 0) {
            $headers = explode("\r\n", trim($content));
            foreach ($headers as $header) {
                if (substr($header, 0, 10) == 'Location: ') {
                    $responce = get_remote_file(substr($header, 10), $timeout, $head_only, $max_redirects - 1);
                    if ($responce !== null) {
                        $responce['headers'] = array_merge($headers, $responce['headers']);
                    }
                    return $responce;
                }
            }
        }
        // Ignore everything except a 200 response code
        if ($content !== false && $responce_code == '200') {
            if ($head_only) {
                $result['headers'] = explode("\r\n", str_replace("\r\n\r\n", "\r\n", trim($content)));
            } else {
                preg_match('#HTTP/1.[01] 200 OK#', $content, $match, PREG_OFFSET_CAPTURE);
                $last_content = substr($content, $match[0][1]);
                $content_start = strpos($last_content, "\r\n\r\n");
                if ($content_start !== false) {
                    $result['headers'] = explode("\r\n", str_replace("\r\n\r\n", "\r\n", substr($content, 0, $match[0][1] + $content_start)));
                    $result['content'] = substr($last_content, $content_start + 4);
                }
            }
        }
    } else {
        if (function_exists('fsockopen')) {
            $remote = @fsockopen($parsed_url['host'], !empty($parsed_url['port']) ? intval($parsed_url['port']) : 80, $errno, $errstr, $timeout);
            if ($remote) {
                // Send a standard HTTP 1.0 request for the page
                fwrite($remote, ($head_only ? 'HEAD' : 'GET') . ' ' . (!empty($parsed_url['path']) ? $parsed_url['path'] : '/') . (!empty($parsed_url['query']) ? '?' . $parsed_url['query'] : '') . ' HTTP/1.0' . "\r\n");
                fwrite($remote, 'Host: ' . $parsed_url['host'] . "\r\n");
                fwrite($remote, 'User-Agent: PunBB' . "\r\n");
                fwrite($remote, 'Connection: Close' . "\r\n\r\n");
                stream_set_timeout($remote, $timeout);
                $stream_meta = stream_get_meta_data($remote);
                // Fetch the response 1024 bytes at a time and watch out for a timeout
                $content = false;
                while (!feof($remote) && !$stream_meta['timed_out']) {
                    $content .= fgets($remote, 1024);
                    $stream_meta = stream_get_meta_data($remote);
                }
                fclose($remote);
                // Process 301/302 redirect
                if ($content !== false && $max_redirects > 0 && preg_match('#^HTTP/1.[01] 30[12]#', $content)) {
                    $headers = explode("\r\n", trim($content));
                    foreach ($headers as $header) {
                        if (substr($header, 0, 10) == 'Location: ') {
                            $responce = get_remote_file(substr($header, 10), $timeout, $head_only, $max_redirects - 1);
                            if ($responce !== null) {
                                $responce['headers'] = array_merge($headers, $responce['headers']);
                            }
                            return $responce;
                        }
                    }
                }
                // Ignore everything except a 200 response code
                if ($content !== false && preg_match('#^HTTP/1.[01] 200 OK#', $content)) {
                    if ($head_only) {
                        $result['headers'] = explode("\r\n", trim($content));
                    } else {
                        $content_start = strpos($content, "\r\n\r\n");
                        if ($content_start !== false) {
                            $result['headers'] = explode("\r\n", substr($content, 0, $content_start));
                            $result['content'] = substr($content, $content_start + 4);
                        }
                    }
                }
            }
        } else {
            if (in_array($allow_url_fopen, array('on', 'true', '1'))) {
                // PHP5's version of file_get_contents() supports stream options
                if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
                    // Setup a stream context
                    $stream_context = stream_context_create(array('http' => array('method' => $head_only ? 'HEAD' : 'GET', 'user_agent' => 'PunBB', 'max_redirects' => $max_redirects + 1, 'timeout' => $timeout)));
                    $content = @file_get_contents($url, false, $stream_context);
                } else {
                    $content = @file_get_contents($url);
                }
                // Did we get anything?
                if ($content !== false) {
                    // Gotta love the fact that $http_response_header just appears in the global scope (*cough* hack! *cough*)
                    $result['headers'] = $http_response_header;
                    if (!$head_only) {
                        $result['content'] = $content;
                    }
                }
            }
        }
    }
    return $result;
}
    message($lang_admin_ext['No XML support']);
}
$section = isset($_GET['section']) ? $_GET['section'] : null;
// Install an extension
if (isset($_GET['install']) || isset($_GET['install_hotfix'])) {
    ($hook = get_hook('aex_install_selected')) ? eval($hook) : null;
    // User pressed the cancel button
    if (isset($_POST['install_cancel'])) {
        redirect(forum_link(isset($_GET['install']) ? $forum_url['admin_extensions_manage'] : $forum_url['admin_extensions_hotfixes']), $lang_admin_common['Cancel redirect']);
    }
    $id = preg_replace('/[^0-9a-z_]/', '', isset($_GET['install']) ? $_GET['install'] : $_GET['install_hotfix']);
    // Load manifest (either locally or from punbb.informer.com updates service)
    if (isset($_GET['install'])) {
        $manifest = is_readable(FORUM_ROOT . 'extensions/' . $id . '/manifest.xml') ? file_get_contents(FORUM_ROOT . 'extensions/' . $id . '/manifest.xml') : false;
    } else {
        $remote_file = get_remote_file('http://punbb.informer.com/update/manifest/' . $id . '.xml', 16);
        if (!empty($remote_file['content'])) {
            $manifest = $remote_file['content'];
        }
    }
    // Parse manifest.xml into an array and validate it
    $ext_data = xml_to_array($manifest);
    $errors = validate_manifest($ext_data, $id);
    if (!empty($errors)) {
        message(isset($_GET['install']) ? $lang_common['Bad request'] : $lang_admin_ext['Hotfix download failed']);
    }
    // Get core amd major versions
    if (!defined('FORUM_DISABLE_EXTENSIONS_VERSION_CHECK')) {
        list($forum_version_core, $forum_version_major) = explode('.', clean_version($forum_config['o_cur_version']));
        list($extension_maxtestedon_version_core, $extension_maxtestedon_version_major) = explode('.', clean_version($ext_data['extension']['maxtestedon']));
        if (version_compare($forum_version_core . '.' . $forum_version_major, $extension_maxtestedon_version_core . '.' . $extension_maxtestedon_version_major, '>')) {
Exemplo n.º 13
0
/**
 * Obtains the latest version information
 *
 * @param bool $force_update Ignores cached data. Defaults to false.
 * @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false.
 * @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours).
 *
 * @return string | false Version info on success, false on failure.
 */
function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400)
{
    global $cache;
    $info = $cache->get('versioncheck');
    if ($info === false || $force_update) {
        $errstr = '';
        $errno = 0;
        // www.phpBB-SEO.com SEO TOOLKIT BEGIN
        global $config;
        $url = 'www.phpbb-seo.com';
        $dir = (strpos($config['default_lang'], 'fr') !== false ? '/fr' : '/en') . '/updatecheck';
        $info = get_remote_file($url, $dir, defined('PHPBB_SEO_QA') ? 'test_30x.txt' : 'premod_30x.txt', $errstr, $errno);
        //$info = get_remote_file('version.phpbb.com', '/phpbb',
        //		((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);
        // www.phpBB-SEO.com SEO TOOLKIT END
        if ($info === false) {
            $cache->destroy('versioncheck');
            if ($warn_fail) {
                trigger_error($errstr, E_USER_WARNING);
            }
            return false;
        }
        $cache->put('versioncheck', $info, $ttl);
    }
    return $info;
}
Exemplo n.º 14
0
 function main($id, $mode)
 {
     global $db, $user, $auth, $template;
     global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     $user->add_lang(array('acp/board', 'acp/mods/ajax_shoutbox'));
     require $phpbb_root_path . 'includes/functions_shoutbox.' . $phpEx;
     $action = request_var('action', '');
     $submit = isset($_POST['submit']) ? true : false;
     $form_key = 'acp_shoutbox';
     add_form_key($form_key);
     $this->tpl_name = 'acp_shoutbox';
     /**
      *	Validation types are:
      *		string, int, bool,
      *		script_path (absolute path in url - beginning with / and no trailing slash),
      *		rpath (relative), rwpath (realtive, writable), path (relative path, but able to escape the root), wpath (writable)
      */
     switch ($mode) {
         case 'settings':
             $this->tpl_name = 'acp_board';
             $display_vars = array('title' => 'ACP_SHOUTBOX_SETTINGS', 'vars' => array('legend1' => 'GENERAL_SETTINGS', 'as_prune' => array('lang' => 'AS_PRUNE_TIME', 'validate' => 'int', 'type' => 'text:3:10', 'explain' => true, 'append' => ' ' . $user->lang['HOURS']), 'as_max_posts' => array('lang' => 'AS_MAX_POSTS', 'validate' => 'int', 'type' => 'text:3:10', 'explain' => true), 'as_flood_interval' => array('lang' => 'AS_FLOOD_INTERVAL', 'validate' => 'int', 'type' => 'text:3:10', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']), 'as_ie_nr' => array('lang' => 'AS_IE_NR', 'validate' => 'int', 'type' => 'text:3:10', 'explain' => true, 'append' => ' ' . $user->lang['MESSAGES']), 'as_non_ie_nr' => array('lang' => 'AS_NON_IE_NR', 'validate' => 'int', 'type' => 'text:3:10', 'explain' => true, 'append' => ' ' . $user->lang['MESSAGES'])));
             break;
         case 'overview':
             $this->page_title = 'ACP_SHOUTBOX_OVERVIEW';
             $action = request_var('action', '');
             if ($action) {
                 if (!confirm_box(true)) {
                     switch ($action) {
                         default:
                             $confirm = true;
                             $confirm_lang = 'CONFIRM_OPERATION';
                     }
                     if ($confirm) {
                         confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                     }
                 } else {
                     switch ($action) {
                         case 'purge':
                             $sql = 'DELETE FROM ' . SHOUTBOX_TABLE;
                             $db->sql_query($sql);
                             add_log('admin', 'LOG_PURGE_SHOUTBOX');
                             break;
                     }
                 }
             }
             // Get current and latest version
             $errstr = '';
             $errno = 0;
             $info = get_remote_file('www.paulscripts.nl', '/', 'shoutbox.txt', $errstr, $errno);
             if ($info !== false) {
                 $info = explode("\n", $info);
                 $latest_version = trim($info[0]);
                 $up_to_date = version_compare(str_replace('rc', 'RC', strtolower(VERSION)), str_replace('rc', 'RC', strtolower($latest_version)), '<') ? false : true;
                 if (!$up_to_date) {
                     $template->assign_vars(array('S_ERROR' => true, 'ERROR_MSG' => sprintf($user->lang['NEW_VERSION'], VERSION, $latest_version, trim($info[1]))));
                 }
             } else {
                 $template->assign_vars(array('S_ERROR' => true, 'ERROR_MSG' => sprintf($user->lang['UNABLE_CONNECT'], $errstr)));
             }
             $sql = 'SELECT COUNT(shout_id) as total FROM ' . SHOUTBOX_TABLE;
             $result = $db->sql_query($sql);
             $total_posts = $db->sql_fetchfield('total', $result);
             $template->assign_vars(array('TOTAL_POSTS' => $total_posts, 'AS_VERSION' => VERSION, 'U_ACTION' => append_sid($this->u_action)));
             break;
         default:
             trigger_error('NO_MODE', E_USER_ERROR);
             break;
     }
     if ($mode == 'settings') {
         if (isset($display_vars['lang'])) {
             $user->add_lang($display_vars['lang']);
         }
         $this->new_config = $config;
         $cfg_array = isset($_REQUEST['config']) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
         $error = array();
         // We validate the complete config if whished
         validate_config_vars($display_vars['vars'], $cfg_array, $error);
         if ($submit && !check_form_key($form_key)) {
             $error[] = $user->lang['FORM_INVALID'];
         }
         // Do not write values if there is an error
         if (sizeof($error)) {
             $submit = false;
         }
         // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
         foreach ($display_vars['vars'] as $config_name => $null) {
             if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
                 continue;
             }
             $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
             if ($submit) {
                 set_config($config_name, $config_value);
             }
         }
         if ($submit) {
             add_log('admin', 'LOG_AS_CONFIG_' . strtoupper($mode));
             trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
         }
         $this->tpl_name = 'acp_board';
         $this->page_title = $display_vars['title'];
         $template->assign_vars(array('L_TITLE' => $user->lang[$display_vars['title']], 'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'], 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'U_ACTION' => $this->u_action));
         // Output relevant page
         foreach ($display_vars['vars'] as $config_key => $vars) {
             if (!is_array($vars) && strpos($config_key, 'legend') === false) {
                 continue;
             }
             if (strpos($config_key, 'legend') !== false) {
                 $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars));
                 continue;
             }
             $type = explode(':', $vars['type']);
             $l_explain = '';
             if ($vars['explain'] && isset($vars['lang_explain'])) {
                 $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
             } else {
                 if ($vars['explain']) {
                     $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
                 }
             }
             $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($user->lang[$vars['lang']]) ? $user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars)));
             unset($display_vars['vars'][$config_key]);
         }
     }
 }
	/**
	* Get remote file
	*/
	function get_file($mode)
	{
		global $user, $db;

		$errstr = '';
		$errno = 0;

		switch ($mode)
		{
			case 'version_info':
				global $phpbb_root_path, $phpEx;
				$info = get_remote_file('www.phpbb.com', '/updatecheck', ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);

				if ($info !== false)
				{
					$info = explode("\n", $info);
					$info = trim($info[0]);
				}

				if ($this->test_update !== false)
				{
					$info = $this->test_update;
				}

				// If info is false the fsockopen function may not be working. Instead get the latest version from our update file (and pray it is up-to-date)
				if ($info === false)
				{
					$update_info = array();
					include($phpbb_root_path . 'install/update/index.php');
					$info = (empty($update_info) || !is_array($update_info)) ? false : $update_info;

					if ($info !== false)
					{
						$info = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false;
					}
				}
			break;

			case 'update_info':
				global $phpbb_root_path, $phpEx;

				$update_info = array();
				include($phpbb_root_path . 'install/update/index.php');

				$info = (empty($update_info) || !is_array($update_info)) ? false : $update_info;
				$errstr = ($info === false) ? $user->lang['WRONG_INFO_FILE_FORMAT'] : '';

				if ($info !== false)
				{
					// Adjust the update info file to hold some specific style-related information
					$info['custom'] = array();
/*
					// Get custom installed styles...
					$sql = 'SELECT template_name, template_path
						FROM ' . STYLES_TEMPLATE_TABLE . "
						WHERE LOWER(template_name) NOT IN ('subsilver2', 'prosilver')";
					$result = $db->sql_query($sql);

					$templates = array();
					while ($row = $db->sql_fetchrow($result))
					{
						$templates[] = $row;
					}
					$db->sql_freeresult($result);

					if (sizeof($templates))
					{
						foreach ($info['files'] as $filename)
						{
							// Template update?
							if (strpos(strtolower($filename), 'styles/prosilver/template/') === 0)
							{
								foreach ($templates as $row)
								{
									$info['custom'][$filename][] = str_replace('/prosilver/', '/' . $row['template_path'] . '/', $filename);
								}
							}
						}
					}
*/
				}
			break;

			default:
				trigger_error('Mode for getting remote file not specified', E_USER_ERROR);
			break;
		}

		if ($info === false)
		{
			trigger_error($errstr, E_USER_ERROR);
		}

		return $info;
	}
Exemplo n.º 16
0
/**
 * Get remote files
 *
 * @param string $url the file link
 * @param bool|string $save_in save file to this path, or false if not
 * @param int $timeout trying getting the file timeout
 * @param bool $head_only gets only the headers without the contents
 * @param int $max_redirects allowed number of redirects
 * @param bool $binary is the file content binary or not
 * @author punbb and kleeja team
 */
function fetch_remote_file($url, $save_in = false, $timeout = 20, $head_only = false, $max_redirects = 10, $binary = false)
{
    global $plugin;
    ($hook = $plugin->run_hook('kleeja_fetch_remote_file_func')) ? eval($hook) : null;
    //run hook
    #Quite unlikely that this will be allowed on a shared host, but it can't hurt
    if (function_exists('ini_set')) {
        @ini_set('default_socket_timeout', $timeout);
    }
    $allow_url_fopen = function_exists('ini_get') ? strtolower(@ini_get('allow_url_fopen')) : strtolower(@get_cfg_var('allow_url_fopen'));
    if (function_exists('curl_init') && !$save_in) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_NOBODY, $head_only);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; Kleeja)');
        // Grab the page
        $data = @curl_exec($ch);
        $responce_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        // Process 301/302 redirect
        if ($data !== false && ($responce_code == '301' || $responce_code == '302') && $max_redirects > 0) {
            $headers = explode("\r\n", trim($data));
            foreach ($headers as $header) {
                if (substr($header, 0, 10) == 'Location: ') {
                    $responce = fetch_remote_file(substr($header, 10), $save_in, $timeout, $head_only, $max_redirects - 1);
                    if ($head_only) {
                        if ($responce != false) {
                            $headers[] = $responce;
                        }
                        return $headers;
                    } else {
                        return false;
                    }
                }
            }
        }
        #Ignore everything except a 200 response code
        if ($data !== false && $responce_code == '200') {
            if ($head_only) {
                return explode("\r\n", str_replace("\r\n\r\n", "\r\n", trim($data)));
            } else {
                preg_match('#HTTP/1.[01] 200 OK#', $data, $match, PREG_OFFSET_CAPTURE);
                $last_content = substr($data, $match[0][1]);
                $content_start = strpos($last_content, "\r\n\r\n");
                if ($content_start !== false) {
                    return substr($last_content, $content_start + 4);
                }
            }
        }
    } else {
        if (function_exists('fsockopen')) {
            $url_parsed = parse_url($url);
            $host = $url_parsed['host'];
            $port = empty($url_parsed['port']) || $url_parsed['port'] == 0 ? 80 : $url_parsed['port'];
            $path = $url_parsed['path'];
            if (isset($url_parsed["query"]) && $url_parsed["query"] != '') {
                $path .= '?' . $url_parsed['query'];
            }
            if (!($fp = @fsockopen($host, $port, $errno, $errstr, $timeout))) {
                return false;
            }
            #Send a standard HTTP 1.0 request for the page
            fwrite($fp, ($head_only ? 'HEAD' : 'GET') . " {$path} HTTP/1.0\r\n");
            fwrite($fp, "Host: {$host}\r\n");
            fwrite($fp, 'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; Kleeja)' . "\r\n");
            fwrite($fp, 'Connection: Close' . "\r\n\r\n");
            stream_set_timeout($fp, $timeout);
            $stream_meta = stream_get_meta_data($fp);
            #let's open new file to save it in.
            if ($save_in) {
                $fp2 = @fopen($save_in, 'w' . ($binary ? '' : ''));
            }
            #Fetch the response 1024 bytes at a time and watch out for a timeout
            $in = false;
            $h = false;
            $s = '';
            while (!feof($fp) && !$stream_meta['timed_out']) {
                $s = fgets($fp, 1024);
                if ($save_in) {
                    if ($s == "\r\n") {
                        $h = true;
                        continue;
                    }
                    if ($h) {
                        @fwrite($fp2, $s);
                    }
                }
                $in .= $s;
                $stream_meta = stream_get_meta_data($fp);
            }
            fclose($fp);
            if ($save_in) {
                unset($in);
                @fclose($fp2);
                return true;
            }
            #Process 301/302 redirect
            if ($in !== false && $max_redirects > 0 && preg_match('#^HTTP/1.[01] 30[12]#', $in)) {
                $headers = explode("\r\n", trim($in));
                foreach ($headers as $header) {
                    if (substr($header, 0, 10) == 'Location: ') {
                        $responce = get_remote_file(substr($header, 10), $save_in, $timeout, $head_only, $max_redirects - 1);
                        if ($responce != false) {
                            $headers[] = $responce;
                        }
                        return $headers;
                    }
                }
            }
            #Ignore everything except a 200 response code
            if ($in !== false && preg_match('#^HTTP/1.[01] 200 OK#', $in)) {
                if ($head_only) {
                    return explode("\r\n", trim($in));
                } else {
                    $content_start = strpos($in, "\r\n\r\n");
                    if ($content_start !== false) {
                        return substr($in, $content_start + 4);
                    }
                }
            }
            return $in;
        } else {
            if (in_array($allow_url_fopen, array('on', 'true', '1'))) {
                #PHP5's version of file_get_contents() supports stream options
                if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
                    #Setup a stream context
                    $stream_context = stream_context_create(array('http' => array('method' => $head_only ? 'HEAD' : 'GET', 'user_agent' => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; Kleeja)', 'max_redirects' => $max_redirects + 1, 'timeout' => $timeout)));
                    $content = @file_get_contents($url, false, $stream_context);
                } else {
                    $content = @file_get_contents($url);
                }
                # Did we get anything?
                if ($content !== false) {
                    #Gotta love the fact that $http_response_header just appears in the global scope (*cough* hack! *cough*)
                    if ($head_only) {
                        return $http_response_header;
                    }
                    if ($save_in) {
                        $fp2 = fopen($save_in, 'w' . ($binary ? 'b' : ''));
                        @fwrite($fp2, $content);
                        @fclose($fp2);
                        unset($content);
                        return true;
                    }
                    return $content;
                }
            }
        }
    }
    return false;
}
Exemplo n.º 17
0
function generate_ext_versions_cache($inst_exts, $repository_urls, $repository_url_by_extension)
{
    $forum_ext_last_versions = array();
    $forum_ext_repos = array();
    foreach (array_unique(array_merge($repository_urls, $repository_url_by_extension)) as $url) {
        //Get repository timestamp
        $remote_file = get_remote_file($url . '/timestamp', 2);
        $repository_timestamp = empty($remote_file['content']) ? '' : forum_trim($remote_file['content']);
        unset($remote_file);
        if (!is_numeric($repository_timestamp)) {
            continue;
        }
        if (!isset($forum_ext_repos[$url]['timestamp'])) {
            $forum_ext_repos[$url]['timestamp'] = $repository_timestamp;
        }
        if ($forum_ext_repos[$url]['timestamp'] <= $repository_timestamp) {
            foreach ($inst_exts as $ext) {
                $remote_file = get_remote_file($url . '/' . $ext['id'] . '/lastversion', 2);
                $version = empty($remote_file['content']) ? '' : forum_trim($remote_file['content']);
                unset($remote_file);
                if (empty($version) || !preg_match('~^[0-9a-zA-Z\\. +-]+$~u', $version)) {
                    continue;
                }
                $forum_ext_repos[$url]['extension_versions'][$ext['id']] = $version;
                //If key with current extension exist in array, compare it with version in rep-ry
                if (!isset($forum_ext_last_versions[$ext['id']]) || version_compare($forum_ext_last_versions[$ext['id']]['version'], $version, '<')) {
                    $forum_ext_last_versions[$ext['id']] = array('version' => $version, 'repo_url' => $url);
                    $remote_file = get_remote_file($url . '/' . $ext['id'] . '/lastchanges', 2);
                    $last_changes = empty($remote_file['content']) ? '' : forum_trim($remote_file['content']);
                    unset($remote_file);
                    if (!empty($last_changes)) {
                        $forum_ext_last_versions[$ext['id']]['changes'] = $last_changes;
                    }
                }
            }
            //Write timestamp to cache
            $forum_ext_repos[$url]['timestamp'] = $repository_timestamp;
        }
    }
    if (array_keys($forum_ext_last_versions) != array_keys($inst_exts)) {
        foreach ($inst_exts as $ext) {
            if (!in_array($ext['id'], array_keys($forum_ext_last_versions))) {
                $forum_ext_last_versions[$ext['id']] = array('version' => $ext['version'], 'repo_url' => '', 'changes' => '');
            }
        }
    }
    ($hook = get_hook('ch_generate_ext_versions_cache_check_repository')) ? eval($hook) : null;
    // Output config as PHP code
    $fh = @fopen(FORUM_CACHE_DIR . 'cache_ext_version_notifications.php', 'wb');
    if (!$fh) {
        error('Unable to write configuration cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__);
    }
    fwrite($fh, '<?php' . "\n\n" . 'if (!defined(\'FORUM_EXT_VERSIONS_LOADED\')) define(\'FORUM_EXT_VERSIONS_LOADED\', 1);' . "\n\n" . '$forum_ext_repos = ' . var_export($forum_ext_repos, true) . ';' . "\n\n" . ' $forum_ext_last_versions = ' . var_export($forum_ext_last_versions, true) . ";\n\n" . '$forum_ext_versions_update_cache = ' . time() . ";\n\n" . '?>');
    fclose($fh);
}
Exemplo n.º 18
0
/**
 * Obtains the latest version information
 *
 * @param bool $force_update Ignores cached data. Defaults to false.
 * @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false.
 * @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours).
 *
 * @return string | false Version info on success, false on failure.
 */
function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400)
{
    global $cache;
    $info = $cache->get('versioncheck');
    if ($info === false || $force_update) {
        $errstr = '';
        $errno = 0;
        $info = get_remote_file('version.phpbb.com', '/phpbb', defined('PHPBB_QA') ? '30x_qa.txt' : '30x.txt', $errstr, $errno);
        if ($info === false) {
            $cache->destroy('versioncheck');
            if ($warn_fail) {
                trigger_error($errstr, E_USER_WARNING);
            }
            return false;
        }
        $cache->put('versioncheck', $info, $ttl);
    }
    return $info;
}
Exemplo n.º 19
0
 /**
  * Version Checker
  *
  * Format the file like the following:
  * http://www.phpbb.com/updatecheck/30x.txt
  *
  * @param string $url The url to access (ex: www.phpbb.com)
  * @param string $path The path to access (ex: /updatecheck)
  * @param string $file The name of the file to access (ex: 30x.txt)
  *
  * @return array|string Error Message if there was any error, or an array (each line in the file as a value)
  */
 function version_check($url, $path, $file, $timeout = 10, $port = 80)
 {
     if (!function_exists('get_remote_file')) {
         global $phpbb_root_path, $phpEx;
         include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
     }
     $errstr = $errno = '';
     $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout);
     if ($info === false) {
         return $errstr . ' [ ' . $errno . ' ]';
     }
     $info = str_replace("\r\n", "\n", $info);
     $info = explode("\n", $info);
     return $info;
 }
Exemplo n.º 20
0
	/**
	* Get the latest version number from Lithium Studios
	*/
	public static function version_check()
	{
		global $cache;

		$version = $cache->get('asacp_version');
		if ($version === false)
		{
			if (!function_exists('get_remote_file'))
			{
				global $phpbb_root_path, $phpEx;
				include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
			}

			$errstr = $errno = '';
			$version = get_remote_file('lithiumstudios.org', '/updatecheck', 'anti_spam_acp_3_version.txt', $errstr, $errno, 80, 1);

			if ($version !== false)
			{
				$cache->put('asacp_version', $version, 3600);
			}
		}

		return $version;
	}
Exemplo n.º 21
0
 function latest_version_info($force_update = false, $warn_fail = false)
 {
     global $cache;
     $info = $cache->get('_invite_versioncheck');
     if ($info === false || $force_update) {
         $errstr = '';
         $errno = 0;
         $info = get_remote_file('raw.github.com', '/Bycoja/invite-a-friend-versioncheck/master/', 'version.txt', $errstr, $errno);
         if ($info === false) {
             $cache->destroy('_invite_versioncheck');
             if ($warn_fail) {
                 trigger_error($errstr . adm_back_link($this->u_action), E_USER_WARNING);
             }
             return false;
         }
         $cache->put('_invite_versioncheck', $info, 86400);
     }
     return $info;
 }
Exemplo n.º 22
0
/**
* Obtains the latest version information
*
* @param bool $force_update Ignores cached data. Defaults to false.
* @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false.
* @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours).
*
* @return string | false Version info on success, false on failure.
*/
function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400)
{
    global $cache;
    $info = $cache->get('versioncheck');
    if ($info === false || $force_update) {
        $errstr = '';
        $errno = 0;
        $info = get_remote_file('www.icyphoenix.com', '/version', 'ip2x.txt', $errstr, $errno);
        if ($info === false) {
            $cache->destroy('versioncheck');
            if ($warn_fail) {
                trigger_error($errstr, E_USER_WARNING);
            }
            return false;
        }
        $cache->put('versioncheck', $info, $ttl);
    }
    return $info;
}
Exemplo n.º 23
0
     }
     $row = (int) $db->sql_fetchfield('nr');
     echo "<nr>{$row}</nr></xml>";
     exit;
     break;
 case 'version':
     if (!$auth->acl_get('a_')) {
         as_error($user->lang['NO_ADMIN_PERM']);
     }
     /*
      * Version checker, currently only in test!
      */
     // Get current and latest version
     $errstr = '';
     $errno = 0;
     $info = get_remote_file('www.paulscripts.nl', '/', 'shoutbox.txt', $errstr, $errno);
     if ($info === false) {
         trigger_error($errstr, E_USER_WARNING);
     }
     $info = explode("\n", $info);
     $latest_version = trim($info[0]);
     $up_to_date = (string) version_compare(str_replace('rc', 'RC', strtolower(VERSION)), str_replace('rc', 'RC', strtolower($latest_version)), '<') ? false : true;
     $current = VERSION;
     print "<newest>{$latest_version}</newest><current>{$current}</current><uptodate>{$up_to_date}</uptodate></xml>";
     exit;
     break;
 case 'view':
     if (!$auth->acl_get('u_as_view')) {
         as_error($user->lang['NO_VIEW_PERM']);
     }
     $start = request_var('start', 0);
        }
        redirect('person.php');
    }
    //Variabel $datei dient nur der Vereinfachung
    $datei = $GLOBALS[img_person_dir][intern] . $_SESSION[userid];
    //L�schen evtl. vorhandener alter Dateien (mit anderer Endung
    if (file_exists($datei . '.jpg')) {
        unlink($datei . '.jpg');
    }
    if (file_exists($datei . '.gif')) {
        unlink($datei . '.gif');
    }
    //Datei verschieben
    copy($file, $datei . $endung);
    if (file_exists($file)) {
        unlink($file);
    }
    //�nderungen in der Datenbank einf�gen
    global $db;
    $db->query('update person set opt=(opt | 8) where id="' . $_SESSION['userid'] . '"');
}
$output->secure();
if (isset($remote_file)) {
    $file = get_remote_file($remote_file);
}
if (isset($loeschen)) {
    avatar_loeschen();
} else {
    mod_avatar($file);
}
redirect('person.php');
function pun_repository_download_extension($ext_id, &$ext_data, $ext_path = FALSE)
{
    global $base_url, $lang_pun_repository;
    ($hook = get_hook('pun_repository_download_extension_start')) ? eval($hook) : null;
    clearstatcache();
    if (!$ext_path) {
        $ext_path = FORUM_ROOT . 'extensions/' . $ext_id;
        $extract_folder = FORUM_ROOT . 'extensions/';
        $manifiest_path = $ext_path . '/manifest.xml';
    } else {
        $extract_folder = $ext_path;
        $manifiest_path = $ext_path . '/' . $ext_id . '/manifest.xml';
    }
    if (!is_dir($ext_path)) {
        // Create new directory  with 777 mode
        if (@mkdir($ext_path) == false) {
            return sprintf($lang_pun_repository['Can\'t create directory'], $ext_path);
        }
        @chmod($ext_path, 0777);
    } else {
        return sprintf($lang_pun_repository['Directory already exists'], $ext_path);
    }
    // Download extension archive
    $pun_repository_archive = get_remote_file(PUN_REPOSITORY_URL . '/' . $ext_id . '/' . $ext_id . '.tgz', 10);
    if (empty($pun_repository_archive) || empty($pun_repository_archive['content'])) {
        rmdir($ext_path);
        return $lang_pun_repository['Extension download failed'];
    }
    // Save extension to file
    $pun_repository_archive_file = @fopen(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz', 'wb');
    if ($pun_repository_archive_file === false) {
        return $lang_pun_repository['No writting right'];
    }
    fwrite($pun_repository_archive_file, $pun_repository_archive['content']);
    fclose($pun_repository_archive_file);
    if (!defined('PUN_REPOSITORY_TAR_EXTRACT_INCLUDED')) {
        require 'pun_repository_tar_extract.php';
    }
    // Extract files from archive
    $pun_repository_tar = new Archive_Tar_Ex(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz');
    if (!$pun_repository_tar->extract($extract_folder, 0777)) {
        $error = $lang_pun_repository['Can\'t extract'];
        if (isset($pun_repository_tar->errors)) {
            $error .= ' ' . $lang_pun_repository['Extract errors:'] . '<br />' . implode('<br />', $pun_repository_tar->errors);
        }
        unlink(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz');
        @pun_repository_rm_recursive($ext_path);
        return $error;
    }
    // Remove archive
    unlink(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz');
    // Verify downloaded and extracted extension
    $ext_data = xml_to_array(@file_get_contents($manifiest_path));
    ($hook = get_hook('pun_repository_download_extension_end')) ? eval($hook) : null;
    return '';
}
Exemplo n.º 26
0
 /**
  * Version Checker
  *
  * Format the file like the following:
  * http://www.phpbb.com/updatecheck/30x.txt
  *
  * @param string $url The url to access (ex: www.phpbb.com)
  * @param string $path The path to access (ex: /updatecheck)
  * @param string $file The name of the file to access (ex: 30x.txt)
  *
  * @return array|string Error Message if there was any error, or an array (each line in the file as a value)
  */
 function version_check($url, $path, $file, $timeout = 10, $port = 80)
 {
     if (!function_exists('get_remote_file')) {
         include IP_ROOT_PATH . 'includes/functions_admin.' . PHP_EXT;
     }
     $errstr = $errno = '';
     $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout);
     if ($info === false) {
         return $errstr . ' [ ' . $errno . ' ]';
     }
     $info = str_replace("\r\n", "\n", $info);
     $info = explode("\n", $info);
     return $info;
 }
Exemplo n.º 27
0
 /**
  * Obtains the latest version information.
  */
 function obtain_remote_version($force_update = false, $debug = false, $warn_fail = false, $ttl = 86400)
 {
     global $cache, $config;
     $host = 'pbwow.com';
     $directory = '/files';
     $filename = 'version3.txt';
     $port = 80;
     $timeout = 5;
     $info = $cache->get('pbwow_versioncheck');
     if ($info === false || $force_update) {
         $errstr = '';
         $errno = 0;
         $info = get_remote_file($host, $directory, $filename, $errstr, $errno);
         if (empty($info)) {
             $cache->destroy('pbwow_versioncheck');
             if ($warn_fail) {
                 trigger_error($errstr, E_USER_WARNING);
             }
             return false;
         }
         $info = explode("\n", $info);
         $versions = array();
         foreach ($info as $component) {
             list($c, $v, $u) = explode(",", $component);
             $u = strpos($u, '&amp;') === false ? str_replace('&', '&amp;', $u) : $u;
             $versions[trim($c)] = array('version' => trim($v), 'url' => trim($u));
         }
         $info = $versions;
         $cache->put('pbwow_versioncheck', $info, $ttl);
         if ($debug && ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout))) {
             // only use when we are debuggin/troubleshooting
             $a = isset($config['sitename']) ? urlencode($config['sitename']) : '';
             $b = isset($config['server_name']) ? urlencode($config['server_name']) : '';
             $c = isset($config['script_path']) ? urlencode($config['script_path']) : '';
             $d = isset($config['server_port']) ? urlencode($config['server_port']) : '';
             $e = isset($config['board_contact']) ? urlencode($config['board_contact']) : '';
             $f = isset($config['num_posts']) ? urlencode($config['num_posts']) : '';
             $g = isset($config['num_topics']) ? urlencode($config['num_topics']) : '';
             $h = isset($config['num_users']) ? urlencode($config['num_users']) : '';
             $i = isset($config['version']) ? urlencode($config['version']) : '';
             $j = isset($config['pbwow3_version']) ? urlencode($config['pbwow3_version']) : '';
             $k = isset($config['rt_version']) ? urlencode($config['rt_version']) : '';
             $l = isset($config['topic_preview_version']) ? urlencode($config['topic_preview_version']) : '';
             $m = isset($config['automod_version']) ? urlencode($config['automod_version']) : '';
             $n = isset($config['load_cpf_memberlist']) ? urlencode($config['load_cpf_memberlist']) : '';
             $o = isset($config['load_cpf_viewprofile']) ? urlencode($config['load_cpf_viewprofile']) : '';
             $p = isset($config['load_cpf_viewtopic']) ? urlencode($config['load_cpf_viewtopic']) : '';
             $out = "POST {$directory}/debug.php HTTP/1.1\r\n";
             $out .= "HOST: {$host}\r\n";
             $out .= "Content-type: application/x-www-form-urlencoded\n";
             $out .= "Content-Length: " . strlen("a={$a}&b={$b}&c={$c}&d={$d}&e={$e}&f={$f}&g={$g}&h={$h}&i={$i}&j={$j}&k={$k}&l={$l}&m={$m}&n={$n}&o={$o}&p={$p}") . "\r\n";
             $out .= "Connection: close\r\n\r\n";
             $out .= "a={$a}&b={$b}&c={$c}&d={$d}&e={$e}&f={$f}&g={$g}&h={$h}&i={$i}&j={$j}&k={$k}&l={$l}&m={$m}&n={$n}&o={$o}&p={$p}";
             @fwrite($fsock, $out);
             $response = '';
             while (!@feof($fsock)) {
                 $response .= @fgets($fsock, 1024);
             }
             @fclose($fsock);
         }
     }
     return $info;
 }
Exemplo n.º 28
0
$admin["infos"] .= "<tr><td class=\"header\" align=\"center\">PHP version</td></tr><tr><td align=\"left\">" . phpversion() . "</td></tr>";
$sqlver = mysql_fetch_row(do_sqlquery("SELECT VERSION()"));
$admin["infos"] .= "\n<tr><td class=\"header\" align=\"center\">MYSQL version</td></tr><tr><td align=\"left\">{$sqlver['0']}</td></tr>";
$sqlver = mysql_stat();
$sqlver = explode('  ', $sqlver);
$admin["infos"] .= "\n<tr><td valign=\"top\" class=\"header\" align=\"center\">MYSQL stats</td></tr>\n";
for ($i = 0; $i < count($sqlver); $i++) {
    $admin["infos"] .= "<tr><td align=\"left\">{$sqlver[$i]}</td></tr>\n";
}
$admin["infos"] .= "\n</table><br />\n";
unset($sqlver);
// check for news on btiteam site (read rss from comunication forum)
include "{$THIS_BASEPATH}/include/class.rssreader.php";
$btit_news = get_cached_version($btit_url_rss);
if (!$btit_news) {
    $frss = get_remote_file($btit_url_rss);
    if (!$frss) {
        $btit_news = "<div class=\"blocklist\" style=\"padding:5px; align:center;\">Unable to contact Btiteam's site</div>";
    } else {
        $nrss = new rss_reader();
        $rss_array = $nrss->rss_to_array($frss);
        $btit_news = "<div class=\"blocklist\" style=\"padding:5px;\">";
        if (!$rss_array) {
            $btit_news = "<div class=\"blocklist\" style=\"padding:5px;\">Unable to contact Btiteam's site</div>";
        } else {
            foreach ($rss_array[0]["item"] as $id => $rss) {
                $btit_news .= date("d M Y", strtotime($rss["pubDate"])) . ":&nbsp;\n<a href=\"" . $rss["guid"] . "\">" . $rss["title"] . "</a><br />\n<br />\n";
                $btit_news .= "\n" . $rss["description"] . "<br />\n<hr />\n";
            }
        }
        $btit_news .= "</div>";
Exemplo n.º 29
0
 /**
  * UCP Register
  *
  * @param array $data Data from ucp_register
  * @param array $error
  */
 public static function ucp_register($data, &$error)
 {
     global $config, $user;
     if (!$config['asacp_enable']) {
         return;
     }
     // Profile fields stuff
     foreach (self::$profile_fields as $field => $ary) {
         if ($ary['field_type'] == 'disabled') {
             continue;
         }
         switch ($config['asacp_profile_' . $field]) {
             case 1:
                 // Required
                 if (isset($_POST[$field]) && !request_var($field, '')) {
                     $error[] = sprintf($user->lang['FIELD_REQUIRED'], $user->lang[$ary['lang']]);
                 }
                 break;
             case 2:
                 // Normal
                 if (!$config['asacp_profile_during_reg'] && isset($_POST[$field]) && request_var($field, '')) {
                     $error[] = sprintf($user->lang['FIELD_TOO_LONG'], $user->lang[$ary['lang']], 0);
                 }
                 break;
             case 3:
                 // Never allowed
             // Never allowed
             case 4:
                 // Post Count
                 if (isset($_POST[$field]) && request_var($field, '')) {
                     $error[] = sprintf($user->lang['FIELD_TOO_LONG'], $user->lang[$ary['lang']], 0);
                 }
                 break;
         }
     }
     // Stop Forum Spam stuff
     if (!sizeof($error) && $config['asacp_sfs_action'] > 1) {
         if (!function_exists('get_remote_file')) {
             global $phpbb_root_path, $phpEx;
             include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
         }
         $stop_forum_spam_urls = array('api?username='******'username']), 'api?email=' . urlencode($data['email']));
         foreach ($stop_forum_spam_urls as $url) {
             $errstr = $errno = '';
             $file = get_remote_file('stopforumspam.com', '', $url, $errstr, $errno);
             if ($file !== false) {
                 $file = str_replace("\r\n", "\n", $file);
                 $file = explode("\n", $file);
                 $appears = $frequency = false;
                 foreach ($file as $line) {
                     if (strpos($line, '<appears>') !== false && strpos($line, '</appears>') !== false) {
                         $start = strpos($line, '<appears>') + 9;
                         $end = strpos($line, '</appears>') - $start;
                         $appears = substr($line, $start, $end) == 'yes' ? true : false;
                     } else {
                         if (strpos($line, '<frequency>') !== false && strpos($line, '</frequency>') !== false) {
                             $start = strpos($line, '<frequency>') + 11;
                             $end = strpos($line, '</frequency>') - $start;
                             $frequency = (int) substr($line, $start, $end);
                         }
                     }
                 }
                 if ($appears && $frequency >= $config['asacp_sfs_min_freq']) {
                     self::$sfs_spam = true;
                     if ($config['asacp_sfs_action']) {
                         self::add_log('LOG_SPAM_USER_DENIED_SFS', array($url));
                     }
                     break;
                 }
             }
         }
         if (self::$sfs_spam) {
             switch ($config['asacp_sfs_action']) {
                 case 3:
                     $config['require_activation'] = USER_ACTIVATION_SELF;
                     break;
                 case 4:
                     $config['require_activation'] = USER_ACTIVATION_ADMIN;
                     break;
                 case 5:
                     $user->add_lang('mods/asacp');
                     $error[] = $user->lang['PROFILE_SPAM_DENIED'];
                     break;
             }
         }
     }
 }
Exemplo n.º 30
0
        $out .= "Host: {$host}\r\n";
        $out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
        $out .= "Connection: Close\r\n\r\n";
        @fwrite($fp, $out);
        $b = 0;
        $data = '';
        while (!@feof($fp)) {
            $s = @fgets($fp, 1024);
            if ($b) {
                $data .= $s;
            }
            if ($s == "\r\n") {
                $b = 1;
            }
        }
        @fclose($fp);
        $res .= "<b>sock</b> result={$data}<br>";
    } else {
        print "<font color=red>fsockopen ERROR:<br>{$errno}<br>{$errstr}<br></font>";
    }
    if (function_exists('file_get_contents') && ini_get('allow_url_fopen') == 1) {
        $data = '';
        $full_url = 'http://' . $host . '/' . $url;
        $data = file_get_contents($full_url);
        $res .= "<b>fileget</b> result={$data}<br>";
    }
    return $res;
}
print "<font color=blue>Доступные методы загрузки:</font><br>";
$res = get_remote_file('www.propage.ru', 'get.html');
print $res . '</code>';