[RELEASE] FiveM Web API (start / stop / reboot your server, made easy)

Today I made my first release on the FiveM Forums

It’s a FiveM Web API to start / stop / restart your server from the browser

Also, you can create a curl call to implement it within your own website/application

fivem-webapi

How to install?

  1. Open CMD or a similar Command Line Interface
  2. Make sure that you are in the working directory, I advise you to create a new directory
  3. Excecute this install command: git clone https://github.com/kloentje2/fivem-webapi.git en press Enter
    (Don’t leave the working directory or close the command line!)
  4. Excecute the install command: npm install
  5. Open the file app.js in your plain-text editor and change the variable key to a random string that you can remember
  6. Also change the port to something you want. Be sure to open it in the firewall/router when you want to open it form outside the network
  7. Run node app.js in the Command Line and hit Enter

The console shoud show “Running on port x” (x = your chosen port)

When you are done with the steps above you can navigate to http://server-ip:port/ in your browser. On that page the commands are listed

http://server-ip:port/start

http://server-ip:port/stop

http://server-ip:port/restart

When you want to use one of these functions you need to use the API Key that you’ve changed.

You can use the key as a URL query

http://server-ip:port/start?key=123456

http://server-ip:port/stop?key=123456

http://server-ip:port/restart?key=123456

Without using the key you won’t be able to perform the action

Requirements

  • NodeJS 8.9.4 (You can try lower, but i’ve tested it on this version)
  • Windows Server 2012 R2 (Every recent Windows Server/Client Version should work, but i’ve tested it on this version)
  • Access to the Windows Firewall

You can acces the code at: https://github.com/kloentje2/fivem-webapi

Please be so kind to give your opinion, so I can improve my API!

11 Likes

Thank you for this release.

I’ve moved it to #development:releases

1 Like

Thanks, I’m sorry to cause this extra moderation work

nice man thx :slight_smile: Will get handy for us soon

1 Like

Please test is as much you can and report every bug in an Git issue! :slight_smile:

Awesome… Some issues I had to fix however.

  1. Your instructions are incomplete
  2. your package.json is named packages.json which doesn’t work.

I haven’t finished the install but thats what I’ve noticed so far.

The correct installation instructions are:

  1. Create a directory you want the API to be contained within
  2. CD to your directory (ex: cd C:\webapi)
  3. Run the git clone command: git clone https://github.com/kloentje2/fivem-webapi.git
  4. CD to the new downloaded directory (ex: cd C:\webapi\fivem-webapi
  5. Excecute the install command: npm install
  6. ONLY BECAUSE THE DOWNLOAD IS CURRENTLY BROKEN Rename packages.json to package.json
  7. Edit the app.js with your favorite text editor with the correct variables.
  8. Open the port you used in the variables section. To open a port easily, use the batch file below.
    Variables (Bold Indicates do not edit):
  9. In the CMD prompt execute the following command: node app.js
    server_dir: The server MAIN directory. EX: C:\Users\Administrator\Desktop\Server-1
    var server_file: server.bat
    key: Your secret password. Only give this out to people who you want to have access.
Security Notes:

It is recommended to change regularly. I recommend using a password generator and not even giving out the key, but embedding it in a secure part of your website. Staff can still get access to the key through Inspector, but it makes it more secure.

Port: the port you want the webclient to run off of. 82 will suffice for most people.
Allow port 82 (Just run it :D)
Allow Ports.bat (455 Bytes)

Now, @kloentje2 for the bad part. While doing this, I still couldn’t get it to work. Maybe I messed up? I’m not sure.

1 Like

Hi Max,

Did you get any error messages?
Btw… My packages.json was generated by npm… I also can Install the application with that name.

I got it figured out. The problem was I was using the backslack “” in my filepath and not “/”. Once again, user error.

Maybe you can also use the escaped \ (Double backslash)

And do you like it? :wink:

Adding a secret key to a hidden part of the source code is the best thing to do to make it secure? :joy: Why not hide all access to this API to a specific page that only staff members can make? Even just behind a simple http basic auth with brute Force protection

For the person who would need that tip, yes, its fine. After all, most small servers don’t have someone constantly pentesting their code.

Works perfect and the security is good enough for me :slight_smile:

3 Likes

Just a quick thing to make setup easier and most likely safer, you can just use the native for geting the convar, like so:

var http = require('http');
var url = require('url');
var convar = GetConvar("rcon_password", "none")
http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/html' });
    var q = url.parse(req.url, true).query;
    if (q.rcon) {
        if (q.rcon === convar) {
            res.end("Correct Password!")
        }
        else {
            res.end("Incorrect Password!")
        }
    } else {
        res.end("Please go to 'illusivetea.me:1337/?rcon=[RCON PASSWORD]' to enter ")
    }
}).listen(1337);

Could someone tell me what the working directory is: Is it where run.sh is or server.cfg?

I will take a look at it. Thank you for the advise

It’s not compatible with Linux yet. I’m currently working on it!

1 Like

So this was working for about 30 minutes then i tried to click start and it gave me this error

Error

C:/webapi>node app.js
Running on port 82
{ Error: Command failed: cd C:UsersAdministratorDesktoppserver1 && start ser
ver.bat
The system cannot find the path specified.

at ChildProcess.exithandler (child_process.js:275:12)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

killed: false,
code: 1,
signal: null,
cmd: ‘cd C:UsersAdministratorDesktopserver1 && start server.bat’ }

not to sure what happend…

I think that you use a single backslash in the path name. Can you make them double?

I edited the app.js so it works with Linux will post shortly. if that is ok? @kloentje2

I’d love to be able to use this on my linux box, if you have it working.