Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
24 KB
Referenced Files
None
Subscribers
None
diff --git a/config.demo/src/database/seeds/DatabaseSeeder.php b/config.demo/src/database/seeds/DatabaseSeeder.php
index b7849172..058e2896 100644
--- a/config.demo/src/database/seeds/DatabaseSeeder.php
+++ b/config.demo/src/database/seeds/DatabaseSeeder.php
@@ -1,32 +1,31 @@
<?php
use Illuminate\Database\Seeder;
use Database\Seeds;
// phpcs:ignore
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
- Seeds\PassportSeeder::class,
Seeds\IP4NetSeeder::class,
Seeds\TenantSeeder::class,
Seeds\DiscountSeeder::class,
Seeds\DomainSeeder::class,
Seeds\SkuSeeder::class,
Seeds\PackageSeeder::class,
Seeds\PlanSeeder::class,
Seeds\PowerDNSSeeder::class,
Seeds\UserSeeder::class,
Seeds\ResourceSeeder::class,
Seeds\SharedFolderSeeder::class,
Seeds\MeetRoomSeeder::class,
]);
}
}
diff --git a/config.demo/src/database/seeds/PassportSeeder.php b/config.demo/src/database/seeds/PassportSeeder.php
deleted file mode 100644
index 4d58b973..00000000
--- a/config.demo/src/database/seeds/PassportSeeder.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace Database\Seeds;
-
-use Laravel\Passport\Passport;
-use Illuminate\Database\Seeder;
-
-class PassportSeeder extends Seeder
-{
- /**
- * Run the database seeds.
- *
- * This emulates:
- * './artisan passport:client --password --name="Kolab Password Grant Client" --provider=users'
- *
- * @return void
- */
- public function run()
- {
- //Create a password grant client for the webapp
- $client = Passport::client()->forceFill([
- 'user_id' => null,
- 'name' => "Kolab Password Grant Client",
- 'secret' => \config('auth.proxy.client_secret'),
- 'provider' => 'users',
- 'redirect' => 'https://' . \config('app.website_domain'),
- 'personal_access_client' => 0,
- 'password_client' => 1,
- 'revoked' => false,
- ]);
- $client->id = \config('auth.proxy.client_id');
- $client->save();
-
- // Create a client for Webmail SSO
- $client = Passport::client()->forceFill([
- 'user_id' => null,
- 'name' => 'Webmail SSO client',
- 'secret' => \config('auth.sso.client_secret'),
- 'provider' => 'users',
- 'redirect' => (str_starts_with(\config('app.webmail_url'), 'http') ? '' : 'https://' . \config('app.website_domain')) . \config('app.webmail_url') . 'index.php/login/oauth',
- 'personal_access_client' => 0,
- 'password_client' => 0,
- 'revoked' => false,
- 'allowed_scopes' => ['email', 'auth.token'],
- ]);
- $client->id = \config('auth.sso.client_id');
- $client->save();
-
- // Create a client for synapse oauth
- $client = Passport::client()->forceFill([
- 'user_id' => null,
- 'name' => "Synapse oauth client",
- 'secret' => \config('auth.synapse.client_secret'),
- 'provider' => 'users',
- 'redirect' => 'https://' . \config('app.website_domain') . "/_synapse/client/oidc/callback",
- 'personal_access_client' => 0,
- 'password_client' => 0,
- 'revoked' => false,
- 'allowed_scopes' => ['email'],
- ]);
- $client->id = \config('auth.synapse.client_id');
- $client->save();
- }
-}
diff --git a/config.demo/src/database/seeds/UserSeeder.php b/config.demo/src/database/seeds/UserSeeder.php
index e77b159d..eb0ce49c 100644
--- a/config.demo/src/database/seeds/UserSeeder.php
+++ b/config.demo/src/database/seeds/UserSeeder.php
@@ -1,246 +1,238 @@
<?php
namespace Database\Seeds;
use App\Auth\SecondFactor;
use App\Domain;
use App\Entitlement;
use App\User;
use App\Sku;
use Carbon\Carbon;
use Illuminate\Database\Seeder;
use App\Wallet;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$domain = Domain::create(
[
'namespace' => 'kolab.org',
'status' => Domain::STATUS_NEW
+ Domain::STATUS_ACTIVE
+ Domain::STATUS_CONFIRMED
+ Domain::STATUS_VERIFIED,
'type' => Domain::TYPE_EXTERNAL
]
);
$john = User::create(
[
'email' => 'john@kolab.org',
'password' => \App\Utils::generatePassphrase()
]
);
$john->setSettings(
[
'first_name' => 'John',
'last_name' => 'Doe',
'currency' => 'USD',
'country' => 'US',
'billing_address' => "601 13th Street NW\nSuite 900 South\nWashington, DC 20005",
'external_email' => 'john.doe.external@gmail.com',
'organization' => 'Kolab Developers',
'phone' => '+1 509-248-1111',
]
);
$john->setAliases(['john.doe@kolab.org']);
$wallet = $john->wallets->first();
$packageDomain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$packageKolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first();
$packageLite = \App\Package::withEnvTenantContext()->where('title', 'lite')->first();
$domain->assignPackage($packageDomain, $john);
$john->assignPackage($packageKolab);
$appDomain = \App\Domain::where(
[
'namespace' => \config('app.domain')
]
)->first();
$fred = User::create(
[
'email' => 'fred@' . \config('app.domain'),
'password' => \App\Utils::generatePassphrase()
]
);
$fred->setSettings(
[
'first_name' => 'fred',
'last_name' => 'Doe',
'currency' => 'USD',
'country' => 'US',
'billing_address' => "601 13th Street NW\nSuite 900 South\nWashington, DC 20005",
'external_email' => 'fred.doe.external@gmail.com',
'organization' => 'Kolab Developers',
'phone' => '+1 509-248-1111',
]
);
$appDomain->assignPackage($packageDomain, $fred);
$fred->assignPackage($packageKolab);
$jack = User::create(
[
'email' => 'jack@kolab.org',
'password' => \App\Utils::generatePassphrase()
]
);
$jack->setSettings(
[
'first_name' => 'Jack',
'last_name' => 'Daniels',
'currency' => 'USD',
'country' => 'US'
]
);
$jack->setAliases(['jack.daniels@kolab.org']);
$john->assignPackage($packageKolab, $jack);
foreach ($john->entitlements as $entitlement) {
$entitlement->created_at = Carbon::now()->subMonthsWithoutOverflow(1);
$entitlement->updated_at = Carbon::now()->subMonthsWithoutOverflow(1);
$entitlement->save();
}
$ned = User::create(
[
'email' => 'ned@kolab.org',
'password' => \App\Utils::generatePassphrase()
]
);
$ned->setSettings(
[
'first_name' => 'Edward',
'last_name' => 'Flanders',
'currency' => 'USD',
'country' => 'US',
'guam_enabled' => false,
]
);
$john->assignPackage($packageKolab, $ned);
$ned->assignSku(\App\Sku::withEnvTenantContext()->where('title', 'activesync')->first(), 1);
// Ned is a controller on Jack's wallet
$john->wallets()->first()->addController($ned);
// Ned is also our 2FA test user
$sku2fa = Sku::withEnvTenantContext()->where('title', '2fa')->first();
$ned->assignSku($sku2fa);
SecondFactor::seed('ned@kolab.org');
$joe = User::create(
[
'email' => 'joe@kolab.org',
'password' => \App\Utils::generatePassphrase()
]
);
$john->assignPackage($packageLite, $joe);
//$john->assignSku(Sku::firstOrCreate(['title' => 'beta']));
//$john->assignSku(Sku::firstOrCreate(['title' => 'meet']));
$joe->setAliases(['joe.monster@kolab.org']);
// This only exists so the user create job doesn't fail because the domain is not found
Domain::create(
[
'namespace' => 'jeroen.jeroen',
'status' => Domain::STATUS_NEW
+ Domain::STATUS_ACTIVE
+ Domain::STATUS_CONFIRMED
+ Domain::STATUS_VERIFIED,
'type' => Domain::TYPE_EXTERNAL
]
);
$jeroen = User::create(
[
'email' => 'jeroen@jeroen.jeroen',
'password' => \App\Utils::generatePassphrase()
]
);
$jeroen->role = 'admin';
$jeroen->save();
$reseller = User::create(
[
'email' => 'reseller@' . \config('app.domain'),
'password' => \App\Utils::generatePassphrase()
]
);
$reseller->role = 'reseller';
$reseller->save();
// for tenants that are not the configured tenant id
$tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get();
foreach ($tenants as $tenant) {
$domain = Domain::where('tenant_id', $tenant->id)->first();
$packageKolab = \App\Package::where(
[
'title' => 'kolab',
'tenant_id' => $tenant->id
]
)->first();
if ($domain) {
$reseller = User::create(
[
'email' => 'reseller@' . $domain->namespace,
'password' => \App\Utils::generatePassphrase()
]
);
$reseller->role = 'reseller';
$reseller->tenant_id = $tenant->id;
$reseller->save();
$user = User::create(
[
'email' => 'user@' . $domain->namespace,
'password' => \App\Utils::generatePassphrase()
]
);
$user->tenant_id = $tenant->id;
$user->save();
$user->assignPackage($packageKolab);
}
}
-
- // Create imap admin service account
- User::create(
- [
- 'email' => \config('services.imap.admin_login'),
- 'password' => \config('services.imap.admin_password')
- ]
- );
}
}
diff --git a/config.prod/src/database/seeds/DatabaseSeeder.php b/config.prod/src/database/seeds/DatabaseSeeder.php
index b50c339c..d82b4dd5 100644
--- a/config.prod/src/database/seeds/DatabaseSeeder.php
+++ b/config.prod/src/database/seeds/DatabaseSeeder.php
@@ -1,25 +1,22 @@
<?php
use Illuminate\Database\Seeder;
use Database\Seeds;
// phpcs:ignore
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
- Seeds\PassportSeeder::class,
Seeds\PowerDNSSeeder::class,
Seeds\TenantSeeder::class,
Seeds\AdminSeeder::class,
- Seeds\ImapAdminSeeder::class,
- Seeds\NoreplySeeder::class,
]);
}
}
diff --git a/config.prod/src/database/seeds/ImapAdminSeeder.php b/config.prod/src/database/seeds/ImapAdminSeeder.php
deleted file mode 100644
index a5b86c38..00000000
--- a/config.prod/src/database/seeds/ImapAdminSeeder.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-
-namespace Database\Seeds;
-
-use App\User;
-use Illuminate\Database\Seeder;
-
-class ImapAdminSeeder extends Seeder
-{
- /**
- * Run the database seeds.
- *
- * Create imap admin service account, which is required for sasl httpauth to work
- *
- * @return void
- */
- public function run()
- {
- $user = new \App\User();
- $user->email = \config('services.imap.admin_login');
- $user->password = \config('services.imap.admin_password');
- $user->role = \App\User::ROLE_SERVICE;
- $user->save();
- }
-}
diff --git a/config.prod/src/database/seeds/NoreplySeeder.php b/config.prod/src/database/seeds/NoreplySeeder.php
deleted file mode 100644
index 8cd5088a..00000000
--- a/config.prod/src/database/seeds/NoreplySeeder.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-namespace Database\Seeds;
-
-use App\User;
-use Illuminate\Database\Seeder;
-
-class NoreplySeeder extends Seeder
-{
- /**
- * Run the database seeds.
- *
- * Create imap admin service account, which is required for sasl httpauth to work
- *
- * @return void
- */
- public function run()
- {
- if (!empty(\config('mail.mailers.smtp.username'))) {
- User::create(
- [
- 'email' => \config('mail.mailers.smtp.username'),
- 'password' => \config('mail.mailers.smtp.password')
- ]
- );
- }
- }
-}
diff --git a/config.prod/src/database/seeds/PassportSeeder.php b/config.prod/src/database/seeds/PassportSeeder.php
deleted file mode 100644
index 4d58b973..00000000
--- a/config.prod/src/database/seeds/PassportSeeder.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace Database\Seeds;
-
-use Laravel\Passport\Passport;
-use Illuminate\Database\Seeder;
-
-class PassportSeeder extends Seeder
-{
- /**
- * Run the database seeds.
- *
- * This emulates:
- * './artisan passport:client --password --name="Kolab Password Grant Client" --provider=users'
- *
- * @return void
- */
- public function run()
- {
- //Create a password grant client for the webapp
- $client = Passport::client()->forceFill([
- 'user_id' => null,
- 'name' => "Kolab Password Grant Client",
- 'secret' => \config('auth.proxy.client_secret'),
- 'provider' => 'users',
- 'redirect' => 'https://' . \config('app.website_domain'),
- 'personal_access_client' => 0,
- 'password_client' => 1,
- 'revoked' => false,
- ]);
- $client->id = \config('auth.proxy.client_id');
- $client->save();
-
- // Create a client for Webmail SSO
- $client = Passport::client()->forceFill([
- 'user_id' => null,
- 'name' => 'Webmail SSO client',
- 'secret' => \config('auth.sso.client_secret'),
- 'provider' => 'users',
- 'redirect' => (str_starts_with(\config('app.webmail_url'), 'http') ? '' : 'https://' . \config('app.website_domain')) . \config('app.webmail_url') . 'index.php/login/oauth',
- 'personal_access_client' => 0,
- 'password_client' => 0,
- 'revoked' => false,
- 'allowed_scopes' => ['email', 'auth.token'],
- ]);
- $client->id = \config('auth.sso.client_id');
- $client->save();
-
- // Create a client for synapse oauth
- $client = Passport::client()->forceFill([
- 'user_id' => null,
- 'name' => "Synapse oauth client",
- 'secret' => \config('auth.synapse.client_secret'),
- 'provider' => 'users',
- 'redirect' => 'https://' . \config('app.website_domain') . "/_synapse/client/oidc/callback",
- 'personal_access_client' => 0,
- 'password_client' => 0,
- 'revoked' => false,
- 'allowed_scopes' => ['email'],
- ]);
- $client->id = \config('auth.synapse.client_id');
- $client->save();
- }
-}
diff --git a/docker/webapp/init.sh b/docker/webapp/init.sh
index 13098292..a047aea7 100755
--- a/docker/webapp/init.sh
+++ b/docker/webapp/init.sh
@@ -1,94 +1,96 @@
#!/bin/bash
set -e
set -x
cd /opt/app-root/src/
/update.sh
if [ ! -f 'resources/countries.php' ]; then
echo "----> Importing countries"
./artisan data:countries
fi
echo "----> Waiting for db"
./artisan db:ping --wait
# Import the service ca on openshift
update-ca-trust
function is_not_initialized() {
ROWCOUNT=$(echo "select count(*) from migrations;" | mysql -N -b -u "$DB_USERNAME" -p"$DB_PASSWORD" -h "$DB_HOST" "$DB_DATABASE")
if [[ "$ROWCOUNT" == "" ]]; then
# Treat an error in the above command as uninitialized
ROWCOUNT="0"
fi
[[ "$ROWCOUNT" == "0" ]]
}
case ${KOLAB_ROLE} in
seed|SEED)
echo "----> Running seeder"
# Only run the seeder if we haven't even migrated yet.
if is_not_initialized; then
echo "----> Seeding the database"
# If we seed, we always drop all existing tables
php -dmemory_limit=512M ./artisan migrate:fresh --seed --force
fi
;;
horizon|HORIZON)
echo "----> Waiting for database to be seeded"
while is_not_initialized; do
sleep 1
echo "."
done
echo "----> Running migrations"
php -dmemory_limit=512M ./artisan migrate --force || :
+ php -dmemory_limit=512M ./artisan data:init
echo "----> Starting horizon"
exec ./artisan horizon
;;
octane|OCTANE)
echo "----> Running octane"
echo "----> Waiting for database to be seeded"
while is_not_initialized; do
sleep 1
echo "."
done
exec ./artisan octane:start --host=0.0.0.0
;;
worker|WORKER )
./artisan migrate --force || :
echo "----> Running worker"
exec ./artisan queue:work
;;
combined|COMBINED )
# If there is no db at all then listing users will crash (resulting in us counting the lines of backtrace),
# but migrate:status will just fail.
if is_not_initialized; then
echo "----> Seeding the database"
php -dmemory_limit=512M ./artisan migrate --seed
# If there is a db but no user we reseed
elif test "$( env APP_DEBUG=false ./artisan -n users | wc -l )" -lt "1"; then
echo "----> Initializing the database"
php -dmemory_limit=512M ./artisan migrate:refresh --seed
# Otherwise we just migrate
else
echo "----> Running migrations"
php -dmemory_limit=512M ./artisan migrate --force
fi
+ php -dmemory_limit=512M ./artisan data:init
nohup ./artisan horizon 2>&1 &
exec ./artisan octane:start --host=$(env | grep OCTANE_HTTP_HOST | tail -n1 | sed "s/OCTANE_HTTP_HOST=//")
;;
* )
echo "----> Sleeping"
exec sleep 10000
;;
esac
diff --git a/src/app/Console/Commands/Data/InitCommand.php b/src/app/Console/Commands/Data/InitCommand.php
new file mode 100644
index 00000000..7917cd9b
--- /dev/null
+++ b/src/app/Console/Commands/Data/InitCommand.php
@@ -0,0 +1,137 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Command;
+use App\User;
+use Laravel\Passport\Passport;
+
+class InitCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'data:init';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Initialization command, making sure some expected db entries exist. Rerunnable to apply latest config changes.';
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $this->createImapAdmin();
+ $this->createNoreplyUser();
+ $this->createPassportClients();
+ }
+
+ private function createImapAdmin()
+ {
+ $user = User::where(['email' => \config('services.imap.admin_login')])->first();
+ if (!$user) {
+ $user = new \App\User();
+ $user->email = \config('services.imap.admin_login');
+ $user->password = \config('services.imap.admin_password');
+ $user->role = \App\User::ROLE_SERVICE;
+ $user->save();
+ } else {
+ $user->password = \config('services.imap.admin_password');
+ $user->role = \App\User::ROLE_SERVICE;
+ $user->update();
+ }
+ }
+
+ private function createNoreplyUser()
+ {
+ if (!empty(\config('mail.mailers.smtp.username'))) {
+ $user = User::where(['email' => \config('services.mailers.smtp.username')])->first();
+ if (!$user) {
+ $user = new \App\User();
+ $user->email = \config('mail.mailers.smtp.username');
+ $user->password = \config('mail.mailers.smtp.password');
+ $user->role = \App\User::ROLE_SERVICE;
+ $user->save();
+ } else {
+ $user->password = \config('mail.mailers.smtp.password');
+ $user->role = \App\User::ROLE_SERVICE;
+ $user->update();
+ }
+ }
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ private function createPassportClients()
+ {
+ //Create a password grant client for the webapp
+ if (
+ !empty(\config('auth.proxy.client_secret')) &&
+ !Passport::client()->where('name', 'Kolab Password Grant Client')->whereNull('user_id')->exists()
+ ) {
+ $client = Passport::client()->forceFill([
+ 'user_id' => null,
+ 'name' => "Kolab Password Grant Client",
+ 'secret' => \config('auth.proxy.client_secret'),
+ 'provider' => 'users',
+ 'redirect' => 'https://' . \config('app.website_domain'),
+ 'personal_access_client' => 0,
+ 'password_client' => 1,
+ 'revoked' => false,
+ ]);
+ $client->id = \config('auth.proxy.client_id');
+ $client->save();
+ }
+
+ // Create a client for Webmail SSO
+ if (
+ !empty(\config('auth.sso.client_secret')) &&
+ !Passport::client()->where('name', 'Webmail SSO client')->whereNull('user_id')->exists()
+ ) {
+ $client = Passport::client()->forceFill([
+ 'user_id' => null,
+ 'name' => 'Webmail SSO client',
+ 'secret' => \config('auth.sso.client_secret'),
+ 'provider' => 'users',
+ 'redirect' => (str_starts_with(\config('app.webmail_url'), 'http') ? '' : 'https://' . \config('app.website_domain')) . \config('app.webmail_url') . 'index.php/login/oauth',
+ 'personal_access_client' => 0,
+ 'password_client' => 0,
+ 'revoked' => false,
+ 'allowed_scopes' => ['email', 'auth.token'],
+ ]);
+ $client->id = \config('auth.sso.client_id');
+ $client->save();
+ }
+
+ // Create a client for synapse oauth
+ if (
+ !empty(\config('auth.synapse.client_secret')) &&
+ !Passport::client()->where('name', 'Synapse oauth client')->whereNull('user_id')->exists()
+ ) {
+ $client = Passport::client()->forceFill([
+ 'user_id' => null,
+ 'name' => "Synapse oauth client",
+ 'secret' => \config('auth.synapse.client_secret'),
+ 'provider' => 'users',
+ 'redirect' => 'https://' . \config('app.website_domain') . "/_synapse/client/oidc/callback",
+ 'personal_access_client' => 0,
+ 'password_client' => 0,
+ 'revoked' => false,
+ 'allowed_scopes' => ['email'],
+ ]);
+ $client->id = \config('auth.synapse.client_id');
+ $client->save();
+ }
+ }
+}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Apr 6, 12:55 AM (5 d, 2 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831769
Default Alt Text
(24 KB)

Event Timeline