Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DCM for request version.txt and deb files #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 18 additions & 18 deletions tools/dmon.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int installDeb(NSString *filePath) {
return ext_code;
}

int downloadFile(NSString *url, NSString *userpass, NSString *outfile) {
int downloadFile(NSString *url, NSString *authtoken, NSString *outfile) {
CURL *curl;
FILE *fp;
long httpCode = -1;
Expand All @@ -174,9 +174,14 @@ int downloadFile(NSString *url, NSString *userpass, NSString *outfile) {
// Set the URL
curl_easy_setopt(curl, CURLOPT_URL, [url UTF8String]);

// Set the authentication headers
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(curl, CURLOPT_USERPWD, [userpass UTF8String]);
// Set headers
struct curl_slist* headers = NULL;
curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_XOAUTH2_BEARER, [authtoken UTF8String]);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);

// Redirect
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

// Set the output file
fp = fopen([outfile UTF8String], "wb");
Expand All @@ -189,7 +194,7 @@ int downloadFile(NSString *url, NSString *userpass, NSString *outfile) {
CURLcode res = curl_easy_perform(curl);

// Get the http status code
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &httpCode);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);

// Clean up
fclose(fp);
Expand Down Expand Up @@ -242,11 +247,11 @@ void update(NSDictionary *config) {
// getAptList(@"com.github.clburlison.dmon");

// Strip trailing forward slashes to make things consistent for users
NSString *url = [config[@"dmon_url"] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
NSString *url = [config[@"device_configuration_manager_url"] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
NSLog(@"dmon: Update URL is: %@", url);
int versionDownload = downloadFile(
[NSString stringWithFormat:@"%@/%@", url, versionFile],
[NSString stringWithFormat:@"%@:%@", config[@"dmon_username"], config[@"dmon_password"]],
[NSString stringWithFormat:@"%@/api/%@", url, versionFile],
[NSString stringWithFormat:@"%@", config[@"api_key"]],
versionFile
);
if (versionDownload != 0) {
Expand All @@ -261,8 +266,8 @@ void update(NSDictionary *config) {
if (![pogoVersion isEqualToString:parsedVersion[@"pogo"]]) {
NSLog(@"dmon: Pogo version mismatch. Have '%@'. Need '%@'", pogoVersion, parsedVersion[@"pogo"]);
int pogoDownload = downloadFile(
[NSString stringWithFormat:@"%@/%@", url, pogo_ipa],
[NSString stringWithFormat:@"%@:%@", config[@"dmon_username"], config[@"dmon_password"]],
[NSString stringWithFormat:@"%@/api/download/%@", url, pogo_ipa],
[NSString stringWithFormat:@"%@", config[@"api_key"]],
pogo_ipa
);
if (pogoDownload == 0) {
Expand All @@ -274,8 +279,8 @@ void update(NSDictionary *config) {
if (![gcVersion isEqualToString:parsedVersion[@"gc"]]) {
NSLog(@"dmon: GC version mismatch. Have '%@'. Need '%@'", gcVersion, parsedVersion[@"gc"]);
int gcDownload = downloadFile(
[NSString stringWithFormat:@"%@/%@", url, gc_deb],
[NSString stringWithFormat:@"%@:%@", config[@"dmon_username"], config[@"dmon_password"]],
[NSString stringWithFormat:@"%@/api/download/%@", url, gc_deb],
[NSString stringWithFormat:@"%@", config[@"api_key"]],
gc_deb
);
if (gcDownload == 0) {
Expand Down Expand Up @@ -312,7 +317,7 @@ int main(void) {
while (1) {
// Only call at the start of loop
NSDictionary *config = parseConfig();
if (i == 0 && config[@"dmon_url"] != nil && [config[@"dmon_url"] isKindOfClass:[NSString class]] && ![config[@"dmon_url"] isEqualToString:@""]) {
if (i == 0) {
// NSLog(@"dmon: Full config: %@", config);
update(config);
}
Expand All @@ -328,10 +333,5 @@ int main(void) {
sleep(30);
}

// Start loop
while (1) {
monitor();
sleep(30);
}
return 0;
}