コード例 #1
0
 public function verify_file_contents()
 {
     $uzd = $this->importertransport->get('tempdir') . 'extract/';
     $includedfiles = get_dir_contents($uzd);
     $okfiles = array();
     $badfiles = array();
     // check what arrived in the directory
     foreach ($includedfiles as $k => $f) {
         // @todo penny later we might need this
         if (is_dir($f)) {
             $badfiles[] = $f;
             unset($includedfiles[$k]);
             continue;
         }
         if (get_config('viruschecking')) {
             $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
             if ($pathtoclam && file_exists($pathtoclam) && is_executable($pathtoclam)) {
                 if ($errormsg = mahara_clam_scan_file($uzd . $f)) {
                     throw new ImportException($this, $errormsg);
                 }
             } else {
                 clam_mail_admins(get_string('clamlost', 'mahara', $pathtoclam));
             }
         }
         $sha1 = sha1_file($uzd . $f);
         if (array_key_exists($sha1, $this->manifest)) {
             $tmp = new StdClass();
             $tmp->sha1 = $sha1;
             $tmp->wantsfilename = $this->manifest[$sha1]['filename'];
             $tmp->actualfilename = $f;
             $okfiles[] = $tmp;
             unset($includedfiles[$k]);
             continue;
         }
         $badfiles[] = $f;
         unset($includedfiles[$k]);
     }
     $ok_c = count($okfiles);
     $bad_c = count($badfiles);
     $man_c = count($this->manifest);
     if ($ok_c != $man_c) {
         throw new ImportException($this, 'Files receieved did not exactly match what was in the manifest');
         // @todo penny later - better reporting (missing files, too many files, etc)
     }
     $this->files = $okfiles;
 }
