예제 #1
0
function process_target($target_dir, $file_name, $logger, $content = false)
{
    if ($content === false) {
        $tmp_file = $_FILES['uploadedfile']['tmp_name'];
        $uploaded_file_name = basename($_FILES['uploadedfile']['name']);
    }
    $timestamp = get_timestamp($uploaded_file_name, $content !== false);
    $target_dir = create_directory($target_dir, $timestamp);
    if ($target_dir === null) {
        $logger->log("uploader", "Directory is not created", Logger::CRIT);
        header("HTTP/1.1 500 Server error");
        echo "Could not create directory {$target_dir}\n";
        return;
    }
    $target_file = $target_dir . "/" . $file_name;
    if (isset($tmp_file) && move_uploaded_file($tmp_file, $target_file) || file_put_contents($target_file, $content)) {
        $logger->log("uploader", $target_file . " has been uploaded", Logger::INFO);
        echo "SUCCESS: {$target_file} has been uploaded<br></br>\n";
        touch($target_dir . "/." . basename($target_file));
    } else {
        $logger->log("uploader", "could not move " . $tmp_file . " to " . $target_file, Logger::ERR);
        header("HTTP/1.1 500 Server error");
        echo "FAILED: could not move {$tmp_file} to  {$target_file}<br></br>\n";
    }
    return $target_file;
}
예제 #2
0
function copy_submissions_for_entity($entity, $path)
{
    print $path . "\n";
    if (!file_exists($path)) {
        mkdir($path, 0770, true);
    }
    DB::prepare_query($query, "SELECT * FROM `submission` as s JOIN `file` as f ON s.submissionid = f.submissionid WHERE s.`entity_path` = ?");
    $query->execute(array($entity->path()));
    $query->setFetchMode(PDO::FETCH_ASSOC);
    foreach ($query->fetchAll() as $row) {
        $filename = $path . "submission_" . $row['submissionid'] . "/" . $row['filename'];
        create_directory($filename);
        file_put_contents($filename, $row['data']);
    }
    $query->closeCursor();
}
    }
}
$image_filename = "{$item['0']}";
$template = str_replace("<IMAGE_FILENAME>", $image_filename, $template);
// {{{  ----- create the thumbnails and set the permissions...
// the credit for this litte bit of genius goes to Jon from spiicytuna.org who suggested writing the directory
// and permissions via ftp and sent me some code to prove his point :).
if ($create_thumbnails == "true") {
    $full_www_path = dirname($path);
    $full_ftp_path = $ftp_web_root . "/" . $full_www_path;
    $thumbnail = $path_to_images . "/" . $thumbnail_dir . "/" . $item[0];
    if (file_exists($thumbnail)) {
        // echo "The thumbnail $thumbnail exists";
    } else {
        // create the thumbnail directory for writing
        create_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password);
        // location of the original image
        $sourcefile = "{$path_to_images}/{$item['0']}";
        // output file
        $targetfile = $thumbnail;
        /* Create a new image object (not neccessarily true colour) */
        $source_id = null;
        // prep according to image type
        if (preg_match('/(jpg|jpeg)$/i', $sourcefile)) {
            $source_id = imageCreatefromjpeg("{$sourcefile}");
        } elseif (preg_match('/(png)$/i', $sourcefile)) {
            $source_id = imageCreatefrompng("{$sourcefile}");
        } elseif (preg_match('/(gif)$/i', $sourcefile)) {
            $source_id = imageCreatefromgif("{$sourcefile}");
        } else {
            die("Unknown image file type");
예제 #4
0
function main($server_cfg)
{
    $options = get_options();
    if (isset($options['g']) && $options['g'] !== '') {
        $game_names = explode(",", $options['g']);
    } else {
        $game_names = $server_cfg['game_list'];
    }
    $time_slots = null;
    if (!empty($options['t'])) {
        $time_slots = $options['t'];
    }
    $timestamp = $_SERVER['REQUEST_TIME'];
    $current_time_slot = (int) ($timestamp / (30 * 60));
    foreach ($game_names as $game_name) {
        zpm_preamble($game_name);
        // MODIFIED!!!! Create and mount next two timeslots !!!
        $game_cfg = load_game_config($game_name);
        if (!$game_cfg) {
            error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            continue;
        }
        $target_dir = sprintf($server_cfg['root_upload_directory'], $game_cfg["name"]);
        $target_dir = $target_dir . "/%s/" . $server_cfg["profile_upload_directory"];
        $dir_name_array = create_directory($target_dir, $current_time_slot, $server_cfg, $game_cfg);
        if ($dir_name_array === null) {
            error_log("Directory creation failed for the game " . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            continue;
        }
        if ($dir_name_array === 0) {
            error_log("No Ram disk Exist!!!" . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
        }
        //creating new games and getting the list of web arrays to process data for
        $rs = new RightScale($server_cfg, load_game_config($game_name));
        $rs->make_array_games();
        $array_ids = $rs->get_arrays_to_serve();
        //
        // Wrap processing for each game inside a file lock
        //
        $game_lock_file = sprintf($server_cfg["zperfmon_lock_file"], $game_name);
        $game_lock_handle = grab_lock($game_lock_file, $server_cfg, $game_cfg);
        if (!$game_lock_handle) {
            error_log("Could not get exclusive lock for \"{$game_name}\"\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg);
            continue;
        }
        //processing parent game
        try {
            //
            // process uploaded data
            //
            run_cron_for_game($server_cfg, $game_cfg, $time_slots);
        } catch (Exception $e) {
            error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
        }
        // loop to process data for each web array
        foreach ($array_ids as $array) {
            try {
                $game_cfg = load_game_config($game_name, $array);
                if (!$game_cfg) {
                    error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
                    continue;
                }
                //
                // process uploaded data
                //
                run_cron_for_game($server_cfg, $game_cfg, $time_slots);
            } catch (Exception $e) {
                error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
                error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            }
        }
        // compress for parent game
        // This implementation forces us to always pass a timeslot
        // while calling this script. otherwise compression will fail.
        $game_cfg = load_game_config($game_name);
        compress_unziped_profiles($server_cfg, $game_cfg, $time_slots);
        // Now compress the array games
        foreach ($array_ids as $array) {
            $game_cfg = load_game_config($game_name, $array);
            compress_unziped_profiles($server_cfg, $game_cfg, $time_slots);
        }
        // cleanup the lock
        drop_lock($game_lock_handle, $game_lock_file);
        zpm_postamble($game_name);
        //MODIFIED!!!!
        if ($dir_name_array != 0) {
            delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg);
        }
    }
}
/**
* Save the preferences file
*
* @param array	$preferences	The preferences to save
* @param string	$prefs_file		The preferences file to save
*
* @return boolean
* @access public
*/
function _savePreferences($preferences, $prefs_file)
{
    if (empty($preferences)) {
        return FALSE;
    }
    $str = '<' . '?php $preferences = ' . var_export($preferences, TRUE) . '; ?' . '>';
    // Backup the existing preference file
    if (file_exists($prefs_file)) {
        $i = 0;
        do {
            $i++;
            $old_version = $prefs_file . '.' . $i;
        } while (file_exists($old_version));
        if (!copy($prefs_file, $old_version)) {
            return FALSE;
        }
    }
    // endif
    require_once SQ_FUDGE_PATH . '/general/file_system.inc';
    // make sure the directory exists
    if (!create_directory(dirname($prefs_file))) {
        return FALSE;
    }
    // and save the file
    if (!string_to_file($str, $prefs_file)) {
        return FALSE;
    }
    // Otherwise a OK!
    return TRUE;
}
예제 #6
0
파일: git.php 프로젝트: rwaldron/git-php
function create_cache_directory($repo)
{
    global $repo_directory, $cache_directory;
    $dirname = $cache_directory . $repo;
    create_directory($dirname);
}
예제 #7
0
파일: core.php 프로젝트: cyberorca/dfp-api
function updateJsonDetail($file, $type = "news")
{
    $dir = Config::App()->get('json_detail_dir');
    $dir = $dir . $type . '/';
    $filename = $dir . $file;
    if (is_file($filename)) {
        unlink($filename);
        $dirLog = Config::App()->get('log_dir');
        create_directory($dirLog);
        $log = fopen($dirLog . 'log_update_json.txt', 'a+');
        fwrite($log, date("Y-m-d H:i:s") . "\t" . $file . "\n");
        fclose($log);
        return true;
    } else {
        return false;
    }
}
/**
 * Copy real file to the version file if it does not exist
 *
 * @param File_Versioning $file_versioning	the File_Versioning object
 * @param string $rep_path	the path to the repository directory of the file
 * @param string $real_file	the real file path
 * @param int $version		the current version want to backup
 * @return boolean	return TRUE if success; otherwise, return FALSE
 * @see _updateFile() in file_versioning.inc
 */
function _updateVersionFile($file_versioning, $rep_path, $real_file, $file_info, &$new_version)
{
    $fileid = $file_info['fileid'];
    $version = $file_info['version'];
    $new_version = $version;
    if (file_exists($real_file)) {
        $real_file_size = filesize($real_file);
        $real_file_md5 = md5_file($real_file);
        $real_file_sha1 = sha1_file($real_file);
        require_once SQ_FUDGE_PATH . '/general/file_system.inc';
        $rep_dir = $file_versioning->_dir . '/' . $rep_path;
        if (!is_dir($rep_dir) && !create_directory($rep_dir)) {
            echo "ERROR: CAN NOT CREATE FOLDER: {$rep_dir}\n";
            return FALSE;
        }
        //end if
        $rep_file = $rep_dir . '/' . basename($real_file) . ',ffv' . $version;
        if (!file_exists($rep_file)) {
            //this version does not exist, copy it
            if (!copy($real_file, $rep_file)) {
                return FALSE;
            }
        } else {
            //if this version exists and is different from the real file, increase the version
            if ($real_file_size != filesize($rep_file) || $real_file_md5 != md5_file($rep_file) || $real_file_sha1 != sha1_file($rep_file)) {
                $next_version = _getNextVersion($fileid);
                if ($next_version == 0) {
                    return FALSE;
                }
                //if next version is greater than current version, use _updateFile() method of File_Versioning class
                if ($next_version > $version) {
                    $nv = $file_versioning->_updateFile($fileid, $rep_path, $real_file);
                    if ($nv == 0) {
                        return FALSE;
                    }
                    $new_version = $nv;
                } else {
                    //if next version from database is not greater than version, copy version file and update database manually
                    $version++;
                    $rep_file = $rep_dir . '/' . basename($real_file) . ',ffv' . $version;
                    if (!copy($real_file, $rep_file)) {
                        return FALSE;
                    }
                    if (!_updateFileVersionHistory($file_versioning, $fileid, $real_file, $version)) {
                        return FALSE;
                    }
                    $new_version = $version;
                    $version--;
                }
            }
        }
        //if new_version still equals version, check if the current file is the one stored in db
        if ($new_version == $version && isset($file_info['file_size'])) {
            if ($real_file_size != $file_info['file_size'] || $real_file_md5 != $file_info['md5'] || $real_file_sha1 != $file_info['sha1']) {
                return $file_versioning->_updateFileVersion($real_file, $fileid, $version);
            }
        }
        return TRUE;
    }
    return FALSE;
}
/**
*
* @param string	$file	the file to run through
*
* @return boolean
* @access public
*/
function process_file($path, $file, $force)
{
    $file_contents = file_get_contents($file);
    preg_match('|<files locale="([^"]*)">.*</file>|s', $file_contents, $match);
    // get locale and replace delimiters between locale parts with slashes
    $locale = $match[1];
    $locale = str_replace('@', '/', $locale);
    $locale = str_replace('_', '/', $locale);
    $old_force = $force;
    preg_match_all('|<file source="([^"]*)" name="([^"]*)">(.*)</file>|Us', $file_contents, $matches, PREG_SET_ORDER);
    foreach ($matches as $match) {
        $file_name = $path . '/' . $match[1] . '/' . $locale . '/' . $match[2];
        $file_str = '<?xml version="1.0" ?>' . "\n" . $match[3];
        if (!file_exists($file_name)) {
            $force = true;
        } else {
            $force = $old_force;
        }
        if (!$force) {
            // ask for the root password for the system
            echo 'Overwrite file ' . hide_system_root($file_name) . '?';
            $overwrite_confirm = '';
            while (strlen($overwrite_confirm) == 0 || strtolower($overwrite_confirm[0]) != 'y' && strtolower($overwrite_confirm[0]) != 'n') {
                $overwrite_confirm = rtrim(fgets(STDIN, 4094));
            }
            if (strtolower($overwrite_confirm[0]) == 'y') {
                $force = true;
            }
        }
        if ($force) {
            // create directory and dump file
            create_directory($path . '/' . $match[1] . '/' . $locale);
            string_to_file($file_str, $file_name);
            echo 'Wrote ' . hide_system_root($file_name) . "\n";
        }
    }
    return true;
}
예제 #10
0
/**
 * creates all visible/active network nodes on the current network
 * @param void
 *
 * @return void
 */
function network_create_nodes()
{
    $is_wireless = false;
    $ip = network_get_sys_ip();
    if (!count($ip)) {
        $ip = network_get_sys_ip('wlan0');
        $is_wireless = true;
    } else {
        if (!count($ip)) {
            $ip = network_get_sys_ip('ppp0');
        } else {
            if (!count($ip)) {
                $ip = network_get_sys_ip('lo');
            }
        }
    }
    $broadcast = network_get_sys_broadcast();
    $local_broadcast = "{$ip[0]}/24";
    $nodes = network_get_active_nodes($local_broadcast);
    foreach ($nodes as $node) {
        if ($is_wireless) {
            create_directory(PLATFORM_NETWORKS_PATH . DS . 'wireless' . DS . $node);
        } else {
            create_directory(PLATFORM_NETWORKS_PATH . DS . 'lan' . DS . $node);
        }
    }
}
예제 #11
0
function create_secrets_directory()
{
    global $repo_directory, $secret_name;
    $dname = $repo_directory . $secret_name;
    if (create_directory($dname) == false) {
        return false;
    }
    /* TODO: This is Apache-specific. How to generalize? */
    $file = fopen($dname . ".htaccess", "w");
    fwrite($file, "Deny from all\n");
    fclose($file);
    $file = fopen($dname . "index.html", "w");
    fwrite($file, "Access denied\n");
    fclose($file);
    return true;
}
예제 #12
0
파일: commit.php 프로젝트: rwaldron/git-php
function create_bundles_directory()
{
    global $repo_directory, $bundle_name;
    $repo = $_GET['p'];
    $dname = $repo_directory . $bundle_name . "/";
    create_directory($dname);
    return create_directory("{$dname}{$repo}");
}
function render_static_url($url)
{
    global $STORAGE_PATH;
    global $SYSTEM_ROOT;
    global $_nocache;
    // fake some variables required to correctly describe the current url
    $parts = parse_url($url);
    $method = 'GET';
    $protocol = 'HTTP/1.1';
    $scheme = $parts['scheme'];
    $host = $parts['host'];
    $path = $parts['path'];
    $query = '';
    $_SERVER['SERVER_PROTOCOL'] = $protocol;
    $_SERVER['REQUEST_METHOD'] = $method;
    $_SERVER['QUERY_STRING'] = $query;
    $_SERVER['REQUEST_URI'] = $path . (empty($query) ? '' : '?') . $query;
    $_SERVER['SCRIPT_NAME'] = $path;
    $_SERVER['PHP_SELF'] = $path;
    $_SERVER['HTTP_USER_AGENT'] = 'Static Site Generator';
    $_SERVER['HTTP_HOST'] = $host;
    $_SERVER['SERVER_NAME'] = $host;
    // ask Matrix to draw as if we were in apache
    ob_start();
    require_once $SYSTEM_ROOT . '/core/include/init.inc';
    $GLOBALS['SQ_SYSTEM']->start();
    $content = ob_get_clean();
    $storage_dir = "{$STORAGE_PATH}/{$scheme}/{$host}{$path}/index.html";
    if (create_directory(dirname($storage_dir))) {
        file_put_contents($storage_dir, $content);
        if ($_nocache == FALSE && is_dir(dirname($storage_dir) . '/_nocache')) {
            delete_directory(dirname($storage_dir) . '/_nocache');
        }
    }
}