2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// add.C - add items to the DB
|
|
|
|
//
|
|
|
|
// usages:
|
|
|
|
// add app -app_name x
|
|
|
|
// add application
|
|
|
|
// create DB record
|
|
|
|
// add platform -platform_name x
|
|
|
|
// create DB record
|
|
|
|
// add app_version
|
|
|
|
// -app_name x -platform_name y -version a -exec_dir b -exec_file c
|
|
|
|
// -download_dir d -url_base e
|
|
|
|
// create DB record
|
|
|
|
// copy exec to data directory
|
|
|
|
// add user -email_addr x -name y -web_password z -authenticator a
|
|
|
|
// add prefs -email_addr x -prefs_file y
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "db.h"
|
|
|
|
#include "backend_lib.h"
|
|
|
|
#include "md5_file.h"
|
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
APP app;
|
|
|
|
PLATFORM platform;
|
|
|
|
APP_VERSION app_version;
|
|
|
|
USER user;
|
|
|
|
int version, retval;
|
|
|
|
double nbytes;
|
|
|
|
char buf[256], md5_cksum[64];
|
|
|
|
char *app_name=0, *platform_name=0, *exec_dir=0, *exec_file=0;
|
|
|
|
char *email_addr=0, *user_name=0, *web_password=0, *authenticator=0;
|
|
|
|
char *prefs_file=0, *download_dir, *url_base;
|
2002-07-07 20:39:24 +00:00
|
|
|
char* code_sign_keyfile;
|
2002-05-29 23:25:21 +00:00
|
|
|
char *message=0, *message_priority=0;
|
|
|
|
|
|
|
|
void add_app() {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
memset(&app, 0, sizeof(app));
|
|
|
|
strcpy(app.name, app_name);
|
|
|
|
app.create_time = time(0);
|
|
|
|
app.alpha_vers = version;
|
|
|
|
app.beta_vers = version;
|
|
|
|
app.prod_vers = version;
|
|
|
|
retval = db_app_new(app);
|
|
|
|
if (retval) {
|
|
|
|
db_print_error("db_app_new");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_platform() {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
memset(&platform, 0, sizeof(platform));
|
|
|
|
strcpy(platform.name, platform_name);
|
|
|
|
platform.create_time = time(0);
|
|
|
|
retval = db_platform_new(platform);
|
|
|
|
if (retval) {
|
|
|
|
db_print_error("db_platform_new");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_app_version() {
|
2002-07-07 20:39:24 +00:00
|
|
|
char path[256];
|
|
|
|
DATA_BLOCK signature;
|
2002-07-09 00:10:58 +00:00
|
|
|
unsigned char signature_buf[SIGNATURE_SIZE_BINARY];
|
2002-07-07 20:39:24 +00:00
|
|
|
char signature_text[1024];
|
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
memset(&app_version, 0, sizeof(app_version));
|
|
|
|
|
|
|
|
strcpy(app.name, app_name);
|
|
|
|
retval = db_app_lookup_name(app);
|
|
|
|
if (retval) {
|
2002-06-10 06:14:18 +00:00
|
|
|
fprintf(stderr, "add_app_version(): can't find app %s\n", app_name);
|
2002-05-29 23:25:21 +00:00
|
|
|
db_print_error("db_app_lookup_name");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
app_version.appid = app.id;
|
|
|
|
strcpy(platform.name, platform_name);
|
|
|
|
retval = db_platform_lookup_name(platform);
|
|
|
|
if (retval) {
|
2002-06-10 06:14:18 +00:00
|
|
|
fprintf(stderr, "add_app_version(): can't find platform %s\n", platform_name);
|
2002-05-29 23:25:21 +00:00
|
|
|
db_print_error("db_platform_lookup_name");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
app_version.platformid = platform.id;
|
|
|
|
app_version.version_num = version;
|
|
|
|
if (message) strcpy(app_version.message, message);
|
|
|
|
if (message_priority) strcpy(app_version.message, message_priority);
|
|
|
|
|
|
|
|
// copy executable to download directory
|
|
|
|
//
|
|
|
|
sprintf(
|
|
|
|
buf,
|
|
|
|
"cp %s/%s %s/%s",
|
|
|
|
exec_dir, exec_file, download_dir, exec_file
|
|
|
|
);
|
|
|
|
retval = system(buf);
|
|
|
|
if (retval) {
|
|
|
|
printf("failed: %s\n", buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
// sign the executable
|
2002-05-29 23:25:21 +00:00
|
|
|
//
|
2002-07-07 20:39:24 +00:00
|
|
|
R_RSA_PRIVATE_KEY code_sign_key;
|
|
|
|
FILE* fkey = fopen(code_sign_keyfile, "r");
|
|
|
|
if (!fkey) {
|
|
|
|
fprintf(stderr, "add: can't open key file (%s)\n", code_sign_keyfile);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = scan_key_hex(fkey, (KEY*)&code_sign_key, sizeof(code_sign_key));
|
|
|
|
fclose(fkey);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "add: can't parse key\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
sprintf(path, "%s/%s", exec_dir, exec_file);
|
|
|
|
signature.data = signature_buf;
|
|
|
|
sign_file(path, code_sign_key, signature);
|
|
|
|
sprint_hex_data(signature_text, signature);
|
|
|
|
|
|
|
|
md5_file(path, md5_cksum, nbytes);
|
2002-05-29 23:25:21 +00:00
|
|
|
|
|
|
|
// generate the XML doc directly.
|
|
|
|
// TODO: use a template, as in create_work
|
|
|
|
//
|
|
|
|
sprintf(app_version.xml_doc,
|
|
|
|
"<file_info>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <url>%s/%s</url>\n"
|
|
|
|
" <executable/>\n"
|
2002-07-07 20:39:24 +00:00
|
|
|
" <file_signature>\n%s"
|
|
|
|
" </file_signature>\n"
|
2002-05-29 23:25:21 +00:00
|
|
|
" <nbytes>%f</nbytes>\n"
|
|
|
|
"</file_info>\n"
|
|
|
|
"<app_version>\n"
|
|
|
|
" <app_name>%s</app_name>\n"
|
|
|
|
" <version_num>%d</version_num>\n"
|
|
|
|
" <file_ref>\n"
|
|
|
|
" <file_name>%s</file_name>\n"
|
|
|
|
" <main_program/>\n"
|
|
|
|
" </file_ref>\n"
|
|
|
|
"</app_version>\n",
|
|
|
|
exec_file,
|
|
|
|
url_base, exec_file,
|
2002-07-07 20:39:24 +00:00
|
|
|
signature_text,
|
2002-05-29 23:25:21 +00:00
|
|
|
nbytes,
|
|
|
|
app_name,
|
|
|
|
version,
|
|
|
|
exec_file
|
|
|
|
);
|
|
|
|
|
|
|
|
app_version.create_time = time(0);
|
|
|
|
retval = db_app_version_new(app_version);
|
|
|
|
if (retval) {
|
|
|
|
db_print_error("db_app_version_new");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_user() {
|
|
|
|
memset(&user, 0, sizeof(user));
|
|
|
|
user.create_time = time(0);
|
|
|
|
strcpy(user.email_addr, email_addr);
|
|
|
|
strcpy(user.name, user_name);
|
|
|
|
strcpy(user.web_password, web_password);
|
|
|
|
strcpy(user.authenticator, authenticator);
|
|
|
|
strcpy(user.country, "United States");
|
|
|
|
strcpy(user.postal_code, "94703");
|
|
|
|
if (prefs_file) {
|
2002-07-05 05:33:40 +00:00
|
|
|
retval = read_filename(prefs_file, user.prefs);
|
2002-05-29 23:25:21 +00:00
|
|
|
if (retval) {
|
|
|
|
printf("read_file: %s", prefs_file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
user.prefs_mod_time = time(0);
|
|
|
|
} else {
|
|
|
|
strcpy(user.prefs,
|
|
|
|
"<preferences>\n"
|
2002-06-01 20:26:21 +00:00
|
|
|
"<low_water_days>1.2</low_water_days>\n"
|
|
|
|
"<high_water_days>2.5</high_water_days>\n"
|
2002-05-29 23:25:21 +00:00
|
|
|
"<disk_max_used_gb>0.4</disk_max_used_gb>\n"
|
|
|
|
"<disk_max_used_pct>50</disk_max_used_pct>\n"
|
|
|
|
"<disk_min_free_gb>0.4</disk_min_free_gb>\n"
|
|
|
|
"<project>\n"
|
|
|
|
" <master_url>http://localhost.localdomain</master_url>\n"
|
|
|
|
" <email_addr>david@localdomain</email_addr>\n"
|
|
|
|
" <authenticator>123892398</authenticator>\n"
|
|
|
|
" <resource_share>10</resource_share>\n"
|
|
|
|
" <project_specific>\n"
|
|
|
|
" <color-scheme>Tahiti Sunset</color-scheme>\n"
|
|
|
|
" </project_specific>\n"
|
|
|
|
"</project>\n"
|
|
|
|
"</preferences>\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
retval = db_user_new(user);
|
|
|
|
if (retval) {
|
|
|
|
db_print_error("db_user_new");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int main(int argc, char** argv) {
|
2002-05-29 23:25:21 +00:00
|
|
|
int i;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
db_open("boinc");
|
|
|
|
for (i=2; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-app_name")) {
|
|
|
|
i++;
|
|
|
|
app_name = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-platform_name")) {
|
|
|
|
i++;
|
|
|
|
platform_name = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-exec_dir")) {
|
|
|
|
i++;
|
|
|
|
exec_dir = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-exec_file")) {
|
|
|
|
i++;
|
|
|
|
exec_file= argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-exec_dir")) {
|
|
|
|
i++;
|
|
|
|
exec_dir = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-email_addr")) {
|
|
|
|
i++;
|
|
|
|
email_addr = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-user_name")) {
|
|
|
|
i++;
|
|
|
|
user_name = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-web_password")) {
|
|
|
|
i++;
|
|
|
|
web_password = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-authenticator")) {
|
|
|
|
i++;
|
|
|
|
authenticator = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-prefs_file")) {
|
|
|
|
i++;
|
|
|
|
prefs_file = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-url_base")) {
|
|
|
|
i++;
|
|
|
|
url_base = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-download_dir")) {
|
|
|
|
i++;
|
|
|
|
download_dir = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-version")) {
|
|
|
|
i++;
|
|
|
|
version = atoi(argv[i]);
|
2002-05-17 22:33:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-message")) {
|
|
|
|
i++;
|
|
|
|
message = argv[i];
|
|
|
|
} else if (!strcmp(argv[i], "-message_priority")) {
|
|
|
|
i++;
|
|
|
|
message_priority = argv[i];
|
2002-07-07 20:39:24 +00:00
|
|
|
} else if (!strcmp(argv[i], "-code_sign_keyfile")) {
|
|
|
|
i++;
|
|
|
|
code_sign_keyfile = argv[i];
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[1], "app")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_app();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[1], "platform")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_platform();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[1], "app_version")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_app_version();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[1], "user")) {
|
2002-05-29 23:25:21 +00:00
|
|
|
add_user();
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
printf("Unrecognized command\n");
|
|
|
|
}
|
|
|
|
db_close();
|
|
|
|
exit(0);
|
|
|
|
}
|