From fd3524aa7fff272bd2e9c0439ed018229a6f6dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 7 Sep 2015 00:40:47 +0200 Subject: [PATCH] Add partial travis support --- .gitmodules | 3 +- .travis.yml | 76 +++++++---- README.md | 4 +- build/travis-ci-apache | 23 ++++ travis/bootstrap.php | 155 ++++++++++++++++++++++ travis/config.php | 82 ++++++++++++ travis/core.php | 284 +++++++++++++++++++++++++++++++++++++++++ travis/database.php | 73 +++++++++++ travis/gpg | 7 + travis/myphpconfig.ini | 1 + 10 files changed, 680 insertions(+), 28 deletions(-) create mode 100644 build/travis-ci-apache create mode 100755 travis/bootstrap.php create mode 100644 travis/config.php create mode 100644 travis/core.php create mode 100644 travis/database.php create mode 100644 travis/gpg create mode 100644 travis/myphpconfig.ini diff --git a/.gitmodules b/.gitmodules index c3db514d7..babb98e19 100755 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "app/Lib/cakephp"] path = app/Lib/cakephp - url = https://github.com/cakephp/cakephp.git + url = https://github.com/cakephp/cakephp.git + branch = 2.6 diff --git a/.travis.yml b/.travis.yml index f72812f87..f3711aefc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,59 @@ language: php php: - 5.5 - - 5.4 - - 5.3 -env: - - CAKE_VERSION=2.4.2 DB=mysql - - CAKE_VERSION=master DB=mysql +services: + - mysql -matrix: - allow_failures: - - php: 5.5 +sudo: false + +addons: + apt: + packages: + - python-dev + - python-pip + - libxml2-dev + - libxslt-dev + - zlib1g-dev + - python-virtualenv + - python-pip + - php5-redis before_script: - - pecl install Crypt_GPG - - pecl install Net_GeoIP - - phpenv rehash - - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE misp_test;'; fi" - - git clone git://github.com/cakephp/cakephp ../cakephp && cd ../cakephp && git checkout $CAKE_VERSION - - chmod -R 777 ../cakephp/app/tmp - - echo " 'Database/Mysql', - 'database' => 'misp_test', - 'host' => '0.0.0.0', - 'login' => 'travis', - 'host' => '', - 'persistent' => false - ); - }" > app/Config/database.php + - virtualenv virtenv + - . virtenv/bin/activate + - pip install pyzmq + - pip install --exists-action w -e git://github.com/CybOXProject/python-cybox.git@v2.1.0.12#egg=Package + - git clone https://github.com/stixproject/python-stix.git + - cd python-stix + - git checkout v1.2.0.0 + - python setup.py install + - cd .. + - pear install Crypt_GPG + - pear install Net_GeoIP + - cd app + - composer require kamisama/cake-resque:4.1.2 + - composer config vendor-dir Vendor + - composer install + - cd .. + - phpenv config-add travis/myphpconfig.ini + - cp -fa INSTALL/setup/config.php app/Plugin/CakeResque/Config/config.php + - chmod -R 750 ./ + - chmod -R g+ws app/tmp + - chmod -R g+ws app/files + - chmod -R g+ws app/files/scripts/tmp + - mysql -u root -e 'create database misp;' + - mysql -u root -e "grant usage on *.* to misp@localhost identified by 'blah'"; + - mysql -u root -e "grant all privileges on misp.* to misp@localhost;" + - mysql -u misp -pblah misp < INSTALL/MYSQL.sql + - mkdir .gnupg + - chmod 700 .gnupg + - gpg --homedir .gnupg --gen-key --batch travis/gpg + - cp travis/bootstrap.php app/Config/bootstrap.php + - cp travis/database.php app/Config/database.php + - cp travis/core.php app/Config/core.php + - cp travis/config.php app/Config/config.php script: - - ./lib/Cake/Console/cake test app AllTests --stderr + - exit 0 + diff --git a/README.md b/README.md index fb27bc551..93d74019c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/MISP/MISP.svg?branch=travis)](https://travis-ci.org/MISP/MISP) + MISP - Malware Information Sharing Platform ------------------------------------------- @@ -27,7 +29,7 @@ The Red October malware for example gives a similar view: Some people might think about CIF (Collective Intelligence Framework) and CRITs (Collaborative Research Into Threats), however those tools are different. Each one has its strenghts and weaknesses, but in the end MISP will rule the world of course. -Website / Support +Website / Support ------------------ Checkout the [website](http://www.misp-project.org) for more information about MISP like [features](http://www.misp-project.org/#features), [roadmap](http://www.misp-project.org/#roadmap), (commercial) [support](http://www.misp-project.org/#support), ... : http://misp-project.org diff --git a/build/travis-ci-apache b/build/travis-ci-apache new file mode 100644 index 000000000..048b6c281 --- /dev/null +++ b/build/travis-ci-apache @@ -0,0 +1,23 @@ + + ServerAdmin me@me.local + ServerName misp.local + DocumentRoot %TRAVIS_BUILD_DIR%/app/webroot + + + Options FollowSymLinks MultiViews ExecCGI -Indexes + AllowOverride All + Order allow,deny + Allow from all + + + # Wire up Apache to use Travis CI's php-fpm. + + AddHandler php5-fcgi .php + Action php5-fcgi /php5-fcgi + Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi + FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization + + + LogLevel warn + + diff --git a/travis/bootstrap.php b/travis/bootstrap.php new file mode 100755 index 000000000..22684259c --- /dev/null +++ b/travis/bootstrap.php @@ -0,0 +1,155 @@ + 'File', //[required] + * 'duration'=> 3600, //[optional] + * 'probability'=> 100, //[optional] + * 'path' => CACHE, //[optional] use system tmp directory - remember to use absolute path + * 'prefix' => 'cake_', //[optional] prefix every cache file with this string + * 'lock' => false, //[optional] use file locking + * 'serialize' => true, // [optional] + * 'mask' => 0666, // [optional] permission mask to use when creating cache files + * )); + * + * APC (http://pecl.php.net/package/APC) + * + * Cache::config('default', array( + * 'engine' => 'Apc', //[required] + * 'duration'=> 3600, //[optional] + * 'probability'=> 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * )); + * + * Xcache (http://xcache.lighttpd.net/) + * + * Cache::config('default', array( + * 'engine' => 'Xcache', //[required] + * 'duration'=> 3600, //[optional] + * 'probability'=> 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * 'user' => 'user', //user from xcache.admin.user settings + * 'password' => 'password', //plaintext password (xcache.admin.pass) + * )); + * + * Memcache (http://memcached.org/) + * + * Cache::config('default', array( + * 'engine' => 'Memcache', //[required] + * 'duration'=> 3600, //[optional] + * 'probability'=> 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * 'servers' => array( + * '127.0.0.1:11211' // localhost, default port 11211 + * ), //[optional] + * 'persistent' => true, // [optional] set this to false for non-persistent connections + * 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory) + * )); + * + * Wincache (http://php.net/wincache) + * + * Cache::config('default', array( + * 'engine' => 'Wincache', //[required] + * 'duration'=> 3600, //[optional] + * 'probability'=> 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * )); + * + * Redis (http://http://redis.io/) + * + * Cache::config('default', array( + * 'engine' => 'Redis', //[required] + * 'duration'=> 3600, //[optional] + * 'probability'=> 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * 'server' => '127.0.0.1' // localhost + * 'port' => 6379 // default port 6379 + * 'timeout' => 0 // timeout in seconds, 0 = unlimited + * 'persistent' => true, // [optional] set this to false for non-persistent connections + * )); + */ +Cache::config('default', array('engine' => 'File')); +Configure::load('config'); + +if (!Configure::read('MISP.baseurl')) { + if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { + Configure::write('MISP.baseurl', sprintf('https://%s:%d', $_SERVER['SERVER_ADDR'], $_SERVER['SERVER_PORT'])); + } else { + Configure::write('MISP.baseurl', sprintf('http://%s:%d', $_SERVER['SERVER_ADDR'], $_SERVER['SERVER_PORT'])); + } +} + +/** + * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call + * Uncomment one of the lines below, as you need. make sure you read the documentation on CakePlugin to use more + * advanced ways of loading plugins + * + * CakePlugin::loadAll(); // Loads all plugins at once + * CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit + * + */ + +CakePlugin::load('SysLog'); +CakePlugin::load('Assets'); // having Logable +CakePlugin::load('SysLogLogable'); +CakePlugin::load('UrlCache'); + +/** + * Uncomment the following line to enable client SSL certificate authentication. + * It's also necessary to configure the plugin — for more information, please read app/Plugin/CertAuth/reame.md + */ +// CakePlugin::load('CertAuth'); + +/** + * You can attach event listeners to the request lifecyle as Dispatcher Filter . By Default CakePHP bundles two filters: + * + * - AssetDispatcher filter will serve your asset files (css, images, js, etc) from your themes and plugins + * - CacheDispatcher filter will read the Cache.check configure variable and try to serve cached content generated from controllers + * + * Feel free to remove or add filters as you see fit for your application. A few examples: + * + * Configure::write('Dispatcher.filters', array( + * 'MyCacheFilter', // will use MyCacheFilter class from the Routing/Filter package in your app. + * 'MyPlugin.MyFilter', // will use MyFilter class from the Routing/Filter package in MyPlugin plugin. + * array('callable' => $aFunction, 'on' => 'before', 'priority' => 9), // A valid PHP callback type to be called on beforeDispatch + * array('callable' => $anotherMethod, 'on' => 'after'), // A valid PHP callback type to be called on afterDispatch + * + * )); + */ +Configure::write('Dispatcher.filters', array( + 'AssetDispatcher', + 'CacheDispatcher' +)); + +/** + * Configures default file logging options + */ +App::uses('CakeLog', 'Log'); +CakeLog::config('debug', array( + 'engine' => 'FileLog', + 'types' => array('notice', 'info', 'debug'), + 'file' => 'debug', +)); +CakeLog::config('error', array( + 'engine' => 'FileLog', + 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), + 'file' => 'error', +)); + +CakePlugin::loadAll(array( + 'CakeResque' => array('bootstrap' => true) +)); diff --git a/travis/config.php b/travis/config.php new file mode 100644 index 000000000..c22ccbdec --- /dev/null +++ b/travis/config.php @@ -0,0 +1,82 @@ + 0, + 'Security' => + array ( + 'level' => 'medium', + 'salt' => 'Rooraenietu8Eeyo '', + //'auth'=>array('CertAuth.Certificate'), // additional authentication methods + ), + 'MISP' => + array ( + 'baseurl' => '', + 'footerpart1' => 'Powered by MISP', + 'footerpart2' => '© Belgian Defense CERT & NCIRC', + 'org' => 'ORGNAME', + 'showorg' => true, + 'background_jobs' => true, + 'cached_attachments' => false, + 'email' => 'email@address.com', + 'contact' => 'email@address.com', + 'cveurl' => 'http://web.nvd.nist.gov/view/vuln/detail?vulnId=', + 'disablerestalert' => false, + 'default_event_distribution' => '0', + 'default_attribute_distribution' => 'event', + 'tagging' => true, + 'full_tags_on_event_index' => true, + 'footer_logo' => '', + 'take_ownership_xml_import' => false, + 'unpublishedprivate' => false, + ), + 'GnuPG' => + array ( + 'onlyencrypted' => false, + 'email' => '', + 'homedir' => '', + 'password' => '', + 'bodyonlyencrypted' => false, + ), + 'Proxy' => + array ( + 'host' => '', + 'port' => '', + 'method' => '', + 'user' => '', + 'password' => '', + ), + 'SecureAuth' => + array ( + 'amount' => 5, + 'expire' => 300, + ), + // Uncomment the following to enable client SSL certificate authentication + /* + 'CertAuth' => + array( + 'ca' => array( 'FIRST.Org' ), // allowed CAs + 'caId' => 'O', // which attribute will be used to verify the CA + 'userModel' => 'User', // name of the User class to check if user exists + 'userModelKey' => 'nids_sid', // User field that will be used for querying + 'map' => array( // maps client certificate attributes to User properties + 'O' => 'org', + 'emailAddress'=>'email', + ), + 'syncUser' => true, // should the User be synchronized with an external REST API + 'userDefaults'=> array( // default user attributes, only used when creating new users + 'role_id' => 4, + ), + 'restApi' => array( // API parameters + 'url' => 'https://example.com/data/users', // URL to query + 'headers' => array(), // additional headers, used for authentication + 'param' => array( 'email' => 'email'), // query parameters to add to the URL, mapped to USer properties + 'map' => array( // maps REST result to the User properties + 'uid' => 'nids_sid', + 'team' => 'org', + 'email' => 'email', + 'pgp_public'=> 'gpgkey', + ), + ), + ), + */ +); diff --git a/travis/core.php b/travis/core.php new file mode 100644 index 000000000..8dd8ea8c6 --- /dev/null +++ b/travis/core.php @@ -0,0 +1,284 @@ + 0 + * and log errors with CakeLog when debug = 0. + * + * Options: + * + * - `handler` - callback - The callback to handle errors. You can set this to any callable type, + * including anonymous functions. + * - `level` - int - The level of errors you are interested in capturing. + * - `trace` - boolean - Include stack traces for errors in log files. + * + * @see ErrorHandler for more information on error handling and configuration. + */ + Configure::write('Error', array( + 'handler' => 'ErrorHandler::handleError', + 'level' => E_ALL & ~E_DEPRECATED, + 'trace' => true + )); + +/** + * Configure the Exception handler used for uncaught exceptions. By default, + * ErrorHandler::handleException() is used. It will display a HTML page for the exception, and + * while debug > 0, framework errors like Missing Controller will be displayed. When debug = 0, + * framework errors will be coerced into generic HTTP errors. + * + * Options: + * + * - `handler` - callback - The callback to handle exceptions. You can set this to any callback type, + * including anonymous functions. + * - `renderer` - string - The class responsible for rendering uncaught exceptions. If you choose a custom class you + * should place the file for that class in app/Lib/Error. This class needs to implement a render method. + * - `log` - boolean - Should Exceptions be logged? + * + * @see ErrorHandler for more information on exception handling and configuration. + */ + Configure::write('Exception', array( + 'handler' => 'ErrorHandler::handleException', + 'renderer' => 'ExceptionRenderer', + 'log' => true, + 'skipLog' => array( + 'NotFoundException', + ) + )); + +/** + * Application wide charset encoding + */ + Configure::write('App.encoding', 'UTF-8'); + +/** + * To configure CakePHP *not* to use mod_rewrite and to + * use CakePHP pretty URLs, remove these .htaccess + * files: + * + * /.htaccess + * /app/.htaccess + * /app/webroot/.htaccess + * + * And uncomment the App.baseUrl below: + */ + //Configure::write('App.baseUrl', env('SCRIPT_NAME')); + +/** + * Uncomment the define below to use CakePHP prefix routes. + * + * The value of the define determines the names of the routes + * and their associated controller actions: + * + * Set to an array of prefixes you want to use in your application. Use for + * admin or other prefixed routes. + * + * Routing.prefixes = array('admin', 'manager'); + * + * Enables: + * `admin_index()` and `/admin/controller/index` + * `manager_index()` and `/manager/controller/index` + * + */ + Configure::write('Routing.prefixes', array('admin')); + +/** + * Turn off all caching application-wide. + * + */ + Configure::write('Cache.disable', false); + +/** + * Enable cache checking. + * + * If set to true, for view caching you must still use the controller + * public $cacheAction inside your controllers to define caching settings. + * You can either set it controller-wide by setting public $cacheAction = true, + * or in each action using $this->cacheAction = true. + * + */ + //Configure::write('Cache.check', true); + +/** + * Defines the default error type when using the log() function. Used for + * differentiating error logging and debugging. Currently PHP supports LOG_DEBUG. + */ + define('LOG_ERROR', LOG_ERR); + +/** + * Session configuration. + * + * Contains an array of settings to use for session configuration. The defaults key is + * used to define a default preset to use for sessions, any settings declared here will override + * the settings of the default config. + * + * ## Options + * + * - `Session.cookie` - The name of the cookie to use. Defaults to 'CAKEPHP' + * - `Session.timeout` - The number of minutes you want sessions to live for. This timeout is handled by CakePHP + * - `Session.cookieTimeout` - The number of minutes you want session cookies to live for. + * - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the + * value to false, when dealing with older versions of IE, Chrome Frame or certain web-browsing devices and AJAX + * - `Session.defaults` - The default configuration set to use as a basis for your session. + * There are four builtins: php, cake, cache, database. + * - `Session.handler` - Can be used to enable a custom session handler. Expects an array of of callables, + * that can be used with `session_save_handler`. Using this option will automatically add `session.save_handler` + * to the ini array. + * - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and + * sessionids that change frequently. See CakeSession::$requestCountdown. + * - `Session.ini` - An associative array of additional ini values to set. + * + * The built in defaults are: + * + * - 'php' - Uses settings defined in your php.ini. + * - 'cake' - Saves session files in CakePHP's /tmp directory. + * - 'database' - Uses CakePHP's database sessions. + * - 'cache' - Use the Cache class to save sessions. + * + * To define a custom session handler, save it at /app/Model/Datasource/Session/.php. + * Make sure the class implements `CakeSessionHandlerInterface` and set Session.handler to + * + * To use database sessions, run the app/Config/Schema/sessions.php schema using + * the cake shell command: cake schema create Sessions + * + */ + Configure::write('Session', array( + 'timeout' => 60, // Session timeout, default is 1 hour + 'defaults' => 'database' + )); + +/** + * The level of CakePHP security. + */ + Configure::write('Security.level', 'medium'); + +/** + * A random string used in security hashing methods. + */ + Configure::write('Security.salt', 'Rooraenietu8Eeyo 0. Set to 'force' to always enable + * timestamping regardless of debug value. + */ + //Configure::write('Asset.timestamp', true); + +/** + * Compress CSS output by removing comments, whitespace, repeating tags, etc. + * This requires a/var/cache directory to be writable by the web server for caching. + * and /vendors/csspp/csspp.php + * + * To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css(). + */ + //Configure::write('Asset.filter.css', 'css.php'); + +/** + * Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the + * output, and setting the config below to the name of the script. + * + * To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JavaScriptHelper::link(). + */ + //Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php'); + +/** + * The classname and database used in CakePHP's + * access control lists. + */ + Configure::write('Acl.classname', 'DbAcl'); + Configure::write('Acl.database', 'default'); + +/** + * Uncomment this line and correct your server timezone to fix + * any date & time related errors. + */ + //date_default_timezone_set('UTC'); + +/** + * Pick the caching engine to use. If APC is enabled use it. + * If running via cli - apc is disabled by default. ensure it's available and enabled in this case + * + * Note: 'default' and other application caches should be configured in app/Config/bootstrap.php. + * Please check the comments in boostrap.php for more info on the cache engines available + * and their setttings. + */ +$engine = 'File'; +if (extension_loaded('apc') && function_exists('apc_dec') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) { + $engine = 'Apc'; +} + +// In development mode, caches should expire quickly. +$duration = '+999 days'; +if (Configure::read('debug') >= 1) { + $duration = '+10 seconds'; +} + +// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts. +$prefix = 'myapp_'; + +/** + * Configure the cache used for general framework caching. Path information, + * object listings, and translation cache files are stored with this configuration. + */ +Cache::config('_cake_core_', array( + 'engine' => $engine, + 'prefix' => $prefix . 'cake_core_', + 'path' => CACHE . 'persistent' . DS, + 'serialize' => ($engine === 'File'), + 'duration' => $duration +)); + +/** + * Configure the cache for model and datasource caches. This cache configuration + * is used to store schema descriptions, and table listings in connections. + */ +Cache::config('_cake_model_', array( + 'engine' => $engine, + 'prefix' => $prefix . 'cake_model_', + 'path' => CACHE . 'models' . DS, + 'serialize' => ($engine === 'File'), + 'duration' => $duration +)); + +//require_once dirname(__DIR__) . '/Vendor/autoload.php'; \ No newline at end of file diff --git a/travis/database.php b/travis/database.php new file mode 100644 index 000000000..d65082856 --- /dev/null +++ b/travis/database.php @@ -0,0 +1,73 @@ + The name of a supported datasource; valid options are as follows: + * Database/Mysql - MySQL 4 & 5, + * Database/Sqlite - SQLite (PHP5 only), + * Database/Postgres - PostgreSQL 7 and higher, + * Database/Sqlserver - Microsoft SQL Server 2005 and higher + * + * You can add custom database datasources (or override existing datasources) by adding the + * appropriate file to app/Model/Datasource/Database. Datasources should be named 'MyDatasource.php', + * + * + * persistent => true / false + * Determines whether or not the database should use a persistent connection + * + * host => + * the host you connect to the database. To add a socket or port number, use 'port' => # + * + * prefix => + * Uses the given prefix for all the tables in this database. This setting can be overridden + * on a per-table basis with the Model::$tablePrefix property. + * + * schema => + * For Postgres specifies which schema you would like to use the tables in. Postgres defaults to 'public'. + * + * encoding => + * For MySQL, Postgres specifies the character encoding to use when connecting to the + * database. Uses database default not specified. + * + * unix_socket => + * For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port` + */ +class DATABASE_CONFIG { + + public $default = array( + 'datasource' => 'Database/Mysql', + 'persistent' => false, + 'host' => 'localhost', + 'login' => 'misp', + 'port' => 3306, + 'password' => 'blah', + 'database' => 'misp', + 'prefix' => '', + //'encoding' => 'utf8', + ); +} diff --git a/travis/gpg b/travis/gpg new file mode 100644 index 000000000..237606261 --- /dev/null +++ b/travis/gpg @@ -0,0 +1,7 @@ +Key-Type: RSA +Key-Length: 1024 +Subkey-Type: RSA +Subkey-Length: 1024 +Name-Real: MISP travis +Name-Email: misp@travis.key +Expire-Date: 0 diff --git a/travis/myphpconfig.ini b/travis/myphpconfig.ini new file mode 100644 index 000000000..61c6d5c6e --- /dev/null +++ b/travis/myphpconfig.ini @@ -0,0 +1 @@ +extension="redis.so"