/*
* Uguu
*
- * @copyright Copyright (c) 2022 Go Johansson (nekunekus) <neku@pomf.se> <github.com/nokonoko>
+ * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
public static int $NAME_LENGTH;
public static string $ID_CHARSET;
- public static array $DOUBLE_DOTS;
public static array $BLOCKED_EXTENSIONS;
public static array $BLOCKED_MIME;
*/
public static function loadConfig()
{
- if (!file_exists('/Users/go.johansson/PERSONAL_REPOS/Uguu/dist.json')) {
+ if (!file_exists('/var/www/uguu/dist.json')) {
throw new Exception('Cant read settings file.', 500);
}
try {
$settings_array = json_decode(
- file_get_contents('/Users/go.johansson/PERSONAL_REPOS/Uguu/dist.json'),
+ file_get_contents('/var/www/uguu/dist.json'),
true
);
self::$DB_MODE = $settings_array['DB_MODE'];
self::$ID_CHARSET = $settings_array['ID_CHARSET'];
self::$BLOCKED_EXTENSIONS = $settings_array['BLOCKED_EXTENSIONS'];
self::$BLOCKED_MIME = $settings_array['BLOCKED_MIME'];
- self::$DOUBLE_DOTS = $settings_array['DOUBLE_DOTS'];
} catch (Exception) {
throw new Exception('Cant populate settings.', 500);
}
- (new Database())->assemblePDO();
+ Database::assemblePDO();
}
}
/**
* @throws Exception
*/
- public function dbCheckNameExists()
+ public static function dbCheckNameExists()
{
try {
$q = Settings::$DB->prepare('SELECT COUNT(filename) FROM files WHERE filename = (:name)');
/**
* @throws Exception
*/
- public function checkFileBlacklist()
+ public static function checkFileBlacklist()
{
try {
$q = Settings::$DB->prepare('SELECT hash, COUNT(*) AS count FROM blacklist WHERE hash = (:hash)');
/**
* @throws Exception
*/
- public function antiDupe()
+ public static function antiDupe()
{
try {
$q = Settings::$DB->prepare(
$result = $q->fetch();
if ($result['count'] > 0) {
Upload::$NEW_NAME_FULL = $result['filename'];
+ } else {
+ Upload::generateName();
}
} catch (Exception) {
throw new Exception('Cant check for dupes in DB.', 500);
/**
* @throws Exception
*/
- public function newIntoDB()
+ public static function newIntoDB()
{
try {
$q = Settings::$DB->prepare(
'VALUES (:hash, :orig, :name, :size, :date, :ip)'
);
$q->bindValue(':hash', Upload::$SHA1, PDO::PARAM_STR);
- $q->bindValue(':orig', strip_tags(Upload::$FILE_NAME), PDO::PARAM_STR);
+ $q->bindValue(':orig', Upload::$FILE_NAME, PDO::PARAM_STR);
$q->bindValue(':name', Upload::$NEW_NAME_FULL, PDO::PARAM_STR);
$q->bindValue(':size', Upload::$FILE_SIZE, PDO::PARAM_INT);
- $q->bindValue(':date', time(), PDO::PARAM_STR);
+ $q->bindValue(':date', time(), PDO::PARAM_INT);
$q->bindValue(':ip', Upload::$IP, PDO::PARAM_STR);
$q->execute();
} catch (Exception) {
}
-