'; echo ''; echo 'Dolibarr uploader test POC - Task = '.$task.''; echo ''; echo ''; echo ''; echo ''; // block progression echo ''; // Activation block div echo ''; ob_flush(); flush(); ob_flush(); flush(); $packs = zip_packs(); ////AS THIS IS ONLY A POC i don't care so much about security !!!!! // for doliwamp it seems we need to check empty value as it will issue an erreur undefined // http://www.dolibarr.fr/forum/511-creation-dun-nouveau-module/54363-nouveau-module-extrabackup-sauve-docs-htdocs/reply#69110 if (isset($_POST['pack'])) { $pack = $_POST['pack']; } else { $pack = -1; } if (isset($_POST['custom_tag'])) { $custom_tag = $_POST['custom_tag']; // I know this is not secured and opend to many hack but this is onl a poc tool } // don't use it in real world !!!!! else { $custom_tag = ''; } //echo 'task='.$task . ' - pack='.$pack.' - tag='.$custom_tag; if ($task == 2 && ($pack !="" | $custom_tag !="")) { if ($custom_tag != "") { echo "downloading pack=" . $packs[$pack][0] . ". tag=https://github.com/Dolibarr/dolibarr/archive/". $custom_tag.'.zip'; echo zip_upload('https://github.com/Dolibarr/dolibarr/archive/'.$custom_tag.'.zip'); } else { echo "downloading pack=" . $packs[$pack][0] . ". tag=". $custom_tag; echo zip_upload($packs[$pack][0]); } } if ($task == 3 && file_exists('mydolibarr.zip')) { echo "extracting mydolibarr.zip !
"; $filename= 'mydolibarr.zip'; $select_folder= 'htdocs'; $extract_folder='../htdocs'; $ret=zip_extract($filename, $select_folder, $extract_folder); if($ret['success'] == 0) { echo "ExtraBackupFileUnzipNotOk
"; echo $ret['error']; } else { mkdir ('__is_'.date('Ymd-His').'_install_'.zip_info('mydolibarr.zip'),0704); // $fh = fopen('__is_'.date('Ymd-His').'_install_'.zip_info('../htdocs-pack/mydolibarr.zip'), 'a'); // fwrite($fh, '

Install Dolibarr by dolibarr ExtraBackup Module

'); // fclose($fh); echo "ExtraBackupFileUnzipOk"; } //var_dump($ret); } if ($task == 4 && file_exists('../documents/install.lock')) { unlink('../documents/install.lock'); } if ($task == 5 && !file_exists('../documents/install.lock')) { $fh = fopen('../documents/install.lock', 'a'); fwrite($fh, '

Install.lock created by dolibarr ExtraBackup Module

'); fclose($fh); } if ($task == 6 && file_exists('install/index.php')) { echo ""; //header('Location: install/index.php'); //exit; } if ($task == 91 && file_exists('mydolibarr.zip')) { unlink('mydolibarr.zip'); } if ($task == 101 && file_exists('../htdocs/extract.php')) { unlink('../htdocs/extract-pclzip/gnu-lgpl.txt'); unlink('../htdocs/extract-pclzip/pclzip.lib.php'); unlink('../htdocs/extract-pclzip/readme.txt'); rmdir('../htdocs/extract-pclzip'); unlink('../htdocs/extract.php'); header('Location: index.php'); exit; } ?>

Welcome to extrabackup test tool to upload and upgrade dolibarr in one click

This file is provided as is as a courtesy of elarifr from accedinfo.com
After use of this POC tool do not let it on your server

Rename or delete this file after use as this is a very unsecure tool !!

You have been advised !!

Download a pack

Select a pack to download !
"; echo "and i will do magic for you to extract only htdocs folder !

"; $pack=""; $custom_tag=""; for ($i=0;$i ".$packs[$i][2]." (".$packs[$i][1]." by ".$packs[$i][3].")
"; } echo "
Or you can also specify and upload any version from Github !
"; echo "Open Dolibarr github in new windows and select release name
"; echo "Type only the tag or branche you want like '3.8.5' or '3.9.1'
"; ?> GitHub Branches or Tag :

