Example #1
0
/**
 *	Update domain directory for soecified domain 
 *
 *	@param string $did	domain id
 *	@return bool		return TRUE on success, FALSE on failure
 */
function update_domain_dir($did)
{
    global $data, $_SERWEB;
    $domain_dir = $_SERWEB["serwebdir"] . "domains/" . $did . "/";
    $vf = new Version_file($domain_dir . "versions.ini.php");
    /* Open file containing versions of other files
    	   Do not check for errors here - if there will be error in version file, 
    	   the file will be recreated by values in DB
    	 */
    $vf->open();
    $local_versions = $vf->get_all_files();
    /* get versions of files in DB */
    if (false === ($files = $data->get_latest_file_versions($did, null))) {
        return false;
    }
    /* synchronize directory with DB */
    foreach ($files as $file => $f_prop) {
        if ($f_prop['deleted']) {
            /* file should be deleted */
            if (isset($local_versions[$file])) {
                $vf->remove_file($file);
            }
            if (file_exists($domain_dir . $file)) {
                rm($domain_dir . $file);
            }
        } elseif ($f_prop['dir']) {
            /* directory */
            if (!file_exists($domain_dir . $file)) {
                RecursiveMkdir($domain_dir . $file, 0770);
            }
        } elseif (!isset($local_versions[$file]) or !file_exists($domain_dir . $file) or $local_versions[$file] < $f_prop['version']) {
            /* file should be updated/created */
            $ds =& Domain_settings::singleton($did, $file);
            if (false === $ds->update_local_file($f_prop['version'])) {
                return false;
            }
            $vf->set_version($file, $f_prop['version']);
        }
    }
    $vf->close();
    return true;
}
 /**
  *	create html form 
  *
  *	@param array $errors	array with error messages
  *	@return null			FALSE on failure
  */
 function create_html_form(&$errors)
 {
     global $available_languages;
     parent::create_html_form($errors);
     $file_content = "";
     $kind = "";
     if ($this->action['action'] == "edit_text_file" or $this->action['action'] == "edit_layout_file") {
         $kind = $this->action['action'] == "edit_text_file" ? "text" : "layout";
         if ($this->opt['nr_backups']) {
             if (false === $this->get_versions($kind == "text", $errors)) {
                 return false;
             }
         }
         $ds =& Domain_settings::singleton($this->domain_id, $this->get_filename($kind == "text"), $this->opt['nr_backups']);
         if (is_null($this->file_ver)) {
             if (false === ($ver = $ds->get_last_version())) {
                 return false;
             }
             $this->file_ver = $ver;
         }
         if (false === ($file_content = $ds->get_file_content($this->file_ver))) {
             return false;
         }
         if (is_null($file_content) and $kind == "text") {
             $f = multidomain_get_lang_file($this->filename, "txt", $this->lang, "_default");
             if (!empty($f)) {
                 $fp = fopen($f, "r");
                 $file_content = fread($fp, 65536);
                 fclose($fp);
             }
         }
         /* strip first line containing die() preventing this script from displaying throught http */
         if (!empty($this->fileinfo['ini'])) {
             $first_eol = strpos($file_content, "\n");
             $first_line = substr($file_content, 0, $first_eol);
             if (false !== strpos($first_line, "<?php die(")) {
                 $file_content = substr($file_content, $first_eol);
             }
         }
     }
     $this->f->add_element(array("type" => "textarea", "name" => "dl_content", "rows" => 25, "cols" => 80, "value" => $file_content, "wrap" => "off"));
     $this->f->add_element(array("type" => "hidden", "name" => "dl_filename", "value" => $this->filename));
     $this->f->add_element(array("type" => "hidden", "name" => "dl_kind_of_file", "value" => $kind));
     $this->f->add_element(array("type" => "hidden", "name" => "dl_lang", "value" => $this->lang));
 }
Example #3
0
function uploadFile()
{
    global $MY_ALLOW_UPLOAD, $MY_MESSAGES, $MY_DOCUMENT_ROOT, $MY_PATH, $clear_upload;
    global $MY_ALLOW_EXTENSIONS, $MY_DENY_EXTENSIONS, $MY_MAX_FILE_SIZE;
    global $sess_page_controler_domain_id, $domain_dir_prefix;
    if (!$MY_ALLOW_UPLOAD) {
        return $MY_MESSAGES['nopermtoupload'];
    }
    if (!is_dir($MY_DOCUMENT_ROOT . $MY_PATH)) {
        return $MY_MESSAGES['pathnotfound'];
    }
    $filename = checkName($_FILES['uploadFile']['name']);
    $newFile = $MY_DOCUMENT_ROOT . $MY_PATH . $filename;
    $parts = explode('.', $filename);
    $ext = strtolower($parts[count($parts) - 1]);
    if (is_file($newFile)) {
        return $MY_MESSAGES['uploadfilealreadyexists'];
    }
    if (is_array($MY_DENY_EXTENSIONS)) {
        if (in_array($ext, $MY_DENY_EXTENSIONS)) {
            return $MY_MESSAGES['extnotallowed'];
        }
    }
    if (is_array($MY_ALLOW_EXTENSIONS)) {
        if (!in_array($ext, $MY_ALLOW_EXTENSIONS)) {
            return $MY_MESSAGES['extnotallowed'];
        }
    }
    if ($MY_MAX_FILE_SIZE) {
        if ($_FILES['uploadFile']['size'] > $MY_MAX_FILE_SIZE) {
            return $MY_MESSAGES['filesizeexceedlimit'] . ' of ' . $MY_MAX_FILE_SIZE / 1024 . 'kB.';
        }
    }
    if (!is_file($_FILES['uploadFile']['tmp_name'])) {
        return $MY_MESSAGES['filenotuploaded'];
    }
    /*--- modified in order to store files in DB ---*/
    if (!is_uploaded_file($_FILES['uploadFile']['tmp_name'])) {
        return $MY_MESSAGES['filenotuploaded'];
    }
    $my_file = $domain_dir_prefix . $MY_PATH . $filename;
    if ($my_file[0] == '/') {
        $my_file = substr($my_file, 1);
    }
    $ds =& Domain_settings::singleton($sess_page_controler_domain_id, $my_file, 1);
    if (false === $ds->save_file($_FILES['uploadFile']['tmp_name'])) {
        return "Unknown error";
    }
    //        move_uploaded_file($_FILES['uploadFile']['tmp_name'], $newFile);
    //        chmod($newFile, 0666);
    /*--- end of modified code ---*/
    $clear_upload = true;
    return false;
}