Exemple #1
0
function MessageAdd($msg, $headers, $files = NULL)
{
    global $DB, $LMS, $tmppath;
    $time = time();
    $head = '';
    if ($headers) {
        foreach ($headers as $idx => $header) {
            $head .= $idx . ": " . $header . "\n";
        }
    }
    $DB->Execute('INSERT INTO rtmessages (ticketid, createtime, subject, body, userid, customerid, mailfrom, inreplyto, messageid, replyto, headers)
			VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($msg['ticketid'], $time, $msg['subject'], preg_replace("/\r/", "", $msg['body']), $msg['userid'], $msg['customerid'], $msg['mailfrom'], $msg['inreplyto'], $msg['messageid'], isset($msg['replyto']) ? $msg['replyto'] : $headers['Reply-To'], $head));
    $mail_dir = ConfigHelper::getConfig('rt.mail_dir');
    if (!empty($files) && !empty($mail_dir)) {
        $id = $DB->GetLastInsertId('rtmessages');
        $dir = $mail_dir . sprintf('/%06d/%06d', $msg['ticketid'], $id);
        @mkdir($mail_dir . sprintf('/%06d', $msg['ticketid']), 0700);
        @mkdir($dir, 0700);
        foreach ($files as $file) {
            $newfile = $dir . '/' . $file['name'];
            if (@rename($tmppath . DIRECTORY_SEPARATOR . $file['name'], $newfile)) {
                $DB->Execute('INSERT INTO rtattachments (messageid, filename, contenttype) 
						VALUES (?,?,?)', array($id, $file['name'], $file['type']));
            }
        }
        rrmdir($tmppath);
    }
}
Exemple #2
0
function clear_old_sessions()
{
    global $dbh;
    $lockfile = "data/sessions.lock";
    // do it only once in a while
    if (file_exists($lockfile) && filemtime($lockfile) > time() - 604800) {
        return;
    }
    touch($lockfile);
    if ($handle = opendir("data/sessions/")) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $stemp = unserialize(file_get_contents("data/sessions/" . $file));
                if ($stemp['user'] === 'guest' && $stemp['timestamp'] < time() - 604800) {
                    $query = sprintf("SELECT directory FROM lists\n                          WHERE user_id=2 AND sid=%s", $dbh->quote($stemp['sid']));
                    $result = $dbh->query($query);
                    if ($result == FALSE) {
                        return -1;
                    }
                    while ($row = $result->fetchColumn()) {
                        rrmdir($row);
                    }
                    $query = sprintf("DELETE FROM lists\n                          WHERE user_id=2 AND\n                          sid=%s", $dbh->quote($stemp['sid']));
                    if ($dbh->exec($query) === FALSE) {
                        return -2;
                    }
                    //	  unlink ("data/sessions/" . $file);
                }
            }
        }
        closedir($handle);
    }
}
/**
 *
 * Check if all the parts exist, and
 * gather all the parts of the file together
 * @param string $dir - the temporary directory holding all the parts of the file
 * @param string $fileName - the original file name
 * @param string $chunkSize - each chunk size (in bytes)
 * @param string $totalSize - original file size (in bytes)
 */
function createFileFromChunks($temp_dir, $fileName, $chunkSize, $totalSize)
{
    // count all the parts of this file
    $total_files = 0;
    foreach (scandir($temp_dir) as $file) {
        if (stripos($file, $fileName) !== false) {
            $total_files++;
        }
    }
    // check that all the parts are present
    // the size of the last part is between chunkSize and 2*$chunkSize
    if ($total_files * $chunkSize >= $totalSize - $chunkSize + 1) {
        // create the final destination file
        if (($fp = fopen('../files/' . $_POST['course_id'] . '/' . $fileName, 'w')) !== false) {
            for ($i = 1; $i <= $total_files; $i++) {
                fwrite($fp, file_get_contents($temp_dir . '/' . $fileName . '.part' . $i));
                _log('writing chunk ' . $i);
            }
            fclose($fp);
        } else {
            echo 'cannot create the destination file';
            return false;
        }
        // rename the temporary directory (to avoid access from other
        // concurrent chunks uploads) and than delete it
        if (rename($temp_dir, $temp_dir . '_UNUSED')) {
            rrmdir($temp_dir . '_UNUSED');
        } else {
            rrmdir($temp_dir);
        }
    }
}
/**
 * This functions remove a plugin from the OCS webconsole and database.
 * Delete all created menu entries and all plugin related code
 * 
 * @param integer $pluginid : Plugin id in DB
 */
