This commit is contained in:
Saeed Vaziry
2023-07-02 12:47:50 +02:00
commit 5c72f12490
825 changed files with 41659 additions and 0 deletions

View File

@ -0,0 +1,78 @@
<?php
namespace App\Support\SocialiteProviders;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Arr;
use Laravel\Socialite\Two\AbstractProvider;
use Laravel\Socialite\Two\ProviderInterface;
use Laravel\Socialite\Two\User;
class DropboxProvider extends AbstractProvider implements ProviderInterface
{
/**
* Unique Provider Identifier.
*/
public const IDENTIFIER = 'DROPBOX';
/**
* {@inheritdoc}
*/
protected $scopeSeparator = ' ';
/**
* {@inheritdoc}
*/
protected function getAuthUrl($state): string
{
return $this->buildAuthUrlFromBase('https://www.dropbox.com/oauth2/authorize', $state);
}
/**
* {@inheritdoc}
*/
protected function getTokenUrl(): string
{
return 'https://api.dropboxapi.com/oauth2/token';
}
/**
* {@inheritdoc}
*/
protected function getTokenFields($code): array
{
return array_merge(parent::getTokenFields($code), [
'grant_type' => 'authorization_code',
]);
}
/**
* {@inheritdoc}
*
* @throws GuzzleException
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->post('https://api.dropboxapi.com/2/users/get_current_account', [
'headers' => [
'Authorization' => 'Bearer '.$token,
],
]);
return json_decode($response->getBody(), true);
}
/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $user): User
{
return (new User)->setRaw($user)->map([
'id' => $user['account_id'],
'nickname' => null,
'name' => $user['name']['display_name'],
'email' => $user['email'],
'avatar' => Arr::get($user, 'profile_photo_url'),
]);
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Support\Testing;
use App\Contracts\SSHCommand;
use App\Models\Server;
use Illuminate\Support\Traits\ReflectsClosures;
use PHPUnit\Framework\Assert as PHPUnit;
class SSHFake
{
use ReflectsClosures;
protected array $commands;
protected string $output = '';
public function init(Server $server, string $asUser = null): self
{
return $this;
}
public function outputShouldBe(string $output): self
{
$this->output = $output;
return $this;
}
public function assertExecuted(array|string $commands): void
{
if (! $this->commands) {
PHPUnit::fail('No commands are executed');
}
if (! is_array($commands)) {
$commands = [$commands];
}
$allExecuted = true;
foreach ($commands as $command) {
if (! in_array($command, $commands)) {
$allExecuted = false;
}
}
if (! $allExecuted) {
PHPUnit::fail('The expected commands are not executed');
}
PHPUnit::assertTrue(true, $allExecuted);
}
public function exec(string|array|SSHCommand $commands, string $log = '', int $siteId = null): string
{
if (! is_array($commands)) {
$commands = [$commands];
}
foreach ($commands as $command) {
if (is_string($command)) {
$this->commands[] = $command;
} else {
$this->commands[] = get_class($command);
}
}
return 'fake output';
}
}

65
app/Support/helpers.php Executable file
View File

@ -0,0 +1,65 @@
<?php
use Illuminate\Support\Str;
function random_color(): string
{
return '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
}
function get_hostname_from_repo($repo): string
{
$repo = Str::after($repo, '@');
return Str::before($repo, ':');
}
function generate_uid(): string
{
return hash('sha256', uniqid(rand(1111111111, 9999999999), true).Str::random(64).strtotime('now'));
}
// /**
// * @param $privateKeyPath
// * @return array|string|string[]
// */
// function generate_public_key($privateKeyPath)
// {
// $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyPath));
// $publicKey = openssl_pkey_get_details($privateKey);
//
// return $publicKey['key'];
// }
function generate_public_key($privateKeyPath, $publicKeyPath): void
{
chmod($privateKeyPath, 0400);
exec("ssh-keygen -y -f {$privateKeyPath} > {$publicKeyPath}");
}
function generate_key_pair($path): void
{
exec("ssh-keygen -t ed25519 -m PEM -N '' -f {$path}");
chmod($path, 0400);
}
function make_bash_script($commands): string
{
$script = '';
foreach (preg_split("/((\r?\n)|(\r\n?))/", $commands) as $line) {
$script .= 'if ! '.$line."; then\n echo 'VITO_SSH_ERROR' && exit 1 \nfi"."\n";
}
return $script;
}
/**
* @throws Exception
*/
function date_with_timezone($date, $timezone): string
{
$dt = new DateTime('now', new DateTimeZone($timezone));
$dt->setTimestamp(strtotime($date));
return $dt->format('Y-m-d H:i:s');
}