Skip to content

Commit

Permalink
adding ability to generate API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
deranjer committed Apr 7, 2018
1 parent 3280360 commit 0fdc926
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 239 deletions.
14 changes: 7 additions & 7 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[serverConfig]

ServerPort = ":8000" #leave format as is it expects a string with colon
ServerAddr = "192.168.1.8" #Put in the IP address you want to bind to
ServerAddr = "192.168.1.100" #Put in the IP address you want to bind to
LogLevel = "Info" # Options = Debug, Info, Warn, Error, Fatal, Panic
LogOutput = "stdout" #Options = file, stdout #file will print it to logs/server.log

SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio

#Relative or absolute path accepted, the server will convert any relative path to an absolute path.
DefaultMoveFolder = 'Z:\downloads' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
DefaultMoveFolder = 'downloads' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
TorrentWatchFolder = 'torrentUpload' #folder path that is watched for .torrent files and adds them automatically every 5 minutes

#Limits your upload and download speed globally, all are averages and not burst protected (usually burst on start).
Expand All @@ -25,24 +25,24 @@

[notifications]

PushBulletToken = "o.8sUHemPkTCaty3u7KnyvEBN19EkeT63g" #add your pushbullet api token here to notify of torrent completion to pushbullet
PushBulletToken = "" #add your pushbullet api token here to notify of torrent completion to pushbullet

[reverseProxy]
#This is for setting up goTorrent behind a reverse Proxy (with SSL, reverse proxy with no SSL will require editing the WSS connection to a WS connection manually)
ProxyEnabled = true #bool, either false or true
ProxyEnabled = false #bool, either false or true
#URL is CASE SENSITIVE
BaseURL = "derajnet.duckdns.org/gopher/" # MUST be in the format (if you have a subdomain, and must have trailing slash) "yoursubdomain.domain.org/subroute/"
BaseURL = "domain.com/subroute/" # MUST be in the format (if you have a subdomain, and must have trailing slash) "yoursubdomain.domain.org/subroute/"

[EncryptionPolicy]

DisableEncryption = false
ForceEncryption = false
PreferNoEncryption = false
PreferNoEncryption = true

[torrentClientConfig]
DownloadDir = 'downloading' #the full OR relative path where the torrent server stores in-progress torrents

Seed = false #boolean #seed after download
Seed = true #boolean #seed after download

# Never send chunks to peers.
NoUpload = false #boolean
Expand Down
12 changes: 6 additions & 6 deletions config.toml.bk
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[serverConfig]

ServerPort = ":8000" #leave format as is it expects a string with colon
ServerAddr = "192.168.1.100" #Put in the IP address you want to bind to
ServerAddr = "192.168.1.8" #Put in the IP address you want to bind to
LogLevel = "Info" # Options = Debug, Info, Warn, Error, Fatal, Panic
LogOutput = "stdout" #Options = file, stdout #file will print it to logs/server.log

SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio

#Relative or absolute path accepted, the server will convert any relative path to an absolute path.
DefaultMoveFolder = 'downloads' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
DefaultMoveFolder = 'Z:\downloads' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
TorrentWatchFolder = 'torrentUpload' #folder path that is watched for .torrent files and adds them automatically every 5 minutes

#Limits your upload and download speed globally, all are averages and not burst protected (usually burst on start).
Expand All @@ -25,24 +25,24 @@

[notifications]

PushBulletToken = "" #add your pushbullet api token here to notify of torrent completion to pushbullet
PushBulletToken = "o.8sUHemPkTCaty3u7KnyvEBN19EkeT63g" #add your pushbullet api token here to notify of torrent completion to pushbullet

[reverseProxy]
#This is for setting up goTorrent behind a reverse Proxy (with SSL, reverse proxy with no SSL will require editing the WSS connection to a WS connection manually)
ProxyEnabled = false #bool, either false or true
#URL is CASE SENSITIVE
BaseURL = "domain.com/subroute/" # MUST be in the format (if you have a subdomain, and must have trailing slash) "yoursubdomain.domain.org/subroute/"
BaseURL = "derajnet.duckdns.org/gopher/" # MUST be in the format (if you have a subdomain, and must have trailing slash) "yoursubdomain.domain.org/subroute/"