Extract one packYou can also manually upload a file in /htdocs/ named mydolibarr.zip
'; if (file_exists('mydolibarr.zip')){ echo 'I have found the pack including version ' . zip_info('mydolibarr.zip').'
'; echo '
'; echo '
'; echo '
'; } else { echo '

There is no mydolibarr.zip pack file to extract

'; } if (file_exists('../documents/install.lock')){ echo '

Delete ../documents/install.lock !

'; echo '
'; echo '
'; echo '
'; } else { echo '

Remember to write a file ../documents/install.lock !!!!

'; echo '
'; echo '
'; echo '
'; } if (file_exists('install/index.php')){ echo '

Run dolibarr install !

'; echo '
'; echo '
'; echo '
'; } if ($task == 90 && file_exists('mydolibarr.zip')) { echo '

Delete mydolibarr.zip !

'; echo '
'; echo '
'; echo '
'; } if ($task == 100){ echo '

Delete extract.php !

'; echo '
'; echo '
'; echo '
'; } echo "task 90 will delete file mydolibarr.zip if the file exist
"; echo "task 100 will delete file ../htdocs/extract.php
"; echo "task 951 will delete folder ../htdocs !!!!! TAKE CARE !
"; echo ''; /* ///////////////////////////////////////////////////////////// $filename= '../htdocs-pack/dolibarr361.zip'; $select_folder= 'accountancy'; $extract_folder='../htdocs/accountancy'; // extractzip ($filename, $select_folder, $extract_folder); if($ret == 0) { echo "ExtraBackupFileUnzipNotOk"; } else { echo "ExtraBackupFileUnzipOk"; } var_dump($ret); /* * Function ///////////////////////////////////////////////////////////////////////////////////////////// */ function zip_packs() { $packs = array(); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.6.0.zip", "zip","dolibarr-3.6.0","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.6.6.zip", "zip","dolibarr-3.6.6","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.6.7.zip", "zip","dolibarr-3.6.7","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.7.0.zip", "zip","dolibarr-3.7.0","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.7.3.zip", "zip","dolibarr-3.7.3","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.7.4.zip", "zip","dolibarr-3.7.4","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.8.0.zip", "zip","dolibarr-3.8.0","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.8.3.zip", "zip","dolibarr-3.8.3","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.8.4.zip", "zip","dolibarr-3.8.4","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.8_backported.zip", "zip","dolibarr-3.8 Backported","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.9.0.zip", "zip","dolibarr-3.9.0","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.9.1.zip", "zip","dolibarr-3.9.1","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/3.9_backported.zip", "zip","dolibarr-3.9 Backported","GitHub Official"); $packs[] = array("https://github.com/Dolibarr/dolibarr/archive/develop.zip", "zip","dolibarr-develop Branche","GitHub Official"); return $packs; } function zip_info ($filename="mydolibarr.zip", $select_folder= 'htdocs'){ $zipfile = new PclZip( $filename ); if (($list = $zipfile->listContent()) == 0) { die("Error : ".$zipfile->errorInfo(true)); } else { foreach($list as $i => $value) { if (strpos($value['filename'], $select_folder) !== false ) { $zipfileremoveroot= substr ($value['filename'],0, strpos($value['filename'], "/".$select_folder)); //echo "remove=" . $zipfileremoveroot . " preg=".'#'.$zipfileremoveroot.'htdocs#'. " remove=".$zipfileremoveroot."htdocs"; break; } } } return $zipfileremoveroot; } function zip_upload($url='') { // open basedir restriction we move htdocs-packs folder in htdocs // $out = fopen("../htdocs-pack/mydolibarr.zip", 'wb'); // (w)rite mode (b)inary $out = fopen("mydolibarr.zip", 'wb'); // (w)rite mode (b)inary $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, false); // curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $contents = curl_exec_follow ($ch); if (curl_error($ch)!="") { $zip_upload_result = "Error during download / Erreur durant le telechargement: ".curl_error($ch); curl_close ($ch); exit(); } else { fwrite($out, $contents); fclose($out); curl_close ($ch); $zip_upload_result = "

Downloading Ok...

"; } return $zip_upload_result; } function zip_extract ($filename="mydolibarr.zip", $select_folder= 'htdocs', $extract_folder="../htdocs/") { $ret=array(); $ret['success']=0; //maybe add a chmod option 0604 instead 0705 $zipfile = new PclZip( $filename ); $iswindows = substr(PHP_OS, 0, 3) == 'WIN'; if($iswindows) { define('OS_WINDOWS',1); } else { define('OS_WINDOWS',0); } if (($list = $zipfile->listContent()) == 0) { die("Error : ".$zipfile->errorInfo(true)); } else { foreach($list as $i => $value) { if (strpos($value['filename'], $select_folder) !== false ) { $zipfileremoveroot= substr ($value['filename'],0, strpos($value['filename'], "/".$select_folder)); // echo "remove=" . $zipfileremoveroot . " preg=".'#'.$zipfileremoveroot.'htdocs#'. " remove=".$zipfileremoveroot."htdocs"; break; } } } $ret['success'] = $zipfile->extract( PCLZIP_OPT_PATH, $extract_folder, PCLZIP_OPT_BY_PREG, '#'.$select_folder.'#', PCLZIP_OPT_REMOVE_PATH, $zipfileremoveroot."/".$select_folder, PCLZIP_OPT_SET_CHMOD, 0644, PCLZIP_OPT_ADD_TEMP_FILE_ON ); $ret['error'] = $zipfile->error_string; return $ret; } //curl follow redirect even if open_basedir or safe_mode //http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/ //http://stackoverflow.com/questions/6918623/curlopt-followlocation-cannot-be-activated function curl_exec_follow($ch, &$maxredirect = null) { // we emulate a browser here since some websites detect // us as a bot and don't let us do our job $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)". " Gecko/20041107 Firefox/1.0"; curl_setopt($ch, CURLOPT_USERAGENT, $user_agent ); curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress'); curl_setopt($ch, CURLOPT_NOPROGRESS, false); // needed to make progress function work $mr = $maxredirect === null ? 5 : intval($maxredirect); // if (filter_var(ini_get(‘open_basedir’), FILTER_VALIDATE_BOOLEAN) === false // && filter_var(ini_get(‘safe_mode’), FILTER_VALIDATE_BOOLEAN) === false if (filter_var(ini_get('open_basedir'), FILTER_VALIDATE_BOOLEAN) === false && filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) === false ) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0); curl_setopt($ch, CURLOPT_MAXREDIRS, $mr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } else { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); if ($mr > 0) { $original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $newurl = $original_url; $rch = curl_copy_handle($ch); curl_setopt($rch, CURLOPT_HEADER, true); curl_setopt($rch, CURLOPT_NOBODY, true); curl_setopt($rch, CURLOPT_FORBID_REUSE, false); do { curl_setopt($rch, CURLOPT_URL, $newurl); $header = curl_exec($rch); if (curl_errno($rch)) { $code = 0; } else { $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/i', $header, $matches); $newurl = trim(array_pop($matches)); // if no scheme is present then the new url is a // relative path and thus needs some extra care if(!preg_match("/^https?:/i", $newurl)){ $newurl = $original_url . $newurl; } } else { $code = 0; } } } while ($code && --$mr); curl_close($rch); if (!$mr) { if ($maxredirect === null) trigger_error('Too many redirects.', E_USER_WARNING); else $maxredirect = 0; return false; } curl_setopt($ch, CURLOPT_URL, $newurl); } } return curl_exec($ch); } function progress($resource,$download_size, $downloaded, $upload_size, $uploaded) { if($download_size> 0) { $progress=round($downloaded / $download_size * 100, 1); echo ""; ob_flush(); flush(); ob_flush(); flush(); } }