function delete_plugin($pluginid)
{
    global $l;
    $conn = new PDO('mysql:host=' . SERVER_WRITE . ';dbname=' . DB_NAME . '', COMPTE_BASE, PSWD_BASE);
    $query = $conn->query("SELECT * FROM `plugins` WHERE id = '" . $pluginid . "'");
    $anwser = $query->fetch();
    if (!class_exists('plugins')) {
        require 'plugins.class.php';
    }
    if (!function_exists('exec_plugin_soap_client')) {
        require 'functions_webservices.php';
    }
    if ($anwser['name'] != "" and $anwser['name'] != null) {
        require MAIN_SECTIONS_DIR . "ms_" . $anwser['name'] . "/install.php";
        $fonc = "plugin_delete_" . $anwser['name'];
        $fonc();
    }
    rrmdir(MAIN_SECTIONS_DIR . "ms_" . $anwser['name']);
    rrmdir(PLUGINS_DIR . "computer_detail/cd_" . $anwser['name']);
    if (file_exists(PLUGINS_SRV_SIDE . $anwser['name'] . ".zip")) {
        unlink(PLUGINS_SRV_SIDE . $anwser['name'] . ".zip");
        exec_plugin_soap_client($anwser['name'], 0);
    }
    $conn->query("DELETE FROM `" . DB_NAME . "`.`plugins` WHERE `plugins`.`id` = " . $pluginid . " ");
}
function rrmdir($dir)
{
    $now = time();
    $diff = 2592000;
    if (is_dir($dir)) {
        print "\nScanning: " . $dir . '/';
        $objects = scandir($dir);
        foreach ($objects as $object) {
            if ($object != "." && $object != "..") {
                if (filetype($dir . "/" . $object) == "dir") {
                    rrmdir($dir . "/" . $object);
                } else {
                    $sub = $now - date("U", filemtime($dir . "/" . $object));
                    if ($sub > $diff) {
                        if (@unlink($dir . "/" . $object)) {
                            print "\n" . $dir . "/" . $object . " deleted";
                            //print "\nlast modified time: ".date("U", filemtime($dir."/".$object));
                            //print "\n".$now;
                            //print "\n".$sub;
                        } else {
                            print "\n" . $dir . "/" . $object . " ----------------- failed";
                        }
                    }
                }
            }
        }
        reset($objects);
        //@rmdir($dir);
    }
}
function rcopy($src, $dst)
{
    if (file_exists($dst)) {
        //rrmdir ( $dst );
    }
    if (is_dir($src)) {
        $files = scandir($src);
        mkdir($dst);
        foreach ($files as $file) {
            if ($file != '.' && $file != '..') {
                rcopy($src . '/' . $file, $dst . '/' . $file);
                rrmdir($src . '/' . $file);
            }
            $iterator = new FilesystemIterator($src);
            $isDirEmpty = !$iterator->valid();
            if ($isDirEmpty) {
                rmdir($src);
            }
        }
    } else {
        if (file_exists($src)) {
            copy($src, $dst);
        }
    }
}
 public function clear()
 {
     $location = $this->getCacheLocation();
     if ($location) {
         rrmdir($location);
     }
 }