コード例 #2
0
ファイル: import.php プロジェクト: patkira/mahara
function importskinform_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    require_once get_config('docroot') . 'artefact/file/lib.php';
    // Open XML file and import Skin(s)...
    $filename = $values['file']['tmp_name'];
    $contents = file_get_contents($filename);
    $xmldoc = new DOMDocument('1.0', 'UTF-8');
    //$xmldoc->load($filename);
    $xmldoc->loadXML($contents);
    $skinsdata = $xmldoc->getElementsByTagName('skin');
    $siteskin = $values['skintype'] == 'site';
    // A non-admin can't create a site skin.
    if ($siteskin && !$USER->get('admin')) {
        $values['skintype'] = 'private';
        $siteskin = false;
    }
    foreach ($skinsdata as $skindata) {
        db_begin();
        // Join all view skin css/formating data to array...
        $skin = array();
        // Body element...
        $items = $skindata->getElementsByTagName('body');
        foreach ($items as $item) {
            $skin = array_merge($skin, array('body_background_color' => $item->getAttribute('background-color')));
            $skin = array_merge($skin, array('body_background_image' => 0));
            $skin = array_merge($skin, array('body_background_repeat' => Skin::background_repeat_value_to_number($item->getAttribute('background-repeat'))));
            $skin = array_merge($skin, array('body_background_attachment' => $item->getAttribute('background-attachment')));
            $skin = array_merge($skin, array('body_background_position' => Skin::background_position_value_to_number($item->getAttribute('background-position'))));
        }
        // Header element...
        $items = $skindata->getElementsByTagName('header');
        foreach ($items as $item) {
            $skin = array_merge($skin, array('header_background_color' => $item->getAttribute('background-color')));
            $skin = array_merge($skin, array('header_text_font_color' => $item->getAttribute('font-color')));
            $skin = array_merge($skin, array('header_link_normal_color' => $item->getAttribute('normal-color')));
            if ($item->getAttribute('normal-decoration') == 'none') {
                $skin = array_merge($skin, array('header_link_normal_underline' => 0));
            } else {
                $skin = array_merge($skin, array('header_link_normal_underline' => 1));
            }
            $skin = array_merge($skin, array('header_link_hover_color' => $item->getAttribute('hover-color')));
            if ($item->getAttribute('hover-decoration') == 'none') {
                $skin = array_merge($skin, array('header_link_hover_underline' => 0));
            } else {
                $skin = array_merge($skin, array('header_link_hover_underline' => 1));
            }
            $skin = array_merge($skin, array('header_logo_image' => $item->getAttribute('logo-image')));
        }
        // View element...
        $items = $skindata->getElementsByTagName('view');
        foreach ($items as $item) {
            $skin = array_merge($skin, array('view_background_color' => $item->getAttribute('background-color')));
            $skin = array_merge($skin, array('view_background_image' => 0));
            $skin = array_merge($skin, array('view_background_repeat' => Skin::background_repeat_value_to_number($item->getAttribute('background-repeat'))));
            $skin = array_merge($skin, array('view_background_attachment' => $item->getAttribute('background-attachment')));
            $skin = array_merge($skin, array('view_background_position' => Skin::background_position_value_to_number($item->getAttribute('background-position'))));
            $skin = array_merge($skin, array('view_background_width' => str_replace("%", "", $item->getAttribute('width'))));
            // odstrani znak %!
            $skin = array_merge($skin, array('view_background_margin' => $item->getAttribute('margin-top')));
        }
        // Text element...
        $items = $skindata->getElementsByTagName('text');
        foreach ($items as $item) {
            $skin = array_merge($skin, array('view_text_font_family' => $item->getAttribute('text-font')));
            $skin = array_merge($skin, array('view_heading_font_family' => $item->getAttribute('heading-font')));
            $skin = array_merge($skin, array('view_text_font_size' => $item->getAttribute('font-size')));
            $skin = array_merge($skin, array('view_text_font_color' => $item->getAttribute('font-color')));
            $skin = array_merge($skin, array('view_text_heading_color' => $item->getAttribute('heading-color')));
            $skin = array_merge($skin, array('view_text_emphasized_color' => $item->getAttribute('emphasized-color')));
        }
        // Link element...
        $items = $skindata->getElementsByTagName('link');
        foreach ($items as $item) {
            $skin = array_merge($skin, array('view_link_normal_color' => $item->getAttribute('normal-color')));
            if ($item->getAttribute('normal-decoration') == 'none') {
                $skin = array_merge($skin, array('view_link_normal_underline' => 0));
            } else {
                $skin = array_merge($skin, array('view_link_normal_underline' => 1));
            }
            $skin = array_merge($skin, array('view_link_hover_color' => $item->getAttribute('hover-color')));
            if ($item->getAttribute('hover-decoration') == 'none') {
                $skin = array_merge($skin, array('view_link_hover_underline' => 0));
            } else {
                $skin = array_merge($skin, array('view_link_hover_underline' => 1));
            }
        }
        // Table element...
        $items = $skindata->getElementsByTagName('table');
        foreach ($items as $item) {
            $skin = array_merge($skin, array('view_table_border_color' => $item->getAttribute('border-color')));
            $skin = array_merge($skin, array('view_table_odd_row_color' => $item->getAttribute('odd-row-color')));
            $skin = array_merge($skin, array('view_table_even_row_color' => $item->getAttribute('even-row-color')));
        }
        // Custom CSS element...
        $items = $skindata->getElementsByTagName('customcss');
        foreach ($items as $item) {
            $skin['view_custom_css'] = clean_css(unserialize($item->getAttribute('contents')), $preserve_css = true);
        }
        // Image element...
        // TODO: Background image file support for site skins
        if ($siteskin) {
            $skin['body_background_image'] = 0;
            $skin['view_background_image'] = 0;
        } else {
            $items = $skindata->getElementsByTagName('image');
            foreach ($items as $item) {
                // Write necessary data in 'artefact' table...
                // TODO: When we rework the file upload code to make it more general,
                // rewrite this to reuse content from filebrowser.php
                $now = date("Y-m-d H:i:s");
                $artefact = (object) array_merge((array) unserialize($item->getAttribute('artefact')), (array) unserialize($item->getAttribute('artefact_file_files')), (array) unserialize($item->getAttribute('artefact_file_image')));
                unset($artefact->id);
                unset($artefact->fileid);
                $artefact->owner = $USER->get('id');
                $artefact->author = $USER->get('id');
                $artefact->atime = $now;
                $artefact->ctime = $now;
                $artefact->mtime = $now;
                $artobj = new ArtefactTypeImage(0, $artefact);
                $artobj->commit();
                $id = $artobj->get('id');
                // Create folder and file inside it. then write contents into it...
                $imagedir = get_config('dataroot') . ArtefactTypeFile::get_file_directory($id);
                if (!check_dir_exists($imagedir, true, true)) {
                    throw new SystemException("Unable to create folder {$imagedir}");
                } else {
                    // Write contents to a file...
                    $imagepath = $imagedir . '/' . $id;
                    $contents = base64_decode($item->getAttribute('contents'));
                    $fp = fopen($imagepath, 'w');
                    fwrite($fp, $contents);
                    fclose($fp);
                    // We can keep going, but the skin will be missing one of its files
                    if ($clamerror = mahara_clam_scan_file($imagepath)) {
                        $SESSION->add_error_msg($clamerror);
                    }
                    chmod($imagepath, get_config('filepermissions'));
                }
                $type = $item->getAttribute('type');
                if ($type == 'body-background-image') {
                    $skin['body_background_image'] = $id;
                }
                if ($type == 'view-background-image') {
                    $skin['view_background_image'] = $id;
                }
            }
        }
        $viewskin = array();
        if ($skindata->getAttribute('title') != '') {
            $viewskin['title'] = $skindata->getAttribute('title');
        }
        $viewskin['description'] = $skindata->getAttribute('description');
        $viewskin['owner'] = $USER->get('id');
        $viewskin['type'] = $values['skintype'];
        $viewskin['viewskin'] = $skin;
        // Fonts element...
        // Only admins can install site fonts
        if ($USER->get('admin')) {
            $fonts = $skindata->getElementsByTagName('font');
            foreach ($fonts as $font) {
                $fontname = preg_replace("#[^A-Za-z0-9]#", "", $font->getAttribute('name'));
                $fontname = Skin::new_font_name($fontname);
                // Only upload font if it doesn't already exist on the site
                if (!Skin::font_exists($font->getAttribute('title'))) {
                    $fontdata = array('name' => $fontname, 'title' => $font->getAttribute('title'), 'licence' => $font->getAttribute('font-licence'), 'previewfont' => $font->getAttribute('font-preview'), 'variants' => base64_decode($font->getAttribute('font-variants')), 'fonttype' => $font->getAttribute('font-type'), 'onlyheading' => $font->getAttribute('heading-font-only'), 'fontstack' => $font->getAttribute('font-stack'), 'genericfont' => $font->getAttribute('generic-font'));
                    insert_record('skin_fonts', $fontdata);
                    $fontpath = get_config('dataroot') . 'skins/fonts/' . $fontdata['name'] . '/';
                    if (!check_dir_exists($fontpath, true, true)) {
                        throw new SystemException("Unable to create folder {$fontpath}");
                    } else {
                        $files = $font->getElementsByTagName('file');
                        foreach ($files as $file) {
                            // Read the filename and the contents of each file from XML...
                            $filename = $file->getAttribute('name');
                            $contents = base64_decode($file->getAttribute('contents'));
                            // Import and copy each file to the appropriate folder...
                            $fp = fopen($fontpath . $filename, 'wb');
                            fwrite($fp, $contents);
                            fclose($fp);
                            // We can keep going, but the skin will be missing one of its files
                            if ($clamerror = mahara_clam_scan_file($fontpath . $filename)) {
                                $SESSION->add_error_msg($clamerror);
                            }
                            chmod($fontpath . $filename, get_config('filepermissions'));
                        }
                    }
                }
            }
        }
        Skin::create($viewskin);
        db_commit();
    }
    $SESSION->add_ok_msg(get_string('skinimported', 'skin'));
    if ($values['skintype'] == 'site') {
        redirect('/admin/site/skins.php');
    } else {
        redirect('/skin/index.php');
    }
}
コード例 #3
0
 /**
  * Gets file information out of $_FILES and stores it locally in $files.
  * Checks file against max upload file size.
  * Scans file for viruses.
  * @return false for no errors, or a string describing the error
  */
 public function preprocess_file()
 {
     $name = $this->inputname;
     if (!isset($_FILES[$name])) {
         if ($this->optional) {
             $this->optionalandnotsupplied = true;
             return false;
         } else {
             return get_string('noinputnamesupplied');
         }
     }
     $file = $_FILES[$name];
     $maxsize = get_config('maxuploadsize');
     if (isset($this->inputindex)) {
         $size = $file['size'][$this->inputindex];
         $error = $file['error'][$this->inputindex];
         $tmpname = $file['tmp_name'][$this->inputindex];
     } else {
         $size = $file['size'];
         $error = $file['error'];
         $tmpname = $file['tmp_name'];
     }
     if ($maxsize && $size > $maxsize) {
         return get_string('uploadedfiletoobig');
     }
     if ($error != UPLOAD_ERR_OK) {
         $errormsg = get_string('phpuploaderror', 'mahara', get_string('phpuploaderror_' . $error), $error);
         if ($error == UPLOAD_ERR_NO_TMP_DIR || $error == UPLOAD_ERR_CANT_WRITE) {
             // The admin probably needs to fix this; notify them
             // @TODO: Create a new activity type for general admin messages.
             $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminphpuploaderror'), 'message' => $errormsg);
             require_once 'activity.php';
             activity_occurred('maharamessage', $message);
         } else {
             if ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE) {
                 return get_string('uploadedfiletoobig');
             }
         }
     }
     if (!is_uploaded_file($tmpname)) {
         if ($this->optional) {
             $this->optionalandnotsupplied = true;
             return false;
         } else {
             return get_string('notphpuploadedfile');
         }
     }
     if (get_config('viruschecking')) {
         $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
         if ($pathtoclam && file_exists($pathtoclam) && is_executable($pathtoclam)) {
             if ($errormsg = mahara_clam_scan_file($file, $this->inputindex)) {
                 return $errormsg;
             }
         } else {
             clam_mail_admins(get_string('clamlost', 'mahara', $pathtoclam));
         }
     }
     $this->file = $file;
     return false;
 }
