index.php 22 KB

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