diff --git a/main/config/config-files.js b/main/config/config-files.js new file mode 100644 index 00000000..a7d19d84 --- /dev/null +++ b/main/config/config-files.js @@ -0,0 +1,17 @@ +// Autogenerated code. Do not edit +import { readFileSync, writeFileSync } from 'fs' + +import path from 'path' + +import { getOoniDir } from './global-path' + +const OONI_DIR = getOoniDir() +const CONFIG_FILE_PATH = path.join(OONI_DIR, 'config.json') + +export const prettify = obj => JSON.stringify(obj, null, 2) + +export const readConfigFile = () => readFileSync(CONFIG_FILE_PATH, 'utf8') + +export const writeToConfigFile = obj => writeFileSync(CONFIG_FILE_PATH, prettify(obj)) + +export const getConfigFilePath = () => CONFIG_FILE_PATH diff --git a/main/config/db.js b/main/config/db.js new file mode 100644 index 00000000..e98ab6be --- /dev/null +++ b/main/config/db.js @@ -0,0 +1,79 @@ +// Autogenerated code. Do not edit +import * as fs from 'fs-extra' +import path from 'path' + +import moment from 'moment' +import Sequelize from 'sequelize' + +import { getOoniDir } from './global-path' + +const debug = require('debug')('config.db') + +const OONI_DIR = getOoniDir() + +const DB_DIR = path.join(OONI_DIR, 'db') + +export const sequelize = new Sequelize({ + dialect: 'sqlite', + storage: path.join(DB_DIR, 'main.sqlite3'), + logging: debug, + operatorsAliases: false +}) + +/* Models */ +export const Measurement = sequelize.define('measurement', { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + name: Sequelize.STRING, + startTime: Sequelize.DATE, + endTime: Sequelize.DATE, + // This is an opaque JSON that is test dependent + summary: Sequelize.JSON, + + ip: Sequelize.STRING, + asn: Sequelize.INTEGER, + country: Sequelize.STRING(2), + networkName: Sequelize.STRING, + // The possible states of a measurements are: + // * active, while the measurement is in progress + // * done, when it's finished, but not necessarily uploaded + // * uploaded, if it has been uploaded successfully + // * processed, if the pipeline has processed the measurement + state: { + type: Sequelize.ENUM, + values: ['active', 'done', 'uploaded', 'processed'] + }, + failure: Sequelize.STRING, + + reportFile: Sequelize.STRING, + reportId: Sequelize.STRING, + input: Sequelize.STRING, + measurementId: Sequelize.STRING +}) + +export const Result = sequelize.define('result', { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + name: Sequelize.STRING, + startTime: Sequelize.DATE, + endTime: Sequelize.DATE, + summary: Sequelize.JSON, + done: Sequelize.BOOLEAN, + dataUsageUp: Sequelize.INTEGER, + dataUsageDown: Sequelize.INTEGER +}) +Result.hasMany(Measurement, { as: 'Measurements' }) +sequelize.sync() + +export const initDb = async () => { + await fs.ensureDir(DB_DIR) + await sequelize.sync() +} + +export default initDb diff --git a/main/config/global-path.js b/main/config/global-path.js new file mode 100644 index 00000000..cf197144 --- /dev/null +++ b/main/config/global-path.js @@ -0,0 +1,19 @@ +// Autogenerated code. Do not edit +const { homedir } = require('os') +const path = require('path') + +const mri = require('mri') + +export const getOoniDir = () => { + const args = mri(process.argv.slice(2), { + string: ['ooni-home'] + }) + + const customPath = args['ooni-home'] + + if (!customPath) { + return path.join(homedir(), '.ooni') + } + return path.resolve(customPath) +} +export default getOoniDir diff --git a/scripts/vendor-ooniprobe-cli.py b/scripts/vendor-ooniprobe-cli.py new file mode 100644 index 00000000..bbab3136 --- /dev/null +++ b/scripts/vendor-ooniprobe-cli.py @@ -0,0 +1,37 @@ +import os +from glob import glob +import sys +import shutil + +OONIPROBE_DESKTOP_ROOT = os.path.abspath(os.path.join( + os.path.dirname(__file__), + '..' +)) + +OONIPROBE_CLI_ROOT = os.path.abspath(os.path.join( + os.path.dirname(__file__), + '..', + '..', + 'ooniprobe-cli' +)) + +# Vendorize the config related files from ooniprobe-cli +def main(): + if not os.path.isdir(OONIPROBE_CLI_ROOT): + print('error: ooniprobe-cli must exist in ' + OONIPROBE_CLI_ROOT) + sys.exit(1) + + ignore_files = ['ipc.js', 'geoip.js'] + for path in glob(os.path.join(OONIPROBE_CLI_ROOT, 'src', 'config', '*')): + config_root = os.path.join(OONIPROBE_DESKTOP_ROOT, 'main', 'config') + filename = os.path.basename(path) + if filename in ignore_files: + continue + dst_path = os.path.join(config_root, filename) + with open(path) as in_file: + with open(dst_path, 'w+') as out_file: + out_file.write('// Autogenerated code. Do not edit\n') + shutil.copyfileobj(in_file, out_file) + +if __name__ == '__main__': + main()