function rrmdir($dir)
{
    global $dryrun;
    foreach (glob($dir . '/*') as $file) {
        if (is_dir($file)) {
            rrmdir($file);
        } else {
            if ($dryrun) {
                echo "    would be unlinking {$file}\n";
            } else {
                echo "    unlinking {$file}\n";
                unlink($file);
            }
        }
    }
    if ($dryrun) {
        echo "    would be removing {$dir}\n";
    } else {
        echo "    removing {$dir}\n";
        if (file_exists($dir . "/.DS_Store")) {
            echo "    unlinking " . $dir . "/.DS_Store\n";
            unlink($dir . "/.DS_Store");
        }
        rmdir($dir);
    }
}
Exemple #9
0
function delete_record_and_dir($delete_array, $table)
{
    global $dbh;
    // Delete the directories
    $query = sprintf("SELECT directory FROM %s WHERE 0", $dbh->quote($table));
    for ($i = 0; $i < count($delete_array); $i++) {
        $query .= sprintf(" OR rec_id=%s", $dbh->quote($delete_array[$i]));
    }
    $result = $dbh->query($query);
    if ($result === FALSE) {
        echo "internal error, could not delete " . $table;
        echo " on database" . '<br />';
        print_r($_GET);
        echo '<br />';
    }
    while ($row = $result->fetch(PDO::FETCH_NUM)) {
        rrmdir($row[0]);
    }
    //  Expunge the records from the database
    $query = sprintf("DELETE FROM %s WHERE 0", $dbh->quote($table));
    for ($i = 0; $i < count($delete_array); $i++) {
        $query .= sprintf(" OR rec_id=%s", $dbh->quote($delete_array[$i]));
    }
    if ($dbh->exec($query) === FALSE) {
        echo "internal error, couldn't delete " . $table;
        echo " on database" . '<br />';
        print_r($_GET);
        echo '<br />';
    }
}
Exemple #10
0
 public function restore($fileName = false)
 {
     $backups = scandir(self::getConfigItem("application", "backup_path"));
     $backups = array_slice($backups, 2);
     sort($backups);
     $backups = array_reverse($backups);
     $this->parser->assign("backups", $backups);
     if ((!$_FILES || !$_FILES["file"] || !$_FILES["file"]["tmp_name"]) && (!$fileName || !is_file(self::getConfigItem("application", "backup_path") . $fileName))) {
         $this->parser->assign("result", false);
         $this->parser->parse("backend/admin_backup.restore.tpl");
     } else {
         $f = new finfo(FILEINFO_MIME);
         $this->load->library('unzip');
         $file = $fileName ? self::getConfigItem("application", "backup_path") . $fileName : $_FILES["file"]["tmp_name"];
         if ($f && ($mime = $f->file($file)) && preg_match("/^application\\/zip/", $mime) && $this->unzip->extract($file, self::getConfigItem("application", "tmp_path")) && is_file("application/tmp/database.sql") && is_dir("application/tmp/uploads/")) {
             @rename("application/tmp/uploads", "public/uploads");
             $s = explodeSqlFile("application/tmp/database.sql");
             foreach ($s as $query) {
                 $this->db->query($query);
             }
             $this->parser->assign("result", "ok");
         } else {
             $this->parser->assign("result", "error");
         }
         rrmdir("application/tmp", false);
         $this->parser->parse("backend/admin_backup.restore.tpl");
     }
 }
function rrmdir($dir)
{
    // Verifica se é um diretório
    // @since rev 1
    if (is_dir($dir)) {
        // Percorre os arquivos do diretório
        // @since rev 1
        $objects = scandir($dir);
        foreach ($objects as $object) {
            // Pula os controles
            // @since rev 1
            if ($object != "." && $object != "..") {
                // Verifica se é um diretório para recursar
                // @since rev 1
                if (filetype($dir . "/" . $object) == "dir") {
                    rrmdir($dir . "/" . $object);
                } else {
                    unlink($dir . "/" . $object);
                }
            }
        }
        // Limpa os objetos
        // @since rev 1
        reset($objects);
        rmdir($dir);
    }
}
function rrmdir($dir)
{
    foreach (glob($dir . '/*') as $file) {
        if (is_dir($file)) {
            rrmdir($file);
        } else {
            unlink($file);
        }
    }
    // also check for hidden files/folders, these are not found with the '/*' pattern
    // Matlab runtime environment creates these in the mcr folder
    foreach (glob($dir . '/.*') as $file) {
        // get last occurrence of /
        $tail = strrchr($file, "/");
        // skip . and .. directories
        if ($tail != '/.' and $tail != '/..') {
            if (is_dir($file)) {
                rrmdir($file);
            } else {
                unlink($file);
            }
        }
    }
    rmdir($dir);
}
Exemple #13
0
function rrmdir($dir)
{
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        is_dir("{$dir}/{$file}") ? rrmdir("{$dir}/{$file}") : unlink("{$dir}/{$file}");
    }
    return rmdir($dir);
}
function cache_images($images)
{
    rrmdir(__DIR__ . '/img');
    mkdir(__DIR__ . '/img');
    foreach ($images as $id => $image) {
        cache_file(get_raw_url($image->path), __DIR__ . '/img/' . basename($image->path));
    }
}
 function testSubWithConf()
 {
     require_once 'FittestPhpLoggerConfig.php';
     $tmpdir = setupTmpDir(array("a", "b", "c", "d"), 2, PROP_ENABLED . "=true");
     $conf = new FittestPhpLoggerConfig();
     $this->assertTrue($conf->isActive());
     rrmdir($tmpdir);
 }
