home *** CD-ROM | disk | FTP | other *** search
/ 79.96.193.101 / 79.96.193.101.tar / 79.96.193.101 / www / setup.php < prev    next >
PHP Script  |  2014-10-20  |  14KB  |  447 lines

  1. <?php
  2. //============================================
  3. // Easy 2.0
  4. // Copyright     : .exe Evolution
  5. // Wersja        : 2.0
  6. // Uwagi         : Brak
  7. //============================================
  8. ob_start();
  9. define("SETUP",1);
  10. error_reporting(E_ALL ^ E_NOTICE);
  11. define("BASEDIR", dirname(__FILE__));
  12. header("Content-type: text/html; charset=UTF-8");
  13.  
  14. require_once(BASEDIR . '/system/security/security.class.php');
  15.  
  16. require_once(BASEDIR . "/inc/config.php");
  17. require_once(BASEDIR . "/inc/functions.php");
  18. require_once(BASEDIR . "/inc/functions_post.php");
  19. require_once(BASEDIR . "/inc/functions_shop.php");
  20. require_once(BASEDIR . "/inc/version.ini.php");
  21. require_once(BASEDIR . "/class/tpl/Easy.class.php");
  22. require_once(BASEDIR . "/data/lang/pl_install.php");
  23.  
  24. $tmpl = new Easy("data/tpl/");
  25. $tmpl->assign("kversion", KVERSION);
  26. $tmpl->assign('pref', $pref);
  27. $tmpl->assign('la',$lang_i);
  28.  
  29. $required_php = 423;
  30. $dbprefix = ($dbprefix!="") ? $dbprefix : $_REQUEST['dbprefix'];
  31. $required = array();
  32. $required[] = "data/lang/pl_user.php";
  33. $required[] = "data/lang/pl_admin.php";
  34. $required[] = "data/strukture.sql";
  35. $required[] = "data/data.sql";
  36. $required[] = "data/eula/pl.tpl";
  37. $required[] = "inc/config.php";
  38.  
  39. $writeable = array();
  40. $writeable[] = "cache/";
  41. $writeable[] = "temp/";
  42. $writeable[] = "temp/1/";
  43. $writeable[] = "temp/2/";
  44. $writeable[] = "temp/3/";
  45. $writeable[] = "temp/4/";
  46. $writeable[] = "temp/5/";
  47. $writeable[] = "system/security";
  48. $writeable[] = "uploads/";
  49. $writeable[] = "uploads/affiliates/";
  50. $writeable[] = "uploads/attachment/";
  51. $writeable[] = "uploads/avatars/";
  52. $writeable[] = "uploads/download_images/";
  53. $writeable[] = "uploads/files/";
  54. $writeable[] = "uploads/products/";
  55. $writeable[] = "uploads/galerie/";
  56. $writeable[] = "uploads/inlineshots/";
  57. $writeable[] = "uploads/mediapool/";
  58. $writeable[] = "uploads/mediapool/user_uploads/";
  59. $writeable[] = "uploads/newsletter_attachments/";
  60. $writeable[] = "uploads/topnews_icons/";
  61. $writeable[] = "uploads/shop/";
  62. $writeable[] = "uploads/shop/icons/";
  63. $writeable[] = "uploads/shop/files/";
  64. $writeable[] = "uploads/cheat_files/";
  65. $writeable[] = "uploads/cheat_images/";
  66.  
  67.  
  68. $con = true;
  69. if(!@mysql_connect($dbhost, $dbuser, $dbpass)) {
  70.     $con = false;
  71.     }
  72.  
  73. if(!@mysql_select_db($dbname)) {
  74.     $con = false;
  75.     }
  76.  
  77. if(!$con) {
  78.     $db_error = 1;
  79.     $error = 1;
  80. }
  81.  
  82.  
  83.     $error_is_required = array();
  84.     foreach ($writeable as $must_writeable){
  85.         if(!is_writeable($must_writeable)){
  86.             array_push($error_is_required, $lang_i['error_is_writeable'] . $must_writeable . $lang_i['error_is_writeable_2'] );
  87.             $error = 1;
  88.         }
  89.     }
  90.  
  91.         foreach ($required as $is_required){
  92.         if(@!is_file($is_required)){
  93.             array_push($error_is_required, $lang_i['error_is_required'] . $is_required . $lang_i['error_is_required_2'] );
  94.             $error = 1;
  95.         }
  96.     }
  97.  
  98.         $myphp = @PHP_VERSION;
  99.     if($myphp){
  100.         $myphp_v = str_replace('.', '', $myphp);
  101.         if($myphp_v < $required_php){
  102.             array_push($error_is_required, $lang_i['phpversion_toold'] . $required_php);
  103.         }
  104.     }
  105.  
  106.  
  107.     if(count($error_is_required)>=1){
  108.         $error = 1;
  109.         $tmpl->assign('error_header', $lang_i['erroro_more']);
  110.     } else {
  111.         $tmpl->assign('error_header', $lang_i['erroro']);
  112.     }
  113.  
  114.     if(count($error_is_required)<1){ $error = ""; }
  115.     if( ($error == 1) && ($_REQUEST['force'] != 1) ){
  116.         $tmpl->assign('error_is_required', $error_is_required);
  117.         $tmpl->display('error.tpl');
  118.         exit;
  119.     }
  120.  
  121.     if($_REQUEST['step']!='finish'){
  122.     $query = @mysql_query("SELECT uid FROM ".$dbprefix."_user limit 1");
  123.     $num = @mysql_num_rows($query);
  124.  
  125.     if($num>0){
  126.         echo "<pre>".$lang_i['installed']."</pre>";
  127.         exit;
  128.     }
  129. }
  130.  
  131. if($con) {
  132.     $version_with_encoding = false;
  133.     if(preg_match('/^(\d+\.\d+)/', mysql_get_server_info(), $match)) {
  134.         $v = (float)$match[1];
  135.         if($v>=4.1) {
  136.             $version_with_encoding = true;
  137.             $charset = 'utf8';
  138.         }
  139.     }
  140.     if($version_with_encoding) {
  141.                 $query = 'SET NAMES '.$charset;
  142.         @mysql_query($query);
  143.     }
  144. }
  145.  
  146. switch($_REQUEST['step']){
  147.  
  148.     case "" :
  149.     case "check" :
  150.     switch($_REQUEST['subaction']){
  151.         case "newset" :
  152.  
  153.                 if(@!is_writeable("inc/config.php")){
  154.             $tmpl->assign('step', 'no');
  155.             $tmpl->display('error.tpl');
  156.             exit;
  157.         }
  158.  
  159.      
  160.     $security =& new Security;
  161.     $isSerialValid = $security->checkSerialNo($_POST['sn']);
  162.     if (!$isSerialValid) {
  163.               $tmpl->assign('warnnodb', $lang_i['serial']);
  164.               $tmpl->assign('sn' , stripslashes(trim($_POST['sn'])));
  165.               $tmpl->assign('dbhost' , stripslashes(trim($_POST['dbhost'])));
  166.               $tmpl->assign('dbuser' , stripslashes(trim($_POST['dbuser'])));
  167.               $tmpl->assign('dbpass' , stripslashes(trim($_POST['dbpass'])));
  168.               $tmpl->assign('dbname' , stripslashes(trim($_POST['dbname'])));
  169.               $tmpl->assign('dbprefix' , stripslashes(trim($_POST['dbprefix'])));
  170.         $tmpl->display('step0.tpl');
  171.           break 2;
  172.     } else
  173.       $security->createSecureFile();
  174.     
  175.  
  176.         $connection = 1;
  177.         if(!@mysql_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'])) $connection  = 0;
  178.         if(!@mysql_select_db($_POST['dbname'])) $connection = 0;
  179.         @mysql_query('SET NAMES utf8');
  180.  
  181.         if( ($connection  == 1) && ($_POST['dbprefix'] != "") ){
  182.             $fp=@fopen("inc/config.php","w+");
  183. @fwrite($fp,"<?php
  184. \$dbhost = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbhost'])))."\";
  185. \$dbuser = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbuser'])))."\";
  186. \$dbpass = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbpass'])))."\";
  187. \$dbname = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbname'])))."\";
  188. \$dbprefix = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbprefix'])))."\";
  189.  
  190. // Do tej wielkosci (szerokosc) system jest w stanie wstawic znak wodny widoczny na zdjeciu w galerii
  191. // Uwaga!  po zwiekszeniu tej wielkosci system moze zablokowac dostep do znaku wodnego z powodu np.
  192. // zbyt duzego przeciazenia serwera (zalecane max.1024 )
  193. define(\"MAXWATERMARKED\", 1024);
  194.  
  195. // MOD_REWRITE
  196. // Zmiana dynamicznych URL na URL \"statyczne\" (przyjazne dla uzytkownika). Uwaga! Nalezy sie upewnic,
  197. // ze MOD_REWRITE dziala na serwerze. 1 = wlaczone / 0 = wylaczone
  198. define(\"MRWRITE\", 0);
  199.  
  200. // Funkcja SSL Tak / Nie
  201. // Polaczenie kodowane = 1. Uwaga! Nalezy sie upewnic czy Wasz certyfikat jest wa─╣┼║ny
  202. // gdy─╣┼║ w przeciwnym wypadku wasi klienci moga uznac ze serwis nie jest godny zaufania
  203. define(\"SSLMODE\", 0);
  204. ?>");
  205.  
  206.             @fclose($fp);
  207.             $tmpl->display('license.tpl');
  208.             $license_displayed = true;
  209.  
  210.         } else {
  211.             $tmpl->assign('warnnodb', $lang_i['enoconn']);
  212.             $tmpl->assign('sn' , stripslashes(trim($_POST['sn'])));
  213.             $tmpl->assign('dbhost' , stripslashes(trim($_POST['dbhost'])));
  214.             $tmpl->assign('dbuser' , stripslashes(trim($_POST['dbuser'])));
  215.             $tmpl->assign('dbpass' , stripslashes(trim($_POST['dbpass'])));
  216.             $tmpl->assign('dbname' , stripslashes(trim($_POST['dbname'])));
  217.             $tmpl->assign('dbprefix' , stripslashes(trim($_POST['dbprefix'])));
  218.         }
  219.  
  220.         break;
  221.     }
  222.  
  223.     if(!isset($license_displayed))
  224.         $tmpl->display('start.tpl');
  225.     break;
  226.  
  227.     
  228.  
  229.         case 1 :
  230.     $first_sql = "data/strukture.sql";
  231.     $handle = fopen($first_sql, "r");
  232.     $actdb = fread($handle, filesize($first_sql));
  233.     fclose($handle);
  234.  
  235.     $actdb = str_replace('easy', $dbprefix, $actdb);
  236.  
  237.     $m_ok = 0;
  238.     $m_fail = 0;
  239.  
  240.         $message_ok = array();
  241.     $message_error = array();
  242.  
  243.     if($version_with_encoding) {
  244.         $query = 'SELECT DATABASE()';
  245.         $result = @mysql_query($query);
  246.         $row = @mysql_fetch_row($result);
  247.         $query = 'ALTER DATABASE `'.$row[0].'` DEFAULT CHARACTER SET '.$charset.' COLLATE '.$charset.'_general_ci';
  248.         @mysql_query($query);
  249.     }
  250.  
  251.     $file = explode("\n", $actdb);
  252.     $query = '';
  253.     foreach($file as $line) {
  254.         $tmp = trim($line);
  255.         if($tmp!='' && substr($tmp, 0, 2)!='--' && substr($tmp, 0, 1)!='#') {
  256.                         if(preg_match('/CREATE\s+TABLE\s+(IF\s+NOT\s+EXISTS\s+)?(`)?([\w\d\_]+)(\\2)?/i', $line, $matched)) {
  257.                 $is_create = $matched[3];             }
  258.             if(preg_match('/;\s*([\#|\-\-].*?)?$/', $line)) {
  259.                 $line = preg_replace('/;\s*([\#|\-\-].*?)?$/', '', $line);
  260.                 $query.= $line;
  261.                 $result = mysql_query($query);
  262.                 if($is_create) {                     if($result) {
  263.                         if($version_with_encoding) {
  264.                             $query = 'ALTER TABLE `'.$is_create.'` DEFAULT CHARACTER SET '.$charset.' COLLATE '.$charset.'_general_ci';
  265.                             @mysql_query($query);
  266.                         }
  267.                         $m_ok++;
  268.                         array_push($message_ok, $lang_i['c_table_1'] . " '<b> $is_create </b>'" . $lang_i['c_table_2'] );
  269.                     }
  270.                     else {
  271.                         switch(mysql_errno()){
  272.                             case 1050 :
  273.                                 $mysql_e = $lang_i['table_error_exists_2'];
  274.                             break;
  275.                             default:
  276.                                 $mysql_e = mysql_error();
  277.                             break;
  278.                         }
  279.                         array_push($message_error, $lang_i['table_error_exists'] . " '<b> $is_create </b>' $mysql_e");
  280.                         $m_fail++;
  281.                     }
  282.                     $is_create = false;
  283.                 }
  284.                 $query = '';
  285.             }
  286.             else $query.= $line;
  287.         }
  288.     }
  289.     
  290.  
  291.     $tmpl->assign('header_title', $lang_i['step1_table_status']);
  292.     $tmpl->assign('message_ok', $message_ok);
  293.     $tmpl->assign('message_error', $message_error);
  294.     $tmpl->display('step1.tpl');
  295.     break;
  296.  
  297.         case 2 :
  298.         $message_error = array();
  299.     $message_ok = array();
  300.  
  301.     $klang = array();
  302.     include("data/lang/pl_user.php");
  303.  
  304.     $code = array_keys($klang);
  305.     $lang = $klang[$code[0]];
  306.  
  307.     foreach($lang as $key => $value){
  308.         $sql = "INSERT INTO " . $dbprefix . "_languages (
  309.         code,
  310.         name,
  311.         value,
  312.         value_original
  313.         ) VALUES (
  314.         '".$code[0]."',
  315.         '$key',
  316.         '$value',
  317.         '$value'
  318.         )
  319.         ";
  320.         @mysql_query($sql);
  321.         if(mysql_errno() == 1062){
  322.             array_push($message_error, $lang_i['eimport'] . ' "<b>'.$key.'</b>" ' . $lang_i['eimport_2']);
  323.         } else {
  324.             array_push($message_ok, $lang_i['oimport'] . ' "<b>'.$key.'</b>" ' . $lang_i['oimport_2']);
  325.         }
  326.     }
  327.         $klang_admin = array();
  328.     include("data/lang/pl_admin.php");
  329.  
  330.     $code = array_keys($klang_admin);
  331.     $lang = $klang_admin[$code[0]];
  332.  
  333.  
  334.     foreach($lang as $key => $value){
  335.         $sql = "INSERT INTO " . $dbprefix . "_languages_admin (
  336.         code,
  337.         name,
  338.         value,
  339.         value_original
  340.         ) VALUES (
  341.         '".$code[0]."',
  342.         '$key',
  343.         '$value',
  344.         '$value'
  345.         )
  346.         ";
  347.         @mysql_query($sql);
  348.         if(mysql_errno() == 1062){
  349.             array_push($message_error, $lang_i['eimport'] . ' "<b>'.$key.'</b>" ' . $lang_i['eimport_2']);
  350.         } else {
  351.             array_push($message_ok, $lang_i['oimport'] . ' "<b>'.$key.'</b>" ' . $lang_i['oimport_2']);
  352.         }
  353.     }
  354.  
  355.     $tmpl->assign('message_ok', $message_ok);
  356.     $tmpl->assign('message_error', $message_error);
  357.     $tmpl->assign('header_title', $lang_i['step1_table_status']);
  358.     $tmpl->display('step2.tpl');
  359.     break;
  360.  
  361.  
  362.  
  363.  
  364.     case 3 :
  365.  
  366.     if($_REQUEST['substep'] == "final"){
  367.         $errors = array();
  368.  
  369.                 if($_POST['email'] == "") array_push($errors, $lang_i['noemail']);
  370.         if($_POST['email_confirm'] == "") array_push($errors, $lang_i['noemail_confirm']);
  371.         if($_POST['email'] != $_POST['email_confirm']) array_push($errors, $lang_i['email_notsame']);
  372.         if( (!ereg("^[_A-Za-z─╣┼║-─é┬û─╣┬ÿ-─é┼¢─╣┬Ö-├ï┬Ö0-9-]+(\.[_A-Za-z─╣┼║-─é┬û─╣┬ÿ-─é┼¢─╣┬Ö-├ï┬Ö0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$", $_REQUEST['email'])) ||
  373.         (!ereg("^[_A-Za-z─╣┼║-─é┬û─╣┬ÿ-─é┼¢─╣┬Ö-├ï┬Ö0-9-]+(\.[_A-Za-z─╣┼║-─é┬û─╣┬ÿ-─é┼¢─╣┬Ö-├ï┬Ö0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$", $_REQUEST['email_confirm'])) ) array_push($errors, $lang_i['email_no_specialchars']);
  374.  
  375.                 if($_POST['pass'] == "") array_push($errors, $lang_i['nopass']);
  376.         if($_POST['pass_confirm'] == "") array_push($errors, $lang_i['nopass_confirm']);
  377.         if( $_POST['pass'] != $_POST['pass_confirm']) array_push($errors, $lang_i['pass_notsame']);
  378.         if( (ereg("[^ _A-Za-z─╣┼║-─é┬û─╣┬ÿ-─é┼¢─╣┬Ö-├ï┬Ö0-9-]", $_POST['pass'])) || (ereg("[^ _A-Za-z─╣┼║-─é┬û─╣┬ÿ-─é┼¢─╣┬Ö-├ï┬Ö0-9-]", $_POST['pass_confirm'])) ) array_push($errors, $lang_i['pass_no_specialchars']);
  379.  
  380.                 if($_POST['uname'] == "") array_push($errors, $lang_i['nousername']);
  381.         if(ereg("[^ ._A-Za-z─╣┼║-─é┬û─╣┬ÿ-─é┼¢─╣┬Ö-├ï┬Ö0-9-]", $_POST['uname'])) array_push($errors, $lang_i['username_no_specialchars']);
  382.  
  383.         if($_POST['firstname'] == "" || strlen($_POST['firstname'])<2) array_push($errors, $lang_i['nofirstname']);
  384.         if($_POST['lastname'] == "" || strlen($_POST['lastname'])<2) array_push($errors, $lang_i['nolastname']);
  385.         if($_POST['street'] == "" || strlen($_POST['street'])<4) array_push($errors, $lang_i['nostreet']);
  386.         if($_POST['zip'] == "" || strlen($_POST['zip'])<4) array_push($errors, $lang_i['nozip']);
  387.         if($_POST['town'] == "" || strlen($_POST['town'])<3) array_push($errors, $lang_i['notown']);
  388.         if($_POST['phone'] == "" || strlen($_POST['phone'])<8) array_push($errors, $lang_i['nophone']);
  389.  
  390.         if(count($errors)<1){
  391.                         $first_sql = "data/data.sql";
  392.             $handle = fopen($first_sql, "r");
  393.             $dbin = fread($handle, filesize($first_sql));
  394.             fclose($handle);
  395.  
  396.             $dbin = str_replace('easy', $dbprefix, $dbin);
  397.             $dbin = str_replace('%%USER%%', $_POST['uname'], $dbin);
  398.             $dbin = str_replace('%%EMAIL%%', $_POST['email'], $dbin);
  399.             $dbin = str_replace('%%PASS%%', md5($_POST['pass']), $dbin);
  400.             $dbin = str_replace('%%TIME%%', time(), $dbin);
  401.             $dbin = str_replace('%%FIRSTNAME%%', $_POST['firstname'], $dbin);
  402.             $dbin = str_replace('%%LASTNAME%%', $_POST['lastname'], $dbin);
  403.             $dbin = str_replace('%%PHONE%%', $_POST['phone'], $dbin);
  404.             $dbin = str_replace('%%ZIP%%', $_POST['zip'], $dbin);
  405.             $dbin = str_replace('%%TOWN%%', $_POST['town'], $dbin);
  406.             $dbin = str_replace('%%STREET%%', $_POST['street'], $dbin);
  407.             $dbin = str_replace('%%TITLE%%', $_POST['title'], $dbin);
  408.  
  409.             $m_ok = 0;
  410.             $m_fail = 0;
  411.  
  412.                         $message_ok = array();
  413.             $message_error = array();
  414.             $ar = explode(";#inst#", $dbin);
  415.             while (list($key,$val) = each($ar)) {
  416.                 if (rtrim(ltrim($val)) != "") {
  417.                     $q = str_replace("\n","",$val);
  418.                     $q = $q . ";";
  419.                     if (mysql_query($q)) {
  420.                         $m_ok++;
  421.                     } else {
  422.                                             }
  423.                 }
  424.             }
  425.  
  426.             header("Location:setup.php?step=finish");
  427.         }
  428.     }
  429.  
  430.     if(count($errors)>0){
  431.         $tmpl->assign('errors', $errors);
  432.         $tmpl->assign('uname', stripslashes(trim($_POST['uname'])));
  433.         $tmpl->assign('pass', stripslashes(trim($_POST['pass'])));
  434.         $tmpl->assign('pass_confirm', stripslashes(trim($_POST['pass_confirm'])));
  435.         $tmpl->assign('email', stripslashes(trim($_POST['email'])));
  436.         $tmpl->assign('email_confirm', stripslashes(trim($_POST['email_confirm'])));
  437.     }
  438.  
  439.     $tmpl->display('step3.tpl');
  440.     break;
  441.  
  442.     case "finish" :
  443.     i_tagreplace($m_ok);
  444.     $tmpl->display('finish.tpl');
  445.  
  446. }
  447. ?>