Skip to content

Commit

Permalink
✨ Add Wireguard QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinbreiz committed Jan 3, 2024
1 parent cf6cb56 commit 469148c
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.0.3",
"react-mobile-app-button": "^1.2.17",
"react-monaco-editor": "^0.52.0",
"react-router-dom": "^5.3.4",
"react-toastify": "^9.1.3",
Expand Down
104 changes: 104 additions & 0 deletions src/components/dashboard/MobileLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from 'react';
import { Typography, TextField, Button, Paper, Grid, Snackbar, Alert, List, ListItem, ListItemText, ListItemSecondaryAction, IconButton, Box } from '@mui/material';
import DeleteIcon from '@mui/icons-material/Delete';
import { Divider } from '@mui/material';
import HelpModal from "@components/HelpModal";
import useBlackListRPC from '@hooks/backend/honeypotService/useBlackListRPC';
import { useTranslation } from 'react-i18next';
import { AppGalleryButton, AppStoreButton, ButtonsContainer, GooglePlayButton } from 'react-mobile-app-button';
import useMobileRPC from '@hooks/backend/mobileService/useMobileRPC';

const MobileLink = () => {
const { t } = useTranslation();

const { getWireguardConfig } = useMobileRPC();
const [qrCode, setQrCode] = React.useState('');
const [isLoading, setIsLoading] = React.useState(true);

React.useEffect(() => {
const fetchQrCode = async () => {
try {
const base64Image = await getWireguardConfig();
setQrCode(base64Image);
} catch (error) {
console.error('Failed to fetch QR code:', error);
} finally {
setIsLoading(false);
}
};

fetchQrCode();
}, []);

return (
<Grid container direction="column">
<Grid item>
<Grid container justifyContent="space-between" alignItems="center" mb={2}>
<Grid item>
<Typography variant="h4">{t('mobileLink.mobileLink')}</Typography>
</Grid>
<Grid item>
<HelpModal helpText={t('mobileLink.blockManagerHelpText')}/>
</Grid>
</Grid>
</Grid>
<Grid item xs style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<Box flex={1} display="flex" justifyContent="center" alignItems="center">
<Paper sx={{ p: 2, width: '50em' }}>
<Grid container justifyContent="space-between" alignItems="center" marginBottom="15px">
<Grid item>
<Typography variant="h5">{t('mobileLink.accessDistance')}</Typography>
</Grid>
</Grid>
<Grid container spacing={2} mb={3} direction="row">
<Grid item xs={6}>
<Typography variant="h6" mb={2}>{t('mobileLink.installWireguardStep')}</Typography>
<Typography variant="body2">{t('mobileLink.installWireguardDescription')}</Typography>
<Box display="flex" justifyContent="flex-start" mt={2}>
<ButtonsContainer>
<GooglePlayButton
url='https://play.google.com/store/apps/details?id=com.wireguard.android'
theme={"light"}
className={"custom-style"}
/>
<AppStoreButton
url='https://apps.apple.com/fr/app/wireguard/id1441195209'
theme={"light"}
className={"custom-style"}
/>
</ButtonsContainer>
</Box>
</Grid>
<Grid item xs={12}>
<Typography variant="h6" mb={2}>{t('mobileLink.scanQRCodeStep')}</Typography>
<Typography variant="body2">{t('mobileLink.scanQRCodeDescription')}</Typography>
{isLoading ? (
<Typography>{t('mobileLink.loadingQRCode')}</Typography>
) : (
qrCode ? <img src={`data:image/png;base64,${qrCode}`} alt={t('mobileLink.qrCodeAltText')} style={{ maxWidth: '100%', height: 'auto' }} /> : <Typography>{t('mobileLink.qrCodeUnavailable')}</Typography>
)}
</Grid>
<Grid item xs={12}>
<Grid item xs={12}>
<Typography variant="h6" mb={2}>{t('mobileLink.downloadAppStep')}</Typography>
<Typography variant="body2">
{t('mobileLink.downloadAppDescription')}
<Button
href="https://github.com/Honeybrain/Mobile/releases"
target="_blank" // Opens link in a new tab
rel="noopener noreferrer" // Security for opening links in new tabs
>
Honeybrain Mobile
</Button>
</Typography>
</Grid>
</Grid>
</Grid>
</Paper>
</Box>
</Grid>
</Grid>
);
};

export default MobileLink;
21 changes: 21 additions & 0 deletions src/hooks/backend/mobileService/useMobileRPC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";
import { transport } from "../../../environment";
import { MobileClient } from '@protos/mobile.client';
import { WireguardConfigRequest, WireguardConfigResponse } from "@protos/mobile";

const useMobileRPC = () => {
const client = React.useMemo(() => new MobileClient(transport), []);

const getWireguardConfig = React.useCallback(async (): Promise<string> => {
const request: WireguardConfigRequest = WireguardConfigRequest.create();

const signinResponse = await client.getWireguardConfig(request, {});
return signinResponse.response.base64Image;
}, []);

return {
getWireguardConfig,
};
};

