示例#1
0
function nc_widgetclass_import($import)
{
    global $db, $nc_core;
    $file = file_get_contents($import['tmp_name']);
    $xml = new SimpleXmlElement($file, LIBXML_NOCDATA);
    $widgetclass = array();
    $widgetclass['Name'] = (string) $xml->widgetclasses->widgetclass->Name;
    $widgetclass['Keyword'] = (string) $xml->widgetclasses->widgetclass->Keyword;
    $widgetclass['Description'] = (string) $xml->widgetclasses->widgetclass->Description;
    $widgetclass['Category'] = (string) $xml->widgetclasses->widgetclass->Category;
    $widgetclass['InDevelop'] = (string) $xml->widgetclasses->widgetclass->InDevelop;
    $widgetclass['Template'] = (string) $xml->widgetclasses->widgetclass->Template;
    $widgetclass['Settings'] = (string) $xml->widgetclasses->widgetclass->Settings;
    $widgetclass['AddForm'] = (string) $xml->widgetclasses->widgetclass->AddForm;
    $widgetclass['EditForm'] = (string) $xml->widgetclasses->widgetclass->EditForm;
    $widgetclass['WidgetDisallow'] = (string) $xml->widgetclasses->widgetclass->WidgetDisallow;
    $widgetclass['Update'] = (string) $xml->widgetclasses->widgetclass->Update;
    $widgetclass['File_Mode'] = (string) $xml->widgetclasses->widgetclass->File_Mode;
    if ($xml->widgetclasses->widgetclass->File_Mode) {
        $_REQUEST['fs'] = 1;
    }
    if (!$nc_core->NC_UNICODE) {
        $widgetclass = $nc_core->utf8->array_utf2win($widgetclass);
    }
    $id = $nc_core->widget->add_widgetclass($widgetclass, 1);
    if (!empty($xml->fields->field)) {
        $query = "INSERT INTO `Field` (`Field_Name`, `Description`, `Format`, `NotNull`, `Priority`, `DoSearch`, `DefaultState`, `Inheritance`, `Widget_Class_ID`, `TypeOfEdit_ID`, `TypeOfData_ID`) VALUES ";
        foreach ($xml->fields->field as $field) {
            $query_arr[] = "('" . (string) $field->Field_Name . "', '" . (string) $field->Description . "', '" . (string) $field->Format . "', " . (string) $field->NotNull . ", " . (string) $field->Priority . ", " . (string) $field->DoSearch . ", '" . (string) $field->DefaultState . "', " . (string) $field->Inheritance . ", " . $id . ", " . (string) $field->TypeOfEdit_ID . ", " . (string) $field->attributes()->type_of_data_id . ")";
        }
        $query .= implode(',', $query_arr);
        if (!$nc_core->NC_UNICODE) {
            $query = $nc_core->utf8->utf2win($query);
        }
        $db->query($query);
    }
    $tar = (string) $xml->tar_data;
    $ID = (string) $xml->widgetclasses->widgetclass->ID;
    if (isset($tar)) {
        include_once $nc_core->DOCUMENT_ROOT . $nc_core->ADMIN_PATH . "tar.inc.php";
        $tar_name = $nc_core->TMP_FOLDER . 'widget_import_' . $ID . '_temp.tgz';
        file_put_contents($tar_name, base64_decode(trim($tar)));
        nc_tgz_extract($tar_name, $nc_core->TMP_FOLDER);
        if (is_writable($nc_core->WIDGET_TEMPLATE_FOLDER . $id)) {
            if ($handle = opendir($nc_core->TMP_FOLDER . $ID)) {
                while (false !== ($entry = readdir($handle))) {
                    if ($entry != "." && $entry != "..") {
                        rename($nc_core->TMP_FOLDER . $ID . '/' . $entry, $nc_core->WIDGET_TEMPLATE_FOLDER . $id . '/' . $entry);
                    }
                }
                closedir($handle);
            }
            @rmdir($nc_core->TMP_FOLDER . $ID);
        } else {
            return false;
        }
        unlink($tar_name);
    }
    return $id;
}
示例#2
0
 public function tar_extract($file)
 {
     require_once nc_core('ADMIN_FOLDER') . 'tar.inc.php';
     $archive_path = trim(str_replace(nc_core('DOCUMENT_ROOT'), '', $file), '/');
     $tmp_path = dirname($archive_path) . '/' . uniqid();
     $abs_tmp_path = nc_core('DOCUMENT_ROOT') . '/' . $tmp_path;
     mkdir($abs_tmp_path);
     nc_tgz_extract($archive_path, $tmp_path);
     $files = scandir($abs_tmp_path);
     if (count($files) == 3) {
         $result_path = nc_core('DOCUMENT_ROOT') . '/' . dirname($archive_path) . '/' . $files[2] . '-' . uniqid();
         $this->move_files($abs_tmp_path . '/' . $files[2], $result_path);
         remove_dir($abs_tmp_path);
     } else {
         $result_path = $abs_tmp_path;
     }
     unlink($file);
     return $result_path;
 }
 protected function import_file()
 {
     require_once $this->nc_core->ADMIN_FOLDER . 'tar.inc.php';
     $file_nodes = $this->xpath->query("files/file");
     foreach ($file_nodes as $node) {
         $path = $node->getAttribute('path');
         $file = $node->getAttribute('file');
         $type = $node->getAttribute('type');
         $raw = base64_decode($node->nodeValue);
         $new_path = $this->before_extract($path, $file);
         $new_path = $new_path ? $new_path : $path;
         $full_path = $this->nc_core->DOCUMENT_ROOT . $new_path;
         $archive_name = md5(uniqid());
         $archive_file = $this->nc_core->TMP_FOLDER . $archive_name . '.tgz';
         file_put_contents($archive_file, $raw);
         nc_tgz_extract($archive_file, $this->nc_core->TMP_FOLDER);
         unlink($archive_file);
         $this->result['import_file'] = $this->move_files($this->nc_core->TMP_FOLDER . $file, $full_path);
         if (file_exists($this->nc_core->TMP_FOLDER . $file)) {
             remove_dir($this->nc_core->TMP_FOLDER . $file);
         }
         $this->after_extract($path, $file);
     }
 }
