This commit is contained in:
Paula Quispe
2019-12-16 13:04:14 -04:00
parent 6124bca002
commit 1a79c40d8e

View File

@@ -200,91 +200,83 @@ function newSkin ($baseSkin = 'classic')
function importSkin () function importSkin ()
{ {
try { try {
ValidationUploadedFiles::getValidationUploadedFiles()->dispatch(function($validator) { ValidationUploadedFiles::getValidationUploadedFiles()->dispatch(function ($validator) {
throw new Exception($validator->getMessage()); throw new Exception($validator->getMessage());
}); });
if (! isset( $_FILES['uploadedFile'] )) { if (!isset($_FILES['uploadedFile'])) {
throw (new Exception( G::LoadTranslation( 'ID_SKIN_FILE_REQUIRED' ) )); throw (new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')));
} }
$uploadedInstances = count( $_FILES['uploadedFile']['name'] );
$sw_error = false;
$sw_error_exists = isset( $_FILES['uploadedFile']['error'] );
$emptyInstances = 0;
$quequeUpload = array ();
// upload files & check for errors $sw_error_exists = isset($_FILES['uploadedFile']['error']);
// Upload files & check for errors
$tmp = $_FILES['uploadedFile']['tmp_name']; $tmp = $_FILES['uploadedFile']['tmp_name'];
$items = stripslashes( $_FILES['uploadedFile']['name'] ); $items = stripslashes($_FILES['uploadedFile']['name']);
if ($sw_error_exists) { if ($sw_error_exists) {
$up_err = $_FILES['uploadedFile']['error']; $up_err = $_FILES['uploadedFile']['error'];
} else { } else {
$up_err = (file_exists( $tmp ) ? 0 : 4); $up_err = (file_exists($tmp) ? 0 : 4);
} }
if ($items == "" || $up_err == 4) { if ($items == "" || $up_err == 4) {
throw (new Exception( G::LoadTranslation( 'ID_SKIN_FILE_REQUIRED' ) )); throw (new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')));
} }
if ($up_err == 1 || $up_err == 2) { if ($up_err == 1 || $up_err == 2) {
throw (new Exception( G::LoadTranslation( 'ID_FILE_TOO_BIG' ) )); throw (new Exception(G::LoadTranslation('ID_FILE_TOO_BIG')));
//$errors[$i]='miscfilesize';
} }
if ($up_err == 3) { if ($up_err == 3) {
throw (new Exception( G::LoadTranslation( 'ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR' ) )); throw (new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')));
//$errors[$i]='miscfilepart';
} }
if (! @is_uploaded_file( $tmp )) { if (!@is_uploaded_file($tmp)) {
throw (new Exception( G::LoadTranslation( 'ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR' ) )); throw (new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')));
//$errors[$i]='uploadfile';
} }
$fileInfo = pathinfo( $items ); $fileInfo = pathinfo($items);
$validType = array ('tar','gz' $validType = ['tar', 'gz'];
);
if (! in_array( $fileInfo['extension'], $validType )) { if (!in_array($fileInfo['extension'], $validType)) {
throw (new Exception( G::LoadTranslation( 'ID_FILE_UPLOAD_INCORRECT_EXTENSION' ) )); throw (new Exception(G::LoadTranslation('ID_FILE_UPLOAD_INCORRECT_EXTENSION')));
//$errors[$i]='wrongtype';
} }
$filename = $items; $filename = $items;
$tempPath = PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP; $tempPath = PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP;
G::verifyPath( $tempPath, true ); G::verifyPath($tempPath, true);
$tempName = $tmp; $tempName = $tmp;
G::uploadFile( $tempName, $tempPath, $filename ); G::uploadFile($tempName, $tempPath, $filename);
$tar = new Archive_Tar( $tempPath . $filename ); $tar = new Archive_Tar($tempPath . $filename);
$aFiles = $tar->listContent(); $aFiles = $tar->listContent();
$swConfigFile = false; $swConfigFile = false;
foreach ($aFiles as $key => $val) { foreach ($aFiles as $key => $val) {
if (basename( $val['filename'] ) == 'config.xml') { if (basename($val['filename']) == 'config.xml') {
$skinName = dirname( $val['filename'] ); $skinName = dirname($val['filename']);
$skinArray = explode( "/", $skinName ); $skinArray = explode("/", $skinName);
if (count( $skinArray ) == 1) { if (count($skinArray) == 1) {
$swConfigFile = true; $swConfigFile = true;
} }
} }
} }
if (! $swConfigFile) { if (!$swConfigFile) {
@unlink( PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename ); @unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename);
throw (new Exception( G::LoadTranslation( 'ID_SKIN_CONFIGURATION_MISSING' ) )); throw (new Exception(G::LoadTranslation('ID_SKIN_CONFIGURATION_MISSING')));
} }
if (is_dir( PATH_CUSTOM_SKINS . $skinName )) { if (is_dir(PATH_CUSTOM_SKINS . $skinName)) {
if ((isset( $_REQUEST['overwrite_files'] )) && ($_REQUEST['overwrite_files'] == 'on')) { if ((isset($_REQUEST['overwrite_files'])) && ($_REQUEST['overwrite_files'] == 'on')) {
G::rm_dir( PATH_CUSTOM_SKINS . $skinName, false ); G::rm_dir(PATH_CUSTOM_SKINS . $skinName, false);
} else { } else {
throw (new Exception( G::LoadTranslation( 'ID_SKIN_ALREADY_EXISTS' ) )); throw (new Exception(G::LoadTranslation('ID_SKIN_ALREADY_EXISTS')));
} }
} }
$res = $tar->extract( PATH_CUSTOM_SKINS ); $res = $tar->extract(PATH_CUSTOM_SKINS);
if (! $res) { if (!$res) {
throw (new Exception( G::LoadTranslation( 'ID_SKIN_ERROR_EXTRACTING' ) )); throw (new Exception(G::LoadTranslation('ID_SKIN_ERROR_EXTRACTING')));
} }
$configFileOriginal = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml'; $configFileOriginal = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml';
$configFileFinal = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml'; $configFileFinal = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml';
$xmlConfiguration = file_get_contents( $configFileOriginal ); $xmlConfiguration = file_get_contents($configFileOriginal);
$workspace = ($_REQUEST['workspace'] == 'global') ? '' : config("system.workspace"); $workspace = ($_REQUEST['workspace'] == 'global') ? '' : config("system.workspace");
@@ -292,27 +284,27 @@ function importSkin ()
$skinInformationArray = $xmlConfigurationObj->result["skinConfiguration"]["__CONTENT__"]["information"]["__CONTENT__"]; $skinInformationArray = $xmlConfigurationObj->result["skinConfiguration"]["__CONTENT__"]["information"]["__CONTENT__"];
if (isset($skinInformationArray["workspace"]["__VALUE__"])) { if (isset($skinInformationArray["workspace"]["__VALUE__"])) {
$workspace = ($workspace != "" && !empty($skinInformationArray["workspace"]["__VALUE__"]))? $skinInformationArray["workspace"]["__VALUE__"] . "|" . $workspace : $workspace; $workspace = ($workspace != "" && !empty($skinInformationArray["workspace"]["__VALUE__"])) ? $skinInformationArray["workspace"]["__VALUE__"] . "|" . $workspace : $workspace;
$xmlConfiguration = preg_replace("/(<workspace>)(.*)(<\/workspace>)/i", "<workspace>" . $workspace . "</workspace><!-- $2 -->", $xmlConfiguration); $xmlConfiguration = preg_replace("/(<workspace>)(.*)(<\/workspace>)/i", "<workspace>" . $workspace . "</workspace><!-- $2 -->", $xmlConfiguration);
} else { } else {
$xmlConfiguration = preg_replace("/(<name>)(.*)(<\/name>)/i", "<name>" . $skinName . "</name><!-- $2 -->\n<workspace>" . $workspace . "</workspace>", $xmlConfiguration); $xmlConfiguration = preg_replace("/(<name>)(.*)(<\/name>)/i", "<name>" . $skinName . "</name><!-- $2 -->\n<workspace>" . $workspace . "</workspace>", $xmlConfiguration);
} }
file_put_contents( $configFileFinal, $xmlConfiguration ); file_put_contents($configFileFinal, $xmlConfiguration);
//Delete Temporal // Delete Temporal
@unlink( PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename ); @unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename);
$response['success'] = true; $response['success'] = true;
$response['message'] = G::LoadTranslation( 'ID_SKIN_SUCCESSFUL_IMPORTED' ); $response['message'] = G::LoadTranslation('ID_SKIN_SUCCESSFUL_IMPORTED');
G::auditLog("ImportSkin", "Skin Name: ".$skinName); G::auditLog("ImportSkin", "Skin Name: " . $skinName);
G::outRes( G::json_encode( $response ) ); G::outRes(G::json_encode($response));
} catch (Exception $e) { } catch (Exception $e) {
$response['success'] = false; $response['success'] = false;
$response['message'] = $e->getMessage(); $response['message'] = $e->getMessage();
$response['error'] = $e->getMessage(); $response['error'] = $e->getMessage();
G::outRes( G::json_encode( $response ) ); G::outRes(G::json_encode($response));
} }
} }