|
1 | | -# MISP-module website |
| 1 | +# MISP Modules Website |
2 | 2 |
|
3 | | -Use all modules with a dedicate website without any MISP |
| 3 | +Use all MISP modules through a dedicated website without requiring a MISP instance. |
4 | 4 |
|
5 | | - |
| 5 | + |
6 | 6 |
|
7 | | - |
| 7 | + |
8 | 8 |
|
9 | 9 | ## Installation |
10 | 10 |
|
11 | | -**It is strongly recommended to use a virtual environment** |
| 11 | +The MISP Modules website uses [Poetry](https://python-poetry.org/) for dependency management. It is recommended to install dependencies in a virtual environment managed by Poetry. |
12 | 12 |
|
13 | | -If you want to know more about virtual environments, [python has you covered](https://docs.python.org/3/tutorial/venv.html) |
| 13 | +### Prerequisites |
| 14 | +- Python 3.8 or higher |
| 15 | +- Poetry |
| 16 | +- `misp-modules` installed in the parent directory (`../`) |
14 | 17 |
|
15 | | -```bash |
16 | | -sudo apt-get install screen -y |
17 | | -pip install -r requirements.txt |
18 | | -git submodule init && git submodule update ## Initialize misp-objects submodule |
19 | | -python3 app.py -i ## Initialize db |
20 | | -``` |
| 18 | +### Steps |
| 19 | +1. **Clone the Repository**: |
| 20 | + ```bash |
| 21 | + git clone https://github.com/MISP/misp-modules.git |
| 22 | + cd misp-modules/website |
| 23 | + ``` |
21 | 24 |
|
22 | | -Don't forget to install **misp-modules**... |
| 25 | +2. **Initialize Submodules**: |
| 26 | + ```bash |
| 27 | + git submodule init |
| 28 | + git submodule update # Initialize misp-objects submodule |
| 29 | + ``` |
23 | 30 |
|
24 | | -## Config |
| 31 | +3. **Install Dependencies**: |
| 32 | + ```bash |
| 33 | + poetry install |
| 34 | + ``` |
25 | 35 |
|
26 | | -Edit `config.py` |
| 36 | +4. **Initialize the Database**: |
| 37 | + ```bash |
| 38 | + poetry run db-init |
| 39 | + ``` |
| 40 | + This creates the database (`misp-module.sqlite`), initializes modules, and sets up the admin password (generated in development if not set). |
27 | 41 |
|
28 | | -- `SECRET_KEY`: Secret key for the app |
| 42 | +5. **Install `misp-modules`**: |
| 43 | + Ensure `misp-modules` is installed in the parent directory (`../misp-modules`). Follow the main repository’s instructions for setup. |
29 | 44 |
|
30 | | -- `FLASK_URL` : url for the instance |
| 45 | +## Configuration |
31 | 46 |
|
32 | | -- `FLASK_PORT`: port for the instance |
| 47 | +Configuration is managed via a `.env` file in `website/`. Copy the example and edit as needed: |
33 | 48 |
|
34 | | -- `MISP_MODULE`: url and port where misp-module is running |
| 49 | +```bash |
| 50 | +cp .env.example .env |
| 51 | +nano .env |
| 52 | +``` |
35 | 53 |
|
36 | | -- `ADMIN_USER`: If True, config page will not be accessible |
| 54 | +### `.env` Settings |
| 55 | +- `DATABASE_URI`: Database URL (default: `sqlite:///misp-module.sqlite`). |
| 56 | +- `SECRET_KEY`: Secure key for the Flask app (generate with `python -c "import secrets; print(secrets.token_hex(16))"` or `openssl rand -hex 16`). |
| 57 | +- `FLASK_URL`: Host for the website (default: `127.0.0.1`). |
| 58 | +- `FLASK_PORT`: Port for the website (default: `7008`). |
| 59 | +- `MISP_MODULE`: URL and port of `misp-modules` (default: `127.0.0.1:6666`). |
| 60 | +- `ADMIN_PASSWORD`: Admin user password (optional in development, required in production). |
| 61 | +- `QUERIES_LIMIT`: Maximum queries allowed (default: `100`). |
| 62 | +- `SESSION_TYPE`: Session storage type (default: `sqlalchemy`). |
| 63 | +- `SESSION_SQLALCHEMY_TABLE`: Session table name (default: `flask_sessions`). |
| 64 | +- `FLASK_APP`: Flask entry point (default: `main`). |
| 65 | + |
| 66 | +Example `.env`: |
| 67 | +``` |
| 68 | +DATABASE_URI=sqlite:///misp-module.sqlite |
| 69 | +SECRET_KEY=your-secure-secret-key |
| 70 | +FLASK_URL=127.0.0.1 |
| 71 | +FLASK_PORT=7008 |
| 72 | +MISP_MODULE=127.0.0.1:6666 |
| 73 | +QUERIES_LIMIT=100 |
| 74 | +SESSION_TYPE=sqlalchemy |
| 75 | +SESSION_SQLALCHEMY_TABLE=flask_sessions |
| 76 | +FLASK_APP=main |
| 77 | +# ADMIN_PASSWORD=your-admin-password # Uncomment and set for production |
| 78 | +``` |
37 | 79 |
|
38 | | -- `ADMIN_PASSWORD`: Password for Admin user if `ADMIN_USER` is True |
| 80 | +## Launch |
39 | 81 |
|
40 | | -Rename `config.cfg.sample` to `config.cfg` then edit it: |
| 82 | +### Development |
| 83 | +Run both `misp-modules` and the website in development mode with debug enabled: |
41 | 84 |
|
42 | | -- `ADMIN_USER`: If True, config page will not be accessible |
| 85 | +```bash |
| 86 | +poetry run dev-site |
| 87 | +``` |
43 | 88 |
|
44 | | -- `ADMIN_PASSWORD`: Password for Admin user if `ADMIN_USER` is True |
| 89 | +- If `ADMIN_PASSWORD` is unset in `.env`, a random 20-character password is generated and printed. |
| 90 | +- Access the website at `http://127.0.0.1:7008` (or as configured). |
45 | 91 |
|
46 | | -## Launch |
| 92 | +### Production |
| 93 | +Use systemd services for production deployment (see **Systemd Services** below). Ensure `ADMIN_PASSWORD` is set in `.env` to avoid startup errors. |
| 94 | + |
| 95 | +## Admin User |
| 96 | + |
| 97 | +If `ADMIN_PASSWORD` is set in `.env`, the admin user is active. Access the login page at `/login` and use the password from `.env` (or the generated password in development). |
| 98 | + |
| 99 | +- **Development**: If `ADMIN_PASSWORD` is unset, a password is generated and printed to the console. |
| 100 | +- **Production**: `ADMIN_PASSWORD` must be set in `.env`, or the application will fail to start with an error. |
| 101 | + |
| 102 | +## Database Management |
| 103 | + |
| 104 | +Manage the database with the following commands: |
47 | 105 |
|
48 | 106 | ```bash |
49 | | -./launch.sh -l |
| 107 | +poetry run db-init # Initialize database and modules |
| 108 | +poetry run db-migrate # Generate a new migration |
| 109 | +poetry run db-upgrade # Apply migrations |
| 110 | +poetry run db-downgrade # Revert the latest migration |
50 | 111 | ``` |
51 | 112 |
|
52 | | -## Admin user |
| 113 | +## Systemd Services |
| 114 | + |
| 115 | +Template systemd service files are provided in `etc/` for `misp-modules` and the website. |
| 116 | + |
| 117 | +### Installation |
| 118 | +1. **Copy Service Files**: |
| 119 | + ```bash |
| 120 | + sudo cp website/etc/misp-modules.service /etc/systemd/system/ |
| 121 | + sudo cp website/etc/misp-modules-website.service /etc/systemd/system/ |
| 122 | + ``` |
| 123 | + |
| 124 | +2. **Reload Systemd**: |
| 125 | + ```bash |
| 126 | + sudo systemctl daemon-reload |
| 127 | + ``` |
| 128 | + |
| 129 | +3. **Enable and Start Services**: |
| 130 | + ```bash |
| 131 | + sudo systemctl enable misp-modules.service |
| 132 | + sudo systemctl enable misp-modules-website.service |
| 133 | + sudo systemctl start misp-modules.service |
| 134 | + sudo systemctl start misp-modules-website.service |
| 135 | + ``` |
| 136 | + |
| 137 | +4. **Check Status**: |
| 138 | + ```bash |
| 139 | + sudo systemctl status misp-modules.service |
| 140 | + sudo systemctl status misp-modules-website.service |
| 141 | + ``` |
| 142 | + |
| 143 | +Logs are written to `/var/log/misp-modules_*.log` and `/var/log/misp-modules-website_*.log`. |
| 144 | + |
| 145 | +## Log Rotation |
| 146 | + |
| 147 | +Log rotation configurations are provided in `etc/logrotate.d/` to manage service logs. |
| 148 | + |
| 149 | +### Installation |
| 150 | +1. **Copy Logrotate Files**: |
| 151 | + ```bash |
| 152 | + sudo cp etc/logrotate.d/misp-modules /etc/logrotate.d/ |
| 153 | + ``` |
| 154 | + |
| 155 | +2. **Test Logrotate**: |
| 156 | + ```bash |
| 157 | + sudo logrotate -d /etc/logrotate.d/misp-modules |
| 158 | + ``` |
| 159 | + |
| 160 | +Logs are rotated daily, compressed, and retained for 7 days. |
53 | 161 |
|
54 | | -If admin user is active, type `/login` in url to access a login page and type the password wrote in `config.py` in `ADMIN_PASSOWRD`. |
| 162 | +## Notes |
| 163 | +- Ensure `misp-modules` is installed and running in `../misp-modules`. |
| 164 | +- Set a secure `ADMIN_PASSWORD` in `.env` for production. |
| 165 | +- Adjust `.service` and `logrotate.d` paths or user settings for your environment. |
0 commit comments