[EncryptionPolicy]

DisableEncryption = false
ForceEncryption = false
PreferNoEncryption = true
PreferNoEncryption = false

[torrentClientConfig]
DownloadDir = 'downloading' #the full OR relative path where the torrent server stores in-progress torrents

Seed = true #boolean #seed after download
Seed = false #boolean #seed after download

# Never send chunks to peers.
NoUpload = false #boolean
Expand Down
23 changes: 18 additions & 5 deletions goTorrentWebUI/src/BackendComm/backendWebsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let serverMessage = [];
let serverPushMessage = [];
let webSocketState = false;
let settingsFile = [];
let tokenReturn = "";

var torrentListRequest = {
MessageType: "torrentListRequest"
Expand All @@ -29,7 +30,7 @@ var torrentListRequest = {



//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined 22
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined
ws.onmessage = function (evt) { //When we recieve a message from the websocket
var serverMessage = JSON.parse(evt.data)
console.log("message", serverMessage.MessageType)
Expand Down Expand Up @@ -134,6 +135,10 @@ ws.onmessage = function (evt) { //When we recieve a message from the websocket
settingsFile = [];
console.log("Settings File Returned", serverMessage)
settingsFile = serverMessage.Config

case "TokenReturn":
tokenReturn = serverMessage.TokenReturn
console.log("Token Returned", serverMessage)
}

}
Expand Down Expand Up @@ -222,9 +227,14 @@ class BackendSocket extends React.Component {
console.log("PROPSSERVER", this.props.serverPushMessage, "SERVERPUSH", serverPushMessage)
this.props.newServerMessage(serverPushMessage)
}
if (this.props.settingsModalOpen) { //TODO don't really need to updaate every tick currently until we can edit config
if (this.props.settingsModalOpen) { //TODO don't really need to update every tick currently until we can edit config
this.props.newSettingsFile(settingsFile)
}

if (tokenReturn != ""){ //If we get a return token
console.log("Dispatching token return", tokenReturn)
this.props.newTokenReturn(tokenReturn)
}

ws.send(JSON.stringify(torrentListRequest))//talking to the server to get the torrent list
if (ws.readyState === ws.CLOSED){ //if our websocket gets closed inform the user
Expand Down Expand Up @@ -264,6 +274,9 @@ class BackendSocket extends React.Component {
if (nextProps.selectionHashes.length === 1){ //if we have a selection pass it on for the tabs to verify
this.selectionHandler(nextProps.selectionHashes, nextProps.selectedTab)
}
if (nextProps.tokenReturn != this.props.tokenReturn){ //clearing out the token if we switch from the API tab
tokenReturn = nextProps.tokenReturn
}
}


Expand All @@ -287,6 +300,7 @@ const mapStateToProps = state => {
RSSTorrentList: state.RSSTorrentList,
serverPushMessage: state.serverPushMessage,
settingsModalOpen: state.settingsModalOpen,
tokenReturn: state.tokenReturn,

};
}
Expand All @@ -301,9 +315,8 @@ const mapDispatchToProps = dispatch => {
RSSTorrentList: (RSSTorrentList) => dispatch({type: actionTypes.RSS_TORRENT_LIST, RSSTorrentList}),
newServerMessage: (serverPushMessage) => dispatch({type: actionTypes.SERVER_MESSAGE, serverPushMessage}),
webSocketStateUpdate: (webSocketState) => dispatch({type: actionTypes.WEBSOCKET_STATE, webSocketState}),
newSettingsFile: (settingsFile) => dispatch({type: actionTypes.NEW_SETTINGS_FILE, settingsFile})
//changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection}),//forcing an update to the buttons

newSettingsFile: (settingsFile) => dispatch({type: actionTypes.NEW_SETTINGS_FILE, settingsFile}),
newTokenReturn: (tokenReturn) => dispatch({type: actionTypes.TOKEN_RETURN, tokenReturn}),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import ReactDOM from 'react-dom';
import { withStyles } from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Grid from 'material-ui/Grid';
import Button from 'material-ui/Button';
import TextField from 'material-ui/TextField';

import {connect} from 'react-redux';
import * as actionTypes from '../../../../store/actions';


const styles = theme => ({
root: {
flexGrow: 1,
marginTop: 0,
padding: 10,
},
paper: {
padding: 16,
Expand All @@ -23,19 +27,48 @@ const styles = theme => ({
});


class APISettingsTab extends React.PureComponent {
class APISettingsTab extends React.Component {

state = {
clientName: "",
};

requestNewKey = (keyName) => {
generateKey = (event) => {
let newAuthTokenRequest = {
MessageType: "newAuthToken",
Payload: {"ClientName": this.state.clientName}
}
console.log("Sending New Auth Request: ", newAuthTokenRequest);
ws.send(JSON.stringify(newAuthTokenRequest));
this.setState({clientName: ""})
}

setClientName = (event) => {
this.setState({clientName: event.target.value})
}

componentWillUnmount = () => {
this.props.newTokenReturn("")
}

render() {
const { classes } = this.props;
return (
<div className={classes.root}>
Not yet implemented!
<div className={classes.root}>
<TextField style ={{width: '50%', paddingRight: '10px'}} id="clientName" type="text" label="Client Name" placeholder="Client Name associated with the key" onChange={this.setClientName} />
<Button variant="raised" color="primary" onClick={this.generateKey}>
Generate Key
</Button>
<Paper style = {{padding: '10px'}}> <span className={classes.floatLeft}>{this.props.tokenReturn} </span></Paper>
<Grid container spacing={16}>

<Grid item xs={12} sm={4}>




</Grid>
</Grid>
</div>
);
}
Expand All @@ -44,9 +77,15 @@ class APISettingsTab extends React.PureComponent {

const mapStateToProps = state => {
return {
settingsFile: state.settingsFile,
tokenReturn: state.tokenReturn,
};
}

export default withStyles(styles)(connect(mapStateToProps)(APISettingsTab))
const mapDispatchToProps = dispatch => {
return {
newTokenReturn: (tokenReturn) => dispatch({type: actionTypes.TOKEN_RETURN, tokenReturn}),
}
}

export default withStyles(styles)(connect(mapStateToProps, mapDispatchToProps)(APISettingsTab))

3 changes: 2 additions & 1 deletion goTorrentWebUI/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const SETTINGS_MODAL_OPEN_STATE = 'SETTINGS_MODAL_OPEN_STATE';
export const NEW_SETTINGS_FILE = 'NEW_SETTINGS_FILE';
export const RSS_TORRENT_LIST = 'RSS_TORRENT_LIST';
export const SERVER_MESSAGE = 'SERVER_MESSAGE';
export const WEBSOCKET_STATE = 'WEBSOCKET_STATE';
export const WEBSOCKET_STATE = 'WEBSOCKET_STATE';
export const TOKEN_RETURN = 'TOKEN_RETURN';
7 changes: 7 additions & 0 deletions goTorrentWebUI/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ const reducer = (state = initialState, action) => {
...state,
serverPushMessage: action.serverPushMessage
}

case actionTypes.TOKEN_RETURN:
console.log("New token return", action.tokenReturn)
return {
... state,
tokenReturn: action.tokenReturn
}

case actionTypes.SET_BUTTON_STATE:
if (action.buttonState.length === 0) { //if selection is empty buttons will be default and selectionHashes will be blanked out and pushed to redux
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func main() {
Logger.WithFields(logrus.Fields{"clientName": payloadData["ClientName"].(string)}).Info("New Auth Token creation request")
fmt.Println("Signing Key", signingKey)
token := Settings.GenerateToken(claims, signingKey)
tokenReturn := Settings.TokenReturn{TokenReturn: token}
tokenReturn := Settings.TokenReturn{MessageType: "TokenReturn", TokenReturn: token}
tokensDB := Storage.FetchJWTTokens(db)
tokensDB.TokenNames = append(tokens.TokenNames, Storage.SingleToken{payloadData["ClientName"].(string)})
db.Update(&tokensDB) //adding the new token client name to the database
Expand Down
Loading

0 comments on commit 0fdc926

Please sign in to comment.