Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
414 changes: 414 additions & 0 deletions app/billing/CONFIGURATION.md

Large diffs are not rendered by default.

351 changes: 351 additions & 0 deletions app/billing/CONFIGURATION_REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,351 @@
# FusionPBX config.conf Reference for Billing Module

## Overview

This document explains how the billing module uses your existing FusionPBX configuration file (`/etc/fusionpbx/config.conf`) and confirms that **NO CHANGES are required** to your current configuration.

## ✅ Your Current Configuration is Perfect

The billing module is fully compatible with standard FusionPBX configurations. Your existing `/etc/fusionpbx/config.conf` contains all necessary settings.

## Configuration Usage Analysis

### 1. Database Settings (USED)

```ini
database.0.type = pgsql
database.0.host = 127.0.0.1
database.0.port = 5432
database.0.name = fusionpbx
database.0.username = fusionpbx
database.0.password = [your_password]
```

**How Billing Uses This:**
- ✅ All billing tables are created in the `fusionpbx` database
- ✅ Accessed via FusionPBX's standard database class
- ✅ Uses the configured PostgreSQL connection
- ✅ No additional database configuration needed

**Tables Created:**
- `v_billing_rates`
- `v_billing_balances`
- `v_billing_user_rates`
- `v_billing_agent_rates`
- `v_billing_usage`
- `v_billing_balance_history`

### 2. Document Root (USED)

```ini
document.root = /var/www/fusionpbx
```

**How Billing Uses This:**
- ✅ API endpoint location: `{document.root}/app/billing/api_nibblebill.php`
- ✅ Web UI location: `{document.root}/app/billing/*.php`
- ✅ Full URL: `https://your-ip/app/billing/billing.php`

**API Endpoint:**
```
URL: https://213.199.37.103/app/billing/api_nibblebill.php
Path: /var/www/fusionpbx/app/billing/api_nibblebill.php
```

### 3. FreeSWITCH Configuration Directory (USED)

```ini
switch.conf.dir = /etc/freeswitch
```

**How Billing Uses This:**
- ✅ nibblebill.conf.xml location: `{switch.conf.dir}/autoload_configs/`
- ✅ Dialplan files location: `{switch.conf.dir}/dialplan/default/`

**File Locations:**
```
/etc/freeswitch/autoload_configs/nibblebill.conf.xml
/etc/freeswitch/dialplan/default/888_billing_integration.xml
/etc/freeswitch/dialplan/default/999_billing_check.xml
```

### 4. FreeSWITCH Scripts Directory (USED)

```ini
switch.scripts.dir = /usr/share/freeswitch/scripts
```

**How Billing Uses This:**
- ✅ Lua scripts location: `{switch.scripts.dir}/app/billing/`

**Script Locations:**
```
/usr/share/freeswitch/scripts/app/billing/check_rate.lua
/usr/share/freeswitch/scripts/app/billing/check_balance.lua
```

### 5. Cache Settings (USED)

```ini
cache.method = file
cache.location = /var/cache/fusionpbx
```

**How Billing Uses This:**
- ✅ Billing class uses standard FusionPBX caching
- ✅ Rate lookups cached for performance
- ✅ Balance queries cached (configurable TTL)

### 6. Settings NOT USED by Billing

These settings exist in your config.conf but are not used by the billing module:

```ini
database.1.type = sqlite # Billing uses PostgreSQL only
temp.dir = /tmp # Not used by billing
php.dir = /usr/bin # Standard PHP installation
session.* = [settings] # Standard web session
error.reporting = user # Standard error reporting
```

## Installation Path Reference

Based on your config.conf values, here are the exact installation paths:

### Copy Lua Scripts
```bash
# Target: {switch.scripts.dir}/app/billing/
sudo mkdir -p /usr/share/freeswitch/scripts/app/billing
sudo cp app/billing/resources/install/scripts/*.lua /usr/share/freeswitch/scripts/app/billing/
sudo chown -R www-data:www-data /usr/share/freeswitch/scripts/app/billing/
```

### Copy Dialplan Files
```bash
# Target: {switch.conf.dir}/dialplan/default/
sudo cp app/billing/resources/install/dialplan/888_billing_integration.xml /etc/freeswitch/dialplan/default/
sudo chown www-data:www-data /etc/freeswitch/dialplan/default/888_billing_integration.xml
```

### nibblebill.conf.xml Location
```bash
# Auto-generated by app_defaults.php, or manually copy:
# Target: {switch.conf.dir}/autoload_configs/
sudo cp app/billing/resources/install/nibblebill.conf.xml /etc/freeswitch/autoload_configs/
sudo chown www-data:www-data /etc/freeswitch/autoload_configs/nibblebill.conf.xml
```

### Web Interface
```bash
# Already in place at: {document.root}/app/billing/
# URL: https://213.199.37.103/app/billing/billing.php
```

## Configuration Validation

### 1. Check Database Connection
```bash
# Test PostgreSQL connection with config.conf values
psql -h 127.0.0.1 -p 5432 -U fusionpbx -d fusionpbx -c "SELECT 1"
```

### 2. Check Directory Permissions
```bash
# Verify FreeSWITCH directories are accessible
ls -la /etc/freeswitch/autoload_configs/
ls -la /etc/freeswitch/dialplan/default/
ls -la /usr/share/freeswitch/scripts/
```

### 3. Check Web Access
```bash
# Verify document root
ls -la /var/www/fusionpbx/app/billing/
```

