File size: 7,720 Bytes
0e0fe0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# 🚀 PortWatcher Startup Guide

## Quick Start (Choose Your Method)

### 🎯 Recommended: Interactive Menu
**File**: `START.bat`

Double-click to open a user-friendly menu with all options:
- ✅ Run Development
- ✅ Run Production  
- ✅ Clean & Build
- ✅ Certificate Management
- ✅ System Diagnostics
- ✅ Advanced Options

```batch

START.bat

```

### ⚡ Quick Run (Simple)
**File**: `runPortWatcher.bat`

Direct run without menu (HTTPS enabled):

```batch

runPortWatcher.bat

```

### 🔧 PowerShell Alternative
```powershell

dotnet run --launch-profile https

```

---

## 📋 START.bat Menu Options

### 1️⃣ Run Application (Development)
- Cleans build artifacts
- Builds project
- Starts on `https://localhost:7145`
- Perfect for testing locally

### 2️⃣ Run Application (Production)
- Release mode build
- Uses ports 80 (HTTP) and 443 (HTTPS)
- Requires production certificate configured
- May need admin privileges

### 3️⃣ Clean and Build
- Removes `bin/` and `obj/` directories
- Fresh build without running
- Useful before committing code

### 4️⃣ Certificate Management
**Submenu:**
- Check certificate status
- Create backup
- Manually renew certificate
- List backup certificates
- Restore from backup

### 5️⃣ System Diagnostics
Reports on:
- .NET SDK version
- Certificate status
- Port availability (5293, 7145, 80, 443)
- Project files
- Configuration files

### 6️⃣ Advanced Options
- Open certificate directory in Explorer
- Edit configuration files
- View application logs
- Full system reset (keeps certificates)

### 7️⃣ Exit
Closes the batch script

---

## 🔐 Certificate Auto-Management

### Automatic (On Startup)
1. ✅ Checks if certificate exists
2. ✅ Creates if missing
3. ✅ Validates expiration
4. ✅ Starts renewal background task

### Manual (Via Batch Menu)
```

START.bat → Option 4 (Certificate Management)

```

**Available Actions:**
| Action | Effect |
|--------|--------|
| Check Status | Shows cert info + expiration |
| Create Backup | Backups current certificate |
| Manual Renew | Creates new certificate |
| List Backups | Shows all backup files |
| Restore | Restores from backup |

---

## 📁 File Structure

```

PortWatcher/

├── START.bat                    ← 🌟 Main Entry Point (Recommended)

├── runPortWatcher.bat           ← Quick start (simple)

├── Program.cs                   ← Updated with HTTPS config

├── appsettings.json             ← HTTP/HTTPS settings

├── appsettings.Development.json ← Dev certificate settings

├── appsettings.Production.json  ← Prod template

├── ManageCertificates.ps1       ← Used by START.bat for cert management

├── ManageCertificates.bat       ← Alternative cert management

├── Data/

│   ├── certificates/            ← Auto-created, stores certs

│   │   └── port-watcher-cert.pfx

│   └── logs/                    ← Application logs

└── README_HTTPS.md              ← Full configuration guide

```

---

## ⚙️ Configuration Files

### Development (Default)
**File**: `appsettings.json` + `appsettings.Development.json`

```json

{

  "HttpSettings": {

    "HttpPort": 5293,

    "HttpsPort": 7145

  }

}

```

Automatically used when running with:
- `dotnet run`
- `runPortWatcher.bat`
- `START.bat` → Option 1

### Production
**File**: `appsettings.Production.json`

```json

{

  "HttpSettings": {

    "HttpPort": 80,

    "HttpsPort": 443

  }

}

```

Used when running with:
- `START.bat` → Option 2
- Environment variable: `ASPNETCORE_ENVIRONMENT=Production`

---

## 🛠️ Common Tasks

### Start Application (Dev)
```batch

START.bat

→ Choose option 1

```

### Check Certificate Health
```batch

START.bat

→ Choose option 4

→ Choose option 1

```

