diff --git a/VERSION b/VERSION index 8f0d2fbf..4083b86f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.0-67 +0.9.0-68 diff --git a/html/includes/api_labs.php b/html/includes/api_labs.php index 48cc34a0..92c4693c 100644 --- a/html/includes/api_labs.php +++ b/html/includes/api_labs.php @@ -243,7 +243,7 @@ function apiExportLabs($p) { // Using "element" relative to "path", adding '/' if missing $relement = substr($element, strlen($p['path'])); - if (!strcmp(substr($relement, 1), '/')) { + if ($relement[0] != '/') { $relement = '/'.$relement; } @@ -271,6 +271,20 @@ function apiExportLabs($p) { } } } + + // Now remove UUID from labs + $cmd = BASE_DIR.'/scripts/remove_uuid.sh "'.$export_file.'"'; + exec($cmd, $o, $rc); + if ($rc != 0) { + if (is_file($export_file)) { + unlink($export_file); + } + $output['code'] = 400; + $output['status'] = 'fail'; + $output['message'] = $GLOBALS['messages'][$rc]; + return $output; + } + $output['code'] = 200; $output['status'] = 'success'; $output['message'] = $GLOBALS['messages'][80075]; diff --git a/html/includes/messages_en.php b/html/includes/messages_en.php index 73b624c0..7bd9fd21 100644 --- a/html/includes/messages_en.php +++ b/html/includes/messages_en.php @@ -47,6 +47,7 @@ $messages[12] = 'Failed to start node (12).'; $messages[13] = 'Unable to wipe node(s) (13).'; $messages[14] = 'Cannot create username (14).'; +$messages[15] = 'Cannot remove UUID from exported labs (15).'; /*************************************************************************** * Classes diff --git a/scripts/build_deb_unetlab.sh b/scripts/build_deb_unetlab.sh index 36d1529a..230cd541 100755 --- a/scripts/build_deb_unetlab.sh +++ b/scripts/build_deb_unetlab.sh @@ -20,6 +20,7 @@ cat html/includes/init.php | sed "s/define('VERSION', .*/define('VERSION', '${VE cp -a scripts/set_uuid.php ${DATA_DIR}/opt/unetlab/scripts/ cp -a scripts/import_iou-web.php ${DATA_DIR}/opt/unetlab/scripts/ cp -a scripts/fix_iol_nvram.sh ${DATA_DIR}/opt/unetlab/scripts/ +cp -a scripts/remove_uuid.sh ${DATA_DIR}/opt/unetlab/scripts/ cp -a IOUtools/iou_export ${DATA_DIR}/opt/unetlab/scripts/ chown -R root:root ${DATA_DIR}/opt/unetlab chown -R www-data:www-data ${DATA_DIR}/opt/unetlab/data ${DATA_DIR}/opt/unetlab/labs diff --git a/scripts/remove_uuid.sh b/scripts/remove_uuid.sh new file mode 100755 index 00000000..8a9ee05d --- /dev/null +++ b/scripts/remove_uuid.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +if [ $# -ne 1 ]; then + echo 'ERROR: wrong options given.' + exit 15 +fi + +if [ ! -f ${1} ]; then + echo 'ERROR: file does not exist.' + exit 15 +fi + +TEMP=$(mktemp -d --suffix=_unetlab) +unzip -q -o -d ${TEMP} ${1} "*.unl" +if [ $? -ne 0 ]; then + rm -rf ${TEMP} + echo 'ERROR: cannot unzip file.' + exit 15 +fi + +find ${TEMP} -name "*.unl" -exec sed -i 's/ id="[0-9a-f-]\{36\}"//g' '{}' \; +if [ $? -ne 0 ]; then + rm -rf ${TEMP} + echo 'ERROR: cannot remove lab UUID.' + exit 15 +fi + +cd ${TEMP} + +zip -q -r -u ${1} * +if [ $? -ne 0 ]; then + rm -rf ${TEMP} + echo 'ERROR: cannot update files.' + exit 15 +fi + +exit 0