151 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
			
		
		
	
	
			151 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
<?php
 | 
						|
 | 
						|
function dir_is_empty($dirname)
 | 
						|
{
 | 
						|
  // Check if directory is empty but ignore install script
 | 
						|
  if (!is_dir($dirname)) return false;
 | 
						|
  foreach (scandir($dirname) as $file) {
 | 
						|
    if (!in_array($file, array('.','..','oci-framawiki.php'))) return false;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
// If install directory is not empty stop processing
 | 
						|
$dest = dirname(__FILE__).'/';
 | 
						|
if (dir_is_empty($dest) === false) {
 | 
						|
    echo nl2br("Le dossier httpdocs/ doit être vide pour y migrer votre Framasite.\r\n");
 | 
						|
    exit();
 | 
						|
}
 | 
						|
 | 
						|
// We have a TAR file !
 | 
						|
if($_FILES["tar_file"]["name"]) {
 | 
						|
    $filename = $_FILES["tar_file"]["name"];
 | 
						|
    $sourcetar = $_FILES["tar_file"]["tmp_name"];
 | 
						|
    $type = $_FILES["tar_file"]["type"];
 | 
						|
 | 
						|
    $name = explode(".", $filename);
 | 
						|
    $accepted_types = array('application/x-tar', 'multipart/x-tar');
 | 
						|
    foreach($accepted_types as $mime_type) {
 | 
						|
        if($mime_type == $type) {
 | 
						|
            $okay = true;
 | 
						|
            break;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    $continue = strtolower($name[1]) == 'tar' ? true : false;
 | 
						|
    if(!$continue) {
 | 
						|
        $message = "Votre fichier n'est pas une archive TAR.";
 | 
						|
    }
 | 
						|
 | 
						|
    /* PHP current path */
 | 
						|
    $filenoext = basename ($filename, '.tar');  // absolute path (lowercase)
 | 
						|
    $filenoext = basename ($filenoext, '.TAR');  // absolute path (uppercase)
 | 
						|
 | 
						|
    $targetdir = $path . $filenoext; // target directory
 | 
						|
    $targettar = $path . $filename; // target tar file
 | 
						|
 | 
						|
    // Download latest CMS zip with cURL
 | 
						|
    $ch = curl_init();
 | 
						|
    $source = "https://ouvaton.coop/oci/framawiki.zip";
 | 
						|
    curl_setopt($ch, CURLOPT_URL, $source);
 | 
						|
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 | 
						|
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 | 
						|
    $data = curl_exec($ch);
 | 
						|
    // If any cURL error stop processing
 | 
						|
    if(curl_errno($ch)) {
 | 
						|
    echo nl2br("Une erreur vient de se produire. Rechargez la page pour essayer à nouveau, ou contactez l'assistance si le problème persiste.\r\n");
 | 
						|
    echo 'Erreur cURL : '.curl_error($ch);
 | 
						|
    curl_close($ch);
 | 
						|
    exit;
 | 
						|
    }
 | 
						|
 | 
						|
    // Check HTTP code
 | 
						|
    switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
 | 
						|
    case 200:
 | 
						|
        // Create CMS zip
 | 
						|
        $destination = "framawiki.zip";
 | 
						|
        $file = fopen($destination, "w+");
 | 
						|
        fputs($file, $data);
 | 
						|
        fclose($file);
 | 
						|
        curl_close($ch);
 | 
						|
 | 
						|
        // Unzip archive file
 | 
						|
        $file = 'framawiki.zip';
 | 
						|
        $zip = new ZipArchive;
 | 
						|
        if ($zip->open($file) === TRUE) {
 | 
						|
                $zip->extractTo('.');
 | 
						|
                $zip->close();
 | 
						|
        } else {echo nl2br("Une erreur lors de la décompression de l'archive vient de se produire, contactez l'assistance !\r\n");}
 | 
						|
        // Zip archive is not needed anymore
 | 
						|
        unlink('framawiki.zip');
 | 
						|
 | 
						|
        /* here it is really happening */
 | 
						|
        if(move_uploaded_file($sourcetar, $targettar)) {
 | 
						|
            try {
 | 
						|
                $phar = new PharData($targettar);
 | 
						|
                $phar->extractTo('.', null, true);
 | 
						|
                echo ('File extracted');
 | 
						|
            } catch (Exception $e) {
 | 
						|
                echo nl2br("Une erreur vient de se produire lors de l'extraction de l'archive.\r\n");
 | 
						|
            }
 | 
						|
            unlink($targettar);
 | 
						|
        } else {
 | 
						|
            echo nl2br("Une erreur vient de se produire lors du téléversement de votre fichier.\r\n");
 | 
						|
            exit();
 | 
						|
        }
 | 
						|
 | 
						|
        // CKGEdit plugin must be deactivated
 | 
						|
        $disable_ckgedit = <<<'EOD'
 | 
						|
$plugins['ckgedit'] = 0;
 | 
						|
EOD;
 | 
						|
        $set_french = file_put_contents('conf/plugins.local.php', $disable_ckgedit.PHP_EOL , FILE_APPEND | LOCK_EX);
 | 
						|
 | 
						|
        // Redirecting user to CMS install page
 | 
						|
        $host  = $_SERVER['HTTP_HOST'];
 | 
						|
        $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
 | 
						|
        header("Location: http://$host$uri/");
 | 
						|
        // Remove script
 | 
						|
        unlink(__FILE__);
 | 
						|
        exit;
 | 
						|
    default:
 | 
						|
        // If any HTTP error stop processing
 | 
						|
        echo nl2br("Une erreur vient de se produire. Rechargez la page pour essayer à nouveau, ou contactez l'assistance si le problème persiste.\r\n");
 | 
						|
        echo nl2br("Code HTTP : ".$http_code."\r\n");
 | 
						|
        curl_close($ch);
 | 
						|
        exit;
 | 
						|
    }
 | 
						|
}
 | 
						|
?>
 | 
						|
 | 
						|
<!DOCTYPE html>
 | 
						|
<html>
 | 
						|
<head>
 | 
						|
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 | 
						|
    <title>Migration de votre Framasite chez Ouvaton</title>
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
    <style>
 | 
						|
        body{background:#f0f0f0;font-family:Arial,sans-serif;text-align:center}.vert{color:#6c7e31;fill:#889e3a;}.violet{color:#725794;fill:#977ac2;}header img{display:block;margin-left:auto;margin-right:auto}main article p{width:80%;margin-left:10%;margin-bottom:2%}input[type=submit]{background-color:#4CAF50;border:none;color:white;padding:10px 24px;text-decoration:none;margin:16px 2px 0;border-radius:16px;cursor:pointer;}@media screen and (min-width:600px){main article p{width:50%;margin-left:25%}}@media screen and (min-width:1200px){main article p{width:30%;margin-left:35%}}
 | 
						|
    </style>
 | 
						|
    <header>
 | 
						|
        <img alt="Logo Ouvaton" src="https://ouvaton.coop/wp-content/uploads/2018/04/cropped-logo-ouvaton-hd-refill-3.png">
 | 
						|
        <h1>Importation de votre <b class="violet">Frama</b><b class="vert">site</b></a> Dokuwiki sur la plateforme Ouvaton</h1>
 | 
						|
    </header>
 | 
						|
    <main>
 | 
						|
        <article>
 | 
						|
            <p>
 | 
						|
            <form enctype="multipart/form-data" method="post" action="">
 | 
						|
                <label>Sélectionnez l'archive TAR de votre site :<br />
 | 
						|
                <input type="file" name="tar_file" /></label>
 | 
						|
                <br />
 | 
						|
                <input type="submit" name="submit" value="Envoyer" />
 | 
						|
            </form>
 | 
						|
            </p>
 | 
						|
            <p>Il faut plusieurs dizaines de secondes pour mettre en place votre site.<br />
 | 
						|
            <strong>Ne rechargez ou ne quittez pas la page</strong> avant que votre site ne s'affiche !<br />
 | 
						|
            En cas de problème, contactez-nous sur assistance@listes.ouvaton.coop !</p>
 | 
						|
        </article>
 | 
						|
    </main>
 | 
						|
</body>
 | 
						|
</html>
 |