Exemple #1
0
 /**
  * Constructor - create temporary directories and build paths to
  * external 'helper' binaries.
  * Other platforms could/should be added
  */
 function latex()
 {
     global $CFG;
     // construct directory structure
     $this->temp_dir = $CFG->dataroot . "/temp/latex";
     make_upload_directory('temp/latex');
 }
function webquest_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    $status = true;
    global $CFG;
    if ($oldversion < 2007081222) {
        require_once $CFG->dirroot . '/backup/lib.php';
        //make the change into each course
        $courses = get_records("course");
        foreach ($courses as $course) {
            $newdir = "{$course->id}/{$CFG->moddata}/webquest";
            if (make_upload_directory($newdir)) {
                $olddir = "{$CFG->dataroot}/{$course->id}/{$CFG->moddata}/webquest/submissions";
                //chec k if the old directory exists
                if (is_dir($olddir)) {
                    $status = backup_copy_file($olddir, $CFG->dataroot . "/" . $newdir);
                }
                if ($status) {
                    fulldelete($olddir);
                }
            }
        }
    }
    return $status;
}
Exemple #3
0
 function close()
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     $dir = 'temp/ods/' . time();
     make_upload_directory($dir);
     make_upload_directory($dir . '/META-INF');
     $dir = "{$CFG->dataroot}/{$dir}";
     $files = array();
     $handle = fopen("{$dir}/mimetype", 'w');
     fwrite($handle, get_ods_mimetype());
     $files[] = "{$dir}/mimetype";
     $handle = fopen("{$dir}/content.xml", 'w');
     fwrite($handle, get_ods_content($this->worksheets));
     $files[] = "{$dir}/content.xml";
     $handle = fopen("{$dir}/meta.xml", 'w');
     fwrite($handle, get_ods_meta());
     $files[] = "{$dir}/meta.xml";
     $handle = fopen("{$dir}/styles.xml", 'w');
     fwrite($handle, get_ods_styles());
     $files[] = "{$dir}/styles.xml";
     $handle = fopen("{$dir}/META-INF/manifest.xml", 'w');
     fwrite($handle, get_ods_manifest());
     $files[] = "{$dir}/META-INF";
     $filename = "{$dir}/result.ods";
     zip_files($files, $filename);
     $handle = fopen($filename, 'rb');
     $contents = fread($handle, filesize($filename));
     fclose($handle);
     remove_dir($dir);
     // cleanup the temp directory
     send_file($contents, $this->filename, 0, 0, true, true, 'application/vnd.oasis.opendocument.spreadsheet');
 }
Exemple #4
0
 public function __construct()
 {
     global $CFG;
     make_upload_directory('upgradelogs');
     $date = date('Ymd-His');
     $this->handle = fopen($CFG->dataroot . '/upgradelogs/qe_' . $date . '.html', 'a');
     fwrite($this->handle, '<html><head><title>Question engine upgrade assumptions ' . $date . '</title></head><body><h2>Question engine upgrade assumptions ' . $date . "</h2>\n\n");
 }
Exemple #5
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     make_temp_directory('');
     make_upload_directory('lang');
     $this->info = array();
     $this->errors = array();
     $this->installer = new \lang_installer();
     $this->availablelangs = $this->installer->get_remote_list_of_languages();
 }
Exemple #6
0
/**
 * As we implement the singleton pattern to use this class (only one instance
 * is shared globally), we need this helper function
 *
 * IMPORTANT Note: Typo3 libraries always expect lowercase charsets to use 100%
 * its capabilities so, don't forget to make the conversion
 * from every wrapper function!
 *
 * @return textlib singleton instance of textlib
 */
function textlib_get_instance()
{
    global $CFG;
    static $instance = null;
    if (!$instance) {
        /// initialisation is delayed because we do not want this on each page ;-)
        /// Required files
        require_once $CFG->libdir . '/typo3/class.t3lib_cs.php';
        require_once $CFG->libdir . '/typo3/class.t3lib_div.php';
        /// If ICONV is available, lets Typo3 library use it for convert
        if (extension_loaded('iconv')) {
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv';
            /// Else if mbstring is available, lets Typo3 library use it
        } else {
            if (extension_loaded('mbstring')) {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'mbstring';
                /// Else if recode is available, lets Typo3 library use it
            } else {
                if (extension_loaded('recode')) {
                    $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'recode';
                } else {
                    $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = '';
                }
            }
        }
        /// If mbstring is available, lets Typo3 library use it for functions
        if (extension_loaded('mbstring')) {
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring';
        } else {
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = '';
        }
        /// Tell Typo3 we are curl enabled always (mandatory since 2.0)
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] = '1';
        /// And this directory must exist to allow Typo to cache conversion
        /// tables when using internal functions
        make_upload_directory('temp/typo3temp/cs');
        /// Make sure typo is using our dir permissions
        $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = decoct($CFG->directorypermissions);
        /// Default mask for Typo
        $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = $CFG->directorypermissions;
        /// This full path constants must be defined too, transforming backslashes
        /// to forward slashed beacuse Typo3 requires it.
        define('PATH_t3lib', str_replace('\\', '/', $CFG->libdir . '/typo3/'));
        define('PATH_typo3', str_replace('\\', '/', $CFG->libdir . '/typo3/'));
        define('PATH_site', str_replace('\\', '/', $CFG->dataroot . '/temp/'));
        define('TYPO3_OS', stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin') ? 'WIN' : '');
        $instance = new textlib();
    }
    return $instance;
}
Exemple #7
0
 /**
  * Constructs one Moodle Workbook.
  *
  * @global object
  * @param string $filename The name of the file
  */
 function MoodleExcelWorkbook($filename) {
     global $CFG;
 /// Internally, create one PEAR Spreadsheet_Excel_Writer_Workbook class
     $this->pear_excel_workbook = new Spreadsheet_Excel_Writer($filename);
 /// Prepare it to accept UTF-16LE data and to encode it properly
     if (empty($CFG->latinexcelexport)) { /// Only if don't want to use latin (win1252) stronger output
         $this->pear_excel_workbook->setVersion(8);
         $this->latin_output = false;
     } else { /// We want latin (win1252) output
         $this->latin_output = true;
     }
 /// Choose our temporary directory - see MDL-7176, found by paulo.matos
     make_upload_directory('temp/excel');
     $this->pear_excel_workbook->setTempDir($CFG->dataroot.'/temp/excel');
 }