export default useMobileRPC;
32 changes: 23 additions & 9 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"containerManager": "Container Manager",
"incomingConnections": "Incoming Connections",
"userManagement": "User Management",
"mobileLink": "Mobile Link",
"otherFeatures": "Other Features",
"history": "History Page"
},
Expand Down Expand Up @@ -113,14 +114,27 @@
"logout": "You have been successfully logged out "
},
"userManagement": {
"userManagement":"User management",
"inviteNewUser":"Invite a new user",
"emailNewUser": "new user email",
"sendInvite": "send invite",
"usersList": "Users list",
"user": "user",
"admin": "admin",
"activated": "activated",
"waitingActivation": "waiting for activation"
"userManagement":"User management",
"inviteNewUser":"Invite a new user",
"emailNewUser": "new user email",
"sendInvite": "send invite",
"usersList": "Users list",
"user": "user",
"admin": "admin",
"activated": "activated",
"waitingActivation": "waiting for activation"
},
"mobileLink": {
"mobileLink": "Mobile Link",
"accessDistance": "Link your mobile for remote access 🚀",
"installWireguardStep": "1. Install Wireguard",
"installWireguardDescription": "Install the Wireguard app on your Mobile phone.",
"scanQRCodeStep": "2. Scan the QR code with your Wireguard app",
"scanQRCodeDescription": "Scan this QR code with the Wireguard app to connect to your local network.",
"downloadAppStep": "3. Download Honeybrain Mobile",
"downloadAppDescription": "Download the Mobile app at this link:",
"loadingQRCode": "Loading QR code...",
"qrCodeUnavailable": "QR code not available",
"blockManagerHelpText": "The VPN client serves as a secure gateway to access the HoneyBrain suite remotely, beyond your local network. By establishing a protected connection, it ensures that only authorized users can administer the security suite. This feature is crucial for maintaining the integrity and confidentiality of your network. It allows you to manage configurations, monitor activities, and update security measures from anywhere, ensuring you have full control over your cybersecurity environment."
}
}
20 changes: 17 additions & 3 deletions src/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"containerManager": "Manager des conteneurs",
"incomingConnections": "Connexions entrantes",
"userManagement": "Gestion des utilisateurs",
"mobileLink": "Mobile Link",
"otherFeatures": "Autres fonctionnalités",
"history": "Historique"
},
Expand Down Expand Up @@ -116,8 +117,8 @@
"userManagement":"Gestion des utilisateurs",
"inviteNewUser":"Inviter un nouvel utilisateur",
"emailNewUser": "Email nouvel utilisateur",
"sendInvite": "envoyer l'invitation",
"usersList": "liste des utilisateurs",
"sendInvite": "Envoyer l'invitation",
"usersList": "Liste des utilisateurs",
"activated": "activé",
"waitingActivation": "en attente d'activation"
},
Expand All @@ -129,5 +130,18 @@
"CAN_READ_LOGS": "Lire les logs",
"CAN_MANAGE_CONFIGURATION": "Gérer la configuration",
"CAN_READ_SERVICES": "Lire les services"
}
},
"mobileLink": {
"mobileLink": "Mobile Link",
"accessDistance": "Liez votre mobile pour un accès à distance 🚀",
"installWireguardStep": "1. Installez Wireguard",
"installWireguardDescription": "Installez l'application Wireguard sur votre téléphone Mobile.",
"scanQRCodeStep": "2. Scannez le QR code avec votre application Wireguard",
"scanQRCodeDescription": "Scannez ce QR code avec l'application Wireguard pour se connecter à votre réseau local.",
"downloadAppStep": "3. Téléchargez Honeybrain Mobile",
"downloadAppDescription": "Téléchargez l'application Mobile à ce lien :",
"loadingQRCode": "Chargement du QR code...",
"qrCodeUnavailable": "QR code non disponible",
"blockManagerHelpText": "Le client VPN sert de passerelle sécurisée pour accéder à distance à la suite HoneyBrain, au-delà de votre réseau local. En établissant une connexion protégée, il garantit que seuls les utilisateurs autorisés peuvent administrer la suite de sécurité. Cette fonctionnalité est cruciale pour maintenir l'intégrité et la confidentialité de votre réseau. Elle vous permet de gérer les configurations, surveiller les activités et mettre à jour les mesures de sécurité de n'importe où, vous assurant un contrôle total sur votre environnement de cybersécurité."
}
}
6 changes: 6 additions & 0 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useTranslation } from "react-i18next";
import UsersManagement from "../components/dashboard/UsersManagement";
import { HaveRoles } from "../_utils/function/have-roles";
import { RoleEnum } from "@protos/user";
import MobileLink from "@components/dashboard/MobileLink";

const HomePage = () => {
const { isLoggedIn, user } = useContext(AuthContext);
Expand Down Expand Up @@ -57,6 +58,8 @@ const HomePage = () => {
);
case "usersManagement":
return <UsersManagement />;
case "mobileLink":
return <MobileLink />;
default:
}
};
Expand Down Expand Up @@ -87,6 +90,9 @@ const HomePage = () => {
{t('homePage.userManagement')}
</li>
)}
<li onClick={() => handleMenuClick("mobileLink")}>
{t("homePage.mobileLink")}
</li>
<li onClick={() => handleMenuClick("otherFeatures")}>
{t("homePage.otherFeatures")}
</li>
Expand Down

0 comments on commit 469148c

Please sign in to comment.