Go to file
Rick Carlino 2676171cb6 Exclude db/ folder from code quality metrics 2018-03-07 09:14:20 -06:00
app IDEA: Strip port from confirmation URLs 2018-03-06 09:17:31 -06:00
bin Add more fields, validations to image and start writing model tests. 2017-01-11 09:27:06 -06:00
config Fix password reset regression 2018-03-02 08:52:06 -06:00
db Plant#plant_stage 2018-03-05 11:15:56 -06:00
lib Add mode column back, add fbos_version to devices table + TS interfaces. 2018-02-15 15:43:08 -06:00
mqtt Enforce presence of API_PORT and API_HOST 2017-12-22 13:34:49 -06:00
public 1 2018-03-04 21:07:50 +03:00
spec Bug where tests fail on Travis 2018-03-06 08:51:29 -06:00
typings Extend @types/jest 2017-12-15 08:07:17 -06:00
webpack Merge branch 'staging' of https://github.com/FarmBot/Farmbot-Web-App into router_bugs 2018-03-05 16:19:07 -06:00
.buildpacks use heroku-postbuild 2016-09-22 11:17:12 -05:00
.codebeatignore Remove logger; ignore entrypoint files; call maybeRunLocalstorageMigration(); 2018-01-10 09:27:06 -06:00
.codeclimate.yml Exclude db/ folder from code quality metrics 2018-03-07 09:14:20 -06:00
.coveralls.yml Add coveralls repo token 2017-07-20 11:16:18 -05:00
.gitignore Update GSOD function 2017-11-02 12:15:56 -05:00
.ruby-gemset rename application from `dss` to `farmbot` 2015-03-09 05:31:05 -05:00
.ruby-version Change references to Ruby 2.4.2 to Ruby 2.5.0 2018-02-20 13:50:17 -06:00
.travis.yml Change references to Ruby 2.4.2 to Ruby 2.5.0 2018-02-20 13:50:17 -06:00
CONTRIBUTING.md Move stuff into root 2017-06-29 16:06:19 -05:00
DEPLOYMENT.md Remove manual SSL renewal endpoint (#629) 2018-01-20 10:17:20 -07:00
Gemfile FarmwareInstallations#create 2018-02-26 11:20:38 -06:00
Gemfile.lock FarmwareInstallations#create 2018-02-26 11:20:38 -06:00
ISSUE_TEMPLATE Update issue template 2018-02-21 08:59:34 -06:00
LICENSE Move stuff into root 2017-06-29 16:06:19 -05:00
Procfile 🚧 Experimental `Procfile` for soon-to-be log service. **May break staging**. 2017-12-06 12:12:17 -06:00
Procfile.dev Un-hardcode port from `Procfile.dev` 2017-12-18 09:06:01 -06:00
README.md Change references to Ruby 2.4.2 to Ruby 2.5.0 2018-02-20 13:50:17 -06:00
Rakefile Cruft removal, part I 2015-10-20 13:03:42 -05:00
api_docs.md.erb Remove irrelevant request bodies from doc generation. 2017-07-06 01:38:09 -05:00
codecov.yml Add major/minor/verbosity to DB records 2017-12-06 15:57:28 -06:00
config.ru Added foundation and high voltage. Readme updates, too. 2014-03-31 06:31:38 -07:00
dokku.sh Documentation updates 2017-11-01 13:16:04 -05:00
erd_diagram.png Add ERD diagram to README 2017-10-13 09:57:37 -05:00
favicon.ico Move stuff into root 2017-06-29 16:06:19 -05:00
latest_corpus.rb Plant#plant_stage 2018-03-05 11:15:56 -06:00
migrate_old_sequences.rb Introduce a "Flat IR" for sequence nodes (#655) 2018-02-11 13:33:46 -06:00
package.json Merge branch 'staging' of https://github.com/FarmBot/Farmbot-Web-App into plant_stages 2018-03-05 11:16:04 -06:00
tsconfig.json Restrict move_abs tool selection to active tools only (#544) 2017-11-28 18:01:35 -06:00
tslint.json Update TSLint file 2017-08-27 18:48:07 -05:00
ubuntu_example.sh Change references to Ruby 2.4.2 to Ruby 2.5.0 2018-02-20 13:50:17 -06:00
yarn.lock Merge branch 'staging' of https://github.com/FarmBot/Farmbot-Web-App into plant_stages 2018-03-05 11:16:04 -06:00

README.md

codebeat badge

Coverage Status(Frontend)

codecov(API)

Maintainability

Q: Do I need this?

This repository is intended for software developers who wish to modify the Farmbot Web App. If you are not a developer, you are highly encouraged to use the publicly available web app. Running a server is a non-trivial task with security implications. It requires an intermediate background in Ruby, SQL and Linux system administration.

If you are a developer interested in contributing or would like to provision your own server, you are in the right place.

Q: Where do I report security issues?

We take security seriously and value the input of independent researchers. Please see our responsible disclosure guidelines.

Q: What is the Farmbot Web App?

This repo contains FarmBot's web based user interface, a RESTful JSON API and a Dockerized MQTT server. The API stores data such as user account information, plant data, authorization tokens and a variety of other resources. The MQTT server facilitates realtime messaging from the browser to the device.

Q: Can I see some example API requests?

For a list of example API requests and responses, see our reference documentation. If you wish to write an add-on application that uses the FarmBot API, please let us know in an issue. We are happy to answer any specific questions you may have.

Q: How do I Setup an instance locally?

Prerequisites

You will need the following:

  1. A Linux or Mac based machine. We do not support windows at this time.
  2. Docker 17.06.0-ce or greater
  3. Ruby 2..5.0
  4. ImageMagick (brew install imagemagick (Mac) or sudo apt-get install imagemagick (Ubuntu))
  5. Node JS >= v8.9.0
  6. libpq-dev and postgresql and postgresql-contrib
  7. gem install bundler

Setup

NOTE: A step-by-step setup guide for Ubuntu 17 users can be found here

Setup for non-Ubuntu users after installing the dependencies listed above:

  1. git clone https://github.com/FarmBot/Farmbot-Web-App --branch=master --depth=10
  2. cd Farmbot-Web-App
  3. bundle install
  4. yarn install
  5. Database config: Copy config/database.example.yml to config/database.yml via cp config/database.example.yml config/database.yml
  6. App config: MOST IMPORTANT STEP. Copy config/application.example.yml to config/application.yml via mv config/application.example.yml config/application.yml. Please read the instructions inside the file. Replace the example values provided with real world values.
  7. Give permission to create a database*
  8. rake db:create:all db:migrate db:seed
  9. (optional) Verify installation with RAILS_ENV=test rake db:create db:migrate && rspec spec (API) and npm run test (Frontend).
  10. Start server with rails api:start. Make sure you set an MQTT_HOST entry in application.yml pointing to the IP address or domain of MQTT server. If you are not running the MQTT server on a separate machine, MQTT_HOST and API_HOST will point to the same server.
  11. Start MQTT with rails mqtt:start. Important note: You may be required to enter a sudo password because docker requires root access.
  12. Open localhost:3000.
  13. Raise an issue if you hit problems with any of these steps. We can't fix issues we don't know about.

*Give permission to user to create database:

sudo -u postgres psql
CREATE USER "user" WITH SUPERUSER;

Q: Is Dokku / Docker supported?

Dokku (a Docker management system) is partially supported. Pull requests welcome. Please see deployment.md for more information.

Config Settings (important)

We try our best to follow the 12 Factor Methodology. Part of that means using ENV variables as a means of storing configuration. Your server won't run without setting ENV variables first.

You can accomplish this by setting the ENV variables directly from your shell / server management tool or by writing an application.yml file.

See config/application.example.yml for a list of all the variables that must be set.

Encryption keys: Encryption keys will be auto-generated if not present. They can be reset using rake keys:generate. If ENV['RSA_KEY'] is set, it will be used in place of the *.pem files. Useful for environments like Heroku, where file system access is not allowed.

We can't fix issues we don't know about. Please submit an issue if you are having trouble installing on your local machine.

Q: How can I Generate an API token?

You must pass a token string into most HTTP requests under the Authorization: request header.

Here's what a response looks like when you request a token:

{
    "token": {
        "unencoded": {
            "sub": "test123@test.com",
            "iat": 1459109728,
            "jti": "922a5a0d-0b3a-4767-9318-1e41ae600352",
            "iss": "http://localhost:3000/",
            "exp": 1459455328,
            "mqtt": "localhost",
            "bot": "aa7bb37f-5ba3-4654-b2e4-58ed5746508c"
        },
        "encoded":
        // THE IMPORTANT PART IS HERE!!:
         "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ0ZXN0MTIzQHRlc3QuY29tIiwiaWF0IjoxNDU5MTA5NzI4LCJqdGkiOiI5MjJhNWEwZC0wYjNhLTQ3NjctOTMxOC0xZTQxYWU2MDAzNTIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjMwMDAvIiwiZXhwIjoxNDU5NDU1MzI4LCJtcXR0IjoibG9jYWxob3N0IiwiYm90IjoiYWE3YmIzN2YtNWJhMy00NjU0LWIyZTQtNThlZDU3NDY1MDhjIn0.KpkNGR9YH68AF3iHP48GormqXzspBJrDGm23aMFGyL_eRIN8iKzy4gw733SaJgFjmebJOqZkz3cly9P5ZpCKwlaxAyn9RvfjQgFcUK0mywWAAvKp5lHfOFLhBBGICTW1r4HcZBgY1zTzVBw4BqS4zM7Y0BAAsflYRdl4dDRG_236p9ETCj0MSYxFagfLLLq0W63943jSJtNwv_nzfqi3TTi0xASB14k5vYMzUDXrC-Z2iBdgmwAYUZUVTi2HsfzkIkRcTZGE7l-rF6lvYKIiKpYx23x_d7xGjnQb8hqbDmLDRXZJnSBY3zGY7oEURxncGBMUp4F_Yaf3ftg4Ry7CiA"
    }
}

Important: The response is provided as JSON for human readability. For your Authorization header, you will only be using data.token.encoded. In this example, it's the string starting with eyJ0eXAiOiJ...

Via CURL

curl -H "Content-Type: application/json" \
     -X POST \
     -d '{"user":{"email":"test123@test.com","password":"password123"}}' \
     https://my.farmbot.io/api/tokens

Via JQuery

Since the API supports CORS, you can generate your token right in the browser.

Here's an example:

$.ajax({
    url: "https://my.farmbot.io/api/tokens",
    type: "POST",
    data: JSON.stringify({user: {email: 'admin@admin.com', password: 'password123'}}),
    contentType: "application/json",
    success: function (data) {
                 // You can now use your token:
                 var MY_SHINY_TOKEN = data.token.encoded;
             }
});

Want to Help?

Low Hanging Fruit. Raise an issue if you have any questions.

Translating the web app into your language

Thanks for your interest in internationalizing the FarmBot web app! To add translations:

  1. Fork this repo
  2. Navigate to /public/app-resources/languages and run the command node _helper.js yy where yy is your language's language code. Eg: ru for Russian.
  3. Edit the translations in the file created in the previous step: "phrase": "translated phrase".
  4. When you have updated or added new translations, commit/push your changes and submit a pull request.