Codebase for Chatbot for Assessing System Security with GPT-3.5. Publication available from urn.fi/URN:NBN:fi:oulu-202306292789
This documentation assumes you already have a virtual machine set up for hosting the application.
Connect to the virtual machine via SSH and update the system packages with:
sudo apt update -y;sudo apt upgrade -y Clone pyenv repository via git:
git clone https://github.com/pyenv/pyenv.git ~/.pyenvFor pyenv to work, .bashrc file needs to be updated. Run the following commands to update it and reload the shell:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
exec "$SHELL"Install required Python build dependencies with:
sudo apt-get update; sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-devInstall Python 3.10.6 with:
pyenv install 3.10.6You should see:
Downloading Python-3.10.6.tar.xz...
-> https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz
Installing Python-3.10.6...Make sure the correct Python version is installed with:
pyenv versionsAnd set the system Python:
pyenv global 3.10.6Navigate to the Chatbot-for-Assessing-System-Security/app/backend directory:
cd Chatbot-for-Assessing-System-Security/app/backendUpgrade pip and install requirements:
pip install --upgrade pip
pip install -r requirements.txtNGINX is used for handling HTTP traffic.
Install NGNIX with:
sudo apt install nginxAdjust the UFW firewall to enable ports used by NGNIX. Allow SSH connections, so your connection to the VM will not get interrupted (assuming you are connected via SSH):
sudo ufw allow 22Enable UFW:
sudo ufw enableUFW can see if NGNIX is installed and you can check this with:
sudo ufw app listYou should see something like this:
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSHDepending on configurations of the application and your virtual machine, you can choose to allow HTTP and/or HTTPS traffic. To allow both (default), type:
sudo ufw allow 'Nginx Full'Make sure the rule has been applied with:
sudo ufw statusYou should see:
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
Nginx Full ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
You can make sure NGNIX is set up properly by heading to the IP address of your virtual machine in a browser:
http://<YOUR IP ADDRESS>And you should see the default NGNIX welcome page.
Check with systemd that NGNIX is running:
systemctl status nginxYou should see:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-03-21 12:09:59 UTC; 6min ago
Docs: man:nginx(8)
Process: 5761 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 5749 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 5764 (nginx)
Tasks: 2 (limit: 667)
CGroup: /system.slice/nginx.service
├─5764 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─5767 nginx: worker processCreate a new server block:
sudo nano /etc/nginx/sites-available/appAnd add following to the file:
server {
listen 80;
server_name <YOUR IP ADDRESS>;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/<YOUR USERNAME>/Chatbot-for-Assessing-System-Security/app/backend/app.sock;
}
}
server {
listen 5000;
server_name <YOUR IP ADDRESS>;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/<YOUR USERNAME>/Chatbot-for-Assessing-System-Security/app/backend/app.sock;
}
}For custom domain name, replace <YOUR IP ADDRESS> with the domain name:
server_name example.com www.example.com;Link the created server block to sites-enabled:
sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabledCheck NGNIX for syntax errors with:
sudo nginx -tYou should see:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulMake sure Nginx has permission to access the backend directory:
sudo chmod 755 /home/<YOUR USERNAME>Finally, restart the NGNIX service:
sudo systemctl restart nginxOpen nano with:
sudo nano /etc/systemd/system/app.serviceAdd following to the file:
[Unit]
Description=Backend of Alice
After=network.target
[Service]
User=<YOUR USERNAME HERE>
Group=www-data
WorkingDirectory=/home/<YOUR USERNAME HERE>/Chatbot-for-Assessing-System-Security/app/backend
ExecStart=/home/<YOUR USERNAME HERE>/.pyenv/shims/uwsgi --ini app.ini
[Install]
WantedBy=multi-user.targetSave and close the file. Start and enable the service with:
sudo systemctl start app
sudo systemctl enable appCheck the service status:
sudo systemctl status appYou should see:
● app.service – Backend of Alice
Loaded: loaded (/etc/systemd/system/app.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-06-14 17:11:44 UTC; 2min 56s ago
Main PID: 3680 (uwsgi)
Tasks: 26 (limit: 1087)
Memory: 44.1M
CPU: 715ms
CGroup: /system.slice/app.service
├─33617 /home/ubuntu/.pyenv/versions/3.10.6/bin/uwsgi --ini app.ini
├─33657 /home/ubuntu/.pyenv/versions/3.10.6/bin/uwsgi --ini app.ini
├─33658 /home/ubuntu/.pyenv/versions/3.10.6/bin/uwsgi --ini app.ini
├─33659 /home/ubuntu/.pyenv/versions/3.10.6/bin/uwsgi --ini app.ini
├─33660 /home/ubuntu/.pyenv/versions/3.10.6/bin/uwsgi --ini app.ini
└─33661 /home/ubuntu/.pyenv/versions/3.10.6/bin/uwsgi --ini app.iniNow backend of the application should be up and running. If you already have frontend of the application set up, you should see response messages from Alice when you type messages into the chat box. If not, head into the Chatbot-for-Assessing-System-Security/app/frontend directory and follow the Chatbot-for-Assessing-System-Security/app/frontend/README.md to set up the frontend.