Skip to content

Commit

Permalink
Merge pull request #93 from sinamics/dev
Browse files Browse the repository at this point in the history
Merge dev branch
  • Loading branch information
sinamics authored Aug 19, 2023
2 parents 2fcbbc3 + f771a6d commit 9f0d1e3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/components/modules/controller/privateRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ const PrivateRoot = () => {
<div className="flex gap-3">
<button
onClick={() => downloadPlanet()}
className="btn join-item bg-primary"
className="btn join-item bg-primary btn-sm"
>
{t(
"controller.generatePlanet.buttons.downloadPlanetButton",
)}
</button>
<button
onClick={() => setOpen(!open)}
className="btn join-item"
className="btn join-item btn-sm"
>
{t("controller.generatePlanet.buttons.editPlanetConfig")}
</button>
Expand All @@ -174,7 +174,7 @@ const PrivateRoot = () => {
},
})
}
className="btn btn-outline btn-error"
className="btn btn-outline btn-error btn-sm"
>
{t(
"controller.generatePlanet.buttons.restoreOriginalPlanetButton",
Expand Down
31 changes: 22 additions & 9 deletions src/components/modules/controller/rootForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
const { callModal } = useModalStore((state) => state);
const { data: getOptions, refetch: refetchOptions } =
api.settings.getAllOptions.useQuery();
const { data: getWorld } = api.admin.getWorld.useQuery();

const [world, setWorld] = useState({
plRecommend: true,
plBirth: Date.now(),
plID: Math.floor(Math.random() * 2 ** 32),
endpoints: "",
comment: "",
identity: "",
});

const { mutate: makeWorld } = api.admin.makeWorld.useMutation({
Expand Down Expand Up @@ -67,11 +69,12 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
plRecommend: getOptions?.plRecommend || prev.plRecommend,
plBirth: Number(getOptions?.plBirth) || prev.plBirth,
plID: Number(getOptions?.plID) || prev.plID,
endpoints: getOptions?.plEndpoints,
endpoints: getOptions?.plEndpoints || `${getWorld?.ip}/9993`,
comment: getOptions?.plComment,
identity: getOptions?.plIdentity || getWorld?.identity,
}));
}
}, [getOptions]);
}, [getOptions, getWorld]);

const inputChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
Expand Down Expand Up @@ -109,7 +112,7 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
name="plRecommend"
type="checkbox"
checked={world.plRecommend}
className="checkbox checkbox-primary"
className="checkbox checkbox-primary checkbox-sm"
onChange={inputChange}
/>
</div>
Expand All @@ -125,7 +128,7 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
placeholder={t("controller.generatePlanet.birthLabel")}
value={world.plBirth}
onChange={inputChange}
className="input-bordered input-md px-3 py-2 w-full rounded-md border-gray-300"
className="input-bordered input-sm px-3 py-2 w-full rounded-md border-gray-300"
disabled={world.plRecommend && !getOptions?.customPlanetUsed}
/>
</div>
Expand All @@ -140,7 +143,7 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
placeholder={t("controller.generatePlanet.idPlaceholder")}
value={world.plID}
onChange={inputChange}
className="input-bordered input-md px-3 w-full py-2 rounded-md border-gray-300"
className="input-bordered input-sm px-3 w-full py-2 rounded-md border-gray-300"
disabled={world.plRecommend && !getOptions?.customPlanetUsed}
/>
</div>
Expand All @@ -155,10 +158,20 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
placeholder={t("controller.generatePlanet.endpointsPlaceholder")}
value={world?.endpoints}
onChange={inputChange}
className="input-bordered input-md px-3 py-2 w-full rounded-md border-gray-300"
className="input-bordered input-sm px-3 py-2 w-full rounded-md border-gray-300"
/>
</div>
<div>
<label className="block text-gray-500 mb-2">Idendity</label>
<Input
name="identity"
type="text"
placeholder={t("controller.generatePlanet.commentPlaceholder")}
value={world?.identity}
onChange={inputChange}
className="px-3 py-2 w-full input-sm rounded-md border-gray-300"
/>
</div>

<div>
<label className="block text-gray-500 mb-2">
{t("controller.generatePlanet.commentDescription")}
Expand All @@ -169,7 +182,7 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
placeholder={t("controller.generatePlanet.commentPlaceholder")}
value={world?.comment}
onChange={inputChange}
className="px-3 py-2 w-full rounded-md border-gray-300"
className="px-3 py-2 w-full input-sm rounded-md border-gray-300"
/>
</div>
<button
Expand All @@ -183,7 +196,7 @@ const RootForm: React.FC<{ onClose: () => void }> = ({ onClose }) => {
},
});
}}
className={"btn btn-primary btn-md"}
className={"btn btn-primary btn-sm"}
type="submit"
>
{getOptions?.customPlanetUsed
Expand Down
17 changes: 17 additions & 0 deletions src/server/api/routers/adminRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { NetworkAndMemberResponse } from "~/types/network";
import { execSync } from "child_process";
import fs from "fs";
import { WorldConfig } from "~/types/worldConfig";
import axios from "axios";

export const adminRouter = createTRPCRouter({
getUsers: adminRoleProtectedRoute
Expand Down Expand Up @@ -601,7 +602,23 @@ export const adminRouter = createTRPCRouter({
}
}
}),
getWorld: adminRoleProtectedRoute.query(async () => {
let ip = "External IP";
try {
const response = await axios.get("https://api.ip.sb/ip");
ip = response.data.trim();
} catch (error) {
console.error("Failed to fetch public IP:", error);
}

// Get identity from the file system
const identityPath = "/var/lib/zerotier-one/identity.public";
const identity = fs.existsSync(identityPath)
? fs.readFileSync(identityPath, "utf-8").trim()
: "";

return { ip, identity };
}),
makeWorld: adminRoleProtectedRoute
.input(
z
Expand Down

0 comments on commit 9f0d1e3

Please sign in to comment.