A free open source IT asset/license management system
Add migration for ldap_server URL's to ensure they at least start with ldap:// or ldaps:// (#8936)
Brady Wetherington2a817c212369
diff --git a/database/migrations/2020_12_21_210105_fix_bad_ldap_server_url_for_v5.php b/database/migrations/2020_12_21_210105_fix_bad_ldap_server_url_for_v5.phpnew file mode 100644index 0000000000..04a1530a82--- /dev/null+++ b/database/migrations/2020_12_21_210105_fix_bad_ldap_server_url_for_v5.php@@ -0,0 +1,41 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++class FixBadLdapServerUrlForV5 extends Migration+{+ /**+ * Under v4 and previous versions of Snipe-IT, we permitted users to incorrectly specify LDAP URL's in their settings, and Snipe-IT+ * would silently permit that.+ *+ * v5's LDAP system is not so lenient, and requires either ldap:// or ldaps:// in front of the server's URL. This migration tries+ * to find misconfigured LDAP URL's and prepend 'ldap://' to them. (That's what we assumed if we *didn't* see ldaps://)+ */++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {+ // UPDATE settings SET ldap_server = CONCAT('ldap://',ldap_server) WHERE ldap_server NOT LIKE 'ldap://%' AND ldap_server NOT LIKE 'ldaps://%'+ $settings = App\Models\Setting::where("ldap_server","not like","ldap://%")->where("ldap_server","not like","ldaps://%");+ foreach($settings->get() AS $setting) { // we don't formally support having multiple settings records, but just in case they come up...+ $setting->ldap_server = "ldap://".$setting->ldap_server;+ $setting->save();+ }+ }++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ // Since previous versions supported ldap:// URL's just fine, we don't need to migrate these changes back out on rollback.+ }+}