mirror of
https://github.com/cupcakearmy/coolify.git
synced 2024-10-23 00:24:15 +02:00
fix: Always use IP address for webhooks
This commit is contained in:
parent
8e42203b89
commit
880865f1f2
@ -1,3 +1,5 @@
|
|||||||
|
import { dev } from '$app/env';
|
||||||
|
|
||||||
export const asyncSleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
|
export const asyncSleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
|
||||||
export const dateOptions: DateTimeFormatOptions = {
|
export const dateOptions: DateTimeFormatOptions = {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
@ -21,6 +23,18 @@ export const staticDeployments = [
|
|||||||
];
|
];
|
||||||
export const notNodeDeployments = ['php', 'docker', 'rust', 'python', 'deno', 'laravel'];
|
export const notNodeDeployments = ['php', 'docker', 'rust', 'python', 'deno', 'laravel'];
|
||||||
|
|
||||||
|
export async function getIP() {
|
||||||
|
if (dev) {
|
||||||
|
return 'localhost:3000';
|
||||||
|
}
|
||||||
|
const response = await fetch(`https://api.ipify.org?format=json`);
|
||||||
|
if (response.ok) {
|
||||||
|
const json = await response.json();
|
||||||
|
return `http://${json.ip}`;
|
||||||
|
}
|
||||||
|
return window.location.origin;
|
||||||
|
}
|
||||||
|
|
||||||
export function getDomain(domain) {
|
export function getDomain(domain) {
|
||||||
return domain?.replace('https://', '').replace('http://', '');
|
return domain?.replace('https://', '').replace('http://', '');
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { gitTokens } from '$lib/store';
|
import { gitTokens } from '$lib/store';
|
||||||
import { t } from '$lib/translations';
|
import { t } from '$lib/translations';
|
||||||
|
import { getIP } from '$lib/components/common';
|
||||||
|
|
||||||
const { id } = $page.params;
|
const { id } = $page.params;
|
||||||
const from = $page.url.searchParams.get('from');
|
const from = $page.url.searchParams.get('from');
|
||||||
@ -113,6 +114,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
const ip = await getIP();
|
||||||
try {
|
try {
|
||||||
if (!$gitTokens.githubToken) {
|
if (!$gitTokens.githubToken) {
|
||||||
const { token } = await get(`/applications/${id}/configuration/githubToken.json`);
|
const { token } = await get(`/applications/${id}/configuration/githubToken.json`);
|
||||||
@ -131,7 +133,7 @@
|
|||||||
const left = screen.width / 2 - 1020 / 2;
|
const left = screen.width / 2 - 1020 / 2;
|
||||||
const top = screen.height / 2 - 618 / 2;
|
const top = screen.height / 2 - 618 / 2;
|
||||||
const newWindow = open(
|
const newWindow = open(
|
||||||
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
|
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
|
||||||
'GitLab',
|
'GitLab',
|
||||||
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
|
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
|
||||||
top +
|
top +
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
import { del, get, post, put } from '$lib/api';
|
import { del, get, post, put } from '$lib/api';
|
||||||
import { gitTokens } from '$lib/store';
|
import { gitTokens } from '$lib/store';
|
||||||
import { t } from '$lib/translations';
|
import { t } from '$lib/translations';
|
||||||
|
import { getIP } from '$lib/components/common';
|
||||||
|
|
||||||
const { id } = $page.params;
|
const { id } = $page.params;
|
||||||
const from = $page.url.searchParams.get('from');
|
const from = $page.url.searchParams.get('from');
|
||||||
@ -40,7 +41,7 @@
|
|||||||
};
|
};
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (!$gitTokens.gitlabToken) {
|
if (!$gitTokens.gitlabToken) {
|
||||||
getGitlabToken();
|
await getGitlabToken();
|
||||||
} else {
|
} else {
|
||||||
loading.base = true;
|
loading.base = true;
|
||||||
try {
|
try {
|
||||||
@ -49,7 +50,7 @@
|
|||||||
});
|
});
|
||||||
username = user.username;
|
username = user.username;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return getGitlabToken();
|
return await getGitlabToken();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
groups = await get(`${apiUrl}/v4/groups?per_page=5000`, {
|
groups = await get(`${apiUrl}/v4/groups?per_page=5000`, {
|
||||||
@ -64,11 +65,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function getGitlabToken() {
|
async function getGitlabToken() {
|
||||||
|
const ip = await getIP();
|
||||||
const left = screen.width / 2 - 1020 / 2;
|
const left = screen.width / 2 - 1020 / 2;
|
||||||
const top = screen.height / 2 - 618 / 2;
|
const top = screen.height / 2 - 618 / 2;
|
||||||
const newWindow = open(
|
const newWindow = open(
|
||||||
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
|
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
|
||||||
'GitLab',
|
'GitLab',
|
||||||
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
|
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
|
||||||
top +
|
top +
|
||||||
@ -163,9 +165,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function setWebhook(url, webhookToken) {
|
async function setWebhook(url, webhookToken) {
|
||||||
|
const ip = await getIP();
|
||||||
const host = dev
|
const host = dev
|
||||||
? 'https://webhook.site/0e5beb2c-4e9b-40e2-a89e-32295e570c21'
|
? 'https://webhook.site/0e5beb2c-4e9b-40e2-a89e-32295e570c21'
|
||||||
: `${window.location.origin}/webhooks/gitlab/events`;
|
: `${ip}/webhooks/gitlab/events`;
|
||||||
try {
|
try {
|
||||||
await post(
|
await post(
|
||||||
url,
|
url,
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
import { gitTokens } from '$lib/store';
|
import { gitTokens } from '$lib/store';
|
||||||
import { browser } from '$app/env';
|
import { browser } from '$app/env';
|
||||||
import { t } from '$lib/translations';
|
import { t } from '$lib/translations';
|
||||||
|
import { getIP } from '$lib/components/common';
|
||||||
|
|
||||||
const { id } = $page.params;
|
const { id } = $page.params;
|
||||||
|
|
||||||
@ -174,11 +175,12 @@
|
|||||||
error.message === '401 Unauthorized'
|
error.message === '401 Unauthorized'
|
||||||
) {
|
) {
|
||||||
if (application.gitSource.gitlabAppId) {
|
if (application.gitSource.gitlabAppId) {
|
||||||
|
const ip = await getIP();
|
||||||
let htmlUrl = application.gitSource.htmlUrl;
|
let htmlUrl = application.gitSource.htmlUrl;
|
||||||
const left = screen.width / 2 - 1020 / 2;
|
const left = screen.width / 2 - 1020 / 2;
|
||||||
const top = screen.height / 2 - 618 / 2;
|
const top = screen.height / 2 - 618 / 2;
|
||||||
const newWindow = open(
|
const newWindow = open(
|
||||||
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${window.location.origin}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
|
`${htmlUrl}/oauth/authorize?client_id=${application.gitSource.gitlabApp.appId}&redirect_uri=${ip}/webhooks/gitlab&response_type=code&scope=api+email+read_repository&state=${$page.params.id}`,
|
||||||
'GitLab',
|
'GitLab',
|
||||||
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
|
'resizable=1, scrollbars=1, fullscreen=0, height=618, width=1020,top=' +
|
||||||
top +
|
top +
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
import { toast } from '@zerodevx/svelte-toast';
|
import { toast } from '@zerodevx/svelte-toast';
|
||||||
|
|
||||||
import { t } from '$lib/translations';
|
import { t } from '$lib/translations';
|
||||||
|
import { getIP } from '$lib/components/common';
|
||||||
const { id } = $page.params;
|
const { id } = $page.params;
|
||||||
let url = browser ? (settings.fqdn ? settings.fqdn : window.location.origin) : '';
|
let url = browser ? (settings.fqdn ? settings.fqdn : window.location.origin) : '';
|
||||||
|
|
||||||
@ -26,7 +27,8 @@
|
|||||||
appSecret: null
|
appSecret: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
onMount(() => {
|
onMount(async () => {
|
||||||
|
url = await getIP();
|
||||||
oauthIdEl && oauthIdEl.focus();
|
oauthIdEl && oauthIdEl.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -30,21 +30,21 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { dev } from '$app/env';
|
import { dev } from '$app/env';
|
||||||
import { getDomain, dashify } from '$lib/components/common';
|
import { getDomain, dashify, getIP } from '$lib/components/common';
|
||||||
import { t } from '$lib/translations';
|
import { t } from '$lib/translations';
|
||||||
|
|
||||||
export let source;
|
export let source;
|
||||||
export let settings;
|
export let settings;
|
||||||
onMount(() => {
|
onMount(async () => {
|
||||||
const { organization, id, htmlUrl } = source;
|
const { organization, id, htmlUrl } = source;
|
||||||
const { fqdn } = settings;
|
const { fqdn } = settings;
|
||||||
const host = dev
|
const ip = await getIP();
|
||||||
? 'http://localhost:3000'
|
let host = `http://${ip}`;
|
||||||
: fqdn
|
if (fqdn && fqdn.startsWith('https')) {
|
||||||
? fqdn
|
host = `https://${ip}`;
|
||||||
: `http://${window.location.host}` || '';
|
}
|
||||||
|
console.log(ip, host);
|
||||||
const domain = getDomain(fqdn);
|
const domain = getDomain(fqdn);
|
||||||
|
|
||||||
let url = 'settings/apps/new';
|
let url = 'settings/apps/new';
|
||||||
if (organization) url = `organizations/${organization}/settings/apps/new`;
|
if (organization) url = `organizations/${organization}/settings/apps/new`;
|
||||||
const name = dashify(domain) || 'app';
|
const name = dashify(domain) || 'app';
|
||||||
|
Loading…
Reference in New Issue
Block a user