Skip to content

Commit

Permalink
Fix testing
Browse files Browse the repository at this point in the history
  • Loading branch information
theaquarium committed Dec 22, 2020
1 parent 85c83f7 commit 6dd74ba
Show file tree
Hide file tree
Showing 18 changed files with 77,476 additions and 51,324 deletions.
2 changes: 1 addition & 1 deletion src/create_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

session_start();
auth_user(true);
auth_user($config, true);

if (isset($_SESSION['logged_in']) && $_SESSION['logged_in']) {
unset($_SESSION['message']);
Expand Down
2 changes: 1 addition & 1 deletion src/delete_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include 'functions.php';

session_start();
auth_user();
auth_user($config);

if (isset($_GET['files']) && is_array($_GET['files'])) {
if (isset($config['enable_delete']) && $config['enable_delete']) {
Expand Down
2 changes: 1 addition & 1 deletion src/download_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$config = include 'merge_config.php';

session_start();
auth_user();
auth_user($config);

if (!isset($config['enable_updater']) || !$config['enable_updater']) {
header('Location: '.$config['base_url']);
Expand Down
11 changes: 3 additions & 8 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ function join_paths() {
return $protocol_str.$path_joined;
}

function create_webmanifest() {
$config = include 'merge_config.php';
function create_webmanifest($config) {
$base_host = parse_url($config['base_url'], PHP_URL_PATH);
$manifest = [
'name' => $config['page_title'],
Expand Down Expand Up @@ -93,9 +92,7 @@ function create_webmanifest() {
}
}

function get_file_target($original_file_name, $new_name) {
$config = include 'merge_config.php';

function get_file_target($original_file_name, $new_name, $config) {
$extension = pathinfo($original_file_name, PATHINFO_EXTENSION);
$target = null;
$first_run = true;
Expand Down Expand Up @@ -247,9 +244,7 @@ function show_error_page($message) {
die();
}

function auth_user($ip_only=false){
$config = include 'merge_config.php';

function auth_user($config, $ip_only=false){
if(
!empty($config['allowed_ips']) &&
!in_array(get_ip(), $config['allowed_ips'])
Expand Down
2 changes: 1 addition & 1 deletion src/generate_custom_uploader_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include 'functions.php';

session_start();
auth_user();
auth_user($config);

$result_json = [
'Name' => "{$config['page_title']}",
Expand Down
2 changes: 1 addition & 1 deletion src/generate_shell_uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include 'functions.php';

session_start();
auth_user();
auth_user($config);

$upload_url = join_paths($config['base_url'], 'upload_text.php');
$key = join_paths($config['secure_key']);
Expand Down
2 changes: 1 addition & 1 deletion src/generate_zip_of_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include 'functions.php';

session_start();
auth_user();
auth_user($config);

ini_set("memory_limit", "-1");
set_time_limit(0);
Expand Down
4 changes: 2 additions & 2 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
$config = include 'merge_config.php';
include 'functions.php';
session_start();
auth_user();
auth_user($config);

create_webmanifest();
create_webmanifest($config);

if (!empty($_SESSION) && isset($_SESSION['delete_release']) && $_SESSION['delete_release']) {
delete_files(join_paths(getcwd(), 'release'));
Expand Down
4 changes: 2 additions & 2 deletions src/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}

session_start();
auth_user(true);
auth_user($config, true);

if (isset($_SESSION['logged_in']) && $_SESSION['logged_in']) {
unset($_SESSION['message']);
Expand All @@ -46,7 +46,7 @@
file_put_contents($login_file_path, json_encode($login_file));
}

create_webmanifest();
create_webmanifest($config);

?>
<!DOCTYPE html>
Expand Down
2 changes: 1 addition & 1 deletion src/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include 'functions.php';

session_start();
auth_user();
auth_user($config);

log_out();
header('Location: '.join_paths($config['base_url'], 'login'));
Expand Down
2 changes: 1 addition & 1 deletion src/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
die();
}

create_webmanifest();
create_webmanifest($config);

?>
<!DOCTYPE html>
Expand Down
6 changes: 3 additions & 3 deletions src/rename_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include 'functions.php';

session_start();
auth_user();
auth_user($config);

if (isset($config['enable_rename']) && $config['enable_rename']) {
if (isset($_GET['oldname']) && isset($_GET['newname'])) {
Expand All @@ -19,9 +19,9 @@
$newfile_pathinfo = pathinfo($newfile_basename);
$extension_exists = isset($newfile_pathinfo['extension']) && $newfile_pathinfo['extension'] !== '';
if ($extension_exists) {
$target = get_file_target($newfile_basename, false, $newfile_pathinfo['filename']);
$target = get_file_target($newfile_basename, false, $newfile_pathinfo['filename'], $config);
} else {
$target = get_file_target(basename($old_path), false, $newfile_pathinfo['filename']);
$target = get_file_target(basename($old_path), false, $newfile_pathinfo['filename'], $config);
}

if (rename($old_path, $target)) {
Expand Down
5 changes: 4 additions & 1 deletion src/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

include '../functions.php';

$config = include '../merge_config.php';

session_start();
auth_user();
auth_user($config);

// Check that this isn't a rollback update to not overwrite rollback files
$update_version_path = join_paths(getcwd(), 'VERSION');
Expand Down Expand Up @@ -117,6 +119,7 @@
}
}

// Reinclude updated config
$config = include '../merge_config.php';

foreach ($UPDATE_FILES as $file) {
Expand Down
14 changes: 7 additions & 7 deletions src/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@

switch ($config['sharex_upload_naming_scheme']) {
case 'keep':
$target = get_file_target($_FILES['fileupload']['name'], $filename);
$target = get_file_target($_FILES['fileupload']['name'], $filename, $config);
break;
case 'provided':
$target = get_file_target($_FILES['fileupload']['name'], $_POST['name']);
$target = get_file_target($_FILES['fileupload']['name'], $_POST['name'], $config);
break;
case 'date':
$target = get_file_target($_FILES['fileupload']['name'], date($config['upload_date_format']));
$target = get_file_target($_FILES['fileupload']['name'], date($config['upload_date_format']), $config);
break;
default:
$target = get_file_target($_FILES['fileupload']['name'], '');
$target = get_file_target($_FILES['fileupload']['name'], '', $config);
break;
}

Expand Down Expand Up @@ -65,13 +65,13 @@

switch ($config['gallery_upload_naming_scheme']) {
case 'keep':
$target = get_file_target($_FILES['fileupload']['name'], $filename);
$target = get_file_target($_FILES['fileupload']['name'], $filename, $config);
break;
case 'date':
$target = get_file_target($_FILES['fileupload']['name'], date($config['upload_date_format']));
$target = get_file_target($_FILES['fileupload']['name'], date($config['upload_date_format']), $config);
break;
default:
$target = get_file_target($_FILES['fileupload']['name'], '');
$target = get_file_target($_FILES['fileupload']['name'], '', $config);
break;
}

Expand Down
12 changes: 6 additions & 6 deletions src/upload_text.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

if ($filename_no_extension === '') {
if ($config['text_upload_default_naming_scheme'] === 'date') {
$target = get_file_target($file_basename, date($config['upload_date_format']));
$target = get_file_target($file_basename, date($config['upload_date_format']), $config);
} else {
$target = get_file_target($file_basename, '');
$target = get_file_target($file_basename, '', $config);
}
} else {
$target = get_file_target($file_basename, $filename_no_extension);
$target = get_file_target($file_basename, $filename_no_extension, $config);
}

$dir_path = join_paths(
Expand Down Expand Up @@ -74,12 +74,12 @@

if ($filename_no_extension === '') {
if ($config['text_upload_default_naming_scheme'] === 'date') {
$target = get_file_target($file_basename, date($config['upload_date_format']));
$target = get_file_target($file_basename, date($config['upload_date_format']), $config);
} else {
$target = get_file_target($file_basename, '');
$target = get_file_target($file_basename, '', $config);
}
} else {
$target = get_file_target($file_basename, $filename_no_extension);
$target = get_file_target($file_basename, $filename_no_extension, $config);
}

$dir_path = join_paths(
Expand Down
2 changes: 1 addition & 1 deletion src/verify_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include 'functions.php';

session_start();
auth_user(true);
auth_user($config, true);

if (isset($_SESSION['logged_in']) && $_SESSION['logged_in']) {
unset($_SESSION['message']);
Expand Down
6 changes: 3 additions & 3 deletions tests/FileNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function fileNameHasRightExtensionRandomName(): void
$original_file_name = "TestPngFile.png";

$correct = $original_file_name;
$test = get_file_target($original_file_name, '');
$test = get_file_target($original_file_name, '', $GLOBALS['config']);

$this->assertEquals(
pathinfo($correct, PATHINFO_EXTENSION),
Expand All @@ -39,7 +39,7 @@ public function fileNameHasRightExtensionNoRandomName(): void
$post_name = "07.53.17-08.11.19";

$correct = $original_file_name;
$test = get_file_target($original_file_name, $post_name);
$test = get_file_target($original_file_name, $post_name, $GLOBALS['config']);

$this->assertEquals(
pathinfo($correct, PATHINFO_EXTENSION),
Expand All @@ -54,7 +54,7 @@ public function fileNameHasRightNameNoRandomName(): void
$post_name = "testname";

$correct = $post_name.'.png';
$test = get_file_target($original_file_name, $post_name);
$test = get_file_target($original_file_name, $post_name, $GLOBALS['config']);

$this->assertEquals(
$correct,
Expand Down
Loading

0 comments on commit 6dd74ba

Please sign in to comment.