Skip to content

Commit b30fe32

Browse files
authored
Made a cli for frontend operation of Domainforge (#40)
have made a cli interface in node for interacting with domainforge through cli
2 parents 1d31983 + 4d20361 commit b30fe32

File tree

18 files changed

+1536
-26
lines changed

18 files changed

+1536
-26
lines changed

docker/named_pipe/nohup.out

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
1000
2+
Deleting... news.domains.mdgspace.org
3+
rm: cannot remove '/etc/nginx/sites-available/news.domains.mdgspace.org.conf': No such file or directory
4+
rm: cannot remove '/etc/nginx/sites-enabled/news.domains.mdgspace.org.conf': No such file or directory
5+
Error response from daemon: No such container: news.domains.mdgspace.org
6+
Error response from daemon: No such container: news.domains.mdgspace.org
7+
Error response from daemon: No such image: news.domains.mdgspace.org:latest
8+
1000
9+
Creating subdomain news.domains.mdgspace.org which redirects to https://news.ycombinator.com/
10+
Generating url.conf
11+
url: https://news.ycombinator.com/
12+
1000
13+
Creating subdomain github.domains.mdgspace.org which redirects to https://github.com/
14+
Generating url.conf
15+
url: https://github.com/
16+
1000
17+
Deleting... github.domains.mdgspace.org
18+
Error response from daemon: No such container: github.domains.mdgspace.org
19+
Error response from daemon: No such container: github.domains.mdgspace.org
20+
Error response from daemon: No such image: github.domains.mdgspace.org:latest
21+
1000
22+
Deleting... nik-55.domains.mdgspace.org
23+
Error response from daemon: No such container: nik-55.domains.mdgspace.org
24+
Error response from daemon: No such container: nik-55.domains.mdgspace.org
25+
Error response from daemon: No such image: nik-55.domains.mdgspace.org:latest
26+
1000
27+
Creating subdomain kituuu.mdgspace.org.domains.mdgspace.org which redirects to https://your-personal-gallery.vercel.app/
28+
Generating url.conf
29+
url: https://your-personal-gallery.vercel.app/
30+
1000
31+
Deleting... kituuu.mdgspace.org.domains.mdgspace.org
32+
Error response from daemon: No such container: kituuu.mdgspace.org.domains.mdgspace.org
33+
Error response from daemon: No such container: kituuu.mdgspace.org.domains.mdgspace.org
34+
Error response from daemon: No such image: kituuu.mdgspace.org.domains.mdgspace.org:latest
35+
1000
36+
Creating subdomain kituuu.domains.mdgspace.org which redirects to https://your-personal-gallery.vercel.app/
37+
Generating url.conf
38+
url: https://your-personal-gallery.vercel.app/
39+
1000
40+
Deleting... kituuu.domains.mdgspace.org
41+
Error response from daemon: No such container: kituuu.domains.mdgspace.org
42+
Error response from daemon: No such container: kituuu.domains.mdgspace.org
43+
Error response from daemon: No such image: kituuu.domains.mdgspace.org:latest
44+
1000
45+
Creating subdomain google.domains.mdgspace.org which redirects to https://www.google.com/
46+
Generating url.conf
47+
url: https://www.google.com/
48+
1000
49+
Creating subdomain nano-test.domains.mdgspace.org which redirects to https://nanonish.github.io/
50+
Generating url.conf
51+
url: https://nanonish.github.io/
52+
1000
53+
Creating subdomain wiki.domains.mdgspace.org which redirects to https://www.wikipedia.org/
54+
Generating url.conf
55+
url: https://www.wikipedia.org/
56+
1000
57+
Creating subdomain wiki.domains.mdgspace.org which redirects to https://www.wikipedia.org/
58+
Generating url.conf
59+
url: https://www.wikipedia.org/
60+
1000
61+
Deleting... todo.domains.mdgspace.org
62+
Error response from daemon: No such container: todo.domains.mdgspace.org
63+
Error response from daemon: No such container: todo.domains.mdgspace.org
64+
Error response from daemon: No such image: todo.domains.mdgspace.org:latest
65+
1000
66+
Deleting... hey.domains.mdgspace.org
67+
Error response from daemon: No such container: hey.domains.mdgspace.org
68+
Error response from daemon: No such container: hey.domains.mdgspace.org
69+
Error response from daemon: No such image: hey.domains.mdgspace.org:latest
70+
Available ports: 8067
71+
Creating subdomain hey.domains.mdgspace.org
72+
Cloning into 'hey.domains.mdgspace.org'...
73+
#0 building with "default" instance using docker driver
74+
75+
#1 [internal] load build definition from Dockerfile
76+
#1 transferring dockerfile: 225B done
77+
#1 DONE 0.0s
78+
79+
#2 [internal] load metadata for docker.io/library/python:latest
80+
#2 DONE 2.2s
81+
82+
#3 [internal] load .dockerignore
83+
#3 transferring context: 2B done
84+
#3 DONE 0.0s
85+
86+
#4 [1/5] FROM docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe
87+
#4 resolve docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 0.0s done
88+
#4 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 0B / 64.15MB 0.1s
89+
#4 sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 9.72kB / 9.72kB done
90+
#4 sha256:ea2ebd905ab246ece277be25520ca0cfe82758b3d2b369e2fd69b374c1d6c7fa 5.86kB / 5.86kB done
91+
#4 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0B / 24.05MB 0.1s
92+
#4 sha256:f6b1cea9aa1bba7fdf508248d1ab303a4cb11274997f39c9a0d6646f221379da 2.32kB / 2.32kB done
93+
#4 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 0B / 49.56MB 0.1s
94+
#4 CANCELED
95+
96+
#5 [internal] load build context
97+
#5 transferring context: 16.77MB 0.2s done
98+
#5 DONE 0.3s
99+
100+
#6 [2/5] WORKDIR /app
101+
#6 CACHED
102+
103+
#7 [3/5] COPY requirements.txt .
104+
#7 ERROR: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::pe7dzgi8kpgbwg9fr8gsw1js8: "/requirements.txt": not found
105+
------
106+
> [3/5] COPY requirements.txt .:
107+
------
108+
Dockerfile:3
109+
--------------------
110+
1 | FROM python:latest
111+
2 | WORKDIR /app
112+
3 | >>> COPY requirements.txt .
113+
4 | RUN pip install --no-cache-dir -r requirements.txt
114+
5 | COPY . .
115+
--------------------
116+
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::pe7dzgi8kpgbwg9fr8gsw1js8: "/requirements.txt": not found
117+
Unable to find image 'hey.domains.mdgspace.org:latest' locally
118+
docker: Error response from daemon: pull access denied for hey.domains.mdgspace.org, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
119+
See 'docker run --help'.
120+
Available ports: 8067
121+
Creating subdomain hy.domains.mdgspace.org
122+
Cloning into 'hy.domains.mdgspace.org'...
123+
#0 building with "default" instance using docker driver
124+
125+
#1 [internal] load build definition from Dockerfile
126+
#1 transferring dockerfile: 225B done
127+
#1 DONE 0.0s
128+
129+
#2 [internal] load metadata for docker.io/library/python:latest
130+
#2 DONE 0.7s
131+
132+
#3 [internal] load .dockerignore
133+
#3 transferring context: 2B done
134+
#3 DONE 0.0s
135+
136+
#4 [1/5] FROM docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe
137+
#4 resolve docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 0.0s done
138+
#4 sha256:f6b1cea9aa1bba7fdf508248d1ab303a4cb11274997f39c9a0d6646f221379da 2.32kB / 2.32kB done
139+
#4 sha256:ea2ebd905ab246ece277be25520ca0cfe82758b3d2b369e2fd69b374c1d6c7fa 5.86kB / 5.86kB done
140+
#4 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0B / 24.05MB 0.1s
141+
#4 sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 9.72kB / 9.72kB done
142+
#4 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 0B / 49.56MB 0.1s
143+
#4 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 0B / 64.15MB 0.1s
144+
#4 ...
145+
146+
#5 [internal] load build context
147+
#5 transferring context: 16.77MB 0.1s done
148+
#5 DONE 0.2s
149+
150+
#6 [2/5] WORKDIR /app
151+
#6 CACHED
152+
153+
#7 [3/5] COPY requirements.txt .
154+
#7 ERROR: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::w1g4h9pt6iyidbf3u91xq1fq9: "/requirements.txt": not found
155+
------
156+
> [3/5] COPY requirements.txt .:
157+
------
158+
Dockerfile:3
159+
--------------------
160+
1 | FROM python:latest
161+
2 | WORKDIR /app
162+
3 | >>> COPY requirements.txt .
163+
4 | RUN pip install --no-cache-dir -r requirements.txt
164+
5 | COPY . .
165+
--------------------
166+
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::w1g4h9pt6iyidbf3u91xq1fq9: "/requirements.txt": not found
167+
Unable to find image 'hy.domains.mdgspace.org:latest' locally
168+
docker: Error response from daemon: pull access denied for hy.domains.mdgspace.org, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
169+
See 'docker run --help'.
170+
1000
171+
Creating subdomain alpha.domains.mdgspace.org which redirects to https://github.com
172+
Generating url.conf
173+
url: https://github.com
174+
1000
175+
Creating subdomain raj.domains.mdgspace.org which redirects to https://github.com/raj210809
176+
Generating url.conf
177+
url: https://github.com/raj210809
178+
1000
179+
Deleting... tola.domains.mdgspace.org
180+
Error response from daemon: No such container: tola.domains.mdgspace.org
181+
Error response from daemon: No such container: tola.domains.mdgspace.org
182+
Error response from daemon: No such image: tola.domains.mdgspace.org:latest
183+
1000
184+
Creating subdomain toka.domains.mdgspace.org which redirects to https://github.com/amsorrytola
185+
Generating url.conf
186+
url: https://github.com/amsorrytola
187+
1000
188+
Deleting... toka.domains.mdgspace.org
189+
Error response from daemon: No such container: toka.domains.mdgspace.org
190+
Error response from daemon: No such container: toka.domains.mdgspace.org
191+
Error response from daemon: No such image: toka.domains.mdgspace.org:latest
192+
1000
193+
Deleting... tola.domains.mdgspace.org
194+
Error response from daemon: No such container: tola.domains.mdgspace.org
195+
Error response from daemon: No such container: tola.domains.mdgspace.org
196+
Error response from daemon: No such image: tola.domains.mdgspace.org:latest

src/backend/auth/github.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Context, Sentry } from "../dependencies.ts";
22
import { checkUser } from "../db.ts";
33
import { checkJWT, createJWT } from "../utils/jwt.ts";
4+
import { generateApiKey } from "../utils/apiKeyGen.ts";
45