/**
 * gets a list of all the media files for the given course
 *
 * @param int courseid
 * @return array containing filenames
 * @calledfrom type/<typename>/editquestion.php 
 * @package questionbank
 * @subpackage importexport
 */
function get_course_media_files($courseid)
{
    // this code lifted from mod/quiz/question.php and modified
    global $CFG;
    $images = null;
    make_upload_directory("{$course->id}");
    // Just in case
    $coursefiles = get_directory_list("{$CFG->dataroot}/{$courseid}", $CFG->moddata);
    foreach ($coursefiles as $filename) {
        if (is_media_by_extension($filename)) {
            $images["{$filename}"] = $filename;
        }
    }
    return $images;
}
function moodle_binary_get_path($id, $meta, $course, $wiki, $userid, $groupid)
{
    global $CFG;
    $entry = wiki_get_entry($wiki, $course, $userid, $groupid);
    if (!$entry) {
        print_error('cannotgetentry', 'wiki');
    }
    $dir = make_upload_directory("{$course->id}/{$CFG->moddata}/wiki/{$wiki->id}/{$entry->id}/" . $meta["section"]);
    if (substr($id, 0, strlen(EWIKI_IDF_INTERNAL)) != EWIKI_IDF_INTERNAL) {
        print_error('cannotstartwith', 'wiki', '', EWIKI_IDF_INTERNAL . substr($id, 0, strlen(EWIKI_IDF_INTERNAL)));
    }
    $id = substr($id, strlen(EWIKI_IDF_INTERNAL));
    $id = clean_filename($id);
    return "{$dir}/{$id}";
}
function imagegallery_process_zip_file($file)
{
    global $CFG, $USER, $gallery;
    $tmpdir = random_string(6);
    $fullpath = make_upload_directory($tmpdir);
    $origpath = dirname($file->path);
    if (!unzip_file($file->path, $fullpath)) {
        error(get_string("unzipfileserror", "error"));
    }
    $images = imagegallery_search_images($fullpath);
    if (!empty($images)) {
        foreach ($images as $image) {
            $newpath = $origpath . '/' . basename($image);
            // If file already exists, just skip it.
            if (@file_exists($newpath)) {
                continue;
            }
            $fileinfo = getimagesize($image);
            if (!rename($image, $newpath)) {
                error("Could not move file to new location!");
            }
            $newfile = new stdClass();
            $newfile->galleryid = $file->galleryid;
            $newfile->categoryid = $file->categoryid;
            $newfile->userid = $USER->id;
            $newfile->name = basename($image);
            $newfile->path = $newpath;
            $newfile->size = filesize($newpath);
            $newfile->mime = mimeinfo('type', basename($image));
            $newfile->width = $fileinfo[0];
            $newfile->height = $fileinfo[1];
            $newfile->timecreated = time();
            $newfile->timemodified = time();
            // Check dimensions.
            $gallery->check_dimensions($newfile);
            $newfile->path = $gallery->get_file_path($newpath);
            if (!insert_record("imagegallery_images", $newfile)) {
                @unlink($newpath);
                error("Could not add new file {$file->name} to database!", "{$CFG->wwwroot}/mod/imagegallery/view.php?id={$gallery->cm->id}");
            }
            // Make thumbnail.
            $thumb = $origpath . '/thumb_' . $newfile->name;
            $gallery->make_thumbnail($newpath, $thumb);
        }
    }
    fulldelete($fullpath);
    @unlink($file->path);
}
 /**
  * Helper that sets up the maxima configuration. This allows maxima to be used
  * from test classes that cannot subclass this one, for whatever reason.
  */
 public static function setup_test_maxima_connection()
 {
     global $CFG;
     if (!self::is_test_config_available()) {
         throw new coding_exception('The calling code should call setup_test_maxima_connection ' . 'and skip the test in an appropriate way if it returns false.');
     }
     if (!defined('QTYPE_STACK_EXPECTED_VERSION')) {
         if (!preg_match('~\\[ STACK-Maxima started, library version (\\d{10}) \\]~', file_get_contents($CFG->dirroot . '/question/type/stack/stack/maxima/stackmaxima.mac'), $matches)) {
             throw new coding_exception('Maxima libraries version number not found in stackmaxima.mac.');
         }
         define('QTYPE_STACK_EXPECTED_VERSION', $matches[1]);
     }
     set_config('platform', QTYPE_STACK_TEST_CONFIG_PLATFORM, 'qtype_stack');
     set_config('maximaversion', QTYPE_STACK_TEST_CONFIG_MAXIMAVERSION, 'qtype_stack');
     set_config('castimeout', QTYPE_STACK_TEST_CONFIG_CASTIMEOUT, 'qtype_stack');
     set_config('casresultscache', QTYPE_STACK_TEST_CONFIG_CASRESULTSCACHE, 'qtype_stack');
     set_config('maximacommand', QTYPE_STACK_TEST_CONFIG_MAXIMACOMMAND, 'qtype_stack');
     set_config('plotcommand', QTYPE_STACK_TEST_CONFIG_PLOTCOMMAND, 'qtype_stack');
     set_config('casdebugging', QTYPE_STACK_TEST_CONFIG_CASDEBUGGING, 'qtype_stack');
     set_config('mathsdisplay', 'mathjax', 'qtype_stack');
     set_config('replacedollars', 0, 'qtype_stack');
     set_config('stackmaximaversion', QTYPE_STACK_EXPECTED_VERSION, 'qtype_stack');
     if (QTYPE_STACK_TEST_CONFIG_CASRESULTSCACHE == 'otherdb') {
         set_config('cascachedbtype', QTYPE_STACK_TEST_CONFIG_CASCACHEDBTYPE, 'qtype_stack');
         set_config('cascachedblibrary', QTYPE_STACK_TEST_CONFIG_CASCACHEDBLIBRARY, 'qtype_stack');
         set_config('cascachedbhost', QTYPE_STACK_TEST_CONFIG_CASCACHEDBHOST, 'qtype_stack');
         set_config('cascachedbname', QTYPE_STACK_TEST_CONFIG_CASCACHEDBNAME, 'qtype_stack');
         set_config('cascachedbuser', QTYPE_STACK_TEST_CONFIG_CASCACHEDBUSER, 'qtype_stack');
         set_config('cascachedbpass', QTYPE_STACK_TEST_CONFIG_CASCACHEDBPASS, 'qtype_stack');
         set_config('cascachedbprefix', QTYPE_STACK_TEST_CONFIG_CASCACHEDBPREFIX, 'qtype_stack');
         if (defined('QTYPE_STACK_TEST_CONFIG_CASCACHEDBSOCKET')) {
             set_config('cascachedbsocket', QTYPE_STACK_TEST_CONFIG_CASCACHEDBSOCKET, 'qtype_stack');
         }
     }
     if (defined('QTYPE_STACK_TEST_CONFIG_SERVERUSERPASS')) {
         set_config('serveruserpass', QTYPE_STACK_TEST_CONFIG_SERVERUSERPASS, 'qtype_stack');
     }
     if (stack_cas_configuration::maxima_bat_is_missing()) {
         stack_cas_configuration::create_maximalocal();
     }
     // Create the required directories inside moodledata.
     make_upload_directory('stack');
     make_upload_directory('stack/logs');
     make_upload_directory('stack/plots');
     make_upload_directory('stack/tmp');
 }
 /**
  * Downloads a langpack and fakes it being outdated
  *
  * @param string $langcode The language code (e.g. en)
  * @Given /^outdated langpack \'([^\']*)\' is installed$/
  */
 public function outdated_langpack_is_installed($langcode)
 {
     global $CFG;
     require_once $CFG->libdir . '/componentlib.class.php';
     // Download the langpack.
     $dir = make_upload_directory('lang');
     $installer = new lang_installer($langcode);
     $result = $installer->run();
     if ($result[$langcode] !== lang_installer::RESULT_INSTALLED) {
         throw new coding_exception("Failed to install langpack '{$langcode}'");
     }
     $path = "{$dir}/{$langcode}/{$langcode}.md5";
     if (!file_exists($path)) {
         throw new coding_exception("Failed to find '{$langcode}' checksum");
     }
     file_put_contents($path, '000000');
 }