### Renew Certificate Manually
```batch

START.bat

→ Choose option 4

→ Choose option 3

→ Confirm Y

```

### Create Certificate Backup
```batch

START.bat

→ Choose option 4

→ Choose option 2

```

### View System Status
```batch

START.bat

→ Choose option 5

```

### Full System Reset
```batch

START.bat

→ Choose option 6

→ Choose option 5

→ Confirm Y

```

---

## 🔍 Troubleshooting

### Application Won't Start
```batch

START.bat → Option 5 (Diagnostics)

```
Checks:
- .NET SDK installation
- Certificate availability
- Port availability
- Configuration files

### .NET SDK Not Found
```

Install from: https://dotnet.microsoft.com/download/dotnet/8.0

Then restart START.bat

```

### Port Already in Use
```batch

START.bat → Option 5 (Diagnostics)

```
Shows which ports are available.

Change ports in `appsettings.json`:
```json

{

  "HttpSettings": {

    "HttpPort": 8080,      ← Change this

    "HttpsPort": 8443      ← Or this

  }

}

```

### Certificate Issues
```batch

START.bat

→ Option 4 (Certificate Management)

→ Option 4 (List Backups)

→ Option 5 (Restore)

```

---

## 📊 Useful Command Examples

### Via Batch Menu
```batch

START.bat

```

### Via PowerShell
```powershell

# Run development

dotnet run --launch-profile https



# Run production

$env:ASPNETCORE_ENVIRONMENT = "Production"

dotnet run



# Check certificate

.\ManageCertificates.ps1 -Status



# Renew certificate

.\ManageCertificates.ps1 -Renew -Force

```

### Via REST API (When App Running)
```bash

# Check certificate

curl -k https://localhost:7145/api/certificatediagnostics/status



# Validate and renew

curl -k -X POST https://localhost:7145/api/certificatediagnostics/validate



# Force renewal

curl -k -X POST https://localhost:7145/api/certificatediagnostics/renew

```

---

## 🔒 Security Notes

### Development Certificates
- Self-signed (green warning in browser - normal)
- Auto-created, backed up automatically
- Valid for 365 days
- Auto-renewals 30 days before expiry

### Production Certificates
- Use proper SSL certificate from trusted CA
- Configure path in `appsettings.Production.json`
- Set `UseProductionCert: true`
- Recommended: Let's Encrypt or similar

### Firewall Rules
- **Dev**: Allow ports 5293 (HTTP), 7145 (HTTPS)
- **Prod**: Allow ports 80 (HTTP), 443 (HTTPS)

---

## 📞 Support

### Quick Help
```batch

START.bat → Option 5 (Diagnostics)

```

### Detailed Configuration
- Read: `README_HTTPS.md`
- Read: `HTTPS_CERTIFICATE_GUIDE.md`

### View Application Logs
```batch

START.bat → Option 6 (Advanced) → Option 4 (View Logs)

```

---

## ✅ First-Time Setup Checklist

- [ ] Windows has .NET 8.0 SDK installed
- [ ] Double-click `START.bat`
- [ ] Select Option 1 (Run Development)
- [ ] Wait for build to complete
- [ ] Open browser: `https://localhost:7145`
- [ ] Accept self-signed certificate warning
- [ ] Application appears
- [ ] Certificate auto-created: `Data/certificates/port-watcher-cert.pfx`

---

## 🎯 Key Files

| File | Purpose | Usage |
|------|---------|-------|
| `START.bat` | Main interactive menu | Double-click to start |
| `runPortWatcher.bat` | Simple quick-run | Double-click for fast start |
| `ManageCertificates.ps1` | Advanced cert mgmt | Called by START.bat |
| `appsettings.json` | Main configuration | HTTP/HTTPS ports |
| `appsettings.Development.json` | Dev overrides | Certificate settings |
| `appsettings.Production.json` | Prod template | Production ports/config |

---

**Status**: ✅ Ready to Use  
**Last Updated**: March 3, 2026  
**Framework**: .NET 8.0 / ASP.NET Core