Skip to content

Commit

Permalink
docs and some housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Feb 25, 2020
1 parent fc58bcc commit 1e7bf3b
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 478 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
## Custom:
cache/*
data/*
txData/*
test/*
dist/*
locale/custom.json
extensions/*
!extensions/txAdminClient/
*.ignore.*
/start_*.bat
dist/

## Github's default node gitignore
# Logs
Expand Down
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
txAdmin for FiveM
</h1>
<p align="center">
<img width="420" height="237" src="https://i.imgur.com/acV0dfO.png">
<img width="420" height="237" src="docs/banner.png">
</p>
<h4 align="center">
<!-- FiveM Forum thread: &nbsp; <a href="https://forum.fivem.net/t/530475"><img src="https://img.shields.io/badge/dynamic/json.svg?color=green&label=txAdmin&query=views&suffix=%20views&url=https%3A%2F%2Fforum.fivem.net%2Ft%2F530475.json"></img></a> <br/> -->
Join our Discord Server: &nbsp; <a href="https://discord.gg/f3TsfvD"><img src="https://discordapp.com/api/guilds/577993482761928734/widget.png?style=shield"></img></a>
</h4>
<p align="center">
Expand All @@ -17,9 +16,34 @@
<br/>


## This is the CONVERSION branch.
## Main Features
- Start/Stop/Restart your server instance or resources
- Access control:
- Login via Password, CitizenFX or Discord
- Admin permission system ([more info](docs/permissions.md))
- Action logging
- Brute-force protection
- Discord Integration:
- Server status command (`/status`)
- Custom static commands
- Command spam prevention
- Monitoring:
- Auto Restart on crash
- Server’s CPU/RAM consumption
- Live Console (with log file)
- Hitch Detection statistics
- Online players chart
- Server Activity Log (connections/disconnections, kills, chat, explosions and [custom commands](docs/extra_logging.md))
- Real-time playerlist with ping + steam-linked accounts (when available)
- Scheduled restarts with warning announcements
- Translation Support ([more info](docs/translation.md))
- FiveM's Server CFG editor


## Installing & Running (Windows/Linux)

If your copy of fxserver doesn't come with txAdmin (`citizen/system_resources/txAdmin`), you can install with the following steps:

### Install
```bash
#Inside your fxserver folder, execute:
cd citizen/system_resources
Expand All @@ -36,11 +60,10 @@ An `txData` folder will be created in your current working directory.
- **serverProfile:** The name of the server profile to start. Profiles are saved/loaded from the current directory inside the `txData` folder.
- **txAdminPort:** The TCP port to use as HTTP Server.

### Web Port Behaviour
- **(Planned)** With Nucleus integration (single/multi server):
- Grabs ConVar
- Defaults to null, don't create http server unless port is specified
NOTE: Think about the http calls between the server and txAdmin. Not having a local port will impact it for sure. Should I just let the default 40120?
ConVar usage example on Windows:
```bash
./run.cmd +set serverProfile dev_server +set txAdminPort 40125
```

## License, Credits and Thanks
- This project is licensed under the [MIT License](https://github.com/tabarra/txAdmin/blob/master/LICENSE).
Expand Down
Binary file added docs/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/dev_interface.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Interface Development
**DO NOT** Modify `css/coreui.css`. Either do a patch in the `custom.css` or modify the SCSS variables.
This doc is a reference if you are trying to re-build the `css/coreui.css` from the SCSS source.
The only thing I changed from CoreUI was the `aside-menu` size from 200px to 300px in `scss/_variables.scss : $aside-menu-width`.
Expand Down
14 changes: 6 additions & 8 deletions docs/permissions.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
## Permission System
Introduced in **txAdmin** v1.5.0, the permission system allows you to control which admins can perform which actions.
The permission system allows you to control which admins can perform which actions.
For instance you can allow one admin to only view the console and kick players, but not restart the server and execute arbitrary commands.
The permissions are saved in the `data/admins.json` file and can be edited through the *Admin Manager* page by users with `all` or `manage.admins` permissions.
Any accounts created with the `admin-add` script will be created with all permissions.

**Note:** There is no "root" account, so an account with the `manage.admins` permission could delete the account that created him.
The permissions are saved in the `txData/admins.json` file and can be edited through the *Admin Manager* page by the Master admin, or users with `all_permissions` or `manage.admins` permissions.

### Available Permissions
- `all`: Root permission that allows the user to perform any action. When set, this will remove all other permissions;
- `all_permissions`: Root permission that allows the user to perform any action. When set, this will remove all other permissions;
- `manage.admins`: Permission to create, edit and remove other admin accounts;
- `settings.view`: Permission to view the settings;
- `settings.write`: Permission to edit the settings;
- `control.server`: Permission to start/stop/restart the server;
- `commands.message`: Permission to send admin messages via DM or Broadcast command;
- `commands.kick`: Permission to kick one or all players;
- `commands.resources`: Permission to start/ensure/restart/stop resources;
- `commands.kick`: Permission to kick one or all players;
- `commands.message`: Permission to send admin messages via DM or Broadcast command;
- `commands.custom`: Permission to execute any of the custom commands (**not implemented yet**);
- `console.view`: Permission to view the Live Console;
- `console.write`: Permission to execute commands in the Live Console.
- `server.cfg.editor`: Permission to view and edit the FXServer CFG File (eg `server.cfg`).
20 changes: 0 additions & 20 deletions docs/ssl_support.md

This file was deleted.

26 changes: 10 additions & 16 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@ First and foremost check if you are using the most recent version of txAdmin and
When executing txAdmin, it might show you some errors. Example of an [error](https://i.imgur.com/2huiyBf.png), example of a [successful startup](https://i.imgur.com/QLCBZBm.png).

### [txAdmin:Authenticator] Unable to load admins.
If you haven't created the admins file yet, execute `node src/scripts/admin-add.js` to do so.
- `cannot read file`: the admin file `data/admins.json` could not be found.
- `json parse error`: somehow you broke the file. Use [JSON Editor Online](https://jsoneditoronline.org) to validate and find the error. Also make sure you didn't used `\` instead of `/`. You can either fix the issue, or run the admin-add script again to create a new file.
- `invalid data in the admins file`: You edited or removed the object keys (`name`, `password_hash` and `permissions`). You can either fix the issue, or run the admin-add script again to create a new file.
- `invalid hash`: the `password_hash` must contain the hash of the password and not the password itself. To generate the hashed password, you can use tools like [this](https://www.browserling.com/tools/bcrypt) and [this](https://bcrypt-generator.com) or even [this one](https://passwordhashing.com/BCrypt).
- `no entries`: you must have at least one admin.
If you get `cannot read file`, it means the admin file `txData/admins.json` doesn't exist or txAdmin doesn't have permission to read it.
Any other error message means you somehow broke the admins file, delete it and restart txAdmin to generate a new one.

### [txAdmin:ConfigVault] Error: Unnable to load configuration file 'data/default/config.json'
You haven't created the `default` server profile, execute `node src/scripts/setup.js default` to create it.
Note: This also applies for any other server profile. You can create new profiles by executing `node src/scripts/setup.js <profile name>`
Note2: If on Linux, make sure there is no permission issue (eg file owned by the root account).
### [txAdmin:ConfigVault] Error: Unnable to load configuration file 'txData/<profile>/config.json'
The selected profile (or `default`) cannot be loaded due to permission issues (eg file owned by the root account), or due to broken JSON.


## Problems running FXServer
## Problems starting the server
When you start txAdmin, your server will **not** start automatically (by default). Open the web panel and start txAdmin (actions > START Server). You can change this by enabling autostart in the settings page.
If you are getting `FXServer is not responding!` it means the txAdmin:Monitor could not connect to the FXServer. Check the two items below.
- If the server is actually online and working properly (you can join the server) but txAdmin thinks it's offline, this is an issue with FXServer and not txAdmin. Nothing we can do.
- If you are having trouble starting the FXServer via txAdmin, run `node src/scripts/config-tester.js default` and see which test is failing.
If you are getting `FXServer is not responding!` it means the txAdmin:Monitor could not connect to the FXServer, causes:
- FXServer is not responding to the TCP endpoint, this usually means some resource got stuck;
- FXServer and txAdmin are on the same TCP port. In this case your server will not be able to listen to the configured port and the healthcheck will return a 404 error;
- FXServer is not listening to the local interface;

<hr>

If this guide didn't help you, open an Issue or join our awesome [Discord server](https://discord.gg/f3TsfvD).
If this guide didn't help you, join our awesome [Discord server](https://discord.gg/f3TsfvD).
4 changes: 2 additions & 2 deletions src/components/authenticator/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//Requires
const modulename = 'Authenticator';
const ac = require('ansi-colors');
const fs = require('fs-extra');
const clone = require('clone');
const { dir, log, logOk, logWarn, logError} = require('../../extras/console')(modulename);
Expand Down Expand Up @@ -51,7 +52,7 @@ module.exports = class Authenticator {
let sep = `=`.repeat(42);
log(sep);
log('==> Admins file not found.');
log(`==> PIN to add a master account: ${this.addMasterPin}`);
log(`==> PIN to add a master account: ` + ac.inverse(' ' + this.addMasterPin + ' '));
log(sep);
this.admins = false;
}else{
Expand Down Expand Up @@ -89,7 +90,6 @@ module.exports = class Authenticator {
},
permissions: []
}];
dir(this.admins)

//Saving admin file
try {
Expand Down
1 change: 0 additions & 1 deletion src/components/webServer/ctxUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ module.exports = async function WebCtxUtils(ctx, next){
ctx.body = await renderSoloView(view, viewData);
}else{
ctx.body = await renderMasterView(view, ctx.session, viewData);
// dir(ctx.body)
}
ctx.type = 'text/html';
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/webServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ module.exports = class WebServer {
//================================================================
setupServerCallbacks(){
//Print cfx.re url... when available
//NOTE: perhaps open the URL automatically with the `open` library
let validUrlRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\.users\.cfx\.re$/i
let getUrlInterval = setInterval(() => {
try {
let urlConvar = GetConvar('web_baseUrl', 'false');
if(urlConvar !== 'false'){
if(validUrlRegex.test(urlConvar)){
logOk(`::Listening at https://${urlConvar}/`);
globals.info.cfxUrl = urlConvar;
clearInterval(getUrlInterval)
Expand Down
7 changes: 4 additions & 3 deletions src/scripts/setup.js → src/extras/setup.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//Requires
const modulename = 'SetupScript';
const modulename = 'Setup';
const ac = require('ansi-colors');
const fs = require('fs-extra');
const path = require('path');
const slash = require('slash');
const { dir, log, logOk, logWarn, logError} = require('../extras/console')(modulename);
const { dir, log, logOk, logWarn, logError} = require('./console')(modulename);
const osType = require('os').type();

//Helpers
Expand Down Expand Up @@ -90,7 +91,7 @@ module.exports = (serverRoot, serverProfile, profilePath) => {

logOk(`To start with this profile add the following argument: +set serverProfile "${serverProfile}"`);
if(osType == 'Windows_NT'){
logOk(`You can also execute run 'start_${serverProfile}.bat' added to this folder.`);
logOk(`You can also run ` + ac.inverse(` start_${serverProfile}.bat `) + ` added to this folder.`);
}
printDivider();
}
13 changes: 7 additions & 6 deletions src/extras/xss.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//Require
const xssClass = require('xss');

// console.dir(xss.whiteList)
//Set custom xss rules


module.exports = (incWL = []) => {
/**
* Returns a function with the passed whitelist parameter.
* https://github.com/leizongmin/js-xss#whitelist
*/
module.exports = (customWL = []) => {
const xss = new xssClass.FilterXSS({
whiteList: incWL
whiteList: customWL
});
return (x) => {return xss.process(x)}
return (x) => {return xss.process(x)};
}
39 changes: 19 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ const serverProfile = GetConvar('serverProfile', 'default').replace(/[^a-z0-9._-
if(!serverProfile.length){
logError(`Invalid server profile name. Are you using Google Translator on the instructions page? Make sure there are no additional spaces in your command.`);
process.exit();
}else if(serverProfile === 'example'){
logError(`You can't use the 'example' profile.`);
process.exit();
}
log(`Server profile selected: '${serverProfile}'`);

Expand All @@ -49,9 +46,9 @@ try {
//Check if the profile exists and call setup if it doesn't
const profilePath = cleanPath(path.join(dataPath, serverProfile));
if(!fs.existsSync(profilePath)){
logWarn(`Profile not found in '${dataPath}', setting folder up...`);
logWarn(`Profile not found in '${dataPath}'`);
try {
const SetupScript = require('./scripts/setup.js');
const SetupScript = require('./extras/setup.js');
SetupScript(serverRoot, serverProfile, profilePath);
} catch (error) {
logError(`Failed to create profile '${serverProfile}' with error: ${error.message}`);
Expand All @@ -77,21 +74,23 @@ const app = new txAdmin(dataPath, profilePath, serverProfile, txAdminPort);


//==============================================================
//Freeze detector
let hdTimer = Date.now();
setInterval(() => {
let now = Date.now();
if(now - hdTimer > 2000){
let sep = `=`.repeat(72);
setTimeout(() => {
logError(sep);
logError('Major process freeze detected.');
logError('THIS IS NOT AN ERROR CAUSED BY TXADMIN! Your VPS is probably lagging out.');
logError(sep);
}, 1000);
}
hdTimer = now;
}, 500);
//Freeze detector - starts after 10 seconds
setTimeout(() => {
let hdTimer = Date.now();
setInterval(() => {
let now = Date.now();
if(now - hdTimer > 2000){
let sep = `=`.repeat(72);
setTimeout(() => {
logError(sep);
logError('Major process freeze detected.');
logError('THIS IS NOT AN ERROR CAUSED BY TXADMIN! Your VPS is probably lagging out.');
logError(sep);
}, 1000);
}
hdTimer = now;
}, 500);
}, 10000);

//Handle any stdio error
process.stdin.on('error', (data) => {});
Expand Down
Loading

0 comments on commit 1e7bf3b

Please sign in to comment.