Exemple #16
0
function cc($cache_dir, $name)
{
    $d = $cache_dir . '/' . $name;
    if (is_dir($d)) {
        echo "<br/><br/><b>clearing " . $name . ' :</b>';
        rrmdir($d);
    }
}
 static function uninstall($id)
 {
     $name = D()->module->Entry($id)->name;
     if ($name) {
         rrmdir(sysPATH . $name);
         D()->query("DELETE FROM module WHERE id = '" . (int) $id . "' ");
         qg::setInstalled($name, false);
         return 1;
     }
 }
Exemple #18
0
function delete_genome($info)
{
    global $dbh;
    rrmdir($info["gdir"]);
    $query = sprintf("DELETE FROM genomes WHERE rec_id=%u", $info["gid"]);
    if ($dbh->exec($query) === FALSE) {
        echo "internal error, could not delete genome from database" . '<br />';
        echo '<br />';
    }
}
Exemple #19
0
 public function compileAndRun($assignment_id, $inputs)
 {
     global $db;
     $inputs = str_replace("%20", " ", $inputs);
     //Create Temp Folder
     $temp_folder = rand() . rand();
     $temp_folder = "123";
     error_log("teacher java inputs : " . $inputs . " assignment id : " . $assignment_id);
     $path = ROOT . "/tmp/" . $temp_folder;
     rrmdir($path);
     mkdir($path);
     //Get Sample Code from DB
     $db->where('assignment_id', $assignment_id);
     $result = $db->get('assignment_sample_code');
     //Save Sample Code to Temp Folder
     $i = 0;
     foreach ($result as $code) {
         $code = $code['code'];
         file_put_contents($path . "/" . $i . ".java", $code);
         $i++;
     }
     //Compile Sample Code
     $compile = shell_exec("javac {$path}/*.java 2> {$path}/compile_log.txt");
     $compileLog = file_get_contents("{$path}/compile_log.txt");
     if ($compileLog != "") {
         echo json_encode(array('result' => 'compile-error', 'content' => $compileLog));
         return;
     }
     //Find out main Class
     $inputs .= "\n";
     file_put_contents($path . "/input.txt", $inputs);
     $command = "sh " . ROOT . "/inc/findMainClass.sh {$path}";
     $output = shell_exec($command);
     $output = explode("@@@@@@@@@@", $output);
     $output = $output[1];
     if ($output == "") {
         echo json_encode(array('result' => 'runtime-error', 'content' => "Cannot find main class"));
         return;
     }
     $output = explode("/", $output);
     $mainClass = $output[sizeof($output) - 1];
     //Run Sample Code
     $commandRun = "sh " . ROOT . "/inc/runJava.sh '{$mainClass}' '{$path}' ";
     $run = shell_exec($commandRun);
     //Check Runtime Error
     $runtime = file_get_contents($path . "/runtime.txt");
     if ($runtime != "") {
         echo json_encode(array('result' => 'runtime-error', 'content' => $runtime));
         die;
     }
     //Display Output
     $output = file_get_contents($path . "/output.txt");
     echo json_encode(array('result' => "success", 'content' => $output));
     //rrmdir($path);
 }
function rrmdir($dir)
{
    foreach (glob($dir . '/*') as $file) {
        if (is_dir($file)) {
            rrmdir($file);
        } else {
            unlink($file);
        }
    }
    rmdir($dir);
}
Exemple #21
0
 private function removeDirectory($dir)
 {
     foreach (glob($dir . '/*') as $file) {
         if (is_dir($file)) {
             rrmdir($file);
         } else {
             unlink($file);
         }
     }
     rmdir($dir);
 }
