# Squid Inventory Control - Session Context

**Last Updated:** 2026-01-09
**Documentation:** `/var/www/claudedocs/`

---

## System Overview

Squid Inventory Control is a Mobile Device Management (MDM) system with two main components:

1. **Device API** (`/var/www/html/411b3eebceb45b87ea/`) - Receives AES-256-GCM encrypted data from Android devices
2. **Admin UI** (`/var/www/html/f0a4936828326da599c003/`) - Web interface for administrators

---

## Key Paths

```
/var/www/html/411b3eebceb45b87ea/   - Device API (deviceapi.php)
/var/www/html/f0a4936828326da599c003/   - Admin UI (index.php, api.php)
/var/www/html/libs/leaflet/         - Local Leaflet 1.9.4
/var/www/html/tiles/                - Map tile cache system
/var/www/phonetooltemplates/        - HTML templates
/var/www/phonetooldata/             - Device file storage
/var/www/log/phonetool.log          - Application log
/var/www/claudedocs/                - Full documentation (8 files)
```

---

## Database

```
Host:     192.168.38.55
Database: squidmaster
User:     phonetooluser
Password: 8jsk2jbkgbhd89#@H
```

**Key Tables:** `web_devices`, `devicestatus`, `devicelocation`, `web_vcards`, `web_sms`, `web_calllogs`, `web_user`, `web_session`

**Note:** Admin UI uses `web_` prefixed tables (fixed from original `devices`, `vcards`, etc.)

---

## Encryption

- **Algorithm:** AES-256-GCM
- **Default Key:** `42e59a7580a484ee6ad1fb8277f3c425365438e3cdcd2ecd6b8982fa3f88a47b`
- **Format:** [IV:12B][Ciphertext][Tag:16B]
- **Implementation:** `/var/www/html/411b3eebceb45b87ea/aesgcm.php`

---

## Map System

### Leaflet
- **Version:** 1.9.4
- **Location:** `/var/www/html/libs/leaflet/`
- **Files:** leaflet.js, leaflet.css, images/*

### Tile Cache
- **Location:** `/var/www/html/tiles/`
- **Proxy:** `tile.php` - Downloads from OSM, caches locally
- **USER_AGENT:** `NetScapeMozilla/1.0.1`
- **Scripts:** `download_tiles.php`, `quick_download.sh`
- **Pre-cached:** 55+ tiles for Oklahoma region (35.26215, -99.69283)

### Map Template
- **File:** `/var/www/phonetooltemplates/template_map.html`
- **Features:** Auto-refresh every 5 seconds, local tiles, device markers

---

## Known Issues / Limitations

1. **Clean tile URLs return 404 for uncached tiles**
   - Cause: `AllowOverride None` in Apache config prevents .htaccess processing
   - Workaround: Use direct URLs `/tiles/tile.php?z=9&x=113&y=199`
   - Fix: Add `<Directory /var/www/html/tiles>AllowOverride All</Directory>` to Apache config
   - See: `/var/www/claudedocs/07_APACHE_CONFIGURATION.md`

2. **File permissions**
   - Use `slide chmod 666 <file>` to fix permission issues (not sudo)
   - Tile directory owned by www-data

---

## Recent Changes (2026-01-09)

1. **Fixed Admin UI database tables** - Changed from `devices` to `web_devices`, etc.
2. **Fixed api.php database connection** - Changed from `phonetool` to `squidmaster`
3. **Installed local Leaflet 1.9.4** - Eliminated CDN dependency
4. **Created tile cache system** - On-demand caching from OSM
5. **Downloaded Oklahoma region tiles** - For offline testing
6. **Created comprehensive documentation** - 8 files in `/var/www/claudedocs/`
7. **Fixed device list sorting** - Changed from `wd.modifystamp` to `ds.lastcontact DESC`
   - File: `/var/www/html/f0a4936828326da599c003/index.php`
   - Lines: 2794, 2799

---

## Active Device

- **Serial:** `EMULATOR36X1X2X0`
- **Location:** 35.26215, -99.69283 (Oklahoma)
- **Commands:** `whatdoido` (polling), `loc` (location updates)

---

## Documentation Index

| File | Description |
|------|-------------|
| `00_SYSTEM_OVERVIEW.md` | Architecture and components |
| `01_DEVICE_API.md` | API commands and encryption |
| `02_ADMIN_UI.md` | UI commands and templates |
| `03_DATABASE_SCHEMA.md` | All database tables |
| `04_ENCRYPTION.md` | AES-256-GCM details |
| `05_MAP_INTEGRATION.md` | Leaflet and tile system |
| `06_CONFIGURATION.md` | Deployment guide |
| `07_APACHE_CONFIGURATION.md` | Apache virtual hosts |

---

## Quick Commands

```bash
# Watch log file
tail -f /var/www/log/phonetool.log

# Download more tiles
php /var/www/html/tiles/download_tiles.php

# Test tile proxy
curl -I "https://higrade.xyz/tiles/tile.php?z=10&x=225&y=397"

# Fix file permissions
slide chmod 666 <filename>
slide chown www-data:www-data <path>

# Restart Apache
slide systemctl restart apache2
```

---

## URL Mapping

| URL Path | Application |
|----------|-------------|
| `/411b3eebceb45b87ea/` | Device API |
| `/f0a4936828326da599c003/` | Admin UI |
| `/libs/leaflet/` | Leaflet library |
| `/tiles/` | Map tile cache |
| `/8x6kj3ha9gf8z/` | Syncthing proxy |

---

## To Resume Work

1. Read this file for context
2. Full documentation at `/var/www/claudedocs/`
3. Log file at `/var/www/log/phonetool.log`
4. Main code files:
   - Device API: `/var/www/html/411b3eebceb45b87ea/deviceapi.php`
   - Admin UI: `/var/www/html/f0a4936828326da599c003/index.php`
   - Map template: `/var/www/phonetooltemplates/template_map.html`