Exemple #13
0
 /**
  * Download the community course backup and save it in file API
  * @param integer $courseid
  * @param string $huburl
  * @return array 'privatefile' the file name saved in private area
  *               'tmpfile' the file name saved in the moodledata temp dir (for restore)
  */
 public function block_community_download_course_backup($course)
 {
     global $CFG, $USER;
     require_once $CFG->libdir . "/filelib.php";
     require_once $CFG->dirroot . "/course/publish/lib.php";
     $params['courseid'] = $course->id;
     $params['filetype'] = HUB_BACKUP_FILE_TYPE;
     make_upload_directory('temp/backup');
     $filename = md5(time() . '-' . $course->id . '-' . $USER->id . '-' . random_string(20));
     $url = new moodle_url($course->huburl . '/local/hub/webservice/download.php', $params);
     $path = $CFG->dataroot . '/temp/backup/' . $filename . ".mbz";
     $fp = fopen($path, 'w');
     $curlurl = $course->huburl . '/local/hub/webservice/download.php?filetype=' . HUB_BACKUP_FILE_TYPE . '&courseid=' . $course->id;
     //send an identification token if the site is registered on the hub
     require_once $CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php';
     $registrationmanager = new registration_manager();
     $registeredhub = $registrationmanager->get_registeredhub($course->huburl);
     if (!empty($registeredhub)) {
         $token = $registeredhub->token;
         $curlurl .= '&token=' . $token;
     }
     $ch = curl_init($curlurl);
     curl_setopt($ch, CURLOPT_FILE, $fp);
     $data = curl_exec($ch);
     curl_close($ch);
     fclose($fp);
     $fs = get_file_storage();
     $record = new stdClass();
     $record->contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
     $record->component = 'user';
     $record->filearea = 'private';
     $record->itemid = 0;
     $record->filename = urlencode($course->fullname) . "_" . time() . ".mbz";
     $record->filepath = '/downloaded_backup/';
     if (!$fs->file_exists($record->contextid, $record->component, $record->filearea, 0, $record->filepath, $record->filename)) {
         $fs->create_file_from_pathname($record, $CFG->dataroot . '/temp/backup/' . $filename . ".mbz");
     }
     $filenames = array();
     $filenames['privatefile'] = $record->filename;
     $filenames['tmpfile'] = $filename;
     return $filenames;
 }
 function definition()
 {
     global $CFG;
     global $COURSE;
     $mform =& $this->_form;
     //-- General --------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     /// name
     $mform->addElement('text', 'name', get_string('name'), array('size' => '60'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     /// text (description)
     $mform->addElement('htmleditor', 'text', get_string('description'));
     $mform->setType('text', PARAM_RAW);
     //$mform->addRule('text', get_string('required'), 'required', null, 'client');
     $mform->setHelpButton('text', array('writing', 'richtext'), false, 'editorhelpbutton');
     /// introformat
     $mform->addElement('format', 'introformat', get_string('format'));
     //-- Stamp Collection------------------------------------------------------------
     $mform->addElement('header', 'stampcollection', get_string('modulename', 'stampcoll'));
     /// stampimage
     make_upload_directory("{$COURSE->id}");
     // Just in case
     $images = array();
     $coursefiles = get_directory_list("{$CFG->dataroot}/{$COURSE->id}", $CFG->moddata);
     foreach ($coursefiles as $filename) {
         if (mimeinfo("icon", $filename) == "image.gif") {
             $images["{$filename}"] = $filename;
         }
     }
     $mform->addElement('select', 'image', get_string('stampimage', 'stampcoll'), array_merge(array('' => get_string('default')), $images), 'a', 'b', 'c', 'd');
     $mform->addElement('static', 'stampimageinfo', '', get_string('stampimageinfo', 'stampcoll'));
     /// displayzero
     $mform->addElement('selectyesno', 'displayzero', get_string('displayzero', 'stampcoll'));
     $mform->setDefault('displayzero', 0);
     //-------------------------------------------------------------------------------
     // add standard elements, common to all modules
     $this->standard_coursemodule_elements();
     //-------------------------------------------------------------------------------
     // add standard buttons, common to all modules
     $this->add_action_buttons();
 }
 /**
  * Generates a random token and stores it in a file in moodledata directory.
  *
  * @return array of the (string)filename and (string)password in this order
  */
 public function prepare_authorization()
 {
     global $CFG;
     make_upload_directory('mdeploy/auth/');
     $attempts = 0;
     $success = false;
     while (!$success and $attempts < 5) {
         $attempts++;
         $passfile = $this->generate_passfile();
         $password = $this->generate_password();
         $now = time();
         $filepath = $CFG->dataroot . '/mdeploy/auth/' . $passfile;
         if (!file_exists($filepath)) {
             $success = file_put_contents($filepath, $password . PHP_EOL . $now . PHP_EOL, LOCK_EX);
         }
     }
     if ($success) {
         return array($passfile, $password);
     } else {
         throw new moodle_exception('unable_prepare_authorization', 'core_plugin');
     }
 }
 /**
  * Moves all the files to the destination directory.
  *
  * @uses $CFG
  * @uses $USER
  * @param string $destination The destination directory.
  * @return boolean status;
  */
 function save_files($destination)
 {
     global $CFG, $USER, $OUTPUT;
     if (!$this->status) {
         // preprocess_files hasn't been run
         $this->preprocess_files();
     }
     // if there are no files, bail before we create an empty directory.
     if (empty($this->config->somethingtosave)) {
         return true;
     }
     $savedsomething = false;
     if ($this->status) {
         if (!(strpos($destination, $CFG->dataroot) === false)) {
             // take it out for giving to make_upload_directory
             $destination = substr($destination, strlen($CFG->dataroot) + 1);
         }
         if ($destination[strlen($destination) - 1] == '/') {
             // strip off a trailing / if we have one
             $destination = substr($destination, 0, -1);
         }
         if (!make_upload_directory($destination, true)) {
             //TODO maybe put this function here instead of moodlelib.php now.
             $this->status = false;
             return false;
         }
         $destination = $CFG->dataroot . '/' . $destination;
         // now add it back in so we have a full path
         $exceptions = array();
         //need this later if we're deleting other files.
         foreach (array_keys($this->files) as $i) {
             if (!$this->files[$i]['clear']) {
                 // not ok to save
                 continue;
             }
             if ($this->config->handlecollisions) {
                 $this->handle_filename_collision($destination, $this->files[$i]);
             }
             if (move_uploaded_file($this->files[$i]['tmp_name'], $destination . '/' . $this->files[$i]['name'])) {
                 chmod($destination . '/' . $this->files[$i]['name'], $CFG->directorypermissions);
                 $this->files[$i]['fullpath'] = $destination . '/' . $this->files[$i]['name'];
                 $this->files[$i]['uploadlog'] .= "\n" . get_string('uploadedfile');
                 $this->files[$i]['saved'] = true;
                 $exceptions[] = $this->files[$i]['name'];
                 // now add it to the log (this is important so we know who to notify if a virus is found later on)
                 clam_log_upload($this->files[$i]['fullpath'], $this->course);
                 $savedsomething = true;
             }
         }
         if ($savedsomething && $this->config->deleteothers) {
             $this->delete_other_files($destination, $exceptions);
         }
     }
     if (empty($savedsomething)) {
         $this->status = false;
         if (empty($this->config->allownull) && !empty($this->inputname) || empty($this->inputname) && empty($this->config->allownullmultiple)) {
             echo $OUTPUT->notification(get_string('uploadnofilefound'));
         }
         return false;
     }
     return $this->status;
 }
<?php

// $Id: maintenance.php,v 1.12 2007/04/30 17:08:44 skodak Exp $
// Enables/disables maintenance mode
require '../config.php';
require_once $CFG->libdir . '/adminlib.php';
$action = optional_param('action', '', PARAM_ALPHA);
admin_externalpage_setup('maintenancemode');
//Check folder exists
if (!make_upload_directory(SITEID)) {
    // Site folder
    error("Could not create site folder.  The site administrator needs to fix the file permissions");
}
$filename = $CFG->dataroot . '/' . SITEID . '/maintenance.html';
if ($form = data_submitted()) {
    if (confirm_sesskey()) {
        if ($form->action == "disable") {
            unlink($filename);
            redirect('maintenance.php', get_string('sitemaintenanceoff', 'admin'));
        } else {
            $file = fopen($filename, 'w');
            fwrite($file, stripslashes($form->text));
            fclose($file);
            redirect('maintenance.php', get_string('sitemaintenanceon', 'admin'));
        }
    }
}
/// Print the header stuff
admin_externalpage_print_header();
/// Print the appropriate form
if (file_exists($filename)) {
Exemple #18
0
/**
 * Try to verify that dataroot is not accessible from web.
 *
 * Try to verify that dataroot is not accessible from web.
 * It is not 100% correct but might help to reduce number of vulnerable sites.
 * Protection from httpd.conf and .htaccess is not detected properly.
 *
 * @uses INSECURE_DATAROOT_WARNING
 * @uses INSECURE_DATAROOT_ERROR
 * @param bool $fetchtest try to test public access by fetching file, default false
 * @return mixed empty means secure, INSECURE_DATAROOT_ERROR found a critical problem, INSECURE_DATAROOT_WARNING might be problematic
 */
function is_dataroot_insecure($fetchtest = false)
{
    global $CFG;
    $siteroot = str_replace('\\', '/', strrev($CFG->dirroot . '/'));
    // win32 backslash workaround
    $rp = preg_replace('|https?://[^/]+|i', '', $CFG->wwwroot, 1);
    $rp = strrev(trim($rp, '/'));
    $rp = explode('/', $rp);
    foreach ($rp as $r) {
        if (strpos($siteroot, '/' . $r . '/') === 0) {
            $siteroot = substr($siteroot, strlen($r) + 1);
            // moodle web in subdirectory
        } else {
            break;
            // probably alias root
        }
    }
    $siteroot = strrev($siteroot);
    $dataroot = str_replace('\\', '/', $CFG->dataroot . '/');
    if (strpos($dataroot, $siteroot) !== 0) {
        return false;
    }
    if (!$fetchtest) {
        return INSECURE_DATAROOT_WARNING;
    }
    // now try all methods to fetch a test file using http protocol
    $httpdocroot = str_replace('\\', '/', strrev($CFG->dirroot . '/'));
    preg_match('|(https?://[^/]+)|i', $CFG->wwwroot, $matches);
    $httpdocroot = $matches[1];
    $datarooturl = $httpdocroot . '/' . substr($dataroot, strlen($siteroot));
    make_upload_directory('diag');
    $testfile = $CFG->dataroot . '/diag/public.txt';
    if (!file_exists($testfile)) {
        file_put_contents($testfile, 'test file, do not delete');
    }
    $teststr = trim(file_get_contents($testfile));
    if (empty($teststr)) {
        // hmm, strange
        return INSECURE_DATAROOT_WARNING;
    }
    $testurl = $datarooturl . '/diag/public.txt';
    if (extension_loaded('curl') and !(stripos(ini_get('disable_functions'), 'curl_init') !== FALSE) and !(stripos(ini_get('disable_functions'), 'curl_setop') !== FALSE) and ($ch = @curl_init($testurl)) !== false) {
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        $data = curl_exec($ch);
        if (!curl_errno($ch)) {
            $data = trim($data);
            if ($data === $teststr) {
                curl_close($ch);
                return INSECURE_DATAROOT_ERROR;
            }
        }
        curl_close($ch);
    }
    if ($data = @file_get_contents($testurl)) {
        $data = trim($data);
        if ($data === $teststr) {
            return INSECURE_DATAROOT_ERROR;
        }
    }
    preg_match('|https?://([^/]+)|i', $testurl, $matches);
    $sitename = $matches[1];
    $error = 0;
    if ($fp = @fsockopen($sitename, 80, $error)) {
        preg_match('|https?://[^/]+(.*)|i', $testurl, $matches);
        $localurl = $matches[1];
        $out = "GET {$localurl} HTTP/1.1\r\n";
        $out .= "Host: {$sitename}\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fwrite($fp, $out);
        $data = '';
        $incoming = false;
        while (!feof($fp)) {
            if ($incoming) {
                $data .= fgets($fp, 1024);
            } else {
                if (@fgets($fp, 1024) === "\r\n") {
                    $incoming = true;
                }
            }
        }
        fclose($fp);
        $data = trim($data);
        if ($data === $teststr) {
            return INSECURE_DATAROOT_ERROR;
        }
    }
    return INSECURE_DATAROOT_WARNING;
}
            echo '<input type="hidden" name="action" value="save3" />';
            echo '<input type="hidden" name="d" value="' . $data->id . '" />';
            echo '<input type="hidden" name="sesskey" value="' . $sesskey . '" />';
            echo '<input type="submit" value="' . $stroverwrite . '" /></div></form>';
            echo '</div>';
            print_footer($course);
            exit;
            break;
        }
    case 'save3':
        if (!data_submitted() or !confirm_sesskey()) {
            error("Invalid request");
        }
        $name = optional_param('name', $data->name, PARAM_FILE);
        $presetdirectory = "/data/preset/{$USER->id}/{$name}";
        make_upload_directory($presetdirectory);
        clean_preset($CFG->dataroot . $presetdirectory);
        $file = data_presets_export($course, $cm, $data);
        if (!unzip_file($file, $CFG->dataroot . $presetdirectory, false)) {
            error("Can't unzip to the preset directory");
        }
        notify(get_string('savesuccess', 'data'), 'notifysuccess');
        break;
}
$presets = data_get_available_presets($context);
$strimport = get_string('import');
$strfromfile = get_string('fromfile', 'data');
$strchooseorupload = get_string('chooseorupload', 'data');
$strusestandard = get_string('usestandard', 'data');
$strchoose = get_string('choose');
$strexport = get_string('export', 'data');
Exemple #20
0
 /**
  * Makes an upload directory
  *
  * @param $userid int The user id
  * @return string path to file area.
  */
 function file_area($userid)
 {
     return make_upload_directory($this->file_area_name($userid));
 }
 */
function amos_parse_lang_commit()
{
    global $stage, $timemodified, $commitmsg, $committer, $committeremail, $commithash, $checkout, $startatlock;
    $stage->rebase();
    try {
        $stage->commit($commitmsg, array('source' => 'git', 'userinfo' => $committer . ' <' . $committeremail . '>', 'commithash' => $commithash), true, $timemodified);
    } catch (dml_write_exception $e) {
        fputs(STDERR, "FAILED COMMIT {$checkout}\n");
        $stage->clear();
    }
    // remember the processed commithash
    file_put_contents($startatlock, $commithash);
}
$tmp = make_upload_directory('amos/temp');
$var = make_upload_directory('amos/var');
$mem = memory_get_usage();
$eng = array();
// the following commits contains a syntax typo and they can't be included for processing. They are skipped
$MLANG_BROKEN_CHECKOUTS = array('6ec9481c57031d35ebb5ed19807791264f522d9c_cs_utf8_langconfig.php', '64f9179caba6584f6fcee8e7ed957473301c26e7_cs_utf8_auth.php', '7d35c4bd7ed781fccf1334a0662a6cc2a9c3c627_it_utf8_moodle.php', '3ea6d49f6d2e9785deff089193c878c4cf46a0dc_fr_utf8_enrol_authorize.php', '1852dc59bd96d6a5dfa2f836d3b24a53e317e2ab_fr_utf8_admin.php', 'd76860354ecf3854e0d36cf82aaf23e54064cddc_fr_utf8_admin.php', '1a27c7774de7dc6d2ce5d650eae972344159bdc2_ja_utf8_admin.php', '7fd8390819eae456caa954d1fdb00ba84b3c428b_zh_tw_utf8_dialogues.php', '519dc243ca72b549fdd4a9a4bf27c4f3cea88ec2_mn_utf8_quiz_analysis.php', '8bec8cb0b6edc835707c9eb4af61c0b37a31fed8_mn_utf8_quiz_analysis.php', '4e573ae1b379d0a757104fb121515ce05427b9bf_hu_utf8_enrol_mnet.php', '4e573ae1b379d0a757104fb121515ce05427b9bf_hu_utf8_group.php', 'a669da1017199cd19074b673675e3bba20919595_fr_utf8_mnet.php', '2c4cdacf4a7976cdc1958da949bf28b097e42e88_fr_utf8_mnet.php', '4eb0ae6e276ce2449d3ef3107b4843e7e351ad94_fr_utf8_admin.php', '09f1f1f81dab4e3847876ad5e4803c74b69a493b_zh_tw_utf8_dialogues.php', 'ad2c7d53d9423499edade1cbef08598461d3dbf3_si_utf8_langconfig.php', '3ccc36a2ce7d4359d88a66392cb15ba4843a137c_pt_utf8_editor.php', 'c0a238b29dd9014b6caef14ee79a0d510d364c44_he_utf8_tag.php', '7cf367a33e97e8046cf579282e89956ff18da72f_fr_utf8_error.php', '815d89e7670b47bbaba17bafe2025895e310f81b_fr_utf8_block_search.php', 'd705fde9f580216833552e372a432ad36ff77413_fr_utf8_debug.php', '1f18133335b17348abeb4472904c2a7765ae1009_fr_utf8_gradeimport_xml.php', '8af971ad2265b3efc901985a6f204aa4ba4408a9_fr_utf8_error.php', '77ef858496eda8c000327a7d87802d13643b0aa2_so_utf8_appointment.php', 'd090367ead604f2a65e2b22abbec6f19c1915607_es_utf8_question.php', 'abe4d2a450411820e7eda4d868ff01923597d5bd_eu_utf8_error.php', '079dabb0918bb0e5d35b15886a4b84ed75ee1c7d_tr_utf8_error.php', 'a43d1b0eee00cd8d9f1d485916b24dfb2e85d3cc_km_utf8_auth.php', 'a43d1b0eee00cd8d9f1d485916b24dfb2e85d3cc_km_utf8_enrol_ldap.php', 'a43d1b0eee00cd8d9f1d485916b24dfb2e85d3cc_km_utf8_forum.php', 'a43d1b0eee00cd8d9f1d485916b24dfb2e85d3cc_km_utf8_group.php', 'a43d1b0eee00cd8d9f1d485916b24dfb2e85d3cc_km_utf8_hotpot.php', 'a43d1b0eee00cd8d9f1d485916b24dfb2e85d3cc_km_utf8_question.php', '598095a80d24d982efa2eb5446ba2046ff5a4f80_dv_utf8_moodlelib.php', 'dcb292801654b0fd0bfb76ff0bf597f49f133cc9_da_utf8_moodle.php', 'cfec4b2b359a67abd50eca74fd37f12a54d8ea42_nl_utf8_grades.php', '61b81feac5f42fe346cbf000a1bb40fda00a22a0_el_utf8_fonts_lang_decode.php');
chdir(AMOS_REPO_LANGS);
// find the root commit
//$gitout = array();
//$gitstatus = 0;
//$gitcmd = AMOS_PATH_GIT .  " rev-list HEAD | tail -1";
//echo "RUN {$gitcmd}\n";
//exec($gitcmd, $gitout, $gitstatus);
//if ($gitstatus <> 0) {
//    echo "ERROR\n";
//    exit(1);
//}
Exemple #22
0
         echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n";
         echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
         echo " <input type=\"submit\" value=\"{$strcancel}\" />\n";
         echo "</form>";
         echo "</td></tr>\n</table>\n";
     }
     html_footer();
     break;
 case "mkdir":
     if (!empty($name) and confirm_sesskey()) {
         html_header($course, $wdir);
         $name = clean_filename($name);
         if (file_exists("{$basedir}{$wdir}/{$name}")) {
             echo "Error: {$name} already exists!";
         } else {
             if (!make_upload_directory("{$course->id}/{$wdir}/{$name}")) {
                 echo "Error: could not create {$name}";
             }
         }
         displaydir($wdir);
     } else {
         $strcreate = get_string("create");
         $strcancel = get_string("cancel");
         $strcreatefolder = get_string("createfolder", "moodle", $wdir);
         html_header($course, $wdir, "form.name");
         echo "<p>{$strcreatefolder}:";
         echo "<table border=\"0\">\n<tr><td>\n";
         echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">\n";
         echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n";
         echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n";
         echo " <input type=\"hidden\" name=\"action\" value=\"mkdir\" />\n";
function blog_rss_save_file($type, $id, $tagid = 0, $contents = '')
{
    global $CFG;
    if (!($basedir = make_upload_directory("rss/blog/{$type}/{$id}"))) {
        return false;
    }
    $file = blog_rss_file_name($type, $id, $tagid);
    $rss_file = fopen($file, 'w');
    if ($rss_file) {
        $status = fwrite($rss_file, $contents);
        fclose($rss_file);
    } else {
        $status = false;
    }
    return $status;
}
Exemple #24
0
function data_presets_export($course, $cm, $data, $tostorage=false) {
    global $CFG, $DB;

    $presetname = clean_filename($data->name) . '-preset-' . gmdate("Ymd_Hi");
    $exportsubdir = "temp/mod_data/presetexport/$presetname";
    make_upload_directory($exportsubdir);
    $exportdir = "$CFG->dataroot/$exportsubdir";

    // Assemble "preset.xml":
    $presetxmldata = data_presets_generate_xml($course, $cm, $data);

    // After opening a file in write mode, close it asap
    $presetxmlfile = fopen($exportdir . '/preset.xml', 'w');
    fwrite($presetxmlfile, $presetxmldata);
    fclose($presetxmlfile);

    // Now write the template files
    $singletemplate = fopen($exportdir . '/singletemplate.html', 'w');
    fwrite($singletemplate, $data->singletemplate);
    fclose($singletemplate);

    $listtemplateheader = fopen($exportdir . '/listtemplateheader.html', 'w');
    fwrite($listtemplateheader, $data->listtemplateheader);
    fclose($listtemplateheader);

    $listtemplate = fopen($exportdir . '/listtemplate.html', 'w');
    fwrite($listtemplate, $data->listtemplate);
    fclose($listtemplate);

    $listtemplatefooter = fopen($exportdir . '/listtemplatefooter.html', 'w');
    fwrite($listtemplatefooter, $data->listtemplatefooter);
    fclose($listtemplatefooter);

    $addtemplate = fopen($exportdir . '/addtemplate.html', 'w');
    fwrite($addtemplate, $data->addtemplate);
    fclose($addtemplate);

    $rsstemplate = fopen($exportdir . '/rsstemplate.html', 'w');
    fwrite($rsstemplate, $data->rsstemplate);
    fclose($rsstemplate);

    $rsstitletemplate = fopen($exportdir . '/rsstitletemplate.html', 'w');
    fwrite($rsstitletemplate, $data->rsstitletemplate);
    fclose($rsstitletemplate);

    $csstemplate = fopen($exportdir . '/csstemplate.css', 'w');
    fwrite($csstemplate, $data->csstemplate);
    fclose($csstemplate);

    $jstemplate = fopen($exportdir . '/jstemplate.js', 'w');
    fwrite($jstemplate, $data->jstemplate);
    fclose($jstemplate);

    $asearchtemplate = fopen($exportdir . '/asearchtemplate.html', 'w');
    fwrite($asearchtemplate, $data->asearchtemplate);
    fclose($asearchtemplate);

    // Check if all files have been generated
    if (! is_directory_a_preset($exportdir)) {
        print_error('generateerror', 'data');
    }

    $filenames = array(
        'preset.xml',
        'singletemplate.html',
        'listtemplateheader.html',
        'listtemplate.html',
        'listtemplatefooter.html',
        'addtemplate.html',
        'rsstemplate.html',
        'rsstitletemplate.html',
        'csstemplate.css',
        'jstemplate.js',
        'asearchtemplate.html'
    );

    $filelist = array();
    foreach ($filenames as $filename) {
        $filelist[$filename] = $exportdir . '/' . $filename;
    }

    $exportfile = $exportdir.'.zip';
    file_exists($exportfile) && unlink($exportfile);

    $fp = get_file_packer('application/zip');
    $fp->archive_to_pathname($filelist, $exportfile);

    foreach ($filelist as $file) {
        unlink($file);
    }
    rmdir($exportdir);

    // Return the full path to the exported preset file:
    return $exportfile;
}
Exemple #25
0
function workshop_file_area($workshop, $submission)
{
    return make_upload_directory(workshop_file_area_name($workshop, $submission));
}
 /**
  * Returns a temporary file, do not forget to delete after not needed any more.
  *
  * @param string $elname
  * @return string or false
  */
 function save_temp_file($elname)
 {
     if (!$this->get_new_filename($elname)) {
         return false;
     }
     if (!($dir = make_upload_directory('temp/forms'))) {
         return false;
     }
     if (!($tempfile = tempnam($dir, 'tempup_'))) {
         return false;
     }
     if (!$this->save_file($elname, $tempfile, true)) {
         // something went wrong
         @unlink($tempfile);
         return false;
     }
     return $tempfile;
 }
 * Description:
 * 	Record Video and save it (MP4 file format with h.264 Video track and AAC audio track) inside the course (or user's folder)
 *
 */
require_once "../../../../../config.php";
$id = optional_param('id', SITEID, PARAM_INT);
require_course_login($id);
@header('Content-Type: text/html; charset=utf-8');
$langpath = $CFG->dirroot . "/lib/editor/htmlarea/custom_plugins/videorecorder/lang/";
//print_header_simple();
//print_footer();
$filename = 'videorecorder_' . strftime("%H%M%S", time()) . '.mp4';
$uploads_dir = $COURSE->id . "/users/" . $USER->id;
$url = $CFG->wwwroot . '/file.php/' . $uploads_dir . '/mp4/' . $filename;
// create a folder for the audio files, if none exist.
$path = make_upload_directory($uploads_dir, false);
?>
<html>
<head>
  <title><?php 
echo get_string('title', 'videorecorder', '', $langpath);
?>
</title>

<SCRIPT language="JavaScript">
  function vision()	
  {
    document.getElementById("loading").style.visibility="hidden";
    document.getElementById("loaded").style.visibility="visible";
  }
Exemple #28
0
function scorm_check_package($data)
{
    global $CFG, $COURSE;
    require_once $CFG->libdir . '/filelib.php';
    $courseid = $data->course;
    // Course Module ID
    $reference = $data->reference;
    // Package path
    $scormid = $data->instance;
    // scorm ID
    $validation = new stdClass();
    if (!empty($courseid) && !empty($reference)) {
        $externalpackage = scorm_external_link($reference);
        $validation->launch = 0;
        $referencefield = $reference;
        if (empty($reference)) {
            $validation = null;
        } else {
            if ($reference[0] == '#') {
                if (isset($CFG->repositoryactivate) && $CFG->repositoryactivate) {
                    $referencefield = $reference . '/imsmanifest.xml';
                    $reference = $CFG->repository . substr($reference, 1) . '/imsmanifest.xml';
                } else {
                    $validation = null;
                }
            } else {
                if (!$externalpackage) {
                    $reference = $CFG->dataroot . '/' . $courseid . '/' . $reference;
                }
            }
        }
        if (!empty($scormid)) {
            //
            // SCORM Update
            //
            if (!empty($validation) && (is_file($reference) || $externalpackage)) {
                if (!$externalpackage) {
                    $mdcheck = md5_file($reference);
                } else {
                    if ($externalpackage) {
                        if ($scormdir = make_upload_directory("{$courseid}/{$CFG->moddata}/scorm")) {
                            if ($tempdir = scorm_tempdir($scormdir)) {
                                $content = download_file_content($reference);
                                $file = fopen($tempdir . '/' . basename($reference), 'x');
                                fwrite($file, $content);
                                fclose($file);
                                $mdcheck = md5_file($tempdir . '/' . basename($reference));
                                scorm_delete_files($tempdir);
                            }
                        }
                    }
                }
                if ($scorm = get_record('scorm', 'id', $scormid)) {
                    if ($scorm->reference[0] == '#') {
                        if (isset($CFG->repositoryactivate) && $CFG->repositoryactivate) {
                            $oldreference = $CFG->repository . substr($scorm->reference, 1) . '/imsmanifest.xml';
                        } else {
                            $oldreference = $scorm->reference;
                        }
                    } else {
                        if (!scorm_external_link($scorm->reference)) {
                            $oldreference = $CFG->dataroot . '/' . $courseid . '/' . $scorm->reference;
                        } else {
                            $oldreference = $scorm->reference;
                        }
                    }
                    $validation->launch = $scorm->launch;
                    if ($oldreference == $reference && $mdcheck != $scorm->md5hash || $oldreference != $reference) {
                        // This is a new or a modified package
                        $validation->launch = 0;
                    } else {
                        // Old package already validated
                        if (strpos($scorm->version, 'AICC') !== false) {
                            $validation->pkgtype = 'AICC';
                        } else {
                            $validation->pkgtype = 'SCORM';
                        }
                    }
                } else {
                    $validation = null;
                }
            } else {
                $validation = null;
            }
        }
        //$validation->launch = 0;
        if ($validation != null && $validation->launch == 0) {
            //
            // Package must be validated
            //
            $ext = strtolower(substr(basename($reference), strrpos(basename($reference), '.')));
            $tempdir = '';
            switch ($ext) {
                case '.pif':
                case '.zip':
                    // Create a temporary directory to unzip package and validate package
                    $scormdir = '';
                    if ($scormdir = make_upload_directory("{$courseid}/{$CFG->moddata}/scorm")) {
                        if ($tempdir = scorm_tempdir($scormdir)) {
                            if ($externalpackage) {
                                $content = download_file_content($reference);
                                $file = fopen($tempdir . '/' . basename($reference), 'x');
                                fwrite($file, $content);
                                fclose($file);
                            } else {
                                copy("{$reference}", $tempdir . '/' . basename($reference));
                            }
                            unzip_file($tempdir . '/' . basename($reference), $tempdir, false);
                            if (!$externalpackage) {
                                unlink($tempdir . '/' . basename($reference));
                            }
                            if (is_file($tempdir . '/imsmanifest.xml')) {
                                $validation = scorm_validate_manifest($tempdir . '/imsmanifest.xml');
                                $validation->pkgtype = 'SCORM';
                            } else {
                                $validation = scorm_validate_aicc($tempdir);
                                $validation->pkgtype = 'AICC';
                            }
                        } else {
                            $validation = null;
                        }
                    } else {
                        $validation = null;
                    }
                    break;
                case '.xml':
                    if (basename($reference) == 'imsmanifest.xml') {
                        if ($externalpackage) {
                            if ($scormdir = make_upload_directory("{$courseid}/{$CFG->moddata}/scorm")) {
                                if ($tempdir = scorm_tempdir($scormdir)) {
                                    $content = download_file_content($reference);
                                    $file = fopen($tempdir . '/' . basename($reference), 'x');
                                    fwrite($file, $content);
                                    fclose($file);
                                    if (is_file($tempdir . '/' . basename($reference))) {
                                        $validation = scorm_validate_manifest($tempdir . '/' . basename($reference));
                                    } else {
                                        $validation = null;
                                    }
                                }
                            }
                        } else {
                            $validation = scorm_validate_manifest($reference);
                        }
                        $validation->pkgtype = 'SCORM';
                    } else {
                        $validation = null;
                    }
                    break;
                default:
                    $validation = null;
                    break;
            }
            if ($validation == null) {
                if (is_dir($tempdir)) {
                    // Delete files and temporary directory
                    scorm_delete_files($tempdir);
                }
            } else {
                if ($ext == '.xml' && !$externalpackage) {
                    $validation->datadir = dirname($referencefield);
                } else {
                    $validation->datadir = substr($tempdir, strlen($scormdir));
                }
                $validation->launch = 0;
            }
        }
    } else {
        $validation = null;
    }
    return $validation;
}
Exemple #29
0
 /**
  * Init session storage.
  */
 protected function init_session_storage()
 {
     global $CFG;
     ini_set('session.save_handler', 'files');
     // Some distros disable GC by setting probability to 0
     // overriding the PHP default of 1
     // (gc_probability is divided by gc_divisor, which defaults to 1000)
     if (ini_get('session.gc_probability') == 0) {
         ini_set('session.gc_probability', 1);
     }
     ini_set('session.gc_maxlifetime', $CFG->sessiontimeout);
     // make sure sessions dir exists and is writable, throws exception if not
     make_upload_directory('sessions');
     // Need to disable debugging since disk_free_space()
     // will fail on very large partitions (see MDL-19222)
     $freespace = @disk_free_space($CFG->dataroot . '/sessions');
     if (!($freespace > 2048) and $freespace !== false) {
         print_error('sessiondiskfull', 'error');
     }
     ini_set('session.save_path', $CFG->dataroot . '/sessions');
 }
Exemple #30
0
    if (array_search('filter/tex', $filters) === FALSE) {
        error('Filter not enabled!');
    }
}
$CFG->texfilterdir = "filter/tex";
$CFG->teximagedir = "filter/tex";
error_reporting(E_ALL);
$texexp = urldecode($_SERVER['QUERY_STRING']);
$texexp = str_replace('formdata=', '', $texexp);
if ($texexp) {
    //$texexp = stripslashes($texexp);
    $lifetime = 86400;
    $image = md5($texexp) . ".gif";
    $filetype = 'image/gif';
    if (!file_exists("{$CFG->dataroot}/{$CFG->teximagedir}")) {
        make_upload_directory($CFG->teximagedir);
    }
    $pathname = "{$CFG->dataroot}/{$CFG->teximagedir}/{$image}";
    $texexp = tex_sanitize_formula($texexp);
    $texexp = escapeshellarg($texexp);
    switch (PHP_OS) {
        case "Linux":
            system("{$CFG->dirroot}/{$CFG->texfilterdir}/mimetex.linux -e {$pathname} -- {$texexp}");
            break;
        case "WINNT":
        case "WIN32":
        case "Windows":
            system("{$CFG->dirroot}/{$CFG->texfilterdir}/mimetex.exe -e  {$pathname} -- {$texexp}");
            break;
        case "Darwin":
            system("{$CFG->dirroot}/{$CFG->texfilterdir}/mimetex.darwin -e {$pathname} -- {$texexp}");