### 4. Check Cache Directory
```bash
# Verify cache location is writable
ls -la /var/cache/fusionpbx/
sudo chown -R www-data:www-data /var/cache/fusionpbx/
```

## API Endpoint Configuration

The billing API endpoint uses settings from config.conf:

### URL Construction
```
Protocol: https (from web server config)
Hostname: 213.199.37.103 (from DNS/IP)
Document Root: /var/www/fusionpbx (from config.conf)
App Path: /app/billing/api_nibblebill.php
Full URL: https://213.199.37.103/app/billing/api_nibblebill.php
```

### nibblebill.conf.xml Reference
```xml
<!-- API endpoint uses document.root from config.conf -->
<param name="heartbeat_url" value="https://213.199.37.103/app/billing/api_nibblebill.php?action=heartbeat&amp;extension=${nibble_account}&amp;duration=${nibble_current_balance}"/>
```

## Database Connection Details

The billing module uses FusionPBX's database class which reads config.conf:

### PHP Database Connection
```php
// In billing.php class
require_once "resources/classes/database.php";
$database = new database;

// Database class reads from config.conf:
// - database.0.type = pgsql
// - database.0.host = 127.0.0.1
// - database.0.port = 5432
// - database.0.name = fusionpbx
// - database.0.username = fusionpbx
// - database.0.password = [encrypted]
```

### SQL Connection String
```
Type: PostgreSQL
Host: 127.0.0.1:5432
Database: fusionpbx
Schema: public
Tables: v_billing_* (6 tables)
```

## FreeSWITCH Integration

### Lua Database Connection
Lua scripts connect to the database using FreeSWITCH ODBC:

```lua
-- In check_rate.lua and check_balance.lua
-- Uses FreeSWITCH's configured database connection
-- Typically: /etc/freeswitch/autoload_configs/switch.conf.xml
local dbh = freeswitch.Dbh("pgsql://host=127.0.0.1 dbname=fusionpbx user=fusionpbx password='...'")
```

**Note:** FreeSWITCH database connection is configured separately in switch.conf.xml, not in FusionPBX's config.conf.

## No Configuration Changes Required

### ✅ Confirmation Checklist

- [x] **Database**: Existing PostgreSQL connection works perfectly
- [x] **Paths**: All directory paths are correct
- [x] **Web Access**: Document root is properly configured
- [x] **Scripts**: FreeSWITCH scripts directory is set
- [x] **Cache**: Caching is configured and functional
- [x] **API**: No special API configuration needed

### ❌ No Changes Needed

Your current `/etc/fusionpbx/config.conf` does **NOT** require any modifications for the billing module. The existing configuration is fully compatible.

## Optional: Billing-Specific Settings

While not required, you could add optional billing comments to config.conf for documentation:

```ini
# Billing module uses these standard settings:
# - database.0.* for billing tables
# - document.root for API endpoint
# - switch.conf.dir for nibblebill config
# - switch.scripts.dir for Lua scripts
```

**However, this is purely optional and provides no functional benefit.**

## Troubleshooting Configuration Issues

### Issue: Database Connection Failed

**Check:**
```bash
# Verify config.conf database settings
grep "database.0" /etc/fusionpbx/config.conf

# Test connection
psql -h 127.0.0.1 -U fusionpbx fusionpbx -c "\dt v_billing_*"
```

### Issue: API Endpoint Not Found

**Check:**
```bash
# Verify document root
grep "document.root" /etc/fusionpbx/config.conf

# Check file exists
ls -la /var/www/fusionpbx/app/billing/api_nibblebill.php

# Check web server config
cat /etc/nginx/sites-available/fusionpbx
# or
cat /etc/apache2/sites-available/fusionpbx.conf
```

### Issue: Lua Scripts Not Found

**Check:**
```bash
# Verify scripts directory
grep "switch.scripts.dir" /etc/fusionpbx/config.conf

# Check scripts exist
ls -la /usr/share/freeswitch/scripts/app/billing/

# Check permissions
sudo chown -R www-data:www-data /usr/share/freeswitch/scripts/app/billing/
```

### Issue: nibblebill.conf.xml Not Loaded

**Check:**
```bash
# Verify conf directory
grep "switch.conf.dir" /etc/fusionpbx/config.conf

# Check file exists
ls -la /etc/freeswitch/autoload_configs/nibblebill.conf.xml

# Check mod_nibblebill loaded
fs_cli -x "module_exists mod_nibblebill"
```

## Summary

### ✅ Your Configuration is Ready

Your existing `/etc/fusionpbx/config.conf` contains all necessary settings for the billing module:

| Setting | Current Value | Status |
|---------|---------------|--------|
| Database Type | PostgreSQL | ✅ Compatible |
| Database Host | 127.0.0.1:5432 | ✅ Working |
| Document Root | /var/www/fusionpbx | ✅ Correct |
| Switch Config Dir | /etc/freeswitch | ✅ Correct |
| Switch Scripts Dir | /usr/share/freeswitch/scripts | ✅ Correct |
| Cache Method | file | ✅ Working |

### 🚀 Next Steps

1. **Do NOT modify config.conf** - It's perfect as-is
2. **Run database upgrade** to create billing tables
3. **Copy configuration files** to paths specified above
4. **Reload FreeSWITCH** to load nibblebill module
5. **Access billing module** via web interface

### 📞 Support

If you encounter any configuration issues:
1. Verify config.conf paths match actual file locations
2. Check file permissions (www-data user)
3. Test database connectivity
4. Review installation logs

The billing module is designed to work seamlessly with standard FusionPBX configurations!
Loading