56
async function githubAuth(ctx: Context, id: string, secret: string) {
67
await authenticateAndCreateJWT(ctx, id, secret, "github");
@@ -94,7 +95,9 @@ async function handleJwtAuthentication(ctx: Context) {
9495
}
9596
const jwt_token = document.jwt_token;
9697
const provider = document.provider;
97-
ctx.response.body = await checkJWT(provider, jwt_token);
98+
const user = await checkJWT(provider, jwt_token);
99+
const apiKey = generateApiKey(user)
100+
ctx.response.body = {user , apiKey};
98101
}
99102

100103
export { githubAuth, gitlabAuth, handleJwtAuthentication };

src/backend/dependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { Session } from "https://deno.land/x/oak_sessions@v4.1.9/mod.ts";
99
import { create, verify } from "https://deno.land/x/djwt@v2.9.1/mod.ts";
1010
import { exec } from "https://deno.land/x/exec@0.0.5/mod.ts";
11-
import * as Sentry from "npm:@sentry/node";
11+
import * as Sentry from 'https://deno.land/x/sentry/index.mjs';
1212
import { oakCors } from "https://deno.land/x/cors@v1.2.2/mod.ts";
1313

1414
export {

src/backend/server.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ const frontend: string = Deno.env.get("FRONTEND")!;
2828

2929
Sentry.init({
3030
dsn: dsn,
31-
integrations: [
32-
new Sentry.Integrations.Http({ tracing: true }),
33-
],
3431
debug: true,
3532
tracesSampleRate: 1.0,
3633
});

src/backend/utils/apiKeyGen.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
function encodePayload(payload: string): string {
3+
const encoded = btoa(payload); // Convert payload to Base64
4+
return encoded;
5+
}
6+
7+
function generateRandomString(length: number): string {
8+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
9+
let result = "";
10+
for (let i = 0; i < length; i++) {
11+
result += characters.charAt(Math.floor(Math.random() * characters.length));
12+
}
13+
return result;
14+
}
15+
16+
17+
function getSimpleDateString(): string {
18+
const now = new Date();
19+
const year = now.getFullYear();
20+
const month = String(now.getMonth() + 1).padStart(2, '0');
21+
const day = String(now.getDate()).padStart(2, '0');
22+
return `${year}${month}${day}`;
23+
}
24+
25+
function generateRandomPart(): string {
26+
return generateRandomString(16);
27+
}
28+
29+
export function generateApiKey(payload: string): string {
30+
const datePart = getSimpleDateString();
31+
const encodedPayload = encodePayload(payload);
32+
const randomPart = generateRandomPart();
33+
const apiKey = `${datePart}.${encodedPayload}.${randomPart}`;
34+
return apiKey;
35+
}

src/backend/utils/jwt.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,30 @@ async function createJWT(provider: string, githubId: string) {
1313
return token;
1414
}
1515

16+
function decodePayload(encodedPayload: string): string {
17+
const decoded = atob(encodedPayload);
18+
return decoded;
19+
}
20+
21+
function decodeApiKey(apiKey: string) {
22+
const parts = apiKey.split(".");
23+
if (parts.length !== 3) {
24+
return "not verified";
25+
}
26+
27+
const [datePart, encodedPayload, randomPart] = parts;
28+
const decodedPayload = decodePayload(encodedPayload);
29+
return decodedPayload
30+
}
31+
1632
async function checkJWT(provider: string, token: string) {
1733
try {
18-
const payload = await verify(token, key);
19-
return payload[`${provider}Id`]!;
34+
if (provider === "CLI"){
35+
return decodeApiKey(token)
36+
} else {
37+
const payload = await verify(token, key);
38+
return payload[`${provider}Id`]!;
39+
}
2040
} catch (error) {
2141
return "not verified";
2242
}

src/cli/features/authUser.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import axios from 'axios';
2+
import chalk from 'chalk';
3+
4+
export async function verifyApiKey(apiKey: string, provider: string , backendUrl : string) {
5+
try {
6+
const response = await axios.post(`${backendUrl}/auth/jwt`, {
7+
jwt_token: apiKey,
8+
provider: provider,
9+
});
10+
return response.data;
11+
} catch (error) {
12+
console.error(chalk.red('Error verifying API key:'));
13+
return 'not verified';
14+
}
15+
}

0 commit comments

Comments
 (0)