PageRenderTime 78ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/install/install_functions.php

https://github.com/aravindc/pixelpost
PHP | 1274 lines | 699 code | 267 blank | 308 comment | 185 complexity | 728a560f8edca679891c1ee16b6e049a MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // SVN file version:
  3. // $Id$
  4. if(!defined('PP_INSTALL')) { die(header("Location: ../index.php")); }
  5. ////////////////////////////////////////////////////////////////////////////////////
  6. ////////////////////////////////////////////////////////////////////////////////////
  7. ////
  8. //// LANGUAGE SELECTION
  9. ////
  10. ////////////////////////////////////////////////////////////////////////////////////
  11. ////////////////////////////////////////////////////////////////////////////////////
  12. /**
  13. * Supported install languages
  14. *
  15. */
  16. $supported_langs = array(
  17. 'dutch'=>array('NL','Nederlands'),
  18. 'english'=>array('EN','English'),
  19. 'french'=>array('FR','Français'),
  20. 'german'=>array('DE','Deutsch'),
  21. 'italian'=>array('IT','Italiano'),
  22. 'norwegian'=>array('NO','Norsk'),
  23. 'persian'=>array('FA','Farsi'),
  24. 'polish'=>array('PL','Polskiego'),
  25. 'portuguese'=>array('PT','Português'),
  26. 'simplified_chinese'=>array('CN','Chinese'),
  27. 'spanish'=>array('ES','Español'),
  28. 'swedish'=>array('SE','Svenska'),
  29. 'danish'=>array('DK','Dansk'),
  30. 'japanese'=>array('JP','Japanese'),
  31. 'hungarian'=>array('HU','Magyar'),
  32. 'romanian'=>array('RO','Romana'),
  33. 'russian'=>array('RU','Russian'),
  34. 'czech'=>array('CS','Česky')
  35. );
  36. /**
  37. * Set the appropriate language cookie
  38. * @author: Dkozikowski
  39. */
  40. if(isset($_POST['language'])) {
  41. $lang = eregi_replace('[^a-zA-Z]+','',$_POST['language']);
  42. setcookie('pp_install_lang', $lang, false, '/', false, 0);
  43. }
  44. /**
  45. * Determine the correct language to use
  46. * @author: Dkozikowski
  47. */
  48. if(isset($_COOKIE['pp_install_lang'])){ $lang = $_COOKIE['pp_install_lang']; }else{ $lang = "english"; }
  49. if(isset($_POST['language'])) { $lang = eregi_replace('[^a-zA-Z]+','',$_POST['language']); }
  50. if(file_exists("install/language/install-lang-".$lang.".php")) {
  51. require("install/language/install-lang-".$lang.".php");
  52. }else{
  53. if(file_exists("install/language/install-lang-english.php")) {
  54. require("install/language/install-lang-english.php");
  55. }else{
  56. echo "The requested language was not found!";
  57. exit();
  58. }
  59. }
  60. ////////////////////////////////////////////////////////////////////////////////////
  61. ////////////////////////////////////////////////////////////////////////////////////
  62. ////
  63. //// MENU VARIABLES
  64. ////
  65. ////////////////////////////////////////////////////////////////////////////////////
  66. ////////////////////////////////////////////////////////////////////////////////////
  67. /**
  68. * Apply style to active link (Used for navigation)
  69. * @author Dkozikowski
  70. */
  71. if(isset($_GET['view']) && $_GET['view'] == "overview"){
  72. $menu_cat = "overview";
  73. }elseif(isset($_GET['view']) && $_GET['view'] == "install"){
  74. $menu_cat = "install";
  75. }elseif(isset($_GET['view']) && $_GET['view'] == "db_fix"){
  76. $menu_cat = "db_fix";
  77. }elseif(isset($_GET['view']) && $_GET['view'] == "upgrade"){
  78. $menu_cat = "upgrade";
  79. }
  80. if(isset($_GET['cat']) && $_GET['cat'] == "introduction"){
  81. $cat = "introduction";
  82. }elseif(isset($_GET['cat']) && $_GET['cat'] == "license"){
  83. $cat = "license";
  84. }elseif(isset($_GET['cat']) && $_GET['cat'] == "support"){
  85. $cat = "support";
  86. }elseif(isset($_GET['cat']) && $_GET['cat'] == "requirements"){
  87. $cat = "requirements";
  88. }elseif(isset($_GET['cat']) && $_GET['cat'] == "database"){
  89. $cat = "database";
  90. }elseif(isset($_GET['cat']) && $_GET['cat'] == "administrator"){
  91. $cat = "administrator";
  92. }elseif(isset($_GET['cat']) && $_GET['cat'] == "settings"){
  93. $cat = "settings";
  94. }elseif(isset($_GET['cat']) && $_GET['cat'] == "configuration"){
  95. $cat = "configuration";
  96. }elseif(isset($_GET['cat']) && $_GET['cat'] == "finalize"){
  97. $cat = "finalize";
  98. }elseif(isset($_GET['cat']) && $_GET['cat'] == "upgrade"){
  99. $cat = "upgrade";
  100. }elseif(isset($_GET['view']) && $_GET['view'] == "upgrade"){
  101. $cat = "introduction";
  102. }elseif(isset($_GET['view']) && $_GET['view'] == "db_fix"){
  103. $cat = "database";
  104. }else{
  105. $cat = "introduction";
  106. }
  107. function isActive($var,$value){
  108. if($var == $value){ echo ' class="nav_on"'; }else{ echo ' class="nav_off"'; }
  109. }
  110. ////////////////////////////////////////////////////////////////////////////////////
  111. ////////////////////////////////////////////////////////////////////////////////////
  112. ////
  113. //// CREATE LANGUAGE SELECT
  114. ////
  115. ////////////////////////////////////////////////////////////////////////////////////
  116. ////////////////////////////////////////////////////////////////////////////////////
  117. /**
  118. * Return all available language options for the language drop-down menu
  119. * @author: Dkozikowski
  120. */
  121. function langOptions($language){
  122. $options = "";
  123. $dir = "install/language/";
  124. if($handle = opendir($dir)) {
  125. while (false !== ($file = readdir($handle))) {
  126. if(is_file($dir.$file) && ($file != "index.html")) {
  127. $file = ereg_replace("install-lang-","",$file);
  128. $file = ereg_replace(".php","",$file);
  129. $lang = ucfirst($file);
  130. $selected = ($file == $language) ? ' selected="selected"' : '';
  131. $options .= "<option value=\"$file\"$selected>$lang</option>\n";
  132. }
  133. }
  134. closedir($handle);
  135. }
  136. echo $options;
  137. }
  138. /**
  139. * Return all available admin language options for the language drop-down menu
  140. * @author: Dkozikowski
  141. */
  142. function adminLangOptions($language,$admin_language){
  143. $options = "";
  144. $dir = "../language/";
  145. if($handle = opendir($dir)) {
  146. while (false !== ($file = readdir($handle))) {
  147. $admin_pre = substr("$file",0,6);
  148. if(is_file($dir.$file) && ($file != "index.html") && $admin_pre == "admin-") {
  149. $file = ereg_replace("admin-lang-","",$file);
  150. $file = ereg_replace(".php","",$file);
  151. $file = ereg_replace("_"," ",$file);
  152. $lang = ucwords($file);
  153. $selected = ($admin_language != "" && $file == $admin_language || $file == $language) ? ' selected="selected"' : '';
  154. $options .= "<option value=\"$file\"$selected>$lang</option>\n";
  155. }
  156. }
  157. closedir($handle);
  158. }
  159. echo $options;
  160. }
  161. ////////////////////////////////////////////////////////////////////////////////////
  162. ////////////////////////////////////////////////////////////////////////////////////
  163. ////
  164. //// STORED VARIABLES
  165. ////
  166. ////////////////////////////////////////////////////////////////////////////////////
  167. ////////////////////////////////////////////////////////////////////////////////////
  168. /**
  169. * Do not include the following fields in the output
  170. *
  171. */
  172. $excluded = array('submit', 'db_check', 'admin_check', 'settings_check', 'dlconfig');
  173. /**
  174. * Run encode() function for listed fields
  175. *
  176. */
  177. $sensitive = array('db_pass', 'admin_password1', 'admin_password2');
  178. /**
  179. * Create hidden fields for each posted variable
  180. *
  181. */
  182. $form_values = "";
  183. foreach($_POST as $key => $value) {
  184. if(!in_array($key, $excluded)) {
  185. $value = clean_post_vars($value);
  186. if(in_array($key, $sensitive)) {
  187. /**
  188. * Find the last character in the string
  189. * If it contains a '+', do not re-encode
  190. *
  191. */
  192. $last_char = substr($value, -1, 1);
  193. if($last_char != '+') {
  194. $value = encode($value);
  195. }
  196. }
  197. $form_values .= "<input type=\"hidden\" name=\"$key\" value=\"$value\" />\n";
  198. $data[$key] = $value;
  199. }
  200. }
  201. function clean_post_vars($var){
  202. $var = stripslashes(strip_tags($var));
  203. return $var;
  204. }
  205. /**
  206. * Salt used for encode() / decode() functions
  207. *
  208. */
  209. $salt1 = '714821316d';
  210. $salt2 = 'NzE0ODI5f';
  211. function encode($var){
  212. global $salt1, $salt2;
  213. $var = base64_encode($salt1.$var.$salt2);
  214. $var = $var."+";
  215. return $var;
  216. }
  217. function decode($var){
  218. global $salt1, $salt2;
  219. $var = base64_decode($var);
  220. $var = ereg_replace($salt1, "", $var);
  221. $var = ereg_replace($salt2, "", $var);
  222. return $var;
  223. }
  224. ////////////////////////////////////////////////////////////////////////////////////
  225. ////////////////////////////////////////////////////////////////////////////////////
  226. ////
  227. //// VERIFY ALL REQUIREMENTS ARE MET
  228. ////
  229. ////////////////////////////////////////////////////////////////////////////////////
  230. ////////////////////////////////////////////////////////////////////////////////////
  231. $passed = array('php' => false, 'gdinfo' => false, 'image_found' => false, 'image_write' => false, 'thumb_found' => false, 'thumb_write' => false, 'pcre' => false, 'imagesize' => false);
  232. /**
  233. * Check for PHP version
  234. *
  235. */
  236. $php_version = phpversion();
  237. if (version_compare($php_version, '4.3.3') < 0) {
  238. $result['php'] = $php_version.", ".$lang_fail;
  239. }else{
  240. $passed['php'] = true;
  241. $result['php'] = $php_version;
  242. }
  243. /**
  244. * Check if register_globals is enabled
  245. *
  246. */
  247. if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on') {
  248. $result['globals'] = $lang_no;
  249. $css['globals'] = "redHighlightBold";
  250. }else{
  251. $result['globals'] = $lang_yes;
  252. $css['globals'] = "grnHighlightBold";
  253. }
  254. /**
  255. * Check if getimagesize function exists
  256. *
  257. */
  258. if (@function_exists('getimagesize')) {
  259. $passed['imagesize'] = true;
  260. $result['imagesize'] = $lang_yes;
  261. }else{
  262. $result['imagesize'] = $lang_fail;
  263. }
  264. /**
  265. * Check for PCRE UTF-8 support
  266. *
  267. */
  268. if (@preg_match('//u', '')) {
  269. $passed['pcre'] = true;
  270. $result['pcre'] = $lang_yes;
  271. }else{
  272. $result['pcre'] = $lang_fail;
  273. }
  274. /**
  275. * Check for GD_Info support
  276. *
  277. */
  278. if(@function_exists('gd_info')) {
  279. $passed['gdinfo'] = true;
  280. $gd_array = gd_info();
  281. $gd_version = ereg_replace('[[:alpha:][:space:]()]+', '', $gd_array['GD Version']);
  282. $result['gdinfo'] = $gd_version;
  283. }else{
  284. $result['gdinfo'] = $lang_fail;
  285. }
  286. /**
  287. * Check if images/ directory exist and is writable
  288. *
  289. */
  290. $images = check_and_set("../images/");
  291. if($images == "chmod" || $images == "create") {
  292. $result['image_chmod'] = $lang_writable_no;
  293. }else{
  294. $passed['image_write'] = true;
  295. $result['image_chmod'] = $lang_writable;
  296. }
  297. if($images == "create") {
  298. $result['image_create'] = $lang_not_found;
  299. }else{
  300. $passed['image_found'] = true;
  301. $result['image_create'] = $lang_found;
  302. }
  303. /**
  304. * Check if thumbnails/ directory exist and is writable
  305. *
  306. */
  307. $thumbs = check_and_set("../thumbnails/");
  308. if($thumbs == "chmod" || $thumbs == "create") {
  309. $result['thumb_chmod'] = $lang_writable_no;
  310. }else{
  311. $passed['thumb_write'] = true;
  312. $result['thumb_chmod'] = $lang_writable;
  313. }
  314. if($thumbs == "create") {
  315. $result['thumb_create'] = $lang_not_found;
  316. }else{
  317. $passed['thumb_found'] = true;
  318. $result['thumb_create'] = $lang_found;
  319. }
  320. /**
  321. * Apply correct class name
  322. *
  323. */
  324. foreach($passed as $value => $status) {
  325. $style = ($status == 1) ? 'grnHighlightBold' : 'redHighlightBold';
  326. $css[$value] = $style;
  327. }
  328. ////////////////////////////////////////////////////////////////////////////////////
  329. ////////////////////////////////////////////////////////////////////////////////////
  330. ////
  331. //// VERIFY MYSQL DETAILS
  332. ////
  333. ////////////////////////////////////////////////////////////////////////////////////
  334. ////////////////////////////////////////////////////////////////////////////////////
  335. $connect_test = false;
  336. $error = array();
  337. if(isset($_POST['db_check'])) {
  338. $db_host = clean_post_vars($_POST['db_host']);
  339. $db_name = clean_post_vars($_POST['db_name']);
  340. $db_user = clean_post_vars($_POST['db_user']);
  341. $db_pass = clean_post_vars($_POST['db_pass']);
  342. $tbl_prefix = clean_post_vars($_POST['tbl_prefix']);
  343. $connect_test = connect_check($error, $db_host, $db_name, $db_user, $db_pass, $tbl_prefix);
  344. }else{
  345. $db_host = "";
  346. $db_name = "";
  347. $db_user = "";
  348. $db_pass = "";
  349. $tbl_prefix = "pixelpost_";
  350. }
  351. if($connect_test) {
  352. $result['connect_test'] = "&nbsp;".$lang_conn_success;
  353. }else{
  354. $result['connect_test'] = implode('<br />', $error);
  355. }
  356. function connect_check(&$error, $db_host, $db_name, $db_user, $db_pass, $tbl_prefix) {
  357. global $lang_db_host_error,$lang_db_name_error,$lang_db_prefix_char,$lang_db_max_prefix,$lang_db_conn_error;
  358. /**
  359. * Check that we have a database host
  360. *
  361. */
  362. if($db_host == '') {
  363. $error[] = "&nbsp;".$lang_db_conn_error."&nbsp;".$lang_db_host_error;
  364. }
  365. /**
  366. * Check that we have a database name
  367. *
  368. */
  369. if($db_name == '') {
  370. $error[] = "&nbsp;".$lang_db_conn_error."&nbsp;".$lang_db_name_error;
  371. }
  372. /**
  373. * Make sure our table prefix does not contain illegal characters ( - . )
  374. *
  375. */
  376. if (strpos($tbl_prefix, '-') !== false || strpos($tbl_prefix, '.') !== false) {
  377. $error[] = "&nbsp;".$lang_db_conn_error."&nbsp;".$lang_db_prefix_char;
  378. }
  379. /**
  380. * Make sure the table prefix does not exceed 36 characters in length
  381. *
  382. */
  383. $prefix_max_length = 36;
  384. if (strlen($tbl_prefix) > $prefix_max_length){
  385. $error[] = "&nbsp;".$lang_db_conn_error."&nbsp;".$lang_db_max_prefix;
  386. }
  387. /**
  388. * Try and connect
  389. *
  390. */
  391. if(!@mysql_connect($db_host, $db_user, $db_pass)){
  392. $error[] = "&nbsp;".$lang_db_conn_error."&nbsp;".mysql_error();
  393. }
  394. if(!@mysql_select_db($db_name)){
  395. $error[] = "&nbsp;".$lang_db_conn_error."&nbsp;".mysql_error();
  396. }
  397. if (!isset($error) || !sizeof($error)) {
  398. return true;
  399. }
  400. return false;
  401. }
  402. ////////////////////////////////////////////////////////////////////////////////////
  403. ////////////////////////////////////////////////////////////////////////////////////
  404. ////
  405. //// VERIFY ADMIN DETAILS
  406. ////
  407. ////////////////////////////////////////////////////////////////////////////////////
  408. ////////////////////////////////////////////////////////////////////////////////////
  409. $admin_passed = false;
  410. if(isset($_POST['admin_check'])) {
  411. $admin_language = clean_post_vars($_POST['admin_language']);
  412. $admin_username = clean_post_vars($_POST['admin_username']);
  413. $admin_password1 = clean_post_vars($_POST['admin_password1']);
  414. $admin_password2 = clean_post_vars($_POST['admin_password2']);
  415. $admin_email1 = clean_post_vars($_POST['admin_email1']);
  416. $admin_email2 = clean_post_vars($_POST['admin_email2']);
  417. $admin_error = array();
  418. // Check the entered email address and password
  419. if($admin_username == '' || $admin_password1 == '' || $admin_password2 == '' || $admin_email1 == '' || $admin_email2 == '') {
  420. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_all_fields;
  421. }
  422. if($admin_password1 != $admin_password2 && $admin_password1 != '') {
  423. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_match_psw;
  424. }
  425. // Test against the default username rules
  426. if($admin_username != '' && strlen($admin_username) < 3) {
  427. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_user_short;
  428. }
  429. if($admin_username != '' && strlen($admin_username) > 20) {
  430. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_user_long;
  431. }
  432. // Test against the default password rules
  433. if($admin_password1 != '' && strlen($admin_password1) < 6) {
  434. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_pass_short;
  435. }
  436. if($admin_password1 != '' && strlen($admin_password1) > 30) {
  437. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_pass_long;
  438. }
  439. if($admin_email1 != $admin_email2 && $admin_email1 != '') {
  440. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_mail_match;
  441. }
  442. if($admin_email1 != '' && !check_email_address($admin_email1)) {
  443. $admin_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_mail_wrong;
  444. }
  445. if(isset($_POST['send_email']) && $_POST['send_email'] == '1' && !sizeof($admin_error)){
  446. $email_status = send_email($admin_email1);
  447. if($email_status) {
  448. $admin_success[] = "&nbsp;".$lang_email_sent;
  449. }else{
  450. $admin_error[] = "&nbsp;".$lang_email_failed;
  451. }
  452. }
  453. if(!sizeof($admin_error)) {
  454. $admin_success[] = "&nbsp;".$lang_admin_test_pass;
  455. $admin_passed = true;
  456. $result['admin_details'] = implode('<br />', $admin_success);
  457. }else{
  458. $result['admin_details'] = implode('<br />', $admin_error);
  459. }
  460. }else{
  461. $admin_language = "";
  462. $admin_username = "";
  463. $admin_password1 = "";
  464. $admin_password2 = "";
  465. $admin_email1 = "";
  466. $admin_email2 = "";
  467. $send_email = "";
  468. }
  469. ////////////////////////////////////////////////////////////////////////////////////
  470. ////////////////////////////////////////////////////////////////////////////////////
  471. ////
  472. //// VERIFY SETTINGS DETAILS
  473. ////
  474. ////////////////////////////////////////////////////////////////////////////////////
  475. ////////////////////////////////////////////////////////////////////////////////////
  476. $settings_passed = false;
  477. if(isset($_POST['settings_check'])) {
  478. $pp_title = clean_post_vars($_POST['pp_title']);
  479. $pp_sub_title = clean_post_vars($_POST['pp_sub_title']);
  480. $pp_path = clean_post_vars($_POST['pp_path']);
  481. $pp_timezone = clean_post_vars($_POST['pp_timezone']);
  482. $setting_error = array();
  483. /**
  484. * Check the fields for empty values
  485. *
  486. */
  487. if($pp_title == '' || $pp_path == '') {
  488. $setting_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_admin_all_fields;
  489. }
  490. /**
  491. * Make sure the title and sub-title do not exceed 100 characters in length
  492. *
  493. */
  494. if($pp_title != '' && strlen($pp_title) > 100) {
  495. $setting_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_set_title_long;
  496. }
  497. if($pp_sub_title != '' && strlen($pp_sub_title) > 100) {
  498. $setting_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_set_title_long;
  499. }
  500. /**
  501. * Check the URL for trailing /
  502. *
  503. */
  504. $end_of_string = substr($pp_path, -1);
  505. if($end_of_string != "/") {
  506. $setting_error[] = "&nbsp;".$lang_check_settings."&nbsp;".$lang_set_eos;
  507. }
  508. if(!sizeof($setting_error)) {
  509. $settings_passed = true;
  510. $result['setting_details'] = $lang_admin_test_pass;
  511. }else{
  512. $result['setting_details'] = implode('<br />', $setting_error);
  513. }
  514. }else{
  515. $pp_title = "Pixelpost";
  516. $pp_sub_title = "Authentic photoblog flavour";
  517. $pp_path = get_env('/');
  518. $pp_timezone = "";
  519. $pp_timezone_dst = "";
  520. }
  521. ////////////////////////////////////////////////////////////////////////////////////
  522. ////////////////////////////////////////////////////////////////////////////////////
  523. ////
  524. //// CREATE & SEND EMAIL
  525. ////
  526. ////////////////////////////////////////////////////////////////////////////////////
  527. ////////////////////////////////////////////////////////////////////////////////////
  528. function send_email($recipient) {
  529. global $data;
  530. global $lang_email_subject, $lang_email_message_0, $lang_email_message_1, $lang_email_message_2, $lang_install_admin, $lang_admin_user;
  531. global $lang_admin_pass1, $lang_install_db, $lang_db_host, $lang_db_name, $lang_db_user;
  532. global $lang_db_pass, $lang_db_prefix, $lang_email_footer, $lang_email_signature;
  533. $server_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME');
  534. $server_name = preg_replace('#^www\.#', '', strtolower($server_name));
  535. $admin_username = stripslashes($data['admin_username']);
  536. $admin_password = stripslashes(decode($data['admin_password1']));
  537. $db_host = stripslashes($data['db_host']);
  538. $db_name = stripslashes($data['db_name']);
  539. $db_user = stripslashes($data['db_user']);
  540. $db_pass = stripslashes(decode($data['db_pass']));
  541. $db_prefix = stripslashes($data['tbl_prefix']);
  542. $recipient = strtolower($recipient);
  543. $subject = $lang_email_subject;
  544. $body = "$lang_email_message_0\r\n";
  545. $body .= "$lang_email_message_1\r\n\r\n";
  546. $body .= "$lang_email_message_2\r\n";
  547. $body .= get_env('/',false)."\r\n\r\n";
  548. $body .= $lang_install_admin.":\r\n";
  549. $body .= "------------------------------------------------------------\r\n\r\n";
  550. $body .= "$lang_admin_user $admin_username\r\n\r\n";
  551. $body .= "$lang_admin_pass1 $admin_password\r\n\r\n\r\n";
  552. $body .= $lang_install_db.":\r\n";
  553. $body .= "------------------------------------------------------------\r\n\r\n";
  554. $body .= "$lang_db_host $db_host\r\n\r\n";
  555. $body .= "$lang_db_name $db_name\r\n\r\n";
  556. $body .= "$lang_db_user $db_user\r\n\r\n";
  557. $body .= "$lang_db_pass $db_pass\r\n\r\n";
  558. $body .= "$lang_db_prefix $db_prefix\r\n\r\n\r\n";
  559. $body .= "$lang_email_footer\r\n\r\n";
  560. $body .= "--\r\n";
  561. $body .= "$lang_email_signature\r\n";
  562. $headers = "Content-type: text/plain; charset=UTF-8\r\n";
  563. $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  564. $headers .= "From: Pixelpost Installer <pixelpost@$server_name>\r\n";
  565. if(mail($recipient, $subject, $body, $headers)) {
  566. return true;
  567. }
  568. return false;
  569. }
  570. ////////////////////////////////////////////////////////////////////////////////////
  571. ////////////////////////////////////////////////////////////////////////////////////
  572. ////
  573. //// CREATE ZEBRA TABLE
  574. ////
  575. ////////////////////////////////////////////////////////////////////////////////////
  576. ////////////////////////////////////////////////////////////////////////////////////
  577. function createTableStatus($ins_data) {
  578. $html = "";
  579. //var_dump($ins_data);
  580. $t = (count($ins_data));
  581. $i = 0;
  582. for ($row = 0; $row < $t; $row++) {
  583. foreach($ins_data[$row] as $key => $value) {
  584. if(!empty($value)){
  585. $i++;
  586. $className = ($i % 2) ? 'cellTwo' : 'cellOne';
  587. $html .= "
  588. <tr>
  589. <td class='$className'>
  590. <span class='defaultBold'>$key</span>
  591. </td>
  592. <td class='$className'>
  593. $value
  594. </td>
  595. </tr>";
  596. }
  597. }
  598. }
  599. return $html;
  600. }
  601. function createStatusMsg($status, $cssClass) {
  602. $html = "";
  603. $html .= "<div class='$cssClass messageBox'><div>";
  604. foreach($status as $key => $msg){
  605. $html .= $addon_status['Addon Off'] = $msg;
  606. }
  607. $html .= "</div></div>";
  608. return $html;
  609. }
  610. ////////////////////////////////////////////////////////////////////////////////////
  611. ////////////////////////////////////////////////////////////////////////////////////
  612. ////
  613. //// TIME ZONE SETTINGS
  614. ////
  615. ////////////////////////////////////////////////////////////////////////////////////
  616. ////////////////////////////////////////////////////////////////////////////////////
  617. function tz_select($default = '-5', $truncate = false, $chars = '80') {
  618. global $tz, $data;
  619. $tz_select = '';
  620. foreach ($tz as $offset => $zone) {
  621. if($truncate){
  622. $zone = $zone." ";
  623. $zone = substr($zone,0,$chars);
  624. $zone = substr($zone,0,strrpos($zone,' '));
  625. $zone = $zone;
  626. }
  627. if(is_numeric($offset)) {
  628. $selected = ($offset == $data['pp_timezone']) ? ' selected="selected"' : '';
  629. $tz_select .= "<option value=\"$offset\"$selected>$zone</option>\n";
  630. }
  631. }
  632. return $tz_select;
  633. }
  634. function tz_offset($timezone, $offset) {
  635. $timezone = $timezone+$offset;
  636. return $timezone;
  637. }
  638. $tz = array('-12' => '[UTC - 12] Baker Island Time',
  639. '-11' => '[UTC - 11] Niue Time, Samoa Standard Time',
  640. '-10' => '[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time',
  641. '-9.5' => '[UTC - 9:30] Marquesas Islands Time',
  642. '-9' => '[UTC - 9] Alaska Standard Time, Gambier Island Time',
  643. '-8' => '[UTC - 8] Pacific Standard Time',
  644. '-7' => '[UTC - 7] Mountain Standard Time',
  645. '-6' => '[UTC - 6] Central Standard Time',
  646. '-5' => '[UTC - 5] Eastern Standard Time',
  647. '-4' => '[UTC - 4] Atlantic Standard Time',
  648. '-3.5' => '[UTC - 3:30] Newfoundland Standard Time',
  649. '-3' => '[UTC - 3] Amazon Standard Time, Central Greenland Time',
  650. '-2' => '[UTC - 2] Fernando de Noronha Time, South Georgia &amp; the South Sandwich Islands Time',
  651. '-1' => '[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time',
  652. '0' => '[UTC] Western European Time, Greenwich Mean Time',
  653. '1' => '[UTC + 1] Central European Time, West African Time',
  654. '2' => '[UTC + 2] Eastern European Time, Central African Time',
  655. '3' => '[UTC + 3] Moscow Standard Time, Eastern African Time',
  656. '3.5' => '[UTC + 3:30] Iran Standard Time',
  657. '4' => '[UTC + 4] Gulf Standard Time, Samara Standard Time',
  658. '4.5' => '[UTC + 4:30] Afghanistan Time',
  659. '5' => '[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time',
  660. '5.5' => '[UTC + 5:30] Indian Standard Time, Sri Lanka Time',
  661. '5.75' => '[UTC + 5:45] Nepal Time',
  662. '6' => '[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time',
  663. '6.5' => '[UTC + 6:30] Cocos Islands Time, Myanmar Time',
  664. '7' => '[UTC + 7] Indochina Time, Krasnoyarsk Standard Time',
  665. '8' => '[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time',
  666. '8.75' => '[UTC + 8:45] Southeastern Western Australia Standard Time',
  667. '9' => '[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time',
  668. '9.5' => '[UTC + 9:30] Australian Central Standard Time',
  669. '10' => '[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time',
  670. '10.5' => '[UTC + 10:30] Lord Howe Standard Time',
  671. '11' => '[UTC + 11] Solomon Island Time, Magadan Standard Time',
  672. '11.5' => '[UTC + 11:30] Norfolk Island Time',
  673. '12' => '[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time',
  674. '12.75' => '[UTC + 12:45] Chatham Islands Time',
  675. '13' => '[UTC + 13] Tonga Time, Phoenix Islands Time',
  676. '14' => '[UTC + 14] Line Island Time'
  677. );
  678. ////////////////////////////////////////////////////////////////////////////////////
  679. ////////////////////////////////////////////////////////////////////////////////////
  680. ////
  681. //// STORE ADMINISTRATOR SETTINGS
  682. ////
  683. ////////////////////////////////////////////////////////////////////////////////////
  684. ////////////////////////////////////////////////////////////////////////////////////
  685. function store_vars($prefix) {
  686. global $data;
  687. /**
  688. * The Username and password were already stored in create_tables.php
  689. *
  690. */
  691. $admin_email = addslashes($data['admin_email1']);
  692. $site_url = addslashes($data['pp_path']);
  693. $admin_lang = addslashes($data['admin_language']);
  694. $site_title = addslashes($data['pp_title']);
  695. $sub_title = addslashes($data['pp_sub_title']);
  696. if($data['pp_timezone_dst'] == "1") {
  697. $time_zone = addslashes(tz_offset($data['pp_timezone'], '1'));
  698. }else{
  699. $time_zone = addslashes($data['pp_timezone']);
  700. }
  701. $feed_copyright = "Copyright ".date('Y')." $site_url, All Rights Reserved";
  702. $query = mysql_query("UPDATE {$prefix}config SET
  703. `email` = '$admin_email',
  704. `siteurl` = '$site_url',
  705. `admin_langfile` = '$admin_lang',
  706. `sitetitle`= '$site_title',
  707. `subtitle` = '$sub_title',
  708. `feed_title`= '$site_title',
  709. `feed_description` = '$sub_title',
  710. `feed_copyright` = '$feed_copyright',
  711. `timezone` = '$time_zone'
  712. ") or die("Error: ". mysql_error());
  713. }
  714. ////////////////////////////////////////////////////////////////////////////////////
  715. ////////////////////////////////////////////////////////////////////////////////////
  716. ////
  717. //// ACTIVATE / DEACTIVE ADDONS
  718. ////
  719. ////////////////////////////////////////////////////////////////////////////////////
  720. ////////////////////////////////////////////////////////////////////////////////////
  721. function deactivateAddons($prefix) {
  722. $result = mysql_query("SELECT count(`status`) as `total` FROM `{$prefix}addons` WHERE `status` = 'on'");
  723. while($row = mysql_fetch_assoc($result)) {
  724. if($row['total'] > 0) {
  725. // create a new field to hold previous settings
  726. mysql_query("ALTER TABLE `{$prefix}addons` ADD `status_backup` VARCHAR(3) NOT NULL DEFAULT 'on'");
  727. // copy previous settings
  728. mysql_query("UPDATE `{$prefix}addons` SET `status_backup` = `status`");
  729. // turn all addons off
  730. mysql_query("UPDATE `{$prefix}addons` SET `status` = 'off'");
  731. }
  732. }
  733. }
  734. function activatePxlpstAddons($prefix) {
  735. global $lang_dsb_addon_00, $lang_dsb_addon_01, $lang_dsb_addon_02, $lang_dsb_addon_02_1;
  736. global $lang_dsb_addon_02_2, $lang_dsb_addon_03, $lang_dsb_addon_04, $lang_dsb_addon_04_1;
  737. global $lang_dsb_addon_00_01;
  738. // list of default PP addons:
  739. $default_addons = array('_akismet/admin_akismet_comment',
  740. '_akismet/front_akismet_comment',
  741. '_defensio/admin_defensio',
  742. '_defensio/front_defensio',
  743. 'admin_12CropImage',
  744. 'admin_ping',
  745. 'admin_update_exif',
  746. 'advanced_stat',
  747. 'calendar',
  748. 'copy_folder',
  749. 'current_datetime',
  750. 'paged_archive');
  751. foreach($default_addons as $addon_name) {
  752. mysql_query("UPDATE `{$prefix}addons` SET `status` = `status_backup`, `status_backup` = 'res' WHERE `addon_name` = '{$addon_name}'");
  753. }
  754. // we can get a list of disabled third party addons here:
  755. $result = mysql_query("SELECT `addon_name` FROM `{$prefix}addons` where `status_backup` = 'on'");
  756. $num_rows = @mysql_num_rows($result);
  757. // cleanup temp field
  758. mysql_query("ALTER TABLE `{$prefix}addons` DROP `status_backup`");
  759. if($num_rows > 0){
  760. $create_status['tpa_disabled_01'] = "$lang_dsb_addon_01<br /><br />";
  761. $create_status['tpa_disabled_02'] = "$lang_dsb_addon_02<br />$lang_dsb_addon_02_1<br />$lang_dsb_addon_02_2<p />";
  762. $create_status['tpa_disabled_03'] = "$lang_dsb_addon_03<ul id='disabled_addons'>";
  763. $c = 0;
  764. while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
  765. $addon = $row['addon_name'];
  766. $addon = ereg_replace("_"," ",$addon);
  767. $addon = ucwords(strtolower($addon));
  768. $create_status['tpa_disabled_0_'.$c.''] = "<li>$addon</li>";
  769. $c++;
  770. }
  771. $create_status['tpa_disabled_04'] = "</ul>$lang_dsb_addon_04<br />$lang_dsb_addon_04_1";
  772. $cssClass = "statusmsg";
  773. // Remove lines below if statment below is uncommented
  774. $status = createStatusMsg($create_status, 'statusmsg');
  775. echo $status;
  776. // Remove lines above if statement bellow is uncommented
  777. }
  778. /* I decided not to display a message if no addons were altered.
  779. else{
  780. $create_status['tpa_disabled_00_01'] = "$lang_dsb_addon_00_01<br /><br />";
  781. $create_status['tpa_disabled_00'] = "$lang_dsb_addon_00";
  782. $cssClass = "success";
  783. }
  784. $status = createStatusMsg($create_status, 'statusmsg');
  785. echo $status;
  786. */
  787. }
  788. ////////////////////////////////////////////////////////////////////////////////////
  789. ////////////////////////////////////////////////////////////////////////////////////
  790. ////
  791. //// MISCELLANEOUS FUNCTIONS
  792. ////
  793. ////////////////////////////////////////////////////////////////////////////////////
  794. ////////////////////////////////////////////////////////////////////////////////////
  795. function Show_username_password() {
  796. global $data, $show_psw_msg, $lang_admin_user, $lang_admin_pass1;
  797. /**
  798. * Only show if the user decided not to email themselves their credentials
  799. *
  800. */
  801. if(isset($_POST['send_email']) && $_POST['send_email'] == '0'){
  802. $admin_user = stripslashes($data['admin_username']);
  803. $admin_password = stripslashes(decode($data['admin_password1']));
  804. $create_status['show_psw_msg'] = $show_psw_msg."<p />";
  805. $create_status['username'] = $lang_admin_user."&nbsp;".$admin_user."<br />";
  806. $create_status['password'] = $lang_admin_pass1."&nbsp;&nbsp;".$admin_password;
  807. $status = createStatusMsg($create_status, 'success');
  808. echo $status;
  809. }
  810. }
  811. /**
  812. * Converts the password from the 1.3 base64encoded to MD5 hash
  813. *
  814. * Do not do this unless we are upgrading
  815. *
  816. */
  817. function ConvertPassword($prefix) {
  818. global $lang_convert_psw, $lang_convert_psw_suc, $lang_convert_psw_err;
  819. $result = mysql_query("SELECT `password` FROM `{$prefix}config` LIMIT 1")or die("MySQL Error: ". mysql_error());
  820. if($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
  821. $adm_pass = base64_decode($row['password']);
  822. mysql_query("UPDATE `{$prefix}config` SET `password` = MD5('$adm_pass') LIMIT 1")or die("MySQL Error: ". mysql_error());
  823. $create_status['convert_psw_success'] = "$lang_convert_psw<br />$lang_convert_psw_suc";
  824. $cssClass = "success";
  825. }else{
  826. $create_status['convert_psw_error'] = "$lang_convert_psw<br />$lang_convert_psw_err";
  827. $cssClass = "error";
  828. }
  829. $status = createStatusMsg($create_status, $cssClass);
  830. echo $status;
  831. }
  832. /**
  833. * Returns environment path
  834. *
  835. */
  836. function get_env($append, $admin = true){
  837. $server_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME');
  838. $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
  839. $secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
  840. $script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
  841. if(!$script_name) {
  842. $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
  843. }
  844. /**
  845. * Replace any number of consecutive backslashes and/or slashes with a single slash
  846. * (could happen on some proxy setups and/or Windows servers)
  847. *
  848. */
  849. $script_path = trim(dirname($script_name)).$append;
  850. if($admin){ $script_path = str_replace("/admin", "", $script_path); }
  851. $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path);
  852. $url = (($secure) ? 'https://' : 'http://') . $server_name;
  853. if($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80))) {
  854. $url .= ':' . $server_port;
  855. }
  856. $url .= $script_path;
  857. return $url;
  858. }
  859. ////////////////////////////////////////////////////////////////////////////////////
  860. ////////////////////////////////////////////////////////////////////////////////////
  861. ////
  862. //// WRITE CONFIG FILE
  863. ////
  864. ////////////////////////////////////////////////////////////////////////////////////
  865. ////////////////////////////////////////////////////////////////////////////////////
  866. function create_config_file($config_dir,$config_path) {
  867. global $data;
  868. global $lang_passed,$lang_not_found,$lang_fail,$lang_found;
  869. global $lang_writable_no, $lang_writable;
  870. global $lang_conn_success,$lang_conn_fail;
  871. $db_pass = decode($data['db_pass']);
  872. $written = false;
  873. /**
  874. * Time to convert the data provided into a config file
  875. *
  876. */
  877. $config_data = "<?php\n\n";
  878. $config_data .= "/*\n\n";
  879. $config_data .= "Pixelpost version ".PP_VERSION."\n\n";
  880. $config_data .= "Pixelpost www: http://www.pixelpost.org/\n\n";
  881. $config_data .= "Version ".PP_VERSION.":\n";
  882. $config_data .= "Development Team:\n";
  883. $config_data .= "Ramin Mehran, Will Duncan, Joseph Spurling,\n";
  884. $config_data .= "Piotr \"GeoS\" Galas, Dennis Mooibroek, Karin Uhlig, Jay Williams, David Kozikowski\n";
  885. $config_data .= "Version 1.1 to Version 1.3: Linus <http://www.shapestyle.se>\n\n";
  886. $config_data .= "Contact: thecrew (at) pixelpost (dot) org\n";
  887. $config_data .= "Copyright ".date('Y')." Pixelpost.org <http://www.pixelpost.org>\n\n\n";
  888. $config_data .= "License: http://www.gnu.org/copyleft/gpl.html\n\n";
  889. $config_data .= "This program is free software; you can redistribute it and/or\n";
  890. $config_data .= "modify it under the terms of the GNU General Public License\n";
  891. $config_data .= "as published by the Free Software Foundation; either version 2\n";
  892. $config_data .= "of the License, or (at your option) any later version.\n\n";
  893. $config_data .= "This program is distributed in the hope that it will be useful,\n";
  894. $config_data .= "but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
  895. $config_data .= "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n";
  896. $config_data .= "GNU General Public License for more details.\n\n";
  897. $config_data .= "You should have received a copy of the GNU General Public License\n";
  898. $config_data .= "along with this program; if not, write to the Free Software\n";
  899. $config_data .= "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\n";
  900. $config_data .= "*/\n\n";
  901. $config_data .= "// database variables - this is info you've received from you hosting service\n";
  902. $config_data .= "// those are needed for the script to connect and use MySQL\n\n";
  903. $config_data .= "\$pixelpost_db_host = \"{$data['db_host']}\"; // database host, often \"localhost\"\n";
  904. $config_data .= "\$pixelpost_db_user = \"{$data['db_user']}\"; // database user\n";
  905. $config_data .= "\$pixelpost_db_pass = \"{$db_pass}\"; // database user password\n";
  906. $config_data .= "\$pixelpost_db_pixelpost = \"{$data['db_name']}\"; // database\n\n";
  907. $config_data .= "\$pixelpost_db_prefix = \"{$data['tbl_prefix']}\"; // table prefix, leave as is unless you want to install multiple blogs on the same database\n\n";
  908. $config_data .= '?' . '>';
  909. /**
  910. * Attempt to write out the config file directly.
  911. *
  912. */
  913. //if((file_exists($config_path) && is_writable($config_path)) || is_writable($config_dir)) {
  914. $written = true;
  915. if(!is_writable($config_dir)) {
  916. if(!@chmod($config_dir, 0777)){
  917. $result['writable'] = $lang_writable_no;
  918. $result['error'] = $result['writable'];
  919. $result['css_writable'] = "redHighlightBold";
  920. }else{
  921. $result['writable'] = $lang_writable;
  922. $result['css_writable'] = "grnHighlightBold";
  923. }
  924. }else{
  925. $result['writable'] = $lang_writable;
  926. $result['css_writable'] = "grnHighlightBold";
  927. }
  928. if(!($fp = @fopen($config_path, 'w'))) {
  929. $result['fopen'] = $lang_fail;
  930. $result['error'] = $result['fopen'];
  931. $result['css_fopen'] = "redHighlightBold";
  932. $written = false;
  933. }else{
  934. $result['fopen'] = $lang_passed;
  935. $result['css_fopen'] = "grnHighlightBold";
  936. }
  937. if(!(@fwrite($fp, $config_data))) {
  938. $result['fwrite'] = $lang_fail;
  939. $result['error'] = $result['fwrite'];
  940. $result['css_fwrite'] = "redHighlightBold";
  941. $written = false;
  942. }else{
  943. $result['fwrite'] = $lang_passed;
  944. $result['css_fwrite'] = "grnHighlightBold";
  945. }
  946. @fclose($fp);
  947. if($written){
  948. @chmod($config_path, 0644);
  949. $result['chmod'] = $lang_passed;
  950. $result['css_chmod'] = "grnHighlightBold";
  951. }else{
  952. $result['chmod'] = $lang_fail;
  953. $result['error'] = $result['chmod'];
  954. $result['css_chmod'] = "redHighlightBold";
  955. }
  956. if(file_exists($config_path)){
  957. $written = true;
  958. $result['exists'] = $lang_found;
  959. $result['css_exists'] = "grnHighlightBold";
  960. }else{
  961. $result['exists'] = $lang_not_found;
  962. $result['error'] = $result['exists'];
  963. $result['css_exists'] = "redHighlightBold";
  964. }
  965. $connect_test = false;
  966. if($written){
  967. require($config_path);
  968. $connect_test = connect_check($error, $pixelpost_db_host, $pixelpost_db_pixelpost, $pixelpost_db_user, $pixelpost_db_pass, $pixelpost_db_prefix);
  969. }
  970. if($connect_test){
  971. $result['connect'] = $lang_conn_success;
  972. $result['verifed'] = true;
  973. $result['css_connect'] = "grnHighlightBold";
  974. }else{
  975. $result['connect'] = $lang_conn_fail;
  976. $result['verifed'] = false;
  977. $result['error'] = $result['connect'];
  978. $result['css_connect'] = "redHighlightBold";
  979. /**
  980. * Delete the recently created config file.
  981. * Even though it was successfully created, we were unable to use it to connect so something went wrong.
  982. *
  983. */
  984. if(file_exists($config_path)){
  985. @unlink($config_path);
  986. }
  987. }
  988. @chmod($config_dir, 0755);
  989. //}
  990. if(isset($_POST['dlconfig'])) {
  991. return $config_data;
  992. }
  993. return $result;
  994. }
  995. ?>