Advertisement
yellux

Class install nk

Aug 30th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 41.70 KB | None | 0 0
  1. <?php
  2.  
  3.     class install{
  4.         private $data;
  5.         private $array_lang = array('_ENGLISH' => 'english','_FRENCH' => 'french');
  6.  
  7.         function __construct(){
  8.             $this->initSession();
  9.             $this->importLang();
  10.             $this->routeUser();
  11.         }
  12.  
  13.         ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  14.         // Méthodes du core, elles permettent l'affichage des pages
  15.         ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  16.  
  17.         private function initSession(){
  18.             session_start();
  19.             if(isset($_SESSION['active']) && $_SESSION['active'] === true){
  20.                 foreach($_SESSION as $k => $v){
  21.                     $this->data[$k] = $v;
  22.                 }
  23.             }
  24.             $_SESSION['active'] = true;
  25.         }
  26.  
  27.         private function checkLang(){
  28.             echo '<div style="text-align: center;margin:30px auto;">
  29.                        <h2>'._SELECTLANG.' : </h2>
  30.                        <form id="form_lang" name="form_lang" method="post" action="index.php?action=setLang" >
  31.                            <select id="lang_install" name="lang_install" onChange="renameButton();">';
  32.             if(!isset($this->data['lang_install'])){
  33.                 $lang_selected = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == 'fr' ? 'french' : 'english';
  34.             }
  35.             else{
  36.                 $lang_selected = $this->data['lang_install'];
  37.             }
  38.             foreach($this->array_lang as $k => $v){
  39.                 echo '<option value="'.$v.'" ';
  40.                     if($lang_selected == $v){
  41.                         echo 'selected="selected" ';
  42.                     }
  43.                 echo '>'.constant($k).'</option>';
  44.             }
  45.             echo '         </select><br/><br/>
  46.                            <a href="#" style="display:inline-block;margin-top:30px;" class="button" id="button" onclick="document.forms[\'form_lang\'].submit();" >'._SUBMIT.'</a>
  47.                        </form>
  48.                    </div>
  49.                    <script type="text/javascript" >
  50.                        function renameButton(){
  51.                            choix = $("#lang_install").val();
  52.                            if(choix == "french"){ $("#button").html("Valider");}
  53.                            else{$("#button").html("Submit");}
  54.                        }
  55.                    </script>';
  56.         }
  57.  
  58.         private function setLang(){
  59.             if(isset($_REQUEST['lang_install']) && in_array($_REQUEST['lang_install'], $this->array_lang)){
  60.                 $_SESSION['lang_install'] = $_REQUEST['lang_install'];
  61.             }
  62.             self::redirect('index.php?action=main', 0);
  63.         }
  64.  
  65.         private function main(){
  66.             if(isset($_REQUEST['type'])){
  67.                 if($_REQUEST['type'] == 'install' || $_REQUEST['type'] == 'update'){
  68.                     $_SESSION['type'] = $this->data['type'] = $_REQUEST['type'];
  69.                     self::redirect('index.php?action=checkCompatibility', 0);
  70.                 }
  71.             }
  72.             global $global,$dbprefix;
  73.             echo '<div style="text-align: center;margin:30px auto;">
  74.                        <h2>'._WELCOMEINSTALL.'</h2>
  75.                        <p>'._GUIDEINSTALL.'</p>';
  76.             if(is_file('../conf.inc.php')){
  77.                 define('INDEX_CHECK', '');
  78.                 if(is_file('../Includes/version.php')){
  79.                     include('../Includes/version.php');
  80.                     $version = $nk_version;
  81.                 }
  82.                 else{
  83.                     include('../conf.inc.php');
  84.                     $connect = $this->bddConnect($global['db_host'], $global['db_user'], $global['db_pass'], $global['db_name']);
  85.  
  86.                     if ($connect == 'OK') {
  87.                         $sql_version = mysql_query ('SELECT value FROM `'.$db_prefix.'_config` WHERE name=\'version\' ') or die (mysql_error());
  88.                         list($version) = mysql_fetch_array($sql_version);
  89.  
  90.                     } else {
  91.                         echo $connect;
  92.                         return;
  93.                     }
  94.                 }
  95.  
  96.                 $_SESSION['version'] = $version;
  97.                 echo '<h3 style="background:#ECEADB;width:60%;padding:5px;border:1px solid #ddd;margin:20px auto;" >'._DETECTUPDATE.' '.$_SESSION['version'].' '._DETECTUPDATEEND.'</h3>';
  98.                 $versionStatus = $this->validVersion($_SESSION['version']);
  99.                 if ($versionStatus === 0) {
  100.                     echo '<a href="index.php?action=main&amp;type=update" class="button" >'._STARTUPDATE.'</a>';
  101.                 } else if ($versionStatus === -1){
  102.                     echo '<p>'._BADVERSION.'</p>';
  103.                 } else {
  104.                     echo '<p>'._LASTVERSIONSET.'</p>';
  105.                 }
  106.                 echo '</div>';
  107.             }
  108.             else{
  109.                 echo '<a href="index.php?action=main&amp;type=install" class="button" >'._STARTINSTALL.'</a>
  110.                        </div>';
  111.             }
  112.         }
  113.  
  114.         private function checkCompatibility(){
  115.             echo '<div style="text-align: center;margin:30px auto;">
  116.                        <h3 style="margin-bottom:5px;" >'. _CHECKCOMPATIBILITYHOSTING .'</h3>
  117.                        <table style="width:500px;margin:15px auto;border:1px solid #ddd;text-align:left;background:#fff;" cellpadding="3">
  118.                            <tr>
  119.                                <td style="width:80%;"><b>'._COMPOSANT.'</b></td>
  120.                                <td style="width:20%;text-align:center;"><b>'._COMPATIBILITY.'</b></td>';
  121.             $array_requirements = $this->requirements();
  122.             $i=0;
  123.             foreach($array_requirements as $k => $v){
  124.                 $src = $v == 1 ? 'images/ok.png' : 'images/nook.png';
  125.                 $src = $v == 2 ? 'images/warning.png' : $src;
  126.                 echo '<tr';
  127.                 if($i==0){
  128.                     echo ' style="background:#e9e9e9;" ';
  129.                     $i++;
  130.                 }
  131.                 else{
  132.                     echo ' style="background:#f5f5f5;" ';
  133.                     $i=0;
  134.                 }
  135.                 echo '>
  136.                                <td>'.constant($k).'</td>
  137.                                <td style="text-align:center;"><img src='.$src.' alt="" />
  138.                            </tr>';
  139.                 if($v == 3 || $v == 2){
  140.                     $class_error = $v == 2 ? 'warning' : 'error';
  141.                     echo '<tr>
  142.                                <td colspan="2" class="'.$class_error.'_compatibility" >'.constant($k.'ERROR').'</td>
  143.                            </tr>';
  144.                 }
  145.             }
  146.             echo '</table>';
  147.             $compatibility = (in_array(3, $array_requirements) || in_array(3, $array_requirements)) ? false : true;
  148.             if($compatibility === true){
  149.                 echo '<a href="index.php?action=checkStats" class="button" >'._CONTINUE.'</a>
  150.                    </div>';
  151.             }
  152.             else{
  153.                 echo '<p>'._BADHOSTING.'</p>
  154.                        <a href="index.php?action=checkStats" class="button" >'._FORCE.'</a>
  155.                        </div>';
  156.             }
  157.         }
  158.  
  159.         private function checkStats(){
  160.             $checked = isset($this->data['stats']) && $this->data['stats'] === false ? '' : 'checked="checked" ';
  161.             echo '<div style="text-align: center;margin:30px auto;">
  162.                        <h3 style="margin-bottom:30px;" >'._SELECTSTATS.'</h3>
  163.                        '._TXTSTATS.'
  164.                        <form action="index.php?action=setStats" method="post" id="form_stats" >
  165.                            <label><input type="checkbox" name="conf_stats" '.$checked.' style="margin-top:20px;" />&nbsp; '._CONFIRMSTATS.'</label>
  166.                            <br/><a href="#" style="margin-top:20px;" class="button" onclick="document.forms[\'form_stats\'].submit();" >'._CONFIRM.'</a>
  167.                        </form>
  168.                    </div>';
  169.         }
  170.  
  171.         private function setStats(){
  172.             if(isset($_REQUEST['conf_stats'])){
  173.                 $_SESSION['stats'] = $_REQUEST['conf_stats'] == 'on' ? 'yes' : 'no';
  174.             }
  175.             else{
  176.                 $_SESSION['stats'] = 'no';
  177.             }
  178.             if($this->data['type'] == 'update'){
  179.                 self::redirect('index.php?action=checkSave', 0);
  180.             }
  181.             else{
  182.                 self::redirect('index.php?action=checkTypeInstall', 0);
  183.             }
  184.         }
  185.  
  186.         private function checkSave(){
  187.             echo '<div style="text-align: center;margin:30px auto;">
  188.                        <h3 style="margin-bottom:30px;" >'._SELECTSAVE.'</h3>
  189.                        <a href="index.php?action=makeSave" style="margin-top:20px;" class="button" >'._TOSAVE.'</a>
  190.                        <a href="index.php?action=checkTypeInstall" class="button" >'._NOTHANKS.'</a>
  191.                    </div>';
  192.             $_SESSION['db_save'] = 'no';
  193.         }
  194.  
  195.         private function makeSave(){
  196.                 $_SESSION['db_save'] = 'yes';
  197.                 echo '<div style="text-align: center;margin:30px auto;">
  198.                        <h3 style="margin-bottom:30px;" >'._DBSAVED.'</h3>
  199.                        <p>'._DBSAVEDTXT.'</p>
  200.                        <p>
  201.                            <a href="index.php?action=createBackupBdd" target="_blank">'._SAVE.'</a>
  202.                        </p>
  203.                        <p>
  204.                            <a href="index.php?action=checkTypeInstall" class="button" >'._CONTINUE.'</a>
  205.                        </p>
  206.                    </div>';
  207.         }
  208.  
  209.         private function checkTypeInstall(){
  210.             if(isset($_REQUEST['assist'])){
  211.                 if($_REQUEST['assist'] == $this->data['type'].'assist'){
  212.                     $_SESSION['assist'] = $_REQUEST['assist'];
  213.                     self::redirect('index.php?action=setConfigAssistant', 0);
  214.                 }
  215.                 elseif($_REQUEST['assist'] == $this->data['type'].'speed'){
  216.                     $_SESSION['assist'] = $_REQUEST['assist'];
  217.                     self::redirect('index.php?action=setConfig', 0);
  218.                 }
  219.             }
  220.             if($this->data['type'] == 'install'){
  221.                 $speed = _INSTALLSPEED;
  222.                 $assist = _INSTALLASSIST;
  223.             }
  224.             elseif($this->data['type'] == 'update'){
  225.                 $speed = _UPDATESPEED;
  226.                 $assist = _UPDATEASSIST;
  227.             }
  228.             echo '<div style="text-align: center;margin:30px auto;">
  229.                        <h3 style="margin-bottom:30px;" >'. _CHECKTYPEINSTALL .'</h3>
  230.                            <a href="index.php?action=checkTypeInstall&amp;assist='.$this->data['type'].'speed" class="button" >'.$speed.'</a>
  231.                            <a href="index.php?action=checkTypeInstall&amp;assist='.$this->data['type'].'assist" class="button" >'.$assist.'</a>
  232.                    </div>';
  233.         }
  234.  
  235.         private function setConfig(){
  236.             if($this->data['type'] == 'update'){
  237.                 $type = _UPDATESPEED;
  238.                 include('../conf.inc.php');
  239.                 $host = $global['db_host'];
  240.                 $user = $global['db_user'];
  241.                 $pass = '';
  242.                 $name = $global['db_name'];
  243.                 $prefix = $db_prefix;
  244.             }
  245.             elseif($this->data['type'] == 'install'){
  246.                 $type = _INSTALLSPEED;
  247.                 $host = $user = $name = $pass = '';
  248.                 $prefix = 'nuked';
  249.             }
  250.             echo '<div style="text-align: center;margin:30px auto;">
  251.                        <h2>'.$type.'</h2>
  252.                        <form method="post" action="index.php?action=installDB" id="form_config">
  253.                            <h4>' . _CONFIG . '</h4>
  254.                            <div id="config" >';
  255.                             $array_fields = array('host', 'user', 'pass', 'prefix', 'name');
  256.                             foreach($array_fields as $k){
  257.                                 echo '<label>
  258.                                            <strong>'.constant('_DB'.strtoupper($k)).'</strong>
  259.                                            <input type="';
  260.                                 echo $k == 'pass' ? 'password" autocomplete="off"' : 'text"';
  261.                                 if($this->data['type'] == 'update' && $k != 'pass'){
  262.                                     echo ' disabled="disabled"';
  263.                                 }
  264.                                 echo ' name="db_'.$k.'" id="form_bdd_'.$k.'" value="'.${$k}.'" onblur="checkInputBDD($(this));" />
  265.                                            </label>';
  266.                             }
  267.             echo '</div>
  268.                            <div id="infos" style="text-align: center;margin:30px auto;color:#FF4040;"></div>
  269.                            <div style="text-align: center;">
  270.                                <a href="#" id="submit" class="button" onclick="verifFormBDD(\''.$this->data['type'].'\', \'form_config\', \''.addslashes(_WAIT).'\', \''.addslashes(_ERROR_HOST).'\', \''.addslashes(_ERROR_USER).'\', \''.addslashes(_ERROR_DB).'\', \''.addslashes(_ERROR_PREFIX).'\');"  >' . _SUBMIT . '</a>
  271.                                <a href="index.php?action=checkTypeInstall" class="button" >' . _BACK . '</a>
  272.                            </div>
  273.                        </form>
  274.                    </div>';
  275.         }
  276.  
  277.         private function setConfigAssistant(){
  278.             $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
  279.             if($page == 'set'){
  280.                 if($this->data['type'] == 'update'){
  281.                     $type = _UPDATEASSIST;
  282.                     include('../conf.inc.php');
  283.                     $host = $global['db_host'];
  284.                     $user = $global['db_user'];
  285.                     $pass = '';
  286.                     $name = $global['db_name'];
  287.                     $prefix = $db_prefix;
  288.                 }
  289.                 elseif($this->data['type'] == 'install'){
  290.                     $type = _INSTALLASSIST;
  291.                     $host = $user = $name = $pass = '';
  292.                     $prefix = 'nuked';
  293.                 }
  294.                 echo '<div style="text-align: center;">
  295.                        <h2>'.$type.'</h2>
  296.                        <form method="post" action="index.php?action=installDB" id="form_config">
  297.                            <h4>' . _CONFIG . '</h4>
  298.                            <div id="config" >';
  299.                             $array_fields = array('host', 'user', 'pass', 'prefix', 'name');
  300.                             foreach($array_fields as $k){
  301.                                 echo '<label>
  302.                                            <strong>'.constant('_DB'.strtoupper($k)).'</strong>
  303.                                            <input type="';
  304.                                 echo $k == 'pass' ? 'password" autocomplete="off"' : 'text"';
  305.                                 if($this->data['type'] == 'update' && $k != 'pass'){
  306.                                     echo ' disabled="disabled"';
  307.                                 }
  308.                                 echo ' name="db_'.$k.'" id="form_bdd_'.$k.'"  value="'.${$k}.'" onblur="checkInputBDD($(this));" />
  309.                                            </label>
  310.                                            <p><img src="images/info.png" style="float:left;margin-right:5px;" />'.constant('_INSTALLDB'.strtoupper($k)).'</p>';
  311.                             }
  312.                 echo '</div>
  313.                            <div id="infos" style="text-align: center;margin:30px auto;color:#FF4040;"></div>
  314.                            <div style="text-align: center;">
  315.                                <a href="#" id="submit" class="button" onclick="verifFormBDD(\''.$this->data['type'].'\', \'form_config\', \''.addslashes(_WAIT).'\', \''.addslashes(_ERROR_HOST).'\', \''.addslashes(_ERROR_USER).'\', \''.addslashes(_ERROR_DB).'\', \''.addslashes(_ERROR_PREFIX).'\');"  >' . _SUBMIT . '</a>';
  316.                 if($page == 'set'){
  317.                     echo '<a href="index.php?action=checkTypeInstall" class="button" >' . _BACK . '</a>';
  318.                 }
  319.                 echo '</div>
  320.                        </form>
  321.                    </div>';
  322.             }
  323.             else{
  324.                 echo '<div style="text-align:center;">
  325.                                <img src="images/nk.png"/>
  326.                                <h2><b>'. _NEWNKNEWRELEASE.'</b></h2>
  327.                            </div>
  328.                            <div style="width:90%;margin: 20px auto;">';
  329.                 $array_infos = array('_SECURITE', '_OPTIMISATION', '_ADMINISTRATION', '_BANTEMP', '_SHOUTBOX', '_ERRORSQL', '_MULTIWARS', '_COMSYS', '_EDITWYS', '_CONT', '_ERREURPASS', '_DIFFMODIF');
  330.                 foreach($array_infos as $k){
  331.                     echo '<p>
  332.                                    <b>'.constant($k).':</b>
  333.                                    <br />
  334.                                    '.constant($k.'1').'
  335.                                    <br />
  336.                                </p>';
  337.                 }
  338.                 echo '</div>
  339.                            <div style="text-align: center;">
  340.                                <a href="index.php?action=setConfigAssistant&page=set" class="button" >' . _CONTINUE . '</a>
  341.                            </div>';
  342.             }
  343.         }
  344.  
  345.         private function installDB(){
  346.             if($this->data['type'] == 'install'){
  347.                 $_SESSION['host'] = $_REQUEST['db_host'];
  348.                 $_SESSION['user'] = $_REQUEST['db_user'];
  349.                 $_SESSION['pass'] = $_REQUEST['db_pass'];
  350.                 $_SESSION['db_name'] = $_REQUEST['db_name'];
  351.                 $db_prefix = $_SESSION['db_prefix'] = $_REQUEST['db_prefix'];
  352.                 $array_text = array( _LOGITXTSUCCESS);
  353.                 $error = _LOGITXTERROR;
  354.                 $complete = _LOGITXTENDSUCCESS;
  355.                 $complete_error_start = _LOGITXTENDERRORSTART;
  356.                 $complete_error_end = _LOGITXTENDERROREND;
  357.             }
  358.             elseif($this->data['type'] == 'update'){
  359.                 unset($_SESSION['hash']);
  360.                 include('../conf.inc.php');
  361.                 $_SESSION['host'] = $global['db_host'];
  362.                 $_SESSION['user'] = $global['db_user'];
  363.                 $_SESSION['pass'] = $_REQUEST['db_pass'];
  364.                 $_SESSION['db_name'] = $global['db_name'];
  365.                 $_SESSION['db_prefix'] = $db_prefix;
  366.                 $array_text = array( _LOGUTXTSUCCESS, _LOGUTXTUPDATE, _LOGUTXTUPDATE2, _LOGUTXTREMOVE, _LOGUTXTREMOVE2);
  367.                 $error = _LOGUTXTERROR;
  368.                 $complete = _LOGUTXTENDSUCCESS;
  369.                 $complete_error_start = _LOGUTXTENDERRORSTART;
  370.                 $complete_error_end = _LOGUTXTENDERROREND;
  371.             }
  372.             echo '<div style="text-align: center;"><h2>';
  373.             echo $this->data['type'] == 'install' ? _CREATEDB : _UPDATEDB;
  374.             echo '</h2>
  375.                    <div id="log_install" >'._WAITING.'</div>
  376.                    <div id="progress" class="progress-bar-bg">
  377.                    <span class="progress-bar" ></span></div>
  378.                    <script type="text/javascript">
  379.                    var array_text = new Array(\''.implode("','", $array_text).'\');
  380.                        function start_'.$this->data['type'].'(){
  381.                            if(busy == false){
  382.                                busy = true;
  383.                                $("#log_install").text("'.constant('_STARTING'.strtoupper($this->data['type'])).'");
  384.                                $("#log_install").append("<img src=\"images/loading.gif\" alt=\"\" id=\"loading_img\" />");
  385.                                $("#continue_install").removeClass("button");
  386.                                $("#continue_install").addClass("button_disabled");
  387.                                queue_install("'.$this->data['type'].'");
  388.                            }
  389.                        }
  390.                        function ajaxTable(table){
  391.                            $.ajax({
  392.                                async: true,
  393.                                type: "POST",
  394.                                url: "index.php?action=creatingDB",
  395.                                data: "table="+table+"&db_prefix='.$db_prefix.'"
  396.                            }).done(function(txt) {
  397.                                if(txt == "OK"){
  398.                                    writeInfo("'.$this->data['type'].'", "'.$db_prefix.'", table, array_text, "OK");
  399.                                    $(".progress-bar").css("width", progress_'.$this->data['type'].'*i+"%");
  400.                                    i++;
  401.                                }
  402.                                else{
  403.                                    writeInfo("'.$this->data['type'].'", "'.$db_prefix.'", table, "'.$error.'", "NO");errors++;
  404.                                    writeError("'._PRINTERROR.'", txt);
  405.                                }
  406.                                $("#log_install").scrollTop(1000);
  407.                                ajaxBusy = false;
  408.                            });
  409.                        }
  410.                        function viewEnd(){
  411.                            if(errors == 0){
  412.                                txt_end = "'.$complete.'";
  413.                                $("#continue_install").text("' . _CONTINUE . '");
  414.                                install = true;
  415.                            }
  416.                            else{
  417.                                txt_end = "'.$complete_error_start.'"+errors+"'.$complete_error_end.'";
  418.                                $("#continue_install").text("' . _RETRY . '");
  419.                            }
  420.                            writeComplete(txt_end);
  421.                            $("#continue_install").removeClass("button_disabled");
  422.                            $("#continue_install").addClass("button");
  423.                        }
  424.                    </script>';
  425.             echo '<a href="#" class="button" id="continue_install" onclick="submit(\''.$this->data['type'].'\')" >' . _START . '</a>
  426.                    </div>';
  427.         }
  428.  
  429.         private function creatingDB(){
  430.             $table = $_REQUEST['table'];
  431.             $db_prefix = $_REQUEST['db_prefix'];
  432.             if($this->bddConnect($this->data['host'], $this->data['user'], $this->data['pass'], $this->data['db_name']) == 'OK'){
  433.                 if($this->data['type'] == 'install'){
  434.                     include('install.inc');
  435.                 }
  436.                 elseif($this->data['type'] == 'update'){
  437.                     include('update.inc');
  438.                 }
  439.             }
  440.             else{
  441.                 echo 'pass = '.$this->data['pass'].'<br/>';
  442.                 echo $this->bddConnect($this->data['host'], $this->data['user'], $this->data['pass'], $this->data['db_name']);
  443.             }
  444.         }
  445.  
  446.         private function checkUserAdmin(){
  447.             $_SESSION['user_admin'] = 'INPROGRESS';
  448.             if(isset($_REQUEST['send'])){
  449.                 if (!isset($_REQUEST['pseudo']) || !isset($_REQUEST['pass']) || !isset($_REQUEST['pass2']) || !isset($_REQUEST['mail'])
  450.                     || strlen($_REQUEST['pseudo']) < 3 || $_REQUEST['pass'] != $_REQUEST['pass2'] || preg_match("`[\$\^\(\)'\"?%#<>,;:]`", $_REQUEST['pseudo'])
  451.                     || !preg_match("/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/", $_REQUEST['mail']) ){
  452.                     echo '<div style="text-align: center;margin:30px auto;">
  453.                            <h2>'._CHECKUSERADMIN.'</h2>
  454.                            <p>'._ERRORFIELDS.'</p>
  455.                            <a href="index.php?action=checkUserAdmin" class="button" >' . _BACK . '</a>
  456.                            </div>';
  457.                 }
  458.                 else{
  459.                     if($this->bddConnect($this->data['host'], $this->data['user'], $this->data['pass'], $this->data['db_name']) == 'OK'){
  460.                         include('user.inc');
  461.                         $save_config = saveConfig('install');
  462.                         if($save_config == 1){
  463.                             $_SESSION['user_admin'] = 'FINISH';
  464.                             self::redirect("index.php?action=checkInstallSuccess", 0);
  465.                         }
  466.                         else{
  467.                             self::redirect("index.php?action=checkInstallFailure&error=".$save_config, 0);
  468.                         }
  469.                     }
  470.                 }
  471.             }
  472.             else{
  473.                 echo '<div style="text-align: center;margin:30px auto;">
  474.                        <h2>'._CHECKUSERADMIN.'</h2>';
  475.             }
  476.             if(!isset($_REQUEST['send'])){
  477.                 echo '<form method="post" action="index.php?action=checkUserAdmin" id="form_user_admin">
  478.                                <div id="config" >';
  479.                                 $array_fields = array('pseudo', 'pass', 'pass2', 'mail');
  480.                                 foreach($array_fields as $k){
  481.                                     echo '<label>
  482.                                                <strong>'.constant('_'.strtoupper($k)).'</strong>
  483.                                                <input type="';
  484.                                     echo (($k == 'pass') || ($k == 'pass2')) ? 'password' : 'text';
  485.                                     echo '" name="'.$k.'" value="" onblur="checkInputAdmin($(this));" />
  486.                                                </label>';
  487.                                 }
  488.                 echo '</div>
  489.                                <input type="hidden" name="send" value="ok" />
  490.                                <div id="infos" style="text-align: center;margin:30px auto;color:#FF4040;"></div>
  491.                                <div style="text-align: center;margin:30px auto;">
  492.                                    <a href="#" class="button" onclick="verifFormAdmin(\'form_user_admin\',  \''.addslashes(_WAIT).'\', \''.addslashes(_ERROR_PSEUDO).'\', \''.addslashes(_ERROR_PASS).'\', \''.addslashes(_ERROR_PASS2).'\',  \''.addslashes(_ERROR_MAIL).'\');"  >' . _SUBMIT . '</a>
  493.                                </div>
  494.                            </form>
  495.                        </div>';
  496.             }
  497.         }
  498.  
  499.         private function updateConfig(){
  500.             include('user.inc');
  501.             $save_config = saveConfig('update');
  502.             if($save_config == 1){
  503.                 self::redirect("index.php?action=checkInstallSuccess", 0);
  504.             }
  505.             else{
  506.                 self::redirect("index.php?action=checkInstallFailure&error=".$save_config, 0);
  507.             }
  508.         }
  509.  
  510.         private function checkInstallFailure(){
  511.             $_SESSION['user_admin'] = 'FINISH';
  512.             $error = isset($_REQUEST['error']) ? $_REQUEST['error'] : '';
  513.             echo '<div style="text-align: center;margin:30px auto;">
  514.                        <h2>'._ERROR.'</h2>
  515.                        <p>'.constant('_'.$error).'</p>';
  516.             if($error == 'CONF.INC' || $error == 'COPY'){
  517.                 echo '<div id="log_install">';
  518.                 if(isset($_SESSION['content_web'])){
  519.                     echo $_SESSION['content_web'];
  520.                     echo '</div><p>'.constant('_'.$error.'2').'</p>';
  521.  
  522.                 }
  523.                 else{
  524.                     echo _ERRORGENERATECONFINC;
  525.                     echo '</div>';
  526.                 }
  527.             }
  528.             if(isset($_SESSION['content_web']) && $error != 'CHMOD'){
  529.                 echo '<a href="index.php?action=printConfig" class="button" >'._DOWNLOAD.'</a>&nbsp;';
  530.             }
  531.             else{
  532.                 echo '<a href="index.php?action=checkUserAdmin" class="button" >'._BACK.'</a>&nbsp;';
  533.             }
  534.             if(isset($_SESSION['content_web'])){
  535.                 echo '<a href="index.php?action=checkInstallSuccess" class="button" >' . _CONTINUE . '</a>
  536.                        </div>';
  537.             }
  538.         }
  539.  
  540.         private function checkInstallSuccess(){
  541.             echo '<div style="text-align: center;margin:30px auto;">
  542.                        <h2>'._INSTALLSUCCESS.'</h2>
  543.                        <p>'._INFOPARTNERS.'</p>
  544.                        <div id="partners" ><img src="images/loading.gif" alt="" /><br/>'._WAIT.'</div>';
  545.             echo '<script type="text/javascript" >
  546.                            function ajaxPartners(){
  547.                                $.ajax({
  548.                                    async: true,
  549.                                    type: "POST",
  550.                                    url: "index.php?action=getPartners",
  551.                                }).done(function(txt) {
  552.                                    $("#partners").css("display", "none");
  553.                                    $("#partners").html(txt);
  554.                                    $("#partners").fadeIn("slow");
  555.                                });
  556.                            }
  557.                            $(document).ready(ajaxPartners());
  558.                        </script>';
  559.  
  560.             echo '<a href="index.php?action=deleteSession" class="button" >' . _ACCESS_SITE . '</a>
  561.                    </div>';
  562.         }
  563.  
  564.         private function getPartners(){
  565.             $content = @file_get_contents('http://www.nuked-klan.org/extra/partners.php?key=iS5scBmNTNyE6M07Jna3');
  566.             $content = @unserialize($content);
  567.             $content = !is_array($content) ? array() : $content;
  568.             $i = 0;
  569.             foreach($content as $k => $v){
  570.                 echo '<a href="'.$v[2].'" ><img src="'.$v[1].'" alt="'.$v[0].'" /></a>';
  571.                 $i++;
  572.             }
  573.             if($i == 0){
  574.                 echo _NOPARTNERS;
  575.             }
  576.         }
  577.  
  578.         private function resetSession(){
  579.             unset($_SESSION);
  580.             session_destroy();
  581.             self::redirect('index.php', 0);
  582.         }
  583.  
  584.         private function deleteSession(){
  585.             unset($_SESSION);
  586.             session_destroy();
  587.             self::redirect('../index.php', 0);
  588.         }
  589.  
  590.         ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  591.         // Méthodes de services, appelées pour effectuer une tâche précise
  592.         ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  593.  
  594.         private function importLang(){
  595.             if(isset($this->data['lang_install']) && in_array($this->data['lang_install'], $this->array_lang)){
  596.                 include('lang/'.$this->data['lang_install'].'.lang.php');
  597.             }
  598.             else{
  599.                 $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == 'fr' ? 'french' : 'english';
  600.                 include('lang/'.$lang.'.lang.php');
  601.             }
  602.         }
  603.  
  604.         private function bddConnect($host, $user, $pass, $db_name) {
  605.             if (($db = @mysql_connect($host, $user, $pass)) === false)
  606.                return mysql_error();
  607.  
  608.             if (! @mysql_select_db($db_name, $db))
  609.                return mysql_error();
  610.  
  611.             @mysql_query('SET NAMES \'latin1\'');
  612.  
  613.             return 'OK';
  614.         }
  615.  
  616.         private function testBddConnect(){
  617.             $connect = $this->bddConnect($_REQUEST['db_host'], $_REQUEST['db_user'], utf8_decode($_REQUEST['db_pass']), $_REQUEST['db_name']);
  618.             if(preg_match('#Unknown MySQL server host#', $connect)){
  619.                 echo 'error_host';
  620.             }
  621.             else if(preg_match('#Access denied for user#', $connect)){
  622.                 echo 'error_login';
  623.             }
  624.             else if(preg_match('#Unknown database#', $connect)){
  625.                 echo 'error_db';
  626.             }
  627.             else if($connect == 'OK'){
  628.                 if(isset($_REQUEST['type'])){
  629.                     if($_REQUEST['type'] == 'update'){
  630.                         $result = mysql_query('SELECT name, value FROM '.$_REQUEST['db_prefix'].'_config');
  631.                         if ($result == false) {
  632.                             echo 'error_prefix';
  633.                         } else {
  634.                             echo 'OK';
  635.                         }
  636.  
  637.                     }
  638.                     else{
  639.                         echo 'OK';
  640.                     }
  641.                 }
  642.                 else{
  643.                     echo 'OK';
  644.                 }
  645.             }
  646.  
  647.             else{
  648.                 echo $connect;
  649.             }
  650.         }
  651.  
  652.         private function requirements(){
  653.             $array_requirements = array();
  654.             $array_requirements['_PHPVERSION'] = version_compare(phpversion() > 0, '5.1') ? 1 : 3;
  655.             $array_requirements['_MYSQLEXT'] = extension_loaded('mysql') ? 1 : 3;
  656.             $array_requirements['_SESSIONSEXT'] = extension_loaded('session') ? 1 : 3;
  657.             $array_requirements['_ZIPEXT'] = extension_loaded('zip') ? 1 : 3;
  658.             $array_requirements['_FILEINFOEXT'] = extension_loaded('fileinfo') ? 1 : 2;
  659.             $array_requirements['_HASHEXT'] = function_exists('hash') ? 1 : 3;
  660.             $array_requirements['_GDEXT'] = extension_loaded('gd') ? 1 : 3;
  661.             $array_requirements['_TESTCHMOD'] = is_writable(dirname(dirname(__FILE__)).'/') ? 1 : 3;
  662.             return $array_requirements;
  663.         }
  664.  
  665.         private function createBackupBdd(){
  666.             header("Content-disposition:filename=save".time().".sql");
  667.             header("Content-type:application/octetstream");
  668.  
  669.             include('../conf.inc.php');
  670.             $this->bddConnect($global['db_host'], $global['db_user'], $global['db_pass'], $global['db_name']);
  671.             $array_sqlTables = array();
  672.             $result = mysql_query('SHOW TABLES');
  673.             while($row = mysql_fetch_row($result)){
  674.               $array_sqlTables[] = $row[0];
  675.             }
  676.             $return = "#------------------------------------------\n"
  677.                         ."# Save of database for Nuked-Klan\n"
  678.                         ."# Database: ".$global['db_name']."\n"
  679.                         ."# Date: ".strftime("%c")."\n"
  680.                         ."#------------------------------------------\n\n";
  681.             foreach($array_sqlTables as $table){
  682.                 $result = mysql_query('SELECT * FROM '.$table);
  683.                 $num_fields = mysql_num_fields($result);
  684.                 $return.= 'DROP TABLE IF EXISTS '.$table.';';
  685.                 $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
  686.                 $return.= "\n\n".$row2[1].";\n\n";
  687.                 $return.= "#------------------------------------------\n"
  688.                             ."# Data inserts for ".$table."\n"
  689.                             ."#------------------------------------------\n\n";
  690.                 for ($i = 0; $i < $num_fields; $i++) {
  691.                     while($row = mysql_fetch_row($result)){
  692.                         $return.= 'INSERT INTO '.$table.' VALUES(';
  693.                         for($j=0; $j<$num_fields; $j++){
  694.                             $row[$j] = addslashes($row[$j]);
  695.                             $row[$j] = preg_replace("#\\n#","\\n",$row[$j]);
  696.                             if (isset($row[$j]))
  697.                                 $return.= '"'.$row[$j].'"' ;
  698.                             else
  699.                                 $return.= '""';
  700.                             if ($j<($num_fields-1))
  701.                                 $return.= ',';
  702.                         }
  703.                         $return.= ");\n";
  704.                     }
  705.                 }
  706.                 $return.="\n\n\n";
  707.             }
  708.  
  709.             echo $return;
  710.         }
  711.        
  712.         private function validVersion($version){
  713.             if (version_compare($version, _NKVERSION, '=')) { // last version already set
  714.                 return 1;
  715.             } else if ((version_compare($version, '1.7.8', '>') && version_compare($version, '1.7.9 RC3', '<')) || version_compare($version, '1.7.7', '<')) { // cannot update
  716.                 return -1;
  717.             } else {// can update, version == 1.7.7, 1.7.8 or greater than 1.7.9
  718.                 return 0;
  719.             }
  720.         }
  721.  
  722.         private function printConfig(){
  723.             header("Content-disposition:filename=conf.inc.php");
  724.             header("Content-type:application/octetstream");
  725.             if(isset($_SESSION['content'])){
  726.                 echo $_SESSION['content'];
  727.             }
  728.         }
  729.  
  730.         private function showError($text){
  731.             echo '<div id="error_div" >'.$text.'</div>';
  732.         }
  733.  
  734.         ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  735.         // Méthodes d'affichage, appelées pour effectuer la mise en page
  736.         ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  737.  
  738.         static function viewTop(){
  739.             echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  740.                    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
  741.                        <head>
  742.                            <title>Installation de Nuked-klan</title>
  743.                            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  744.                            <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
  745.                            <script type="text/javascript" src="jquery-1.7-min.js" ></script>
  746.                            <script type="text/javascript" src="script.js" ></script>
  747.                        </head>
  748.                        <body>
  749.                            <div id="content" class="greyscale">
  750.                                <div id="sidebar" >
  751.                                     <a href="http://www.nuked-klan.org">
  752.                                         <img id="logo" src="../modules/Admin/images/logo.png" alt="Nuked-Klan" />
  753.                                     </a>';
  754.         }
  755.  
  756.         private function navigation(){
  757.             echo '<div id="navigation" >';
  758.             $array_menu = array('lang_install' => _SELECTLANG, 'type' => _SELECTTYPE, 'stats' => _SELECTSTATS, 'db_save' => _SELECTSAVE, 'assist' => _CHECKTYPEINSTALL, 'user_admin' => _CHECKUSERADMIN);
  759.             if(isset($this->data)){
  760.                 $i = 0;
  761.                 foreach($this->data as $k => $v){
  762.                     $a = isset($array_menu[$k]) ? $array_menu[$k] : null;
  763.                     if($a !== null){
  764.                         if($i > 0)  echo '<hr style="margin:0 auto;width:80%;" />';
  765.                         echo '<p style="margin:5px auto;"><span class="link_nav">'.$a.'</span><br/><span>'.constant('_'.strtoupper($this->data[$k])).'<span></p>';
  766.                         $i++;
  767.                     }
  768.                 }
  769.                 if(isset($_REQUEST['action'])){
  770.                     if($_REQUEST['action'] != 'checkInstallSuccess'){
  771.                         echo '<a href="index.php?action=resetSession" id="reset" class="button" >' . _RESETSESSION . '</a>';
  772.                     }
  773.                 }
  774.             }
  775.             echo '</div></div>';
  776.         }
  777.  
  778.         static function viewBottom(){
  779.             echo '</div></body></html>';
  780.         }
  781.  
  782.         static function viewInfos(){
  783.             $step = rand(1,4); // A modifier en cas d'ajout d'infos
  784.             echo '<hr style="margin-top:30px;margin-bottom:15px;width:90%;" />
  785.                    <div style="width:580px;overflow:hidden;margin:auto;">';
  786.                         switch($step){
  787.                             case'1':
  788.                             $a = '_DISCOVERY';
  789.                             break;
  790.                             case'2':
  791.                             $a = '_NEWSADMIN';
  792.                             break;
  793.                             case'3':
  794.                             $a = '_INSTALL_AND_UPDATE';
  795.                             break;
  796.                             case'4':
  797.                             $a = '_COMMUNAUTY_NK';
  798.                             break;
  799.                         }
  800.                         echo '<div id="slide'.$step.'" style="display:block;width:580px;">
  801.                                    <h2>'.constant($a).'</h2>
  802.                                    <p>
  803.                                        <img src="images/img_slide_0'.$step.'.png" alt="" style=" float:right;" width="200" height="194" />
  804.                                        '.constant($a.'_DESCR').'
  805.                                    </p>
  806.                                </div>
  807.                    </div>';
  808.         }
  809.  
  810.         static function redirect($url, $tps){
  811.             $temps = $tps * 1000;
  812.             echo '<script type="text/javascript">function redirect(){window.location=\'' . $url . '\'}setTimeout(\'redirect()\',\'' . $temps .'\');</script>';
  813.         }
  814.  
  815.         private function routeUser(){
  816.             $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  817.             $array_page_nude = array('creatingDB', 'printConfig', 'testBddConnect', 'getPartners', 'createBackupBdd');
  818.  
  819.             if(in_array($action, $array_page_nude)){
  820.                 $this->{$action}();
  821.             }
  822.             else{
  823.                 self::viewTop();
  824.                 $this->navigation();
  825.                 if(method_exists($this, $action) && (isset($_SESSION['lang_install']) || isset($_REQUEST['lang_install']))){
  826.                     $this->{$action}();
  827.                 }
  828.                 else{
  829.                     $this->checkLang();
  830.                 }
  831.                 self::viewInfos();
  832.                 self::viewBottom();
  833.             }
  834.         }
  835.        
  836.         static function generateHashKey() {
  837.             $str = str_replace(array('\'', "\n"), '#', @sha1(uniqid(''), true));
  838.             return addslashes($str);
  839.         }
  840.  
  841.     }
  842.  
  843.     $install = new install();
  844. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement