mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 15:44:11 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
fb8d52d599
|
@ -304,14 +304,13 @@ class Ldap extends Model
|
||||||
|
|
||||||
// HUGE thanks to this article: https://stackoverflow.com/questions/68275972/how-to-get-paged-ldap-queries-in-php-8-and-read-more-than-1000-entries
|
// HUGE thanks to this article: https://stackoverflow.com/questions/68275972/how-to-get-paged-ldap-queries-in-php-8-and-read-more-than-1000-entries
|
||||||
// which helped me wrap my head around paged results!
|
// which helped me wrap my head around paged results!
|
||||||
\Log::info("ldap conn is: ".$ldapconn." basedn is: $base_dn, filter is: $filter - count is: $count. page size is: $page_size"); //FIXME - remove
|
|
||||||
// if a $count is set and it's smaller than $page_size then use that as the page size
|
// if a $count is set and it's smaller than $page_size then use that as the page size
|
||||||
$ldap_controls = [];
|
$ldap_controls = [];
|
||||||
//if($count == -1) { //count is -1 means we have to employ paging to query the entire directory
|
//if($count == -1) { //count is -1 means we have to employ paging to query the entire directory
|
||||||
$ldap_controls = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'iscritical' => false, 'value' => ['size'=> $count == -1||$count>$page_size ? $page_size : $count, 'cookie' => $cookie]]];
|
$ldap_controls = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'iscritical' => false, 'value' => ['size'=> $count == -1||$count>$page_size ? $page_size : $count, 'cookie' => $cookie]]];
|
||||||
//}
|
//}
|
||||||
$search_results = ldap_search($ldapconn, $base_dn, $filter, [], 0, /* $page_size */ -1, -1, LDAP_DEREF_NEVER, $ldap_controls); // TODO - I hate the @, and I hate that we get a full page even if we ask for 10 records. Can we use an ldap_control?
|
$search_results = ldap_search($ldapconn, $base_dn, $filter, [], 0, /* $page_size */ -1, -1, LDAP_DEREF_NEVER, $ldap_controls); // TODO - I hate the @, and I hate that we get a full page even if we ask for 10 records. Can we use an ldap_control?
|
||||||
\Log::info("did the search run? I guess so if you got here!");
|
\Log::debug("did the search run? I guess so if you got here!");
|
||||||
if (! $search_results) {
|
if (! $search_results) {
|
||||||
return redirect()->route('users.index')->with('error', trans('admin/users/message.error.ldap_could_not_search').ldap_error($ldapconn)); // TODO this is never called in any routed context - only from the Artisan command. So this redirect will never work.
|
return redirect()->route('users.index')->with('error', trans('admin/users/message.error.ldap_could_not_search').ldap_error($ldapconn)); // TODO this is never called in any routed context - only from the Artisan command. So this redirect will never work.
|
||||||
}
|
}
|
||||||
|
|
176
upgrade.php
176
upgrade.php
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');
|
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');
|
||||||
|
|
||||||
$required_version = '7.4.0';
|
$required_php_min = '7.4.0';
|
||||||
|
|
||||||
if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_getpwuid'))) {
|
if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_getpwuid'))) {
|
||||||
echo "Skipping user check as it is not supported on Windows or Posix is not installed on this server. \n";
|
echo "Skipping user check as it is not supported on Windows or Posix is not installed on this server. \n";
|
||||||
|
@ -15,6 +15,7 @@ if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_get
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Check if a branch or tag was passed in the command line,
|
// Check if a branch or tag was passed in the command line,
|
||||||
// otherwise just use master
|
// otherwise just use master
|
||||||
(array_key_exists('1', $argv)) ? $branch = $argv[1] : $branch = 'master';
|
(array_key_exists('1', $argv)) ? $branch = $argv[1] : $branch = 'master';
|
||||||
|
@ -23,25 +24,108 @@ echo "--------------------------------------------------------\n";
|
||||||
echo "WELCOME TO THE SNIPE-IT UPGRADER! \n";
|
echo "WELCOME TO THE SNIPE-IT UPGRADER! \n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
echo "This script will attempt to: \n\n";
|
echo "This script will attempt to: \n\n";
|
||||||
|
echo "- validate some very basic .env file settings \n";
|
||||||
echo "- check your PHP version and extension requirements \n";
|
echo "- check your PHP version and extension requirements \n";
|
||||||
|
echo "- check directory permissions \n";
|
||||||
echo "- do a git pull to bring you to the latest version \n";
|
echo "- do a git pull to bring you to the latest version \n";
|
||||||
echo "- run composer install to get your vendors up to date \n";
|
echo "- run composer install to get your vendors up to date \n";
|
||||||
echo "- run migrations to get your schema up to date \n";
|
echo "- run migrations to get your schema up to date \n";
|
||||||
echo "- clear out old cache settings\n\n";
|
echo "- clear out old cache settings\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "STEP 1: Checking PHP requirements: \n";
|
echo "STEP 1: Checking .env file: \n";
|
||||||
|
echo "- Your .env is located at ".getcwd()."/.env \n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
if (version_compare(PHP_VERSION, $required_version, '<')) {
|
|
||||||
|
// Check the .env looks ok
|
||||||
|
$env = file('.env');
|
||||||
|
$env_error_count = 0;
|
||||||
|
$env_good = '';
|
||||||
|
$env_bad = '';
|
||||||
|
|
||||||
|
// Loop through each line of the .env
|
||||||
|
foreach ($env as $line_num => $line) {
|
||||||
|
|
||||||
|
if ((strlen($line) > 1) && (strpos($line, "#") !== 0)) {
|
||||||
|
|
||||||
|
list ($env_key, $env_value) = $env_line = explode('=', $line);
|
||||||
|
|
||||||
|
// The array starts at 0
|
||||||
|
$show_line_num = $line_num+1;
|
||||||
|
|
||||||
|
$env_value = trim($env_value);
|
||||||
|
|
||||||
|
if ($env_key == 'APP_KEY') {
|
||||||
|
if (($env_value=='') || (strlen($env_value) < 20)) {
|
||||||
|
$env_bad .= "✘ APP_KEY ERROR in your .env on line #'.$show_line_num.': Your APP_KEY should not be blank. Run `php artisan key:generate` to generate one.\n";
|
||||||
|
} else {
|
||||||
|
$env_good .= "√ Your APP_KEY is not blank. \n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($env_key == 'APP_URL') {
|
||||||
|
|
||||||
|
$app_url_length = strlen($env_value);
|
||||||
|
|
||||||
|
if (($env_value!="null") && ($env_value!="")) {
|
||||||
|
$env_good .= '√ Your APP_URL is not null or blank. It is set to '.$env_value."\n";
|
||||||
|
|
||||||
|
if (!str_begins(trim($env_value), 'http://') && (!str_begins($env_value, 'https://'))) {
|
||||||
|
$env_bad .= '✘ APP_URL ERROR in your .env on line #'.$show_line_num.': Your APP_URL should start with https:// or http://!! It is currently set to: '.$env_value;
|
||||||
|
} else {
|
||||||
|
$env_good .= '√ Your APP_URL is set to '.$env_value.' and starts with the protocol (https:// or http://)'."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str_ends(trim($env_value), "/")) {
|
||||||
|
$env_bad .= '✘ APP_URL ERROR in your .env on line #'.$show_line_num.': Your APP_URL should NOT end with a trailing slash. It is currently set to: '.$env_value;
|
||||||
|
} else {
|
||||||
|
$env_good .= '√ Your APP_URL ('.$env_value.') does not have a trailing slash.'."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$env_bad .= "✘ APP_URL ERROR in your .env on line #".$show_line_num.": Your APP_URL CANNOT be set to null or left blank.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $env_good;
|
||||||
|
|
||||||
|
if ($env_bad !='') {
|
||||||
|
|
||||||
|
echo "\n--------------------- !! ERROR !! ----------------------\n";
|
||||||
|
echo "Your .env file is misconfigured. Upgrade cannot continue.\n";
|
||||||
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
echo $env_bad;
|
||||||
|
echo "\n\n--------------------------------------------------------\n";
|
||||||
|
echo "ABORTING THE INSTALLER \n";
|
||||||
|
echo "Please correct the issues above in ".getcwd()."/.env and try again.\n";
|
||||||
|
echo "--------------------------------------------------------\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo "--------------------------------------------------------\n";
|
||||||
|
echo "STEP 2: Checking PHP requirements: \n";
|
||||||
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
|
if (version_compare(PHP_VERSION, $required_php_min, '<')) {
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
|
||||||
echo "This version of PHP (".PHP_VERSION.") is not compatible with Snipe-IT.\n";
|
echo "This version of PHP (".PHP_VERSION.") is not compatible with Snipe-IT.\n";
|
||||||
echo "Snipe-IT requires PHP version ".$required_version." or greater. Please upgrade \n";
|
echo "Snipe-IT requires PHP version ".$required_php_min." or greater. Please upgrade \n";
|
||||||
echo "your version of PHP (web/php-fcgi and cli) and try running this script again.\n\n\n";
|
echo "your version of PHP (web/php-fcgi and cli) and try running this script again.\n\n\n";
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo "Current PHP version: (" . PHP_VERSION . ") is at least ".$required_version." - continuing... \n";
|
echo "Current PHP version: (" . PHP_VERSION . ") is at least ".$required_php_min." - continuing... \n";
|
||||||
echo sprintf("FYI: The php.ini used by this PHP is: %s\n\n", get_cfg_var('cfg_file_path'));
|
echo sprintf("FYI: The php.ini used by this PHP is: %s\n\n", get_cfg_var('cfg_file_path'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,10 +205,10 @@ if ($ext_missing!='') {
|
||||||
|
|
||||||
echo "--------------------- !! ERROR !! ----------------------\n";
|
echo "--------------------- !! ERROR !! ----------------------\n";
|
||||||
echo $ext_missing;
|
echo $ext_missing;
|
||||||
echo "------------------------- :( ---------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "ABORTING THE INSTALLER \n";
|
echo "ABORTING THE INSTALLER \n";
|
||||||
echo "Please install the extensions above and re-run this script.\n";
|
echo "Please install the extensions above and re-run this script.\n";
|
||||||
echo "------------------------- :( ---------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
echo $ext_installed."\n";
|
echo $ext_installed."\n";
|
||||||
|
@ -132,21 +216,73 @@ if ($ext_missing!='') {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "STEP 2: Backing up database: \n";
|
echo "STEP 3: Checking directory permissions: \n";
|
||||||
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
$writable_dirs_array =
|
||||||
|
[
|
||||||
|
'bootstrap/cache',
|
||||||
|
'storage',
|
||||||
|
'storage/logs',
|
||||||
|
'storage/logs/laravel.log',
|
||||||
|
'storage/framework',
|
||||||
|
'storage/framework/cache',
|
||||||
|
'storage/framework/sessions',
|
||||||
|
'storage/framework/views',
|
||||||
|
'storage/app',
|
||||||
|
'storage/app/backups',
|
||||||
|
'storage/app/backup-temp',
|
||||||
|
'storage/private_uploads',
|
||||||
|
'public/uploads',
|
||||||
|
];
|
||||||
|
|
||||||
|
$dirs_writable = '';
|
||||||
|
$dirs_not_writable = '';
|
||||||
|
|
||||||
|
// Loop through the directories that need to be writable
|
||||||
|
foreach ($writable_dirs_array as $writable_dir) {
|
||||||
|
if (is_writable($writable_dir)) {
|
||||||
|
$dirs_writable .= '√ '.getcwd().'/'.$writable_dir." is writable \n";
|
||||||
|
} else {
|
||||||
|
$dirs_not_writable .= '✘ PERMISSIONS ERROR: '.getcwd().'/'.$writable_dir." is NOT writable\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $dirs_writable."\n";
|
||||||
|
|
||||||
|
// Print out a useful error message
|
||||||
|
if ($dirs_not_writable!='') {
|
||||||
|
echo "--------------------------------------------------------\n";
|
||||||
|
echo "The following directories/files do not seem writable: \n";
|
||||||
|
echo "--------------------------------------------------------\n";
|
||||||
|
|
||||||
|
echo $dirs_not_writable;
|
||||||
|
|
||||||
|
echo "--------------------- !! ERROR !! ----------------------\n";
|
||||||
|
echo "Please check the permissions on the directories above and re-run this script.\n";
|
||||||
|
echo "------------------------- :( ---------------------------\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo "--------------------------------------------------------\n";
|
||||||
|
echo "STEP 4: Backing up database: \n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
$backup = shell_exec('php artisan snipeit:backup');
|
$backup = shell_exec('php artisan snipeit:backup');
|
||||||
echo '-- '.$backup."\n\n";
|
echo '-- '.$backup."\n\n";
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "STEP 3: Putting application into maintenance mode: \n";
|
echo "STEP 5: Putting application into maintenance mode: \n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
$down = shell_exec('php artisan down');
|
$down = shell_exec('php artisan down');
|
||||||
echo '-- '.$down."\n";
|
echo '-- '.$down."\n";
|
||||||
|
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "STEP 4: Pulling latest from Git (".$branch." branch): \n";
|
echo "STEP 6: Pulling latest from Git (".$branch." branch): \n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
$git_version = shell_exec('git --version');
|
$git_version = shell_exec('git --version');
|
||||||
|
|
||||||
|
@ -172,7 +308,7 @@ if ((strpos('git version', $git_version)) === false) {
|
||||||
|
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "Step 5: Cleaning up old cached files:\n";
|
echo "STEP 7: Cleaning up old cached files:\n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
// Build an array of the files we generally want to delete because they
|
// Build an array of the files we generally want to delete because they
|
||||||
|
@ -205,7 +341,7 @@ echo '-- '.$view_clear;
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "Step 6: Updating composer dependencies:\n";
|
echo "STEP 8: Updating composer dependencies:\n";
|
||||||
echo "(This may take a moment.)\n";
|
echo "(This may take a moment.)\n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
|
@ -231,7 +367,7 @@ echo $composer;
|
||||||
|
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "Step 7: Migrating database:\n";
|
echo "STEP 9: Migrating database:\n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
$migrations = shell_exec('php artisan migrate --force');
|
$migrations = shell_exec('php artisan migrate --force');
|
||||||
|
@ -239,7 +375,7 @@ echo $migrations."\n";
|
||||||
|
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "Step 8: Checking for OAuth keys:\n";
|
echo "STEP 10: Checking for OAuth keys:\n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,7 +389,7 @@ if ((!file_exists('storage/oauth-public.key')) || (!file_exists('storage/oauth-p
|
||||||
|
|
||||||
|
|
||||||
echo "--------------------------------------------------------\n";
|
echo "--------------------------------------------------------\n";
|
||||||
echo "Step 9: Taking application out of maintenance mode:\n";
|
echo "STEP 11: Taking application out of maintenance mode:\n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
$up = shell_exec('php artisan up');
|
$up = shell_exec('php artisan up');
|
||||||
|
@ -267,3 +403,13 @@ echo "your upgraded Snipe-IT!\n";
|
||||||
echo "--------------------------------------------------------\n\n";
|
echo "--------------------------------------------------------\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
function str_begins($haystack, $needle) {
|
||||||
|
return 0 === substr_compare($haystack, $needle, 0, strlen($needle));
|
||||||
|
}
|
||||||
|
|
||||||
|
function str_ends($haystack, $needle) {
|
||||||
|
return 0 === substr_compare($haystack, $needle, -strlen($needle));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue