Add object detection, tracking, mobile notifications, and search to any security camera.
can test own server now
roryclear8528317f4244
diff --git a/clearcam/Email.m b/clearcam/Email.mindex 17850fb..d3ac4ab 100644--- a/clearcam/Email.m+++ b/clearcam/Email.m@@ -1,5 +1,6 @@#import "Email.h"#import "SecretManager.h"+#import <UIKit/UIKit.h>@implementation Email@@ -14,42 +15,61 @@- (void)sendEmailWithImageAtPath:(NSString *)imagePath {NSString *server = @"http://192.168.1.105:8080";- if([[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_email_server_enabled"]){+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_email_server_enabled"]) {server = [[NSUserDefaults standardUserDefaults] valueForKey:@"own_email_server_address"];}NSString *endpoint = @"/";NSString *toEmail = [[NSUserDefaults standardUserDefaults] stringForKey:@"user_email"];if (!toEmail) return;- NSData *imageData = [NSData dataWithContentsOfFile:imagePath];+ NSData *imageData = nil;+ NSString *filePathToSend = imagePath;++ if (imagePath.length == 0) { //todo, to test user's endpoint+ NSLog(@"Image path is empty. Generating blank image.");+ CGSize imageSize = CGSizeMake(1280, 720);+ UIGraphicsBeginImageContext(imageSize);+ CGContextRef context = UIGraphicsGetCurrentContext();+ CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);+ CGContextFillRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height));+ UIImage *blankImage = UIGraphicsGetImageFromCurrentImageContext();+ UIGraphicsEndImageContext();++ // Convert blank image to JPEG+ imageData = UIImageJPEGRepresentation(blankImage, 1.0);++ // Save temporarily+ NSString *tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"test_blank_img.jpg"];+ [imageData writeToFile:tempPath atomically:YES];+ filePathToSend = tempPath;+ } else {+ imageData = [NSData dataWithContentsOfFile:imagePath];+ }+if (!imageData) {- NSLog(@"Failed to read image data from path: %@", imagePath);+ NSLog(@"Failed to read image data.");return;}NSData *fileData = imageData;- NSString *filePathToSend = imagePath;-- // Check if encryption is enabled in SettingsManager++ // Check if encryption is enabledBOOL encryptImage = [[NSUserDefaults standardUserDefaults] boolForKey:@"encrypt_email_data_enabled"];-if (encryptImage) {- // Retrieve the user's password from the KeychainNSString *encryptionKey = [[SecretManager sharedManager] getEncryptionKey];-if (!encryptionKey) {- NSLog(@"Encryption key not found in Keychain. Encryption aborted.");+ NSLog(@"Encryption key not found. Encryption aborted.");return;}- // Encrypt the image data using the retrieved keyfileData = [[SecretManager sharedManager] encryptData:imageData withKey:encryptionKey];if (!fileData) {NSLog(@"Encryption failed.");return;}- }+ filePathToSend = [filePathToSend stringByAppendingString:@".aes"];+ }NSString *boundary = [NSString stringWithFormat:@"Boundary-%@", [[NSUUID UUID] UUIDString]];NSMutableData *bodyData = [NSMutableData data];@@ -60,12 +80,10 @@[bodyData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];[bodyData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];- [bodyData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", encryptImage ? [[filePathToSend lastPathComponent] stringByAppendingString:@".aes"] : [filePathToSend lastPathComponent]-] dataUsingEncoding:NSUTF8StringEncoding]];- [bodyData appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];+ [bodyData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", [filePathToSend lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];+ [bodyData appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];[bodyData appendData:fileData];[bodyData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];-[bodyData appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];NSURL *url = [NSURL URLWithString:[server stringByAppendingString:endpoint]];@@ -87,4 +105,5 @@[task resume];}+@enddiff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.mindex 1e1bf9e..ad4b349 100644--- a/clearcam/SettingsViewController.m+++ b/clearcam/SettingsViewController.m@@ -3,6 +3,7 @@#import "SecretManager.h"#import "StoreManager.h"#import "NumberSelectionViewController.h"+#import "Email.h"@interface SettingsViewController () <UITableViewDelegate, UITableViewDataSource>@@ -143,9 +144,9 @@- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {if (section == 0) {// Resolution, Detect objects, Email, Send Email Alerts, Encrypt Email Data, Use own email server- NSInteger baseRows = 6; // Existing 5 rows + new "Use own email server" toggle+ NSInteger baseRows = 6; // Existing 6 rowsif (self.useOwnEmailServerEnabled && self.isEmailServerSectionExpanded) {- return baseRows + 1; // Add 1 row for the expandable Address field and Test button+ return baseRows + 2; // Add 2 rows: one for Address field and one for Test button}return baseRows;} else if (section == 1) {@@ -245,9 +246,15 @@cell.textLabel.textColor = [UIColor labelColor];cell.userInteractionEnabled = YES;} else if (indexPath.row == 6 && self.useOwnEmailServerEnabled && self.isEmailServerSectionExpanded) {- cell.textLabel.text = @"Server Address";- cell.detailTextLabel.text = self.emailServerAddress;- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;+ cell.textLabel.text = @"Server Address";+ cell.detailTextLabel.text = self.emailServerAddress;+ cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;+ cell.userInteractionEnabled = YES;+ } else if (indexPath.row == 7 && self.useOwnEmailServerEnabled && self.isEmailServerSectionExpanded) {+ cell.textLabel.text = @"Test own server";+ cell.textLabel.textColor = [UIColor systemBlueColor];+ cell.detailTextLabel.text = nil;+ cell.accessoryType = UITableViewCellAccessoryNone;cell.userInteractionEnabled = YES;}} else if (indexPath.section == 1) {@@ -297,8 +304,11 @@NSLog(@"Tapped Email Address row");[self showEmailInputDialog];} else if (indexPath.row == 6 && self.useOwnEmailServerEnabled && self.isEmailServerSectionExpanded) {- NSLog(@"Tapped Server Address row");- [self showEmailServerAddressInputDialog];+ NSLog(@"Tapped Server Address row");+ [self showEmailServerAddressInputDialog];+ } else if (indexPath.row == 7 && self.useOwnEmailServerEnabled && self.isEmailServerSectionExpanded) {+ NSLog(@"Tapped Test own server row");+ [self testEmailServer];}} else if (indexPath.section == 1) {NSArray *presetKeys = [[[NSUserDefaults standardUserDefaults] objectForKey:@"yolo_presets"] allKeys];@@ -365,24 +375,29 @@}}];- UIAlertAction *testAction = [UIAlertAction actionWithTitle:@"Test"- style:UIAlertActionStyleDefault- handler:^(UIAlertAction * _Nonnull action) {- // Log a test message- NSLog(@"Testing email server at address: %@", self.emailServerAddress);- }];-UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"style:UIAlertActionStyleCancelhandler:nil];[alert addAction:saveAction];- [alert addAction:testAction];[alert addAction:cancelAction];-+[self presentViewController:alert animated:YES completion:nil];}+- (void)testEmailServer {+ [[Email sharedInstance] sendEmailWithImageAtPath:@""];+ // You might want to add some feedback here, like an alert showing success/failure+ UIAlertController *resultAlert = [UIAlertController alertControllerWithTitle:@"Test Initiated"+ message:@"Test email has been initiated. Check your server logs for results."+ preferredStyle:UIAlertControllerStyleAlert];+ UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"+ style:UIAlertActionStyleDefault+ handler:nil];+ [resultAlert addAction:okAction];+ [self presentViewController:resultAlert animated:YES completion:nil];+}+- (void)encryptEmailDataSwitchToggled:(UISwitch *)sender {if (sender.on) {// Check if a password already exists in the secrets manager