index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Index page of the admin tools
  5. * @package chamilo.admin
  6. */
  7. /**
  8. * Code
  9. */
  10. // Language files that need to be included.
  11. $language_file = array('admin', 'tracking','coursebackup');
  12. // Setting the section (for the tabs).
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. // Access restrictions.
  15. api_protect_admin_script(true);
  16. $nameTools = get_lang('PlatformAdmin');
  17. // Displaying the header
  18. $message = '';
  19. if (api_is_platform_admin()) {
  20. if (is_dir(api_get_path(SYS_CODE_PATH).'install/') && is_readable(api_get_path(SYS_CODE_PATH).'install/index.php')) {
  21. $message = Display::return_message(get_lang('InstallDirAccessibleSecurityThreat'),'warning');
  22. }
  23. if (is_dir(api_get_path(SYS_ARCHIVE_PATH)) && !is_writable(api_get_path(SYS_ARCHIVE_PATH))) {
  24. $message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'),'warning');
  25. }
  26. /* ACTION HANDLING */
  27. if (!empty($_POST['Register'])) {
  28. register_site();
  29. $message = Display :: return_message(get_lang('VersionCheckEnabled'),'confirmation');
  30. }
  31. $keyword_url = Security::remove_XSS((empty($_GET['keyword']) ? '' : $_GET['keyword']));
  32. }
  33. if (isset($_GET['msg']) && isset($_GET['type'])) {
  34. if (in_array($_GET['msg'], array('ArchiveDirCleanupSucceeded', 'ArchiveDirCleanupFailed')))
  35. switch($_GET['type']) {
  36. case 'error':
  37. $message = Display::return_message(get_lang($_GET['msg']), 'error');
  38. break;
  39. case 'confirmation':
  40. $message = Display::return_message(get_lang($_GET['msg']), 'confirm');
  41. }
  42. }
  43. $blocks = array();
  44. /* Users */
  45. $blocks['users']['icon'] = Display::return_icon('members.gif', get_lang('Users'), array(), ICON_SIZE_SMALL, false);
  46. $blocks['users']['label'] = api_ucfirst(get_lang('Users'));
  47. if (api_is_platform_admin()) {
  48. $search_form = ' <form method="get" class="form-search" action="user_list.php">
  49. <input class="span3" type="text" name="keyword" value="">
  50. <button class="btn" type="submit">'.get_lang('Search').'</button>
  51. </form>';
  52. $blocks['users']['search_form'] = $search_form;
  53. $items = array(
  54. array('url'=>'user_list.php', 'label' => get_lang('UserList')),
  55. array('url'=>'user_add.php', 'label' => get_lang('AddUsers')),
  56. array('url'=>'user_export.php', 'label' => get_lang('ExportUserListXMLCSV')),
  57. array('url'=>'user_import.php', 'label' => get_lang('ImportUserListXMLCSV')),
  58. );
  59. /*if (api_get_setting('allow_social_tool') == 'true') {
  60. $items[] = array('url'=>'group_add.php', 'label' => get_lang('AddGroups'));
  61. $items[] = array('url'=>'group_list.php', 'label' => get_lang('GroupList'));
  62. }*/
  63. if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
  64. $items[] = array('url'=>'ldap_users_list.php', 'label' => get_lang('ImportLDAPUsersIntoPlatform'));
  65. }
  66. // $items[] = array('url'=>'user_fields.php', 'label' => get_lang('ManageUserFields'));
  67. $items[] = array('url'=>'extra_fields.php?type=user', 'label' => get_lang('ManageUserFields'));
  68. $items[] = array('url'=> api_get_path(WEB_PUBLIC_PATH).'admin/administrator/roles', 'label' => get_lang('Roles'));
  69. } else {
  70. $items = array(
  71. array('url'=>'user_list.php', 'label' => get_lang('UserList')),
  72. array('url'=>'user_add.php', 'label' => get_lang('AddUsers')),
  73. array('url'=>'user_import.php', 'label' => get_lang('ImportUserListXMLCSV')),
  74. );
  75. }
  76. $blocks['users']['items'] = $items;
  77. $blocks['users']['extra'] = null;
  78. if (api_is_platform_admin()) {
  79. /* Courses */
  80. $blocks['courses']['icon'] = Display::return_icon('course.gif', get_lang('Courses'), array(), ICON_SIZE_MEDIUM, false);
  81. $blocks['courses']['label'] = api_ucfirst(get_lang('Courses'));
  82. $search_form = ' <form method="get" class="form-search" action="course_list.php">
  83. <input class="span3" type="text" name="keyword" value="">
  84. <button class="btn" type="submit">'.get_lang('Search').'</button>
  85. </form>';
  86. $blocks['courses']['search_form'] = $search_form;
  87. $items = array();
  88. $items[] = array('url'=>'course_list.php', 'label' => get_lang('CourseList'));
  89. if (api_get_setting('course_validation') != 'true') {
  90. $items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse'));
  91. } else {
  92. $items[] = array('url'=>'course_request_review.php', 'label' => get_lang('ReviewCourseRequests'));
  93. $items[] = array('url'=>'course_request_accepted.php', 'label' => get_lang('AcceptedCourseRequests'));
  94. $items[] = array('url'=>'course_request_rejected.php', 'label' => get_lang('RejectedCourseRequests'));
  95. }
  96. $items[] = array('url'=>'course_export.php', 'label' => get_lang('ExportCourses'));
  97. $items[] = array('url'=>'course_import.php', 'label' => get_lang('ImportCourses'));
  98. $items[] = array('url'=>'course_category.php', 'label' => get_lang('AdminCategories'));
  99. $items[] = array('url'=>'subscribe_user2course.php', 'label' => get_lang('AddUsersToACourse'));
  100. $items[] = array('url'=>'course_user_import.php', 'label' => get_lang('ImportUsersToACourse'));
  101. $items[] = array('url'=>'extra_fields.php?type=course', 'label' => get_lang('ManageCourseFields'));
  102. $items[] = array('url'=>'extra_fields.php?type=question', 'label' => get_lang('ManageQuestionFields'));
  103. if (api_get_setting('gradebook_enable_grade_model') == 'true') {
  104. $items[] = array('url'=>'grade_models.php', 'label' => get_lang('GradeModel'));
  105. }
  106. if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
  107. $items[] = array('url'=>'ldap_import_students.php', 'label' => get_lang('ImportLDAPUsersIntoCourse'));
  108. }
  109. $blocks['courses']['items'] = $items;
  110. $blocks['courses']['extra'] = null;
  111. /* Platform */
  112. $blocks['platform']['icon'] = Display::return_icon('platform.png', get_lang('Platform'), array(), ICON_SIZE_MEDIUM, false);
  113. $blocks['platform']['label'] = api_ucfirst(get_lang('Platform'));
  114. $search_form = ' <form method="get" action="settings.php" class="form-search">
  115. <input class="span3" type="text" name="search_field" value="" >
  116. <input type="hidden" value="search_setting" name="category">
  117. <button class="btn" type="submit">'.get_lang('Search').'</button>
  118. </form>';
  119. $blocks['platform']['search_form'] = $search_form;
  120. $items = array();
  121. $items[] = array('url'=>'settings.php', 'label' => get_lang('PlatformConfigSettings'));
  122. $items[] = array('url'=>'settings.php?category=Plugins','label' => get_lang('Plugins'));
  123. $items[] = array('url'=>'settings.php?category=Regions','label' => get_lang('Regions'));
  124. $items[] = array('url'=>'system_announcements.php', 'label' => get_lang('SystemAnnouncements'));
  125. $items[] = array('url'=> api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=admin', 'label' => get_lang('GlobalAgenda'));
  126. $items[] = array('url'=>'configure_homepage.php', 'label' => get_lang('ConfigureHomePage'));
  127. $items[] = array('url'=>'configure_inscription.php', 'label' => get_lang('ConfigureInscription'));
  128. $items[] = array('url'=>'statistics/index.php', 'label' => get_lang('Statistics'));
  129. $items[] = array('url'=> api_get_path(WEB_CODE_PATH).'mySpace/company_reports.php', 'label' => get_lang('Reports'));
  130. /* Event settings */
  131. if (api_get_setting('activate_email_template') == 'true') {
  132. $items[] = array('url'=>'event_controller.php?action=listing', 'label' => get_lang('EventMessageManagement'));
  133. }
  134. if (api_get_multiple_access_url()) {
  135. if (api_is_global_platform_admin()) {
  136. $items[] = array('url'=>'access_urls.php', 'label' => get_lang('ConfigureMultipleAccessURLs'));
  137. }
  138. }
  139. if (api_get_setting('allow_reservation') == 'true') {
  140. $items[] = array('url'=>'../reservation/m_category.php', 'label' => get_lang('BookingSystem'));
  141. }
  142. if (api_get_setting('allow_terms_conditions') == 'true') {
  143. $items[] = array('url'=>'legal_add.php', 'label' => get_lang('TermsAndConditions'));
  144. }
  145. $blocks['platform']['items'] = $items;
  146. $blocks['platform']['extra'] = null;
  147. }
  148. /* Sessions */
  149. $blocks['sessions']['icon'] = Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_SMALL, false);
  150. $blocks['sessions']['label'] = api_ucfirst(get_lang('Sessions'));
  151. $search_form = ' <form method="GET" class="form-search" action="'.api_get_path(WEB_CODE_PATH).'session/session_list.php">
  152. <input class="span3" type="text" name="keyword" value="">
  153. <button class="btn" type="submit">'.get_lang('Search').'</button>
  154. </form>';
  155. $blocks['sessions']['search_form'] = $search_form;
  156. $items = array();
  157. $items[] = array('url'=> api_get_path(WEB_CODE_PATH).'session/session_list.php', 'label' => get_lang('ListSession'));
  158. $items[] = array('url'=> api_get_path(WEB_CODE_PATH).'session/session_add.php', 'label' => get_lang('AddSession'));
  159. $items[] = array('url'=>'session_category_list.php', 'label' => get_lang('ListSessionCategory'));
  160. $items[] = array('url'=> api_get_path(WEB_CODE_PATH).'session/session_import.php', 'label' => get_lang('ImportSessionListXMLCSV'));
  161. if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
  162. $items[] = array('url'=>'ldap_import_students_to_session.php', 'label' => get_lang('ImportLDAPUsersIntoSession'));
  163. }
  164. $items[] = array('url'=>api_get_path(WEB_CODE_PATH).'session/session_export.php', 'label' => get_lang('ExportSessionListXMLCSV'));
  165. $items[] = array('url'=>'../coursecopy/copy_course_session.php', 'label' => get_lang('CopyFromCourseInSessionToAnotherSession'));
  166. if (api_is_platform_admin()) {
  167. if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) { // option only visible in development mode. Enable through code if required
  168. $items[] = array('url'=>'user_move_stats.php', 'label' => get_lang('MoveUserStats'));
  169. }
  170. $items[] = array('url'=>'career_dashboard.php', 'label' => get_lang('CareersAndPromotions'));
  171. }
  172. $items[] = array('url'=>'usergroups.php', 'label' => get_lang('Classes'));
  173. $items[] = array('url'=>'extra_fields.php?type=session', 'label' => get_lang('ManageSessionFields'));
  174. $blocks['sessions']['items'] = $items;
  175. $blocks['sessions']['extra'] = null;
  176. /* Settings */
  177. if (api_is_platform_admin()) {
  178. $blocks['settings']['icon'] = Display::return_icon('settings.png', get_lang('System'), array(), ICON_SIZE_SMALL, false);
  179. $blocks['settings']['label'] = api_ucfirst(get_lang('System'));
  180. $items = array();
  181. $items[] = array('url'=>'special_exports.php', 'label' => get_lang('SpecialExports'));
  182. if (!empty($_configuration['db_admin_path'])) {
  183. $items[] = array('url'=>$_configuration['db_admin_path'], 'label' => get_lang('AdminDatabases').' ('.get_lang('DBManagementOnlyForServerAdmin').') ');
  184. }
  185. $items[] = array('url'=>'system_status.php', 'label' => get_lang('SystemStatus'));
  186. if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) {
  187. $items[] = array('url'=>'filler.php', 'label' => get_lang('DataFiller'));
  188. }
  189. $items[] = array('url'=>'archive_cleanup.php', 'label' => get_lang('ArchiveDirCleanup'));
  190. $items[] = array('url'=>'system_management.php', 'label' => get_lang('SystemManagement'));
  191. $blocks['settings']['items'] = $items;
  192. $blocks['settings']['extra'] = null;
  193. $blocks['settings']['search_form'] = null;
  194. /* Extensions */
  195. /*
  196. $blocks['extensions']['icon'] = Display::return_icon('visio_meeting.gif', get_lang('ConfigureExtensions'), array(), ICON_SIZE_SMALL, false);
  197. $blocks['extensions']['label'] = api_ucfirst(get_lang('ConfigureExtensions'));
  198. $items = array();
  199. $items[] = array('url'=>'configure_extensions.php?display=visio', 'label' => get_lang('Visioconf'));
  200. $items[] = array('url'=>'configure_extensions.php?display=ppt2lp', 'label' => get_lang('Ppt2lp'));
  201. //$items[] = array('url'=>'configure_extensions.php?display=ephorus', 'label' => get_lang('EphorusPlagiarismPrevention'));
  202. $items[] = array('url'=>'configure_extensions.php?display=search', 'label' => get_lang('SearchEngine'));
  203. $items[] = array('url'=>'configure_extensions.php?display=serverstats', 'label' => get_lang('ServerStatistics'));
  204. $items[] = array('url'=>'configure_extensions.php?display=bandwidthstats', 'label' => get_lang('BandWidthStatistics'));
  205. $blocks['extensions']['items'] = $items;
  206. */
  207. //Skills
  208. if (api_get_setting('allow_skills_tool') == 'true') {
  209. $blocks['skills']['icon'] = Display::return_icon('logo.png', get_lang('Skills'), array(), ICON_SIZE_SMALL, false);
  210. $blocks['skills']['label'] = get_lang('Skills');
  211. $items = array();
  212. //$items[] = array('url'=>'skills.php', 'label' => get_lang('SkillsTree'));
  213. $items[] = array('url'=>'skills_wheel.php', 'label' => get_lang('SkillsWheel'));
  214. $items[] = array('url'=>'skills_import.php', 'label' => get_lang('SkillsImport'));
  215. //$items[] = array('url'=>'skills_profile.php', 'label' => get_lang('SkillsProfile'));
  216. $items[] = array('url'=>api_get_path(WEB_CODE_PATH).'social/skills_ranking.php', 'label' => get_lang('SkillsRanking'));
  217. $items[] = array('url'=>'skills_gradebook.php', 'label' => get_lang('SkillsAndGradebooks'));
  218. $blocks['skills']['items'] = $items;
  219. $blocks['skills']['extra'] = null;
  220. $blocks['skills']['search_form'] = null;
  221. }
  222. /* Chamilo.org */
  223. $blocks['chamilo']['icon'] = Display::return_icon('logo.png', 'Chamilo.org', array(), ICON_SIZE_SMALL, false);
  224. $blocks['chamilo']['label'] = 'Chamilo.org';
  225. $items = array();
  226. $items[] = array('url'=>'http://www.chamilo.org/', 'label' => get_lang('ChamiloHomepage'));
  227. $items[] = array('url'=>'http://www.chamilo.org/forum', 'label' => get_lang('ChamiloForum'));
  228. $items[] = array('url'=>'../../documentation/installation_guide.html', 'label' => get_lang('InstallationGuide'));
  229. $items[] = array('url'=>'../../documentation/changelog.html', 'label' => get_lang('ChangesInLastVersion'));
  230. $items[] = array('url'=>'../../documentation/credits.html', 'label' => get_lang('ContributorsList'));
  231. $items[] = array('url'=>'../../documentation/security.html', 'label' => get_lang('SecurityGuide'));
  232. $items[] = array('url'=>'../../documentation/optimization.html', 'label' => get_lang('OptimizationGuide'));
  233. $items[] = array('url'=>'http://www.chamilo.org/extensions', 'label' => get_lang('ChamiloExtensions'));
  234. $items[] = array('url'=>'http://www.chamilo.org/en/providers', 'label' => get_lang('ChamiloOfficialServicesProviders'));
  235. $blocks['chamilo']['items'] = $items;
  236. $blocks['chamilo']['extra'] = null;
  237. $blocks['chamilo']['search_form'] = null;
  238. // Try to display a maximum before we check the chamilo version and all that.
  239. //session_write_close(); //close session to avoid blocking concurrent access
  240. //flush(); //send data to client as much as allowed by the web server
  241. //ob_flush();
  242. //Version check
  243. $blocks['version_check']['icon'] = Display::return_icon('logo.png', 'Chamilo.org', array(), ICON_SIZE_SMALL, false);
  244. $blocks['version_check']['label'] = get_lang('VersionCheck');
  245. $blocks['version_check']['extra'] = '<div class="admin-block-version"></div>';
  246. $blocks['version_check']['search_form'] = null;
  247. $blocks['version_check']['items'] = null;
  248. //$blocks['version_check']['class'] = '';
  249. }
  250. $admin_ajax_url = api_get_path(WEB_AJAX_PATH).'admin.ajax.php';
  251. $app['template']->assign('web_admin_ajax_url', $admin_ajax_url);
  252. $app['template']->assign('blocks', $blocks);
  253. $app['template']->display('default/admin/settings_index.tpl');
  254. /**
  255. * Displays either the text for the registration or the message that the installation is (not) up to date
  256. *
  257. * @return string html code
  258. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  259. * @version august 2006
  260. * @todo have a 6monthly re-registration
  261. */
  262. function version_check() {
  263. $tbl_settings = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  264. $sql = 'SELECT selected_value FROM '.$tbl_settings.' WHERE variable="registered" ';
  265. $result = Database::query($sql);
  266. $row = Database::fetch_array($result, 'ASSOC');
  267. // The site has not been registered yet.
  268. $return = '';
  269. if ($row['selected_value'] == 'false') {
  270. $return .= get_lang('VersionCheckExplanation');
  271. $return .= '<form class="well" action="'.api_get_self().'" id="VersionCheck" name="VersionCheck" method="post">';
  272. $return .= '<label class="checkbox"><input type="checkbox" name="donotlistcampus" value="1" id="checkbox" />'.get_lang('HideCampusFromPublicPlatformsList');
  273. $return .= '</label><button type="submit" class="btn btn-primary" name="Register" value="'.get_lang('EnableVersionCheck').'" id="register" >'.get_lang('EnableVersionCheck').'</button>';
  274. $return .= '</form>';
  275. check_system_version();
  276. } else {
  277. // Site registered. Call anyway
  278. $return .= check_system_version();
  279. }
  280. return $return;
  281. }
  282. /**
  283. * Check if the current installation is up to date
  284. * The code is borrowed from phpBB and slighlty modified
  285. * @author The phpBB Group <support@phpbb.com> (the code)
  286. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University (the modifications)
  287. * @author Yannick Warnier <ywarnier@beeznest.org> for the move to HTTP request
  288. * @copyright (C) 2001 The phpBB Group
  289. * @return language string with some layout (color)
  290. */
  291. function check_system_version() {
  292. global $_configuration;
  293. $system_version = trim($_configuration['system_version']); // the chamilo version of your installation
  294. if (ini_get('allow_url_fopen') == 1) {
  295. // The number of courses
  296. $number_of_courses = Statistics::count_courses();
  297. // The number of users
  298. $number_of_users = statistics::count_users();
  299. $number_of_active_users = statistics::count_users(null,null,null,true);
  300. $data = array(
  301. 'url' => api_get_path(WEB_PATH),
  302. 'campus' => api_get_setting('siteName'),
  303. 'contact' => api_get_setting('emailAdministrator'),
  304. 'version' => $system_version,
  305. 'numberofcourses' => $number_of_courses,
  306. 'numberofusers' => $number_of_users,
  307. 'numberofactiveusers' => $number_of_active_users,
  308. //The donotlistcampus setting recovery should be improved to make
  309. // it true by default - this does not affect numbers counting
  310. 'donotlistcampus' => api_get_setting('donotlistcampus'),
  311. 'organisation' => api_get_setting('Institution'),
  312. 'language' => api_get_setting('platformLanguage'),
  313. 'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'),
  314. );
  315. $res = _http_request('version.chamilo.org', 80, '/version.php', $data);
  316. if ($res != 0) {
  317. $version_info = $res;
  318. if ($system_version != $version_info) {
  319. $output = '<br /><span style="color:red">' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' <b>Chamilo '.$version_info.'</b>. '.get_lang('YourVersionIs').' <b>Chamilo '.$system_version. '</b>. '.str_replace('http://www.chamilo.org', '<a href="http://www.chamilo.org">http://www.chamilo.org</a>', get_lang('PleaseVisitOurWebsite')).'</span>';
  320. } else {
  321. $output = '<br /><span style="color:green">'.get_lang('VersionUpToDate').': Chamilo '.$version_info.'</span>';
  322. }
  323. } else {
  324. $output = '<span style="color:red">' . get_lang('ImpossibleToContactVersionServerPleaseTryAgain') . '</span>';
  325. }
  326. } else {
  327. $output = '<span style="color:red">' . get_lang('AllowurlfopenIsSetToOff') . '</span>';
  328. }
  329. return $output;
  330. }
  331. /**
  332. * Function to make an HTTP request through fsockopen (specialised for GET)
  333. * Derived from Jeremy Saintot: http://www.php.net/manual/en/function.fsockopen.php#101872
  334. * @param string IP or hostname
  335. * @param int Target port
  336. * @param string URI (defaults to '/')
  337. * @param array GET data
  338. * @param float Timeout
  339. * @param bool Include HTTP Request headers?
  340. * @param bool Include HTTP Response headers?
  341. */
  342. function _http_request($ip, $port = 80, $uri = '/', $getdata = array(), $timeout = 1, $req_hdr = false, $res_hdr = false) {
  343. $verb = 'GET';
  344. $ret = '';
  345. $getdata_str = count($getdata) ? '?' : '';
  346. foreach ($getdata as $k => $v) {
  347. $getdata_str .= urlencode($k) .'='. urlencode($v) . '&';
  348. }
  349. $crlf = "\r\n";
  350. $req = $verb .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf;
  351. $req .= 'Host: '. $ip . $crlf;
  352. $req .= 'User-Agent: Mozilla/5.0 Firefox/3.6.12' . $crlf;
  353. $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf;
  354. $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf;
  355. $req .= 'Accept-Encoding: deflate' . $crlf;
  356. $req .= 'Accept-Charset: utf-8;q=0.7,*;q=0.7' . $crlf;
  357. $req .= $crlf;
  358. if ($req_hdr) { $ret .= $req; }
  359. if (($fp = @fsockopen($ip, $port, $errno, $errstr, $timeout)) == false) {
  360. return "Error $errno: $errstr\n";
  361. }
  362. stream_set_timeout($fp, $timeout);
  363. $r = @fwrite($fp, $req);
  364. $line = @fread($fp,512);
  365. $ret .= $line;
  366. fclose($fp);
  367. if (!$res_hdr) {
  368. $ret = substr($ret, strpos($ret, "\r\n\r\n") + 4);
  369. }
  370. return trim($ret);
  371. }