2022-08-06 05:22:07 +00:00
|
|
|
import React, {useContext} from 'react';
|
2022-12-15 11:48:46 -07:00
|
|
|
import {Divider, SegmentGroup, StatisticLabel, StatisticValue} from "semantic-ui-react";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {Route, Routes} from "react-router-dom";
|
2021-11-01 16:42:52 -06:00
|
|
|
import "../static/wrolpi.css";
|
|
|
|
|
import {decryptOTP, encryptOTP} from "../api";
|
2022-12-15 13:39:00 -07:00
|
|
|
import {mimetypeColor, PageContainer, useTitle} from "./Common";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {ThemeContext} from "../contexts/contexts";
|
2022-12-15 11:48:46 -07:00
|
|
|
import {Button, Header, Loader, Segment, Statistic, StatisticGroup, TextArea} from "./Theme";
|
|
|
|
|
import {useFileStatistics} from "../hooks/customHooks";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
class Encrypt extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
2022-08-06 05:22:07 +00:00
|
|
|
otp: '', plaintext: '', ciphertext: '',
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleSubmit = async (e) => {
|
|
|
|
|
e.preventDefault();
|
2022-05-01 21:03:30 -06:00
|
|
|
try {
|
|
|
|
|
let {otp, plaintext, ciphertext} = await encryptOTP(this.state.otp, this.state.plaintext);
|
|
|
|
|
this.setState({otp, plaintext, ciphertext});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleInputChange = async (event, {name, value}) => {
|
|
|
|
|
this.setState({[name]: value});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2022-08-06 05:22:07 +00:00
|
|
|
return <>
|
|
|
|
|
<Header as='h2'>Encrypt</Header>
|
|
|
|
|
<SegmentGroup>
|
|
|
|
|
<Segment>
|
|
|
|
|
<h3>Key</h3>
|
|
|
|
|
<TextArea
|
|
|
|
|
name='otp'
|
|
|
|
|
className='otp'
|
|
|
|
|
value={this.state.otp}
|
|
|
|
|
onChange={this.handleInputChange}
|
|
|
|
|
placeholder='The random letters from your One-Time Pad'
|
|
|
|
|
/>
|
|
|
|
|
</Segment>
|
|
|
|
|
<Segment>
|
|
|
|
|
<h3>Plaintext</h3>
|
|
|
|
|
<TextArea
|
|
|
|
|
name='plaintext'
|
|
|
|
|
className='otp'
|
|
|
|
|
value={this.state.plaintext}
|
|
|
|
|
onChange={this.handleInputChange}
|
|
|
|
|
placeholder='The message you want to send'
|
|
|
|
|
/>
|
|
|
|
|
</Segment>
|
|
|
|
|
<Segment>
|
|
|
|
|
<h3>Ciphertext</h3>
|
|
|
|
|
<pre>{this.state.ciphertext || 'Enter your message above'}</pre>
|
|
|
|
|
</Segment>
|
|
|
|
|
</SegmentGroup>
|
|
|
|
|
<br/>
|
|
|
|
|
<Button onClick={this.handleSubmit}>Encrypt</Button>
|
|
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Decrypt extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
2022-08-06 05:22:07 +00:00
|
|
|
otp: '', plaintext: '', ciphertext: '',
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleSubmit = async (e) => {
|
|
|
|
|
e.preventDefault();
|
2022-05-01 21:03:30 -06:00
|
|
|
try {
|
|
|
|
|
let {otp, plaintext, ciphertext} = await decryptOTP(this.state.otp, this.state.ciphertext);
|
|
|
|
|
this.setState({otp, plaintext, ciphertext});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleInputChange = async (event, {name, value}) => {
|
|
|
|
|
this.setState({[name]: value});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2022-08-06 05:22:07 +00:00
|
|
|
return <>
|
|
|
|
|
<Header as='h2'>Decrypt</Header>
|
|
|
|
|
<SegmentGroup>
|
|
|
|
|
<Segment>
|
|
|
|
|
<h3>Key</h3>
|
|
|
|
|
<TextArea
|
|
|
|
|
name='otp'
|
|
|
|
|
className='otp'
|
|
|
|
|
value={this.state.otp}
|
|
|
|
|
onChange={this.handleInputChange}
|
|
|
|
|
placeholder='The random letters from your One-Time Pad'
|
|
|
|
|
/>
|
|
|
|
|
</Segment>
|
|
|
|
|
<Segment>
|
|
|
|
|
<h3>Ciphertext</h3>
|
|
|
|
|
<TextArea
|
|
|
|
|
name='ciphertext'
|
|
|
|
|
className='otp'
|
|
|
|
|
value={this.state.ciphertext}
|
|
|
|
|
onChange={this.handleInputChange}
|
|
|
|
|
placeholder='The message you received'
|
|
|
|
|
/>
|
|
|
|
|
</Segment>
|
|
|
|
|
<Segment>
|
|
|
|
|
<h3>Plaintext</h3>
|
|
|
|
|
<pre>{this.state.plaintext || 'Enter the encrypted message above'}</pre>
|
|
|
|
|
</Segment>
|
|
|
|
|
</SegmentGroup>
|
|
|
|
|
<br/>
|
|
|
|
|
<Button onClick={this.handleSubmit}>Decrypt</Button>
|
|
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
function OTP() {
|
2022-10-25 15:57:44 -06:00
|
|
|
useTitle('One Time Pad');
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
const {t} = useContext(ThemeContext);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
let newPadURL = `http://${window.location.host}/api/otp/html`;
|
|
|
|
|
let cheatSheetURL = `${process.env.PUBLIC_URL}/one-time-pad-cheat-sheet.pdf`;
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
return <>
|
|
|
|
|
<Header as='h1'>One-Time Pad</Header>
|
|
|
|
|
<Header as='h4'>One-Time Pads can be used to encrypt your communications. This can be done by hand
|
|
|
|
|
(yes, really) or in this app.</Header>
|
|
|
|
|
<p {...t}>These messages are never stored and cannot be retrieved.</p>
|
|
|
|
|
<Button primary href={newPadURL}>Generate New Pad</Button>
|
|
|
|
|
<Button secondary href={cheatSheetURL}>Cheat Sheet PDF</Button>
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
<Divider/>
|
|
|
|
|
<Encrypt/>
|
|
|
|
|
|
|
|
|
|
<Divider/>
|
|
|
|
|
<Decrypt/>
|
|
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-12-15 11:48:46 -07:00
|
|
|
function FileStatistics() {
|
|
|
|
|
useTitle('File Statistics');
|
|
|
|
|
|
|
|
|
|
const {s} = useContext(ThemeContext);
|
|
|
|
|
|
|
|
|
|
const {statistics} = useFileStatistics();
|
|
|
|
|
|
2022-12-15 13:39:00 -07:00
|
|
|
let body = <Segment><Loader inline active/></Segment>;
|
2022-12-15 11:48:46 -07:00
|
|
|
|
|
|
|
|
if (statistics === undefined) {
|
2022-12-15 13:39:00 -07:00
|
|
|
body = <Segment><p {...s}>Failed to fetch statistics</p></Segment>;
|
2022-12-15 11:48:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (statistics !== undefined && statistics !== null) {
|
2022-12-15 13:39:00 -07:00
|
|
|
const {
|
|
|
|
|
archive_count,
|
|
|
|
|
audio_count,
|
|
|
|
|
ebook_count,
|
|
|
|
|
image_count,
|
|
|
|
|
pdf_count,
|
|
|
|
|
total_count,
|
|
|
|
|
video_count,
|
|
|
|
|
zip_count,
|
|
|
|
|
} = statistics;
|
2022-12-15 11:48:46 -07:00
|
|
|
body = <>
|
2022-12-15 13:39:00 -07:00
|
|
|
<Segment>
|
|
|
|
|
<StatisticGroup>
|
|
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{total_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>All Files</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
</StatisticGroup>
|
|
|
|
|
</Segment>
|
|
|
|
|
<Segment>
|
|
|
|
|
<StatisticGroup size='small'>
|
|
|
|
|
<Statistic color={mimetypeColor('video/')}>
|
|
|
|
|
<StatisticValue>{video_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Videos</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
<Statistic color={mimetypeColor('application/pdf')}>
|
|
|
|
|
<StatisticValue>{pdf_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>PDFs</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
<Statistic color={mimetypeColor('application/epub')}>
|
|
|
|
|
<StatisticValue>{ebook_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>eBooks</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
<Statistic color={mimetypeColor('text/html')}>
|
|
|
|
|
<StatisticValue>{archive_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Archives</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
<Statistic color={mimetypeColor('image/')}>
|
|
|
|
|
<StatisticValue>{image_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Images</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
</StatisticGroup>
|
|
|
|
|
</Segment>
|
|
|
|
|
<Segment>
|
|
|
|
|
<StatisticGroup size='tiny'>
|
|
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{zip_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>ZIP</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
<Statistic>
|
|
|
|
|
<StatisticValue>{audio_count}</StatisticValue>
|
|
|
|
|
<StatisticLabel>Audio</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
</StatisticGroup>
|
|
|
|
|
</Segment>
|
2022-12-15 11:48:46 -07:00
|
|
|
</>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
<Header as='h1'>File Statistics</Header>
|
2022-12-15 13:39:00 -07:00
|
|
|
{body}
|
2022-12-15 11:48:46 -07:00
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 22:34:37 -07:00
|
|
|
export function AppsRoute(props) {
|
2022-08-06 05:22:07 +00:00
|
|
|
return (<PageContainer>
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path='otp' exact element={<OTP/>}/>
|
2022-12-15 11:48:46 -07:00
|
|
|
<Route path='file_statistics' exact element={<FileStatistics/>}/>
|
2022-08-06 05:22:07 +00:00
|
|
|
</Routes>
|
|
|
|
|
</PageContainer>)
|
2022-01-04 09:07:28 -07:00
|
|
|
}
|