コード例 #4
0
ファイル: uploadmanager.php プロジェクト: Br3nda/mahara
 /** 
  * Gets file information out of $_FILES and stores it locally in $files.
  * Checks file against max upload file size.
  * Scans file for viruses.
  * @return false for no errors, or a string describing the error
  */
 function preprocess_file()
 {
     $name = $this->inputname;
     if (!isset($_FILES[$name])) {
         return get_string('noinputnamesupplied');
     }
     $file = $_FILES[$name];
     $maxsize = get_config('maxuploadsize');
     if ($maxsize && $file['size'] > $maxsize) {
         return get_string('uploadedfiletoobig');
     }
     if ($file['error'] != UPLOAD_ERR_OK) {
         $errormsg = get_string('phpuploaderror', 'mahara', get_string('phpuploaderror_' . $file['error']), $file['error']);
         log_debug($errormsg);
         if ($file['error'] == UPLOAD_ERR_NO_TMP_DIR || $file['error'] == UPLOAD_ERR_CANT_WRITE) {
             // The admin probably needs to fix this; notify them
             // @TODO: Create a new activity type for general admin messages.
             $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminphpuploaderror'), 'message' => $errormsg);
             require_once 'activity.php';
             activity_occurred('maharamessage', $message);
         } else {
             if ($file['error'] == UPLOAD_ERR_INI_SIZE || $file['error'] == UPLOAD_ERR_FORM_SIZE) {
                 return get_string('uploadedfiletoobig');
             }
         }
     }
     if (!is_uploaded_file($file['tmp_name'])) {
         return get_string('notphpuploadedfile');
     }
     if (get_config('viruschecking') && ($errormsg = mahara_clam_scan_file($file))) {
         return $errormsg;
     }
     $this->file = $file;
     return false;
 }