# CMON Installation for Ubuntu 24.04

This document provides installation steps for setting up CMON on Ubuntu 24.04 LTS.

## Prerequisites

First, install the required packages:

```bash
sudo apt update
sudo apt install apache2 php php-mysql php-mbstring php-xml php-curl 
sudo apt install mysql-server python3-mysqldb
sudo systemctl restart apache2
```

## PHP Configuration

Ensure PHP is properly configured:

```bash
# Enable necessary PHP modules
sudo phpenmod pdo_mysql mbstring
sudo systemctl restart apache2
```

## Database Setup

Set up the MySQL databases:

```bash
# Set up timezone info
sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | sudo mysql -u root mysql

# Log into MySQL
sudo mysql -u root

# Create database and user (customize as needed)
mysql> CREATE DATABASE gxdb_cmon;
mysql> CREATE USER 'gxu_cmon'@'localhost' IDENTIFIED BY 'secure_password';
mysql> GRANT ALL PRIVILEGES ON gxdb_cmon.* TO 'gxu_cmon'@'localhost';
mysql> EXIT;

# Import the database schemas
mysql -u gxu_cmon -p gxdb_cmon < ./howto.init.status.mysql
mysql -u gxu_cmon -p gxdb_cmon < ./howto.init.web.mysql
```

## Application Configuration

Configure the application:

```bash
# Copy and edit the configuration file
cp includes/config.php.template includes/config.php
nano includes/config.php

# Set appropriate values for:
# - $abs_path
# - $myversion
# - $mypass
# - Database connection details
```

## Apache Configuration

Configure Apache to run the application:

```bash
# Create a virtual host configuration
sudo nano /etc/apache2/sites-available/cmon.conf

# Add configuration like:
<VirtualHost *:80>
    ServerName cmon.example.com
    DocumentRoot /path/to/cmon
    
    <Directory /path/to/cmon>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/cmon_error.log
    CustomLog ${APACHE_LOG_DIR}/cmon_access.log combined
</VirtualHost>

# Enable the site and required modules
sudo a2ensite cmon.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
```

## Security

Secure the admin area:

```bash
# Create a password file
sudo mkdir -p /etc/groovix
sudo htpasswd -c /etc/groovix/cmon_staff.pw staff
sudo htpasswd /etc/groovix/cmon_staff.pw admin

# Add to Apache configuration or .htaccess:
<Directory /path/to/cmon/admin>
    AuthName "Cmon Staff"
    AuthType Basic
    AuthUserFile /etc/groovix/cmon_staff.pw
    Require valid-user
</Directory>
```

## Testing

Verify the installation:

1. Visit the application URL in your browser
2. Check error logs if needed:
   ```bash
   sudo tail -f /var/log/apache2/error.log
   ```

## Adding Workstations

Add workstations to the system:

```bash
mysql -u gxu_cmon -p gxdb_cmon
mysql> INSERT INTO `maps` VALUES (null,1,'WORKSTATION_ID','DISPLAY_NAME','left:100px; top:200px;','',1,'','');
```

## Note on PHP Changes

This version of CMON has been modernized with:

1. PDO database connections instead of ADOdb
2. Parameterized queries for improved security
3. Modern PHP syntax (null coalescing, strict typing)
4. Proper HTML escaping to prevent XSS
5. UTF-8 character encoding