function clean_d() { $dh1 = opendir(ROOT_PATH . '/d/'); if (!$dh1) { return; } # Error while (($file1 = readdir($dh1)) !== false) { if ($file1[0] == '.' || !is_dir(ROOT_PATH . '/d/' . $file1)) { continue; } # Hidden # Clean sub-d level 1 $dh2 = opendir(ROOT_PATH . '/d/' . $file1); if (!$dh2) { continue; } # Error while (($file2 = readdir($dh2)) !== false) { if ($file2[0] == '.' || !is_dir(ROOT_PATH . '/d/' . $file1 . '/' . $file2)) { continue; } # Hidden # Okay, we got key! $code = $file1 . $file2; $res = ldb_select_one('upload', array('id'), $code, 'code'); if (!$res && !ldb_error()) { # Delete this f**k'n file echo 'Deleting: ' . ROOT_PATH . '/d/' . $file1 . '/' . $file2 . "\n"; recursive_remove_directory(ROOT_PATH . '/d/' . $file1 . '/' . $file2); } } } }
/** * Recursively delete an entire directory. * * @since 4.6 * @package all * @param string $directory The dir you want to remove. * @param bool $empty Should the dir remain empty? * @return bool */ function recursive_remove_directory($directory, $empty = false) { if (substr($directory, -1) == '/') { $directory = substr($directory, 0, -1); } if (!file_exists($directory) || !is_dir($directory)) { return false; } elseif (is_readable($directory)) { $handle = opendir($directory); while (false !== ($item = readdir($handle))) { if ($item != '.' && $item != '..') { $path = $directory . '/' . $item; if (is_dir($path)) { recursive_remove_directory($path); } else { unlink($path); } } } closedir($handle); if (!$empty) { if (!rmdir($directory)) { return false; } } } return true; }
public function actionClear() { $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'cache'; switch ($type) { case 'cache': if (Yii::app()->cache instanceof CApcCache) { // Not support Cache for APC Cache user()->setFlash('error', t('cms', 'Not support for APC Cache!')); } else { if (Yii::app()->cache->flush()) { user()->setFlash('success', t('cms', 'Cache cleared!')); } else { user()->setFlash('error', t('cms', 'Error whilte clearing cache!')); } } break; case 'asset': # Clear Asset Cache $path = Yii::getPathOfAlias('webroot.assets'); $get_sub_folders = get_subfolders_name($path); foreach ($get_sub_folders as $folder) { recursive_remove_directory($path . DIRECTORY_SEPARATOR . $folder); } user()->setFlash('success', t('cms', 'Assets cleared!')); break; } $this->redirect(Yii::app()->createUrl('cache/default/index')); }
/** * @param string $directory * @param bool $deleteDir * @return success * implementation from http://lixlpixel.org/recursive_function/php/recursive_directory_delete/ */ public static function unlinkRecursive($directory, $deleteDir = FALSE) { if (substr($directory, -1) == '/') { $directory = substr($directory, 0, -1); } if (!file_exists($directory) || !is_dir($directory)) { return FALSE; } elseif (is_readable($directory)) { $handle = opendir($directory); while (FALSE !== ($item = readdir($handle))) { if ($item != '.' && $item != '..') { $path = $directory . '/' . $item; if (is_dir($path)) { recursive_remove_directory($path); } else { unlink($path); } } } closedir($handle); if ($deleteDir == FALSE) { if (!rmdir($directory)) { return FALSE; } } } return TRUE; }
public function __construct() { $this->baseDirectory = 'renders/' . Season::getInstance()->nefub_id . '/' . date('Y') . '_wk' . date('W'); parent::__construct(); if (isset($_GET['clear']) && $_GET['clear'] == 1 && (isset($_GET['clearall']) && $_GET['clearall'] == 1)) { recursive_remove_directory($this->baseDirectory); } }
function recursive_remove_directory($directory, $empty = TRUE) { // if the path has a slash at the end we remove it here if (substr($directory, -1) == '../cache') { $directory = substr($directory, 0, -1); } // if the path is not valid or is not a directory ... if (!file_exists($directory) || !is_dir($directory)) { // ... we return false and exit the function return FALSE; // ... if the path is not readable } elseif (!is_readable($directory)) { // ... we return false and exit the function return FALSE; // ... else if the path is readable } else { // we open the directory $handle = opendir($directory); // and scan through the items inside while (FALSE !== ($item = readdir($handle))) { // if the filepointer is not the current directory // or the parent directory if ($item != '.' && $item != '..') { // we build the new path to delete $path = $directory . '/' . $item; // if the new path is a directory if (is_dir($path)) { // we call this function with the new path recursive_remove_directory($path); // if the new path is a file } else { // we remove the file unlink($path); } } } // close the directory closedir($handle); // if the option to empty is not set to true if ($empty == FALSE) { // try to delete the now empty directory if (!rmdir($directory)) { // return false if not possible return FALSE; } } //rebuild blank index.html files $html = ''; file_put_contents('../cache/index.html', $html); file_put_contents('../cache/admin_c/index.html', $html); file_put_contents('../cache/templates_c/index.html', $html); // return success return TRUE; } }
/** * * @global $htmlwarrior * @param string site_name What site to build */ public function build($arr = array()) { global $htmlwarrior, $txt; $site_path = $htmlwarrior->config['basepath'] . '/' . $arr['site_name']; // cleanup - delete contents of build dir prior to copy and compile recursive_remove_directory($site_path . '/' . $htmlwarrior->config['build_dir'], true); // compile templates // todo: also compile loggedin templates $files = array(); if ($handle = opendir($site_path . '/templates/pages')) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $tpl_files[] = $file; } } closedir($handle); foreach ($tpl_files as $tpl_file) { file_get_contents($htmlwarrior->config['baseurl'] . '/' . $arr['site_name'] . '/' . str_replace('.tpl', '.html', $tpl_file) . '?debug=0'); } } // copy dirs to build dir // all except build, templates, overlays and cfg $site_root_files = glob($site_path . '/*'); foreach ($site_root_files as $path) { if (is_dir($path)) { // check if dir is templates dir $path_templates = str_replace('/', '\\/', $htmlwarrior->config['path_templates']); $is_templates_dir = preg_match('/' . $path_templates . '$/imsU', $path, $mt); // check if dir is cfg dir $path_cfg = str_replace('/', '\\/', $htmlwarrior->config['path_cfg']); $is_cfg_dir = preg_match('/' . $path_cfg . '$/imsU', $path, $mt); // check if dir is build dir $path_build = str_replace('/', '\\/', $htmlwarrior->config['path_build']); $is_build_dir = preg_match('/' . $path_build . '$/imsU', $path, $mt); // check if dir is overlays dir $path_overlays = str_replace('/', '\\/', $htmlwarrior->config['path_overlays']); $is_overlays_dir = preg_match('/' . $path_overlays . '$/imsU', $path, $mt); if (!$is_templates_dir && !$is_cfg_dir && !$is_build_dir && !$is_overlays_dir) { $dir = end(explode('/', $path)); $target = $site_path . '/' . $htmlwarrior->config['build_dir'] . '/' . $dir; recursive_remove_directory($target); full_copy($path, $target); } } } printf($txt['site_build_done'], $arr['site_name'], $arr['return_url']); }
/** * * Will remove a directory deleting all its files. * * @see http://lixlpixel.org/recursive_function/php/recursive_directory_delete/ **/ function recursive_remove_directory($directory, $empty = FALSE) { if (substr($directory, -1) == '/') { $directory = substr($directory, 0, -1); } if (!file_exists($directory) || !is_dir($directory)) { return FALSE; } elseif (!is_readable($directory)) { return FALSE; } else { $handle = opendir($directory); while (FALSE !== ($item = readdir($handle))) { // if the filepointer is not the current directory // or the parent directory if ($item != '.' && $item != '..') { // we build the new path to delete $path = $directory . '/' . $item; // if the new path is a directory if (is_dir($path)) { // we call this function with the new path recursive_remove_directory($path); // if the new path is a file } else { // we remove the file unlink($path); } } } // close the directory closedir($handle); // if the option to empty is not set to true if ($empty == FALSE) { // try to delete the now empty directory if (!rmdir($directory)) { // return false if not possible return FALSE; } } // return success return TRUE; } }
/** * Proxies deleting a folder to the restore.php version * * @param string $folderName The path to the folder to be deleted * * @return void * * @since 3.5.1 */ public static function delete($folderName) { recursive_remove_directory($folderName); }
//izbriše definicijo $db->query('DELETE FROM cms_modules_def WHERE ID=' . $id . ''); } } echo "ok"; exit; } else { if ($db->filter('type') == 'DD_#com') { $id = $crypt->decrypt($db->filter('id')); $query = $db->fetch($db->query('SELECT ID, componentName, tables FROM cms_components_def WHERE ID="' . $id . '"')); //izbris datotek $q = $db->query('SELECT name FROM cms_domains'); while ($r = $db->fetch($q)) { if (is_dir('../../modules/' . $r['name'] . '/' . $query['componentName'])) { recursive_remove_directory('../../modules/' . $query['componentName']); recursive_remove_directory('../modules/' . $query['componentName']); } } //izbris iz system.xml if (ob_get_length() > 0) { ob_end_clean(); } header('Content-Type: text/xml;charset=UTF-8'); $xdoc = new DOMDocument('1.0', 'UTF-8'); $xdoc->formatOutput = true; $xdoc->preserveWhiteSpace = false; $xdoc->load('../modules/system.xml'); $xmlDialog = $xdoc->getElementsByTagName('dialog')->item(0); $newItems = $xmlDialog->getElementsByTagName('item'); $length = $newItems->length; for ($i = $length - 1; $i >= 0; $i--) {
public static function cleanCacheDir($aCacheGroup = self::GROUP_GLOBAL) { recursive_remove_directory(CACHEDIR_ROOT . $aCacheGroup); }
public function delete($book_id = 0) { if (empty($book_id)) { return false; } $this->load->helper('directory'); $this->db->select('slug'); $this->db->from($this->books_table); $this->db->where('book_id', $book_id); $query = $this->db->get(); $result = $query->result(); if (!isset($result[0])) { throw new Exception('Could not find book'); } $slug = $result[0]->slug; if (empty($slug)) { die('Could not determine slug.'); } if (file_exists($slug) && !recursive_remove_directory($slug)) { die('Could not remove directory from file structure.'); } $CI =& get_instance(); $CI->load->model('page_model', 'pages'); // NOTE: loading a model within a model $pages = $CI->pages->get_all($book_id); foreach ($pages as $page) { $CI->pages->delete($page->content_id); usleep(500); // .0005 seconds -- let MySQL locked tables catch up } $this->db->where('book_id', $book_id); $this->db->delete($this->books_table); $this->db->where('book_id', $book_id); $this->db->delete($this->user_book_table); return true; }
$extension = end(explode('.', $oldFile)); $path = str_replace($oldFile, '', $old); if (rename($old, $path . $newName . '.' . $extension)) { echo 'done'; } else { echo 'problem - ' . $old . ' - ' . $path . $newName . '.' . $extension; } } else { if ($db->is('delete')) { $old = $db->filter('path'); unlink($old); echo 'ok'; } else { if ($db->is('deletef')) { $old = $db->filter('path'); recursive_remove_directory($old); echo 'ok'; } else { if ($db->is('renamef')) { $old = $db->filter('path'); $newName = $db->filter('name'); $oldFile = end(explode('/', $old)); $new = str_replace($oldFile, $newName, $old); if (rename($old, $new)) { echo 'done'; } else { echo 'problem - ' . $old . ' - ' . $new; } } else { if ($db->is('newf')) { $old = $db->filter('path');
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ $_page_title = $step_desc[$language] . " " . (array_search($_GET['step'], $_SESSION['steps']) + 1) . " - " . $webgen_delete_title[$language]; // spracovanie formulara if (count($_POST)) { // sem spracovanie/osetrenie prislich premennych // presmerovani zpet na editaci $next_step = "3"; $next_type = "all"; header("Location: ./index.php?step={$next_step}&type={$next_type}"); exit; } echo "<h1>" . $webgen_delete_title[$language] . "</h1>"; if (strlen($_SESSION['step_all_2']['user_name']) > 2 && strlen($_SESSION['step_all_3']['delete_presentation_name']) > 2) { if (recursive_remove_directory("./presentations/" . $_SESSION['step_all_2']['user_name'] . "/" . $_SESSION['step_all_3']['delete_presentation_name'])) { echo "<h2 class=\"ok\">" . $webgen_delete_info[$language] . " " . $_SESSION['step_all_3']['delete_presentation_name'] . " " . $webgen_delete_info2[$language] . "</h2>"; } else { echo "<h2 class=\"error\">" . $webgen_delete_error[$language] . "</h2>"; } } else { echo "<h2 class=\"error\">" . $webgen_delete_error[$language] . "</h2>"; } ?> <form action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <input name="empty" type="hidden" />
include '../config.php'; include mnminclude . 'html1.php'; include mnminclude . 'link.php'; include mnminclude . 'user.php'; include mnminclude . 'smartyvariables.php'; check_referrer(); // require user to log in force_authentication(); // restrict access to admins $canIhaveAccess = 0; $canIhaveAccess = $canIhaveAccess + checklevel('admin'); if ($canIhaveAccess == 0) { header("Location: " . getmyurl('admin_login', $_SERVER['REQUEST_URI'])); die; } recursive_remove_directory('../cache', TRUE); ?> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title"><?php echo $main_smarty->get_config_vars('PLIGG_Visual_AdminPanel_Cleared_Cache'); ?> </h4> </div> <div class="modal-body"> <p><?php echo $main_smarty->get_config_vars('PLIGG_Visual_AdminPanel_Cleared_Cache_Message'); ?> </p>
function recursive_remove_directory($directory) { // if the path has a slash at the end we remove it here if (substr($directory, -1) == '/') { $directory = substr($directory, 0, -1); } // if the path is not valid or is not a directory ... if (!file_exists($directory) || !is_dir($directory)) { // ... we return false and exit the function return FALSE; // ... if the path is not readable } elseif (!is_readable($directory)) { // ... we return false and exit the function return FALSE; // ... else if the path is readable } else { // we open the directory $handle = opendir($directory); $postproc = AKFactory::getPostProc(); // and scan through the items inside while (FALSE !== ($item = readdir($handle))) { // if the filepointer is not the current directory // or the parent directory if ($item != '.' && $item != '..') { // we build the new path to delete $path = $directory . '/' . $item; // if the new path is a directory if (is_dir($path)) { // we call this function with the new path recursive_remove_directory($path); // if the new path is a file } else { // we remove the file $postproc->unlink($path); } } } // close the directory closedir($handle); // try to delete the now empty directory if (!$postproc->rmdir($directory)) { // return false if not possible return FALSE; } // return success return TRUE; } }
function recursive_remove_directory($directory, $empty = FALSE) { // if the path has a slash at the end we remove it here if (substr($directory, -1) == '/') { $directory = substr($directory, 0, -1); } // if the path is not valid or is not a directory ... if (!file_exists($directory) || !is_dir($directory)) { // ... we return false and exit the function return FALSE; // ... if the path is not readable } elseif (!is_readable($directory)) { // ... we return false and exit the function return FALSE; // ... else if the path is readable } else { // we open the directory $handle = opendir($directory); // and scan through the items inside while (FALSE !== ($item = readdir($handle))) { // if the filepointer is not the current directory // or the parent directory if ($item != '.' && $item != '..') { // we build the new path to delete $path = $directory . '/' . $item; // if the new path is a directory if (is_dir($path)) { // we call this function with the new path recursive_remove_directory($path); // if the new path is a file } else { // we remove the file unlink($path); } } } // close the directory closedir($handle); // if the option to empty is not set to true if ($empty == FALSE) { @rmdir($directory); } return TRUE; } }
function RestoreFromBackup($backuppath) { $unix = new unix(); $PidRestore = "/etc/artica-postfix/pids/zarafaRestore.pid"; $rm = $unix->find_program("rm"); $pid = $unix->get_pid_from_file($PidRestore); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n"; } return; } $pid = $unix->PIDOF_PATTERN("exec.zarafa-db.php --restorefrom"); if ($pid != getmypid()) { if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n"; } return; } } $mysql = $unix->find_program("mysql"); $pid = $unix->PIDOF_PATTERN("{$mysql}\\s+.*?--socket=/var/run/mysqld/zarafa-db.sock.*?database=zarafa"); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($PidRestore, getmypid()); $sock = new sockets(); $SourceDir = dirname($backuppath); $WORKDIR = $sock->GET_INFO("ZarafaDedicateMySQLWorkDir"); if ($WORKDIR == null) { $WORKDIR = "/home/zarafa-db"; } if (is_file("{$SourceDir}/ldap.ldif")) { RestoreFromBackup_progress("{restore_ldap_database}", 10); RestoreFromBackup_ldap("{$SourceDir}/ldap.ldif"); } $unix = new unix(); if (!is_file($backuppath)) { echo "Action: `{$backuppath}` no such file: ABORT!\n"; RestoreFromBackup_progress("{failed}", 100); return; } echo "Action: Removing Zarafa Database MySQL client `{$mysql}`....\n"; RestoreFromBackup_progress("Removing Zarafa Database", 30); $cmd = "{$mysql} --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa --execute=\"DROP DATABASE zarafa\" 2>&1"; $results = array(); exec("{$cmd}", $results); while (list($num, $ligne) = each($results)) { echo "MySQL: (Delete Database) {$ligne}\n"; } RestoreFromBackup_progress("Removing all content", 32); if (is_dir("{$WORKDIR}/data/zarafa")) { recursive_remove_directory("{$WORKDIR}"); } RestoreFromBackup_progress("Restarting MySQL service (recovery)", 40); echo "Action: Restarting MySQL service...\n"; echo "Action: Stopping MySQL service...\n"; stop(true); echo "Action: Starting MySQL service (InnoDB recovery mode)...\n"; start(true, true); while (list($num, $ligne) = each($results)) { echo "Service: {$ligne}\n"; } sleep(5); $ZARAFADB_PID = ZARAFADB_PID(); if (!$unix->process_exists($ZARAFADB_PID)) { RestoreFromBackup_progress("Failed to restart dedicated MySQL", 100); return; } RestoreFromBackup_progress("Stopping Zarafa server", 43); @unlink("/tmp/zarafa-upgrade-lock"); shell_exec("/etc/init.d/zarafa-server stop --force"); $pid = XZARAFA_SERVER_PID(); if ($unix->process_exists($pid)) { $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } RestoreFromBackup_progress("Restarting MySQL service (normal)", 45); echo "Action: Restarting MySQL service...\n"; echo "Action: Stopping MySQL service...\n"; stop(true); echo "Action: Starting MySQL service (InnoDB normal mode)...\n"; start(true, false); while (list($num, $ligne) = each($results)) { echo "Service: {$ligne}\n"; } sleep(2); $ZARAFADB_PID = ZARAFADB_PID(); if (!$unix->process_exists($ZARAFADB_PID)) { RestoreFromBackup_progress("Failed to restart dedicated MySQL", 100); return; } if (!$unix->is_socket("/var/run/mysqld/zarafa-db.sock")) { echo "Action: /var/run/mysqld/zarafa-db.sock waiting socket\n"; for ($i = 0; $i < 5; $i++) { if ($unix->is_socket("/var/run/mysqld/zarafa-db.sock")) { break; } echo "Action: Waiting zarafa-db.sock {$i}/4\n"; sleep(1); } } if (!$unix->is_socket("/var/run/mysqld/zarafa-db.sock")) { echo "Action: /var/run/mysqld/zarafa-db.sock no such socket\n"; RestoreFromBackup_progress("zarafa-db.sock no such socket", 100); return; } echo "Action: /var/run/mysqld/zarafa-db.sock OK\n"; echo "Action: create a freshed Zarafa database\n"; $ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath"); if ($ZarafaIndexPath == null) { $ZarafaIndexPath = "/var/lib/zarafa/index"; } RestoreFromBackup_progress("Cleaning/Stopping Zarafa search DBs", 50); if (is_dir($ZarafaIndexPath)) { recursive_remove_directory("{$ZarafaIndexPath}"); shell_exec("/etc/init.d/zarafa-search stop"); } RestoreFromBackup_progress("Create a freshed Zarafa database", 50); $results = array(); $cmd = "{$mysql} --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --execute=\"CREATE DATABASE zarafa\" 2>&1"; $results = array(); exec("{$cmd}", $results); while (list($num, $ligne) = each($results)) { echo "MySQL: (Create Database) {$ligne}\n"; } RestoreFromBackup_progress("Testing Database...", 51); if (!is_dir("{$WORKDIR}/data/zarafa")) { echo "Action: FAILED TO create a freshed Zarafa database: ABORT!!\n"; echo "Action: {$WORKDIR}/data/zarafa no such directory\n"; RestoreFromBackup_progress("FAILED to create a freshed Zarafa database", 100); return; } RestoreFromBackup_progress("Checks Database size", 53); databasesize(true); $gunzip = $unix->find_program("gunzip"); $SourceFileBase = basename($backuppath); $file_ext = $unix->file_ext($SourceFileBase); $tStart = time(); $nohup = $unix->find_program("nohup"); $backuppath1 = $unix->shellEscapeChars($backuppath); $cmd = "{$nohup} {$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa < {$backuppath1} >/root/mysqllog.txt 2>&1 &"; echo "Action: {$SourceFileBase} extension {$file_ext}\n"; echo "Action: Restoring From {$backuppath1}\n"; if ($file_ext == "gz") { echo "Action: Restoring From {$backuppath1} with uncompress..\n"; $cmd = "{$nohup} {$gunzip} -c {$backuppath1} |{$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa >/root/mysqllog.txt 2>&1 &"; } $size = @filesize($backuppath); $size = FormatBytes($size / 1024); echo "Action: Please wait, it should take time...\nAction: Do not shutdown the computer or restart the MySQL service!\n"; $results = array(); RestoreFromBackup_progress("{restoring_data} {$size} {please_wait} !", 70); $lastmd5 = null; $continue = true; shell_exec($cmd); $ALRDLO = array(); while ($continue) { $fileMD5 = @md5_file("/root/mysqllog.txt"); if ($fileMD5 != $lastmd5) { $LOGS = explode("\n", @file_get_contents("/root/mysqllog.txt")); while (list($num, $ligne) = each($LOGS)) { if (trim($ligne) == null) { continue; } if (isset($ALRDLO[md5($ligne)])) { continue; } $ALRDLO[md5($ligne)] = true; if (preg_match("#ERROR\\s+([0-9]+)\\s+\\(#", $ligne, $re)) { echo date("Y-m-d H:i:s") . " MySQL: FAILED !!! {$ligne}\n"; RestoreFromBackup_progress("{failed} {error} {$re[1]} ", 100); return; } echo date("Y-m-d H:i:s") . " MySQL: {$ligne}\n"; } $lastmd5 = $fileMD5; } $pid = $unix->PIDOF_PATTERN("{$mysql}\\s+.*?--socket=/var/run/mysqld/zarafa-db.sock.*?database=zarafa"); echo "Action: PID: {$pid}\n"; if (!$unix->process_exists($pid)) { echo "Action: injection stopped running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n"; $continue = false; break; } echo "Action: PID {$pid} running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . ", please wait...\n"; RestoreFromBackup_progress($unix->distanceOfTimeInWords($tStart, time(), true) . " {please_wait} !", 71); $continue = true; sleep(30); continue; } echo "Action: Done, took: " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n"; echo "Action: Please wait, Checks Database size\n"; RestoreFromBackup_progress("Checks Database size", 75); databasesize(true); RestoreFromBackup_progress("{restoring_data} {success}", 80); echo "Action: restart_services\n"; RestoreFromBackup_progress("{restart_services}", 90); $unix->THREAD_COMMAND_SET("/etc/init.d/zarafa-server restart"); echo "Action: Restore task done...\n"; echo "Action: You can close the windows now...\n"; RestoreFromBackup_progress("{done}", 100); die; }
function __construct($source, $target, $data) { require_once 'pclzip.lib.php'; include_once '/agata/include/util.inc'; $this->buffer = array(); $this->break_style = '<style:style style:name="AgataPageBreak" style:family="paragraph" style:parent-style-name="Standard">' . '<style:properties fo:break-before="page"/>' . '</style:style>'; $this->page_break = '<text:p text:style-name="AgataPageBreak"/>'; define(temp, '/tmp'); define("bar", '/'); $prefix = temp . bar . RemoveExtension($source); $zip = new PclZip($source); if (($list = $zip->listContent()) == 0) { adie("Error : " . $zip->errorInfo(true)); } recursive_remove_directory($prefix); if ($zip->extract(PCLZIP_OPT_PATH, $prefix) == 0) { adie("Error : " . $zip->errorInfo(true)); } $content = file_get_contents($prefix . '/content.xml'); # break xml tags $array_content = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', trim($content), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); //print_r($array_content); $section = 'start'; echo "antes for\n"; foreach ($array_content as $line) { // <text:section text:style-name="Sect1" text:name="header"> if (substr(trim($line), 0, 13) == '<text:section') { $pieces = explode('text:name="', $line); $section = substr($pieces[1], 0, -2); } else { if (substr(trim($line), 0, 14) == '</office:body>') { $section = 'end'; } } if ($line == '</office:automatic-styles>') { $line = $this->break_style . $line; } $this->buffer[$section][] = $line; //echo $section . "\n"; } echo "depois for\n"; print_r($this->buffer); $output = implode('', $this->buffer['start']); $break = false; foreach ($data as $line) { $sub = array(); $sub[] = array('01/01/2005', 'abertura'); $sub[] = array('02/01/2005', 'Software Livre'); $sub[] = array('03/01/2005', 'PHP-GTK'); $sub[] = array('04/01/2005', 'Agata Report'); $sub[] = array('05/01/2005', 'encerramento'); $sub[] = array('06/01/2005', 'encerramento2'); $sub[] = array('07/01/2005', 'encerramento3'); $sub[] = array('08/01/2005', 'encerramento4'); $sub[] = array('09/01/2005', 'encerramento5'); $sub[] = array('10/01/2005', 'encerramento6'); $sub[] = array('11/01/2005', 'encerramento7'); $sub[] = array('12/01/2005', 'encerramento8'); $output .= $this->printSection('header', $line, $break); $output .= $this->printSection('details', $line, $sub); $output .= $this->printSection('footer', $line); //$output .= $page_break; $break = true; while ($this->rest) { if ($this->repeat_header) { $output .= $this->printSection('header', $line, $break); } else { $output .= $this->page_break; } $output .= $this->printSection('details', $line, $this->rest); if ($this->repeat_footer) { $output .= $this->printSection('footer', $line); } } } $output .= implode('', $this->buffer['end']); echo strlen($output); echo "\n"; file_put_contents($prefix . '/content.xml', $output); $zip2 = new PclZip($target); foreach ($list as $file) { $zip2->add($prefix . '/' . $file['filename'], PCLZIP_OPT_REMOVE_PATH, $prefix); echo "Adding " . $file['filename'] . "\n"; } }
protected function parseContent($ODTfile) { try { $fh = null; $zip = new ZipArchive(); $tmpDirectory = "/tmp/Doc_" . time(); if ($zip->open($ODTfile) !== true) { throw new OpenDocumentParserException($ODTfile, OpenDocumentParserException::$ERROR_OPEN_ODT_FILE); } if ($zip->extractTo($tmpDirectory) !== true) { throw new OpenDocumentParserException($ODTfile . "\n" . $zip->getStatusString, OpenDocumentParserException::$ERROR_UNZIP_ODT); } $fh = fopen($tmpDirectory . DS . "content.xml", "r"); if (!$fh) { throw new OpenDocumentParserException($tmpDirectory . DS . "content.xml", OpenDocumentParserException::$ERROR_MISSING_XML_IN_ODT_FILE); } // We parse this document line by line, from begining to end letting // our callbacks do their job. while (!feof($fh)) { if (xml_parse($this->_parser, fgets($fh), feof($fh)) === 0) { throw new OpenDocumentParserException($tmpDirectory . DS . "content.xml", OpenDocumentParserException::$ERROR_PARSING_XML_FILE); } } // Callbacks may have not added last page. if (!empty($this->currentPageContent)) { $this->parsedPages[] = $this->currentPageContent; } } catch (OpenDocumentParserException $openEx) { if ($fh) { fclose($fh); } $zip->close(); recursive_remove_directory($tmpDirectory); throw $openEx; } if ($fh) { fclose($fh); } $zip->close(); recursive_remove_directory($tmpDirectory); }
$newname = strtolower(str_replace(' ', '_', $name)); if (!file_exists('../../templates/' . $user->domainName . '/' . $newname)) { mkdir('../../templates/' . $user->domainName . '/' . $newname, PER_FOLDER); chmod('../../templates/' . $user->domainName . '/' . $newname, PER_FOLDER); } $zip = new ZipArchive(); if ($zip->open('../temp/' . $number . '.zip') === TRUE) { $zip->extractTo('../../templates/' . $user->domainName . '/' . $newname . '/'); if ($zip->close()) { unlink('../temp/' . $number . '.zip'); $files = scandir('../../templates/' . $user->domainName . '/' . $newname . '/'); chmodAll('../../templates/' . $user->domainName . '/' . $newname . '/'); foreach ($files as &$value) { if (is_dir('../../templates/' . $user->domainName . '/' . $newname . '/' . $value) && ($value == "images" || $value == "img")) { setImages('../../templates/' . $user->domainName . '/' . $newname . '/' . $value . '/', $number); recursive_remove_directory('../../templates/' . $user->domainName . '/' . $newname . '/' . $value); } } $db->query('INSERT INTO cms_template (name,folder, domain) VALUES ("' . $name . '", "' . $newname . '", "' . $user->domain . '")'); echo 'ok'; } } exit; } else { if ($db->filter('type') == 'addlb') { $name = $db->filter('name'); $number = $db->filter('number'); $short = $db->filter('short'); if (!file_exists('../language/' . $short)) { mkdir('../language/' . $short, PER_FOLDER, true); chmod('../language/' . $short, PER_FOLDER);
public function clear_renders() { $msStart = microtime(true); $renderDirectory = 'renders/' . Season::getInstance()->nefub_id . '/' . date('Y') . '_wk' . date('W'); recursive_remove_directory($renderDirectory); // Voorpagina self::put('Render voorpagina '); self::render(HOST); // Agenda self::put('Render agenda '); self::render(HOST . '/agenda'); // hier moeten nog de individuele dagen komen // Uitslagen self::put('Render uitslagen '); self::render(HOST . '/uitslagen'); $modelRenders = array('team' => 'Team', 'poule' => 'Poule', 'competitie' => 'Competition', 'wedstrijd' => 'Game', 'persoon' => 'Person', 'locatie' => 'Location', 'club' => 'Club'); foreach ($modelRenders as $name => $class) { self::put('Render ' . $name . "pagina's"); $tableDescription = Database::getTableStructure($class); $where = array(); if ($tableDescription['season_nefub_id']) { $where['season_nefub_id'] = Season::getInstance()->nefub_id; } $aModels = Model::getAllModels($class, $where, 'nefub_id'); foreach ($aModels as $oModel) { if ($oModel->hasAttribute('name')) { self::put('Render ' . $name . "pagina voor " . $oModel->name); } else { self::put('Render ' . $name . "pagina voor #" . $oModel->nefub_id); } self::render(HOST . '/' . $name . '/' . $oModel->nefub_id); } } $msFinish = microtime(true); $msTotal = $msFinish - $msStart; $minutes = floor($msTotal / 60); $seconds = $msTotal % 60; $response = 'renders voltooid in ' . $minutes . ' minuut ' . $seconds . ' seconden<hr />'; self::put($response); return $response; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = new stdClass(); $file->name = $this->get_file_name($name, $type, $index, $content_range); $file->size = $this->fix_integer_overflow(intval($size)); $file->type = $type; if ($this->validate($uploaded_file, $file, $error, $index)) { $this->handle_form_data($file, $index); $upload_dir = $this->get_upload_path(); if (!is_dir($upload_dir)) { mkdir($upload_dir, $this->options['mkdir_mode'], true); } // clean out what's there recursive_remove_directory($upload_dir, $empty=true); $file_path = $this->get_upload_path($file->name); $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents( $file_path, fopen($uploaded_file, 'r'), FILE_APPEND ); } else { move_uploaded_file($uploaded_file, $file_path); } } else { // Non-multipart uploads (PUT method support) file_put_contents( $file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0 ); } $file_size = $this->get_file_size($file_path, $append_file); if ($file_size === $file->size) { if ($this->options['orient_image']) { $this->orient_image($file_path); } $file->url = $this->get_download_url($file->name); foreach($this->options['image_versions'] as $version => $options) { if ($this->create_scaled_image($file->name, $version, $options)) { if (!empty($version)) { $file->{$version.'_url'} = $this->get_download_url( $file->name, $version ); } else { $file_size = $this->get_file_size($file_path, true); } } } } else if (!$content_range && $this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } $file->size = $file_size; $this->set_file_delete_properties($file); } return $file; }
public function reverseFiles() { $javascript = new DOMDocument(); $javascript->load('../modules/javascript.xml'); $jsRoot = $javascript->getElementsByTagName("javascript")->item(0); $items = $javascript->getElementsByTagName("item"); $delItems = array(); foreach ($items as $item) { $attributes = array(); foreach ($item->attributes as $attrName => $attrNode) { $attributes[$attrName] = $attrNode->value; } if ($attributes['deleteId'] && $attributes['deleteId'] == $this->getUnique() . '_' . $this->getID()) { $delItems[] = $item; } } foreach ($delItems as $item) { $item->parentNode->removeChild($item); } $javascript->save('../modules/javascript.xml'); $css = new DOMDocument(); $css->load('../modules/css.xml'); $cssRoot = $css->getElementsByTagName("css")->item(0); $items = $css->getElementsByTagName("item"); $delItems = array(); foreach ($items as $item) { $attributes = array(); foreach ($item->attributes as $attrName => $attrNode) { $attributes[$attrName] = $attrNode->value; } if ($attributes['deleteId'] && $attributes['deleteId'] == $this->getUnique() . '_' . $this->getID()) { $delItems[] = $item; } } foreach ($delItems as $item) { $item->parentNode->removeChild($item); } $css->save('../modules/css.xml'); if (is_dir('../modules/' . $this->getUnique())) { recursive_remove_directory('../modules/' . $this->getUnique() . '/'); } if (is_dir('../../modules/' . $this->getUnique())) { recursive_remove_directory('../../modules/' . $this->getUnique() . '/'); } }
function delete($id) { // delete button is hidden in the page, but // check if parentid is not 0 $cate = $this->MCats->getCategory($id); $parentid = $cate['parentid']; if (!$parentid == 0) { $cat = $this->MCats->getCategory($id); $string = $cat['name']; $catname = createdirname($string); $catname = 'assets/images/' . $catname; recursive_remove_directory($catname, $empty = FALSE); $orphans = $this->MCats->checkOrphans($id); if (count($orphans)) { $this->session->set_userdata('orphans', $orphans); redirect('category/admin/reassign/' . $id, 'refresh'); } else { $this->MCats->deleteCategory($id); flashMsg('success', $this->lang->line('userlib_category_deleted')); redirect('category/admin/index', 'refresh'); } } else { $this->MCats->deleteCategory($id); flashMsg('success', $this->lang->line('userlib_category_deleted')); redirect('category/admin/index', 'refresh'); } }
function installbyPath($SourceFile) { $unix = new unix(); $mount = $unix->find_program("mount"); $umount = $unix->find_program("umount"); $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); if (!is_file($SourceFile)) { build_progress(110, "{$SourceFile} no such file"); events("Failed {$SourceFile} no such file..."); return; } build_progress(15, "Extracting " . basename($SourceFile)); events("Extract " . basename($SourceFile) . " Source package..."); if (is_dir("/root/VMwareArticaInstall")) { recursive_remove_directory("/root/VMwareArticaInstall"); } @mkdir("/root/VMwareArticaInstall", 0640, true); shell_exec("{$tar} -xf {$SourceFile} -C /root/VMwareArticaInstall/"); events("Extract " . basename($SourceFile) . " Source package done"); build_progress(20, "Extracting " . basename($SourceFile) . " success"); if (!is_file("/root/VMwareArticaInstall/vmware-tools-distrib/vmware-install.pl")) { build_progress(110, "vmware-install.pl no such file"); events("Failed /root/VMwareArticaInstall/vmware-tools-distrib/vmware-install.pl no such file"); recursive_remove_directory("/root/VMwareArticaInstall"); return; } build_progress(25, "Execute the setup..."); events("Launch setup vmware-install.pl"); if (!is_dir("/root/VMwareArticaInstall/vmware-tools-distrib")) { events("Failed /root/VMwareArticaInstall/vmware-tools-distrib no such directory"); build_progress(110, "vmware-tools-distrib no such directory"); return; } chdir("/root/VMwareArticaInstall/vmware-tools-distrib"); events("Installing VMWare Tools...."); $results = array(); exec("./vmware-install.pl --default 2>&1", $results); while (list($i, $line) = each($results)) { events("{$line}"); } build_progress(50, "Removing package"); recursive_remove_directory("/root/VMwareArticaInstall"); if (file_exists("/etc/init.d/vmware-tools")) { build_progress(55, "Starting VMWare Tools service"); events("Starting VMWare Tools service"); $results = array(); exec("/etc/init.d/vmware-tools start", $results); while (list($i, $line) = each($results)) { events("{$line}"); } } if (file_exists("/usr/bin/vmware-toolbox-cmd")) { events("VMWare Tools installed"); $results = array(); exec("/usr/bin/vmware-toolbox-cmd -v 2>&1", $results); while (list($i, $line) = each($results)) { events("{$line}"); } } if (is_dir("/root/VMwareArticaInstall")) { recursive_remove_directory("/root/VMwareArticaInstall"); } build_progress(80, "Indexing softwares database"); events("Indexing softwares database"); shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose " . time()); }
function clean($aspid = false) { $unix = new unix(); $sock = new sockets(); $pidfile = "/etc/artica-postfix/pids/zarafa-search-starter.pid"; if (!$aspid) { $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Engine Artica Task Already running PID {$pid} since {$time}mn\n"; } return; } } @file_put_contents($pidfile, getmypid()); $ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath"); if ($ZarafaIndexPath == null) { $ZarafaIndexPath = "/var/lib/zarafa/index"; } $rm = $unix->find_program("rm"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} directory {$ZarafaIndexPath}\n"; } stop(true); recursive_remove_directory($ZarafaIndexPath, true); start(true); }
function move_cp($sourcedir, $nextdir) { $unix = new unix(); if (is_link($sourcedir)) { $linkPath = @readlink($sourcedir); echo "{$sourcedir} is a link of \"{$linkPath}\"\n"; if ($linkPath == $nextdir) { echo "{$sourcedir} already moved\n"; continue; } $sourcedir = $linkPath; } $cp = $unix->find_program("cp"); $mv = $unix->find_program("mv"); $ln = $unix->find_program("ln"); $rm = $unix->find_program("rm"); @mkdir($nextdir, 0644, true); echo "Copy {$sourcedir}/* -> {$nextdir}/\n"; shell_exec("{$cp} -rfb {$sourcedir}/* {$nextdir}/"); echo "Remove {$sourcedir}\n"; recursive_remove_directory($sourcedir); echo "Linking {$nextdir} -> {$sourcedir}\n"; $cmd = "{$ln} -sf {$nextdir} {$sourcedir}"; echo "{$cmd}\n"; shell_exec($cmd); }
function albums_page_admin_deletealbum() { global $var1; //Check if an album was defined, and if the album exists. if (isset($var1) && file_exists(ALBUMS_DIR . '/' . $var1)) { recursive_remove_directory(ALBUMS_DIR . '/' . $var1); unlink(ALBUMS_DIR . '/' . $var1 . '.php'); } redirect('?module=albums', 0); }
function change_docx($file, $docname, $leadData) { // $dir = getcwd(); // echo $dir, "\n"; // echo $docname, "\n"; //file_put_contents("file.txt", "1"); // making a temp directory if (!is_dir("temp")) { mkdir("temp"); } else { recursive_remove_directory("temp", true); } file_put_contents("file.txt", "2"); //add for test //safeify the directory //$edir = escapeshellarg($dir); //unzip everything //system("unzip $file -d temp"); shell_exec("unzip {$file} -d temp"); // replace the tokens $c = file_get_contents("temp/word/document.xml"); $strres = updateValue($c, $leadData); unlink("temp/word/document.xml"); unlink("file.txt"); //@file_put_contents("temp/word/document1.xml",$c); @file_put_contents("temp/word/document.xml", $strres); // rezip if (is_file($docname)) { unlink($docname); } //выжные параметры для упаковки zip -> docx $toZip = array("_rels", "docProps", "word", "[Content_Types].xml", "customXml"); $cmd = "cd temp && zip -r ../files/{$docname} " . implode(" ", $toZip); shell_exec($cmd); //$fdocxname = "/files/$docname"; //rename($fdocxname,$fdocxname.'.docx'); //system($cmd); }