function getFolderSize($path) { $count_size = 0; $count = 0; $dir_array = scandir($path); foreach ($dir_array as $key => $filename) { if ($filename != ".." && $filename != ".") { if (is_dir($path . "/" . $filename)) { $new_foldersize = getFolderSize($path . "/" . $filename); $count_size = $count_size + $new_foldersize; } else { if (is_file($path . "/" . $filename)) { $count_size = $count_size + filesize($path . "/" . $filename); $count++; } } } } return $count_size; }
$line = $result->fetch_assoc(); if ($line["user"] == $user && (strpos($line["rights"], 'all') !== false || strpos($line["rights"], 'notes') !== false)) { $max_size = 26843545600; } else { $max_size = 0; } } elseif (isset($_SESSION["notes-user"])) { //check if teachers user exists an has permissions $user = $_SESSION["notes-user"]; $request = "SELECT * FROM teachers_users WHERE user = '******'"; $result = $connection->query($request); $line = $result->fetch_assoc(); if ($line["user"] == $user) { $max_size = $line["max_user_space"]; } else { $max_size = 0; } } else { $max_size = 0; } if (getFolderSize("../../../" . $config->plugin_notes_engine_fpath) + $_FILES['files']['size'] > $max_size * 1073741824) { echo '{"files":[{"error":"max user folder size exceeded or invalid user"}]}'; exit; } $options = ['upload_dir' => str_replace("core/modules/php/notes-engine-upload.php", "", $_SERVER['SCRIPT_FILENAME']) . $config->plugin_notes_engine_fpath . "/" . findPath($_POST["target"]) . "/", 'upload_url' => str_replace("core/modules/php", "", get_full_url()) . $config->plugin_notes_engine_fpath . "/" . findPath($_POST["target"]) . "/", 'inline_file_types' => '/\\.(?!(php|js|pl|cgi|html|css|xml|json|swf|jar|class|py|rb|sh|bat|fcgi|inc)).+$/i', 'accept_file_types' => '/\\.(?!(php|pl|cgi|sh|fcgi|inc)).+$/i']; $upload_handler = new UploadHandler($options); function get_full_url() { $https = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'on') === 0 || !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0; return ($https ? 'https://' : 'http://') . (!empty($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] . '@' : '') . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ($https && $_SERVER['SERVER_PORT'] === 443 || $_SERVER['SERVER_PORT'] === 80 ? '' : ':' . $_SERVER['SERVER_PORT'])) . substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')); }
echo '<ul>'; if (empty($rep[0]['id'])) { echo '<li>No reports</li>'; } else { foreach ($rep as $entry) { $type = empty($entry['reply_id']) ? 'post' : 'reply'; $id = empty($entry['reply_id']) ? $entry['post_id'] : $entry['reply_id']; echo '<li id="' . $entry['id'] . '"><a href="#" name="' . $entry['id'] . '" class="delLink">Delete</a> - ' . $type . ' nº <a href="' . config::$url . $entry['board'] . 'index.php?reply=' . $entry['post_id'] . '#' . $id . '">' . $id . '</a>: ' . $entry['reason'] . '</li>'; } } echo '</ul><br /><div align="right">[<a href="?admin&readall">Mark all as read</a>] [<a href="?admin">Admin menu</a>] </div>'; } elseif (isset($_GET['readall'])) { $reported->clear(); echo 'All reports marked as readed. [<a href="?admin&reported">Go back</a>]<div align="right"> [<a href="?admin">Admin menu</a>] </div>'; } else { echo 'Welcome ' . $_SESSION['user'] . '!<br />You are now logged in.<br />You will be able to delete all posts and replies and view users IP.<br />HaChan is using <strong>' . round(getFolderSize() / 1024 / 1024) . '</strong> Megabytes of disk space.<br /><div align="right">[<a href="?admin&reported">View Reported Posts</a>] [<a href="?admin&logout">Logout</a>] </div>'; } } echo '</div>'; } else { if ($_POST['Submit']) { $_SESSION['user'] = $_POST['user']; $_SESSION['pass'] = $_POST['pass']; echo 'Verifying data...'; header('refresh:1;url=?admin'); } else { echo '<form action="" method="post"> <table border="0"> <tr> <td>Username</td> <td><input name="user" type="text" id="user" /></td>
function getDiskUsage() { global $connection, $config; if (isset($_SESSION["notes-user"])) { //control if teachers user exists an has permissions $user = $_SESSION["notes-user"]; $request = "SELECT * FROM teachers_users WHERE user = '******'"; $result = $connection->query($request); $line = $result->fetch_assoc(); if ($line["user"] == $user) { $user = $line["user"]; } else { $user = ""; } } else { $user = ""; } if ($user == "") { echo "<p>Si è autenticati in modo backend, non è possibile visualizzare lo spazio utilizzato dall'utente.<br>Per vedere lo spazio utlizzato per utente utilizzare la backend</p>"; } else { $space_percent = round(getFolderSize($config->plugin_notes_engine_fpath . "/" . $user) / ($line["max_user_space"] * 1073741824) * 100, 2); $percent = intval($space_percent); echo "<p><b>Utente</b>: {$user}"; echo "<div class='progress'>\n <div class='progress-bar' role='progressbar' aria-valuenow='60' aria-valuemin='0' aria-valuemax='100' style='width: {$percent}%;'>\n {$percent}%\n </div>\n </div>"; $used_space = formatBytes(getFolderSize($config->plugin_notes_engine_fpath . "/" . $user)); $max_space = formatBytes($line["max_user_space"] * 1073741824); echo "Si sta utilizzando lo {$space_percent} % di spazio disponibile ({$used_space} su {$max_space})"; } }
function generate_users_formlist() { global $auto_restrict; if (is_user_admin()) { $arraykey = array_keys($auto_restrict['users']); $firstkey = array_shift($arraykey); echo '<ul>' . "\n"; foreach ($auto_restrict['users'] as $key => $user) { if ($firstkey != $key) { $size = e('empty', false); // le dossier utilisateur n'est pas créé à la création du compte mais à la 1er connexion if (is_dir($_SESSION['upload_root_path'] . $user['login'])) { $items = count(glob($_SESSION['upload_root_path'] . $user['login'] . '/*', GLOB_BRACE)); // on compte le nombre d'éléments du dossier if ($items != 0) { $size = getFolderSize($_SESSION['upload_root_path'] . $user['login']); } // taille du dossier } echo '<li>' . "\n"; echo '<label>'; echo '<input type="checkbox" name="user_key[]" value="' . $key . '"/>'; newToken(); echo '<span>' . $user['login'] . ' (' . $size . ')</span>'; echo '</li>' . "\n"; } } echo '</ul>' . "\n" . '<p class="clear"><input id="submit" type="submit" class="btn" value="Ok" /></p>' . "\n"; } }