示例#4
0
文件: dump.inc.php 项目: Blu2z/implsk
function ReadBackUP($backupfile, $images, $netcat_files, $sqldump, $modules, $dump, $netcat_template)
{
    global $HTTP_TEMPLATE_PATH, $DOCUMENT_ROOT, $SUB_FOLDER, $HTTP_FILES_PATH, $HTTP_ROOT_PATH, $HTTP_IMAGES_PATH, $TMP_FOLDER;
    if (!checkPermissions($HTTP_ROOT_PATH . "tmp/", $DOCUMENT_ROOT)) {
        return $err = ".";
    }
    $err = 0;
    if (!$dump) {
        if ($err = decompressDumpTGZ1($backupfile)) {
            return $err;
        }
    } else {
        if ($err = decompressDumpTGZ2($backupfile)) {
            return $err;
        }
    }
    //Unpack images
    if ($images) {
        if (!checkPermissions($HTTP_IMAGES_PATH, $DOCUMENT_ROOT)) {
            return $err = ".";
        }
        if (!nc_tgz_extract($TMP_FOLDER . "images.tgz", $DOCUMENT_ROOT . $SUB_FOLDER)) {
            $err = "Error while images extracting";
        }
    }
    //Unpack netcat_files
    if ($netcat_files) {
        if (!checkPermissions($HTTP_FILES_PATH, $DOCUMENT_ROOT)) {
            return $err = ".";
        }
        if (!nc_tgz_extract($TMP_FOLDER . "netcat_files.tgz", $DOCUMENT_ROOT . $SUB_FOLDER)) {
            $err = "Error while netcat_files extracting";
        }
    }
    if ($netcat_template) {
        if (!checkPermissions($HTTP_TEMPLATE_PATH, $DOCUMENT_ROOT)) {
            return $err = ".";
        }
        if (!nc_tgz_extract($TMP_FOLDER . "netcat_template.tgz", $DOCUMENT_ROOT . $SUB_FOLDER)) {
            $err = "Error while netcat_template extracting";
        }
    }
    //Restore MySQL dump
    if ($sqldump) {
        if (!SQLFromFile($TMP_FOLDER . "netcat.sql")) {
            $err = "Error while MySQL dump extracting";
        }
    }
    //Unpack modules
    if ($modules) {
        if (!checkPermissions($HTTP_ROOT_PATH . "modules/", $DOCUMENT_ROOT)) {
            return $err = ".";
        }
        if (!nc_tgz_extract($TMP_FOLDER . "modules.tgz", $DOCUMENT_ROOT . $SUB_FOLDER)) {
            $err = "Error while modules extracting";
        }
    }
    DeleteFilesInDirectory($TMP_FOLDER);
    return $err;
}
示例#5
0
     break;
 }
 $patch_file_data = nc_activation_get_files();
 // get gzip file
 $patch_file_tgz = !empty($patch_file_data) ? $patch_file_data['_FILE'] : "";
 if (!$patch_file_tgz) {
     break;
 }
 if (!file_exists($TMP_FOLDER . $patch_file_tgz)) {
     break;
 }
 if (!checkPermissions($HTTP_ROOT_PATH . "tmp/", $DOCUMENT_ROOT)) {
     break;
 }
 // this temporary file will be deleted in the end of this function or in InstallationAborted()
 if (!nc_tgz_extract($TMP_FOLDER . $patch_file_tgz, $TMP_FOLDER) && !file_exists($TMP_FOLDER . "id.txt")) {
     InstallationAborted(TOOLS_PATCH_ERR_EXTRACT, 'activation');
 }
 // check files in patch
 if (!CheckDeps('patch')) {
     InstallationAborted(TOOLS_PATCH_INFO_NOTINSTALLED . ".<br>", 'activation');
 }
 // other version
 if ($VersionID != $VERSION_ID) {
     InstallationAborted(str_replace(array("%REQUIRE", "%EXIST"), array($VersionID, $VERSION_ID), TOOLS_PATCH_INVALIDVERSION), 'activation');
 }
 // other system
 if ($SystemID && $SystemID != $SYSTEM_ID) {
     list($required_sys_name, $required_sys_color) = nc_system_name_by_id($SystemID);
     list($installed_sys_name, $installed_sys_color) = nc_system_name_by_id($SYSTEM_ID);
     InstallationAborted(str_replace(array("%REQUIRE", "%EXIST"), array($required_sys_name, $installed_sys_name), TOOLS_PATCH_INVALIDVERSION) . "<br>", 'activation');
示例#6
0
文件: index.php 项目: Blu2z/implsk
 BeginHtml($Title2, $Title2, "http://" . $DOC_DOMAIN . "/settings/modules/");
 $perm->ExitIfNotAccess(NC_PERM_MODULE, 0, 0, 0, 1);
 if (!checkPermissions($HTTP_ROOT_PATH . "tmp/", $DOCUMENT_ROOT)) {
     break;
 }
 if (!checkPermissions($HTTP_ROOT_PATH . "modules/", $DOCUMENT_ROOT)) {
     break;
 }
 if (!$_FILES['FilePatch']['tmp_name']) {
     //nc_print_status(TOOLS_MODULES_ERR_NOTUPLOADED, 'error');
     InstallationAborted(TOOLS_MODULES_ERR_NOTUPLOADED, 'module');
 }
 $ModuleFile = tempnam($TMP_FOLDER, "module");
 move_uploaded_file($_FILES['FilePatch']['tmp_name'], $ModuleFile);
 // this temporary file will be deleted in the end of this function or in InstallationAborted()
 if (!nc_tgz_extract($ModuleFile, $TMP_FOLDER) && !file_exists($TMP_FOLDER . "id.txt")) {
     //print TOOLS_MODULES_ERR_EXTRACT;
     InstallationAborted(TOOLS_MODULES_ERR_EXTRACT, 'module');
 }
 $InstallFile = $TMP_FOLDER . "install.php";
 if (!is_readable($InstallFile)) {
     //nc_print_status(TOOLS_MODULES_ERR_CANTOPEN." install.php.", 'error');
     InstallationAborted(TOOLS_MODULES_ERR_CANTOPEN . " install.php.", 'module');
 } else {
     require $InstallFile;
 }
 if (!CheckDeps('module')) {
     InstallationAborted();
 }
 CheckFiles();
 if (!nc_version_control($VERSION_ID)) {
示例#7
0
function ParseClassFile($file)
{
    // system superior object
    $nc_core = nc_Core::get_object();
    include_once $nc_core->DOCUMENT_ROOT . $nc_core->ADMIN_PATH . "tar.inc.php";
    $db =& $nc_core->db;
    $db->captured_errors = array();
    $VersionNumber = $nc_core->get_settings("VersionNumber");
    $fs = $nc_core->input->fetch_get_post('fs');
    $insert_flag = "%INSERT_ID%";
    $xml2array = xml2array(file_get_contents($file));
    $xml_data = $xml2array['data'];
    // STEP 1: System version check
    $tpl_version = $xml_data['version'];
    if (!$tpl_version) {
        nc_print_status(CONTROL_CLASS_IMPORT_ERROR_NO_VERSION_ID, 'info');
        return false;
    }
    if (!nc_version_control($tpl_version)) {
        nc_print_status(sprintf(CONTROL_CLASS_IMPORT_ERROR_VERSION_ID, $tpl_version, $VersionNumber), 'info');
        return false;
    }
    if ($fs && !isset($xml_data['tar_data'])) {
        nc_print_status(CONTROL_CLASS_IMPORT_ERROR_NO_FILES, 'info');
        return false;
    }
    $path_for_file_mode = array();
    $sql_data = $xml_data['sql_data'];
    $class_query = $sql_data['class'];
    if (!$nc_core->NC_UNICODE) {
        $query = $nc_core->utf8->utf2win($class_query);
    }
    $res1 = $db->query($class_query);
    if ($res1) {
        $insert_id = $db->insert_id;
        $path_for_file_mode[$insert_id] = "/{$insert_id}/";
    } else {
        nc_print_status(CONTROL_CLASS_IMPORT_ERROR_CLASS_IMPORT, 'info');
        return false;
    }
    $new_tpl_ids = array();
    $xmlTemplates = $sql_data['templates']['template'];
    if (isset($xmlTemplates['value'])) {
        $templates[0] = $xmlTemplates;
    } else {
        $templates = $xmlTemplates;
    }
    if (!empty($templates)) {
        foreach ($templates as $query) {
            if (!$nc_core->NC_UNICODE) {
                $query = $nc_core->utf8->utf2win($query);
            }
            // replace ID
            $query = str_replace($insert_flag, $insert_id, $query);
            if (!$fs && strpos($query, '%CDATA_START%')) {
                $query = str_replace('%CDATA_START%', '<![CDATA[', $query);
                $query = str_replace('%CDATA_END%', ']]>', $query);
            }
            if (!$db->query($query)) {
                nc_print_status(CONTROL_CLASS_IMPORT_ERROR_CLASS_TEMPLATE_IMPORT, 'info');
                $db->query("DELETE FROM `Class` WHERE `Class_ID` = '" . $insert_id . "'");
                return false;
            }
            $path_for_file_mode[$db->insert_id] = "/{$insert_id}/{$db->insert_id}/";
            $new_tpl_ids[] = $db->insert_id;
        }
    }
    foreach ($path_for_file_mode as $id => $path) {
        $SQL = "UPDATE `Class` \n                    SET `File_Path` = '{$path}' \n                        WHERE `Class_ID` = {$id}";
        $db->query($SQL);
    }
    // STEP 5: create MessageXX table
    $create_message = $sql_data['message_tbl'];
    $create_message = str_replace($insert_flag, $insert_id, $create_message);
    $create_message = str_replace('%%MYSQL_CHARSET%%', $nc_core->MYSQL_CHARSET, $create_message);
    $res2 = $db->query($create_message);
    if ($res2 != 0) {
        nc_print_status(CONTROL_CLASS_IMPORT_ERROR_MESSAGE_TABLE, 'info');
        $db->query("DELETE FROM `Class` WHERE `Class_ID` = '" . $insert_id . "' OR `ClassTemplate` = '" . $insert_id . "'");
        return false;
    }
    $xmlFields = $sql_data['fields']['field'];
    if (!is_array($xmlFields)) {
        $xmlFields = (array) $xmlFields;
    }
    foreach ($xmlFields as $query) {
        if (!$nc_core->NC_UNICODE) {
            $query = $nc_core->utf8->utf2win($query);
        }
        $query = str_replace($insert_flag, $insert_id, $query);
        if ($query) {
            $res3 = $db->query($query);
            if ($db->captured_errors) {
                nc_print_status(CONTROL_CLASS_IMPORT_ERROR_FIELD, 'info');
                $db->query("DELETE FROM `Class` WHERE `Class_ID` = '" . $insert_id . "' OR `ClassTemplate` = '" . $insert_id . "'");
                $db->query("DROP TABLE `Message" . $insert_id . "`");
                $db->query("DELETE FROM `Field` WHERE `Class_ID` = '" . $insert_id . "'");
                return false;
            }
        }
    }
    if (isset($xml_data['tar_data'])) {
        $tar = $xml_data['tar_data'];
        $tar_name = $nc_core->TMP_FOLDER . 'import_class_' . $insert_id . '_' . mktime() . '.tgz';
        file_put_contents($tar_name, base64_decode(trim($tar)));
        nc_tgz_extract($tar_name, $nc_core->TMP_FOLDER);
        rename($nc_core->TMP_FOLDER . $xml_data['class_id'], $nc_core->TMP_FOLDER . $insert_id);
        $xmlTplIds = $xml_data['tpl_ids']['tpl_id'];
        if (!is_array($xmlTplIds)) {
            $xmlTplIds = (array) $xmlTplIds;
        }
        foreach ($xmlTplIds as $i => $tpl_id) {
            rename($nc_core->TMP_FOLDER . $insert_id . '/' . $tpl_id, $nc_core->TMP_FOLDER . $insert_id . '/' . $new_tpl_ids[$i]);
        }
        rename($nc_core->TMP_FOLDER . $insert_id, $nc_core->CLASS_TEMPLATE_FOLDER . $insert_id);
        unlink($tar_name);
    }
    return $insert_id;
}