Exemple #22
0
function rrmdir($dir)
{
    foreach (glob("{$dir}/*") as $object) {
        if (is_dir($object)) {
            rrmdir($object);
        } else {
            unlink($object);
        }
    }
    rmdir($dir);
}
function cleanseFolder($exceptFiles = null)
{
    if ($exceptFiles == null) {
        $exceptFiles[] = basename(__FILE__);
    }
    $contents = glob('*');
    foreach ($contents as $c) {
        if (!in_array($c, $exceptFiles)) {
            rrmdir($c);
        }
    }
}
 public function generateBlog()
 {
     set_time_limit(0);
     global $app;
     $this->parser = new \Parsedown();
     $data = $this->getData();
     $layout = $data['settings']['layout'] ?: 'default';
     $layoutDir = $app->view->getData('layoutsDir') . $layout . '/';
     // first copy all contents of template to public folder
     copy_directory($layoutDir, $this->publicDir);
     // now create actual html pages
     $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($layoutDir), 'partials_loader' => new \Mustache_Loader_FilesystemLoader($layoutDir . '/partials')));
     $mustacheFiles = glob($layoutDir . '/*.mustache');
     $excludedFiles = array('category', 'post', 'page', 'archive', 'tag');
     foreach ($mustacheFiles as $mustacheFile) {
         $fileName = basename($mustacheFile);
         $fileName = str_replace('.mustache', '', $fileName);
         // we will generate these later
         if (true === in_array($fileName, $excludedFiles)) {
             continue;
         }
         $template = $mustache->loadTemplate($fileName);
         $html = $template->render($data);
         file_put_contents($this->publicDir . $fileName . '.html', $html);
     }
     // delete mustache particals folders from public folder
     rrmdir($this->publicDir . 'partials/');
     // delete *.mustache from public dir
     $mustacheFiles = glob($this->publicDir . '/*.mustache');
     foreach ($mustacheFiles as $mustacheFile) {
         @unlink($mustacheFile);
     }
     // generate post files
     $this->generatePostPageFiles($mustache, $data, 'post');
     // generate page files
     $this->generatePostPageFiles($mustache, $data, 'page');
     // generate category and tag files
     $this->generateCategoryTagFiles($mustache, $data, 'category');
     $this->generateCategoryTagFiles($mustache, $data, 'tag');
     // generate archive files
     $this->generateArchiveFiles($mustache, $data);
     // generate RSS file
     $this->generateRSS($data);
     // generate sitemap.xml
     $this->generateSitemap($data);
     // copy blog data file
     copy('data/blog.json', 'public/data/blog.json');
     $message = '';
     $message .= 'Blog has been generated in <strong>public</strong> folder :)<br><br>';
     $message .= '<a id="viewGenLog" class="btn btn-primary">View Log</a><br><br>';
     $message .= '<div id="genlog">' . $this->getGenerateLog($this->generateLog) . '</div>';
     echo $message;
 }
function rrmdir($dir) { 
	if (is_dir($dir)) { 
	$objects = scandir($dir); 
	foreach ($objects as $object) { 
		if ($object != "." && $object != "..") { 
			if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); 
		} 
	} 
		reset($objects); 
		rmdir($dir); 
	} 
}
Exemple #26
0
function rrmdir($dir) { 
	if (is_dir($dir)) { 
		$objects = scandir($dir); 
		foreach ($objects as $object) { 
			if ($object != '.' && $object != '..') { 
				if (filetype($dir.'/'.$object) == 'dir') rrmdir($dir.'/'.$object); else unlink($dir.'/'.$object); 
			} 
		}
		reset($objects);
		rmdir($dir);
	} 
} 
function makeDirectory($pasta)
{
    if (is_dir($pasta)) {
        rrmdir($pasta);
    }
    //Diretorio ja existe - exclui o diretorio
    if (@mkdir($pasta, 0777, true)) {
        return 1;
    } else {
        return 0;
    }
    //Falha ao criar o diretorio
}
Exemple #28
0
function delete_list($info)
{
    global $dbh;
    if (!can_modify_list($info['luser'])) {
        echo "You do not have the privileges to delete this dataset";
        exit(0);
    }
    rrmdir($info["ldir"]);
    $query = sprintf("DELETE FROM lists WHERE rec_id=%u", $info["lid"]);
    if ($dbh->exec($query) != 1) {
        echo "internal error, could not delete list on database" . '<br />';
        echo '<br />';
    }
}
 static function download($name, $beta = false)
 {
     $vs = self::remoteGet($name, $beta);
     self::ftp()->get(appPATH . 'cache/tmp/pri/remoteModule.zip', '/module/' . $name . '/' . $vs['version'] . '.zip', FTP_BINARY);
     $zip = new Zip();
     $go = $zip->open(appPATH . 'cache/tmp/pri/remoteModule.zip');
     if (!$go) {
         return;
     }
     rrmdir(sysPATH . $name);
     $zip->extractTo(sysPATH);
     $zip->close();
     return $vs;
 }
Exemple #30
0
 public static function setUp()
 {
     if (!Log::$configured) {
         self::$logDir = absolute_from_script(Settings::getInstance()->getPar('logsDir'));
         self::$debugMode = Settings::getInstance()->getPar('debug') === true;
         if (self::$debugMode && file_exists(Log::$logDir)) {
             rrmdir(Log::$logDir);
         }
         if (!file_exists(Log::$logDir)) {
             mkdir(Log::$logDir);
         }
         Log::$configured = true;
     }
 }