├── library ├── vendor │ └── aws │ │ └── .keep └── Aws │ ├── AssumeRole.php │ ├── AwsKey.php │ ├── ProvidedHook │ └── Director │ │ └── ImportSource.php │ └── AwsClient.php ├── doc ├── img │ ├── 00_overview.png │ ├── 01_aws_template.png │ ├── 11_aws_add_key.png │ ├── 05_aws_sync_rule.png │ ├── 10_aws_key_config.png │ ├── 03_aws_import_region.png │ ├── 07_aws_host_config.png │ ├── 09_aws_host_preview.png │ ├── 06_aws_sync_properties.png │ ├── 04_aws_import_source_key.png │ ├── 02_aws_import_source_basics.png │ └── 08_aws_host_config_with_vars.png ├── 01-About.md ├── 02-Installation-and-Configuration.md └── 03-Usage.md ├── run.php ├── application ├── views │ └── scripts │ │ └── config │ │ ├── form.phtml │ │ ├── keys.phtml │ │ └── keys-list.phtml ├── forms │ └── Config │ │ ├── KeysListForm.php │ │ └── KeysForm.php └── controllers │ └── ConfigController.php ├── .gitignore ├── module.info ├── configuration.php ├── .github ├── workflows │ └── L10n-update.yml └── ISSUE_TEMPLATE.md ├── composer.json ├── README.md └── LICENSE /library/vendor/aws/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/img/00_overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/00_overview.png -------------------------------------------------------------------------------- /run.php: -------------------------------------------------------------------------------- 1 | provideHook('director/ImportSource'); 4 | } 5 | -------------------------------------------------------------------------------- /doc/img/01_aws_template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/01_aws_template.png -------------------------------------------------------------------------------- /doc/img/11_aws_add_key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/11_aws_add_key.png -------------------------------------------------------------------------------- /doc/img/05_aws_sync_rule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/05_aws_sync_rule.png -------------------------------------------------------------------------------- /doc/img/10_aws_key_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/10_aws_key_config.png -------------------------------------------------------------------------------- /doc/img/03_aws_import_region.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/03_aws_import_region.png -------------------------------------------------------------------------------- /doc/img/07_aws_host_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/07_aws_host_config.png -------------------------------------------------------------------------------- /doc/img/09_aws_host_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/09_aws_host_preview.png -------------------------------------------------------------------------------- /doc/img/06_aws_sync_properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/06_aws_sync_properties.png -------------------------------------------------------------------------------- /doc/img/04_aws_import_source_key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/04_aws_import_source_key.png -------------------------------------------------------------------------------- /doc/img/02_aws_import_source_basics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/02_aws_import_source_basics.png -------------------------------------------------------------------------------- /doc/img/08_aws_host_config_with_vars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Icinga/icingaweb2-module-aws/HEAD/doc/img/08_aws_host_config_with_vars.png -------------------------------------------------------------------------------- /application/views/scripts/config/form.phtml: -------------------------------------------------------------------------------- 1 |
2 | showOnlyCloseButton(); ?> 3 |
4 |
5 | 6 |
-------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Exclude all hidden files 2 | .* 3 | 4 | # Except those related to Git (and GitHub) 5 | !.git* 6 | 7 | # Exclude files from composer install 8 | vendor/ 9 | composer.lock 10 | -------------------------------------------------------------------------------- /module.info: -------------------------------------------------------------------------------- 1 | Name: AWS 2 | Version: 1.1.0 3 | Depends: monitoring 4 | Description: Amazon Web Services module for Icinga Web 2 5 | This module provides an AWS SDK import source for Icinga Director 6 | -------------------------------------------------------------------------------- /configuration.php: -------------------------------------------------------------------------------- 1 | provideConfigTab('keys', array( 4 | 'title' => $this->translate('Configure your AWS access keys'), 5 | 'label' => $this->translate('AWS Keys'), 6 | 'url' => 'config/keys' 7 | )); -------------------------------------------------------------------------------- /.github/workflows/L10n-update.yml: -------------------------------------------------------------------------------- 1 | name: L10n Update 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | update: 10 | uses: icinga/github-actions/.github/workflows/L10n-update.yml@main 11 | secrets: inherit 12 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "icinga/icingaweb2-module-aws", 3 | "config": { 4 | "vendor-dir": "library/vendor" 5 | }, 6 | "repositories": [ 7 | ], 8 | "require": { 9 | "aws/aws-sdk-php": "3.*" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /library/Aws/AssumeRole.php: -------------------------------------------------------------------------------- 1 | arn = $arn; 16 | $assumeRole->session = $session; 17 | 18 | return $assumeRole; 19 | } 20 | 21 | public function getParams() 22 | { 23 | return [ 24 | 'RoleArn' => $this->arn, 25 | 'RoleSessionName' => $this->session 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /application/forms/Config/KeysListForm.php: -------------------------------------------------------------------------------- 1 | setName('form_config_list_aws_keys'); 20 | $this->setViewScript('config/keys-list.phtml'); 21 | } 22 | 23 | /** 24 | * Get the keys config 25 | * 26 | * @return Config 27 | */ 28 | public function getConfig() 29 | { 30 | return Config::module('aws', 'keys'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /doc/01-About.md: -------------------------------------------------------------------------------- 1 | Icinga Module for AWS 2 | ========================================= 3 | 4 | This is a simple Amazon Web Services (AWS) module for Icinga Web 2. Currently 5 | it is nothing but an Import Source provider for [Icinga Director](https://github.com/Icinga/icingaweb2-module-director). 6 | 7 | It allows you to configure an Director automation that new Auto Scaling Groups would 8 | be deployed immediately as new (virtual) hosts to your [Icinga](https://www.icinga.org/) 9 | monitoring system. 10 | 11 | Please read the [Installation and Configuration](02-Installation-and-Configuration.md) 12 | and [Usage](03-Usage.md) sections to learn more about this module. 13 | 14 | ![Icinga Module fow AWS](img/00_overview.png) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Icinga Module for AWS 2 | ========================================= 3 | 4 | This is a simple Amazon Web Services (AWS) module for Icinga Web 2. Currently 5 | it is nothing but an Import Source provider for [Icinga Director](https://github.com/Icinga/icingaweb2-module-director). 6 | 7 | It allows you to configure an Director automation that new Auto Scaling Groups would 8 | be deployed immediately as new (virtual) hosts to your [Icinga](https://www.icinga.org/) 9 | monitoring system. 10 | 11 | Please read the [Installation and Configuration](doc/02-Installation-and-Configuration.md) 12 | and [Usage](doc/03-Usage.md) sections to learn more about this module. 13 | 14 | ![Icinga Module fow AWS](doc/img/00_overview.png) 15 | -------------------------------------------------------------------------------- /application/views/scripts/config/keys.phtml: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |
6 |
7 |

translate('AWS Access Keys') ?>

8 | qlink( 9 | $this->translate('Add a AWS Access Key') , 10 | 'aws/config/createkey', 11 | null, 12 | array( 13 | 'class' => 'button-link', 14 | 'icon' => 'plus', 15 | 'title' => $this->translate('Create a new AWS access key') 16 | ) 17 | ) ?> 18 | 22 |
23 |
-------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | ## Expected Behavior 16 | 17 | 18 | 19 | ## Current Behavior 20 | 21 | 22 | 23 | ## Possible Solution 24 | 25 | 26 | 27 | ## Steps to Reproduce (for bugs) 28 | 29 | 30 | 1. 31 | 2. 32 | 3. 33 | 4. 34 | 35 | ## Context 36 | 37 | 38 | 39 | ## Your Environment 40 | 41 | * Module version (System - About): 42 | * Icinga Web 2 version and modules (System - About): 43 | * Icinga 2 version (`icinga2 --version`): 44 | * Operating System and version: 45 | * Webserver, PHP versions: 46 | 47 | -------------------------------------------------------------------------------- /library/Aws/AwsKey.php: -------------------------------------------------------------------------------- 1 | id = $id; 19 | $this->key = $key; 20 | } 21 | 22 | public function getCredentials() 23 | { 24 | if ($this->credentials === null) { 25 | $this->credentials = new Credentials($this->id, $this->key); 26 | } 27 | 28 | return $this->credentials; 29 | } 30 | 31 | public static function load($name = null) 32 | { 33 | if ($name === null) { 34 | return self::loadDefault(); 35 | } else { 36 | return self::loadByName($name); 37 | } 38 | } 39 | 40 | public static function loadDefault() 41 | { 42 | return static::loadByName(current(self::listNames())); 43 | } 44 | 45 | public static function loadByName($name) 46 | { 47 | $config = static::config(); 48 | return new static( 49 | $config->get($name, 'access_key_id'), 50 | $config->get($name, 'secret_access_key') 51 | ); 52 | } 53 | 54 | public static function listNames() 55 | { 56 | return static::config()->keys(); 57 | } 58 | 59 | public static function enumKeyNames() 60 | { 61 | $names = static::listNames(); 62 | $labels = array_map(function ($name) { return $name . ' (Key)'; }, $names); 63 | return array_combine($names, $labels); 64 | } 65 | 66 | protected static function config() 67 | { 68 | return Config::module('aws', 'keys'); 69 | } 70 | 71 | public function getId() 72 | { 73 | return $this->id; 74 | } 75 | 76 | public function getKey() 77 | { 78 | return $this->key; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /application/views/scripts/config/keys-list.phtml: -------------------------------------------------------------------------------- 1 | 5 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | getConfig(); 27 | foreach ($keyConfig as $keyName => $config): 28 | ?> 29 | 30 | 41 | 53 | 54 | 55 | 56 |
translate('Keys') ?>
31 | qlink( 32 | $keyName, 33 | 'aws/config/editkey', 34 | array('key' => $keyName), 35 | array( 36 | 'icon' => 'edit', 37 | 'title' => sprintf($this->translate('Edit key %s'), $keyName) 38 | ) 39 | ); ?> 40 | 42 | qlink( 43 | '', 44 | 'aws/config/removekey', 45 | array('key' => $keyName), 46 | array( 47 | 'class' => 'action-link', 48 | 'icon' => 'cancel', 49 | 'title' => sprintf($this->translate('Remove key %s'), $keyName) 50 | ) 51 | ); ?> 52 |
57 | getElement($form->getTokenElementName()) ?> 58 | getElement($form->getUidElementName()) ?> 59 |
60 | -------------------------------------------------------------------------------- /doc/02-Installation-and-Configuration.md: -------------------------------------------------------------------------------- 1 | Installation 2 | ========================================================= 3 | 4 | Requirements 5 | ------------ 6 | 7 | This module needs the [AWS PHP SDK v3](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/welcome.html). 8 | 9 | Module installation 10 | ------------------- 11 | 12 | Please extract or clone this module to your Icinga Web 2 module path. The 13 | directory name must fit the module name, `aws`. This would usually lead to 14 | `/usr/share/icingaweb2/modules/aws`. 15 | 16 | Install AWS SDK 17 | ---------------- 18 | 19 | #### Via Composer 20 | 21 | For this you need [Composer](https://getcomposer.org/) on your machine. 22 | In `/icingaweb2/modules/aws`, run `composer install` and all modules dependencies will be installed. 23 | 24 | #### Manual Install 25 | 26 | Next please download and extract the latest v3 standalone ZIP archive from 27 | the AWS PHP SDK [releases](https://github.com/aws/aws-sdk-php/releases) page. 28 | You need to extract the AWS PHP SDK v3 to `library/vendor/aws`. 29 | 30 | AWS IAM role credentials 31 | ------------------------ 32 | 33 | If you run Icinga Web on AWS you can use IAM roles to allow access. This is the 34 | default and there is nothing to configure. Select IAM role and configure access 35 | in AWS itself. 36 | 37 | 38 | AWS key configuration 39 | --------------------- 40 | 41 | If you want to use access keys you need to have at least one key in `keys.ini`. 42 | The easiest way to do that, is by going to the key configuration tab in `Icinga Web 2` under 43 | `Configuration > Modules > aws > AWS Keys`: 44 | 45 | ![AWS key config](img/10_aws_key_config.png) 46 | 47 | After that just click `Add a AWS Access Key`, choose a name and add your key details: 48 | 49 | ![AWS add key](img/11_aws_add_key.png) 50 | 51 | That's it. Now you are ready to enable the AWS module and you'll find a new 52 | Import Source in your Icinga Director frontend. You are now ready to skip to 53 | the [Usage](03-Usage.md) section. 54 | 55 | Proxy usage 56 | ----------- 57 | 58 | In case your server needs to use a proxy when connection to the AWS web service 59 | please create `/etc/icingaweb2/modules/aws/config.ini` with a `network` section 60 | like shown in this example: 61 | 62 | ```ini 63 | [network] 64 | proxy = "192.0.2.192:3128" 65 | ``` 66 | 67 | You could also pass proxy credentials in the form `user:pass@host:port`. 68 | 69 | SSL issues 70 | ---------- 71 | 72 | In case you need to provide a specific SSL CA bundle, once again please create 73 | a `[network]` section in your `config.ini`: 74 | 75 | ```ini 76 | [network] 77 | ssl_ca = "/etc/ssl/certs/ca.pem" 78 | ``` 79 | -------------------------------------------------------------------------------- /doc/03-Usage.md: -------------------------------------------------------------------------------- 1 | Usage 2 | ======================= 3 | 4 | Dynamically create hosts for AWS AutoScaling Groups 5 | --------------------------------------------------- 6 | 7 | Our first use case are virtual Icinga host objects, one for each of your AWS 8 | AutoScaling Group. Single instances come and go, it's tricky to monitor them 9 | in a meaningful way. Your AutoScaling Groups are here to stay, it is vital for 10 | your service that they are alive. 11 | 12 | This example wants to teach you how to configure Director to automagically do 13 | this for you. 14 | 15 | ### Create IAM User 16 | 17 | We suggest creating a new user for Icinga2. In order to use all features of this 18 | module, assign the following policy to the user: 19 | 20 | arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess 21 | 22 | ### Create a new host template 23 | 24 | I'd strongly suggest to create a dedicated template that should be inherited 25 | by all your virtual AWS ASG hosts. This allows you to add service checks to 26 | the template, with the Director automagically deploying them as apply rules 27 | affecting all your ASG hosts. 28 | 29 | ![AWS host template](img/01_aws_template.png) 30 | 31 | Whether you use a dummy host check or a plugin running against the AWS API is 32 | up to your personal preference. 33 | 34 | ### Define a dedicated Import Source 35 | 36 | As soon as you installed and enabled this module, a new Import Source will be 37 | available in your Icinga Director web frontend: 38 | 39 | ![AWS import source basics](img/02_aws_import_source_basics.png) 40 | 41 | You can choose your AWS region from a dropdown: 42 | 43 | ![AWS import source region](img/03_aws_import_region.png) 44 | 45 | It is also necessary to choose your preferred access method: 46 | 47 | ![AWS import source key](img/04_aws_import_source_key.png) 48 | 49 | In case you need a key and this list is empty, please check back to the 50 | [Installation and Configuration](02-Installation-and-Configuration.md) 51 | section. Now you are ready to preview and/or run your first import. Don't 52 | worry, nothing bad will happen. An Import run just imports plain data from 53 | your import source, it won't touch any of your hosts or services in your 54 | Icinga Director. 55 | 56 | ### Create a Sync Rule 57 | 58 | Our Sync Rules are responsible for creating real Icinga objects based on 59 | data imported through one or more Import Sources. So let's create a new 60 | rule: 61 | 62 | ![AWS sync rule](img/05_aws_sync_rule.png) 63 | 64 | Sync Properties allow you to specify how to treat the various properties 65 | in a granular way: 66 | 67 | ![AWS sync properties](img/06_aws_sync_properties.png) 68 | 69 | Now you are ready to trigger your first Sync Run. Activity Log and Sync History 70 | will show you what related actions took place 71 | 72 | ### Have a look at your new hosts 73 | 74 | Let's have a look at our newly created host: 75 | 76 | ![AWS host config](img/07_aws_host_config.png) 77 | 78 | In case you want to achieve visibilty for your imported Custom Vars please 79 | define related Fields directly on your AWS ASG Template. Your hosts could 80 | then look as follows: 81 | 82 | ![AWS host vars](img/08_aws_host_config_with_vars.png) 83 | 84 | The preview tab shows our rendered host, this is how it will get deployed 85 | to Icinga: 86 | 87 | ![AWS host preview](img/09_aws_host_preview.png) 88 | 89 | That's all for now, have fun! 90 | -------------------------------------------------------------------------------- /application/controllers/ConfigController.php: -------------------------------------------------------------------------------- 1 | assertPermission('config/modules'); 16 | parent::init(); 17 | } 18 | 19 | public function keysAction() 20 | { 21 | $this->view->form = $form = new KeysListForm(); 22 | $form->handleRequest(); 23 | 24 | $this->view->config = $this->Config('keys'); 25 | $this->view->tabs = $this->Module()->getConfigTabs()->activate('keys'); 26 | } 27 | 28 | public function removekeyAction() 29 | { 30 | $keyName = $this->params->getRequired('key'); 31 | 32 | $keysForm = new KeysForm(); 33 | $keysForm->setIniConfig($this->Config('keys')); 34 | $form = new ConfirmRemovalForm(); 35 | $form->setRedirectUrl('aws/config/keys'); 36 | $form->setTitle(sprintf($this->translate('Remove Key %s'), $keyName)); 37 | $form->info( 38 | $this->translate( 39 | 'If you still have any import sources referring to this key, ' 40 | . 'you won\'t be able to use them without changing the key.' 41 | ), 42 | false 43 | ); 44 | $form->setOnSuccess(function (ConfirmRemovalForm $form) use ($keysForm, $keyName) { 45 | try { 46 | $keysForm->delete($keyName); 47 | } catch (Exception $e) { 48 | $form->error($e->getMessage()); 49 | return false; 50 | } 51 | 52 | if ($keysForm->save()) { 53 | Notification::success(sprintf(t('Key "%s" successfully removed'), $keyName)); 54 | return true; 55 | } 56 | 57 | return false; 58 | }); 59 | $form->handleRequest(); 60 | 61 | $this->view->form = $form; 62 | $this->render('form'); 63 | } 64 | 65 | public function editkeyAction() 66 | { 67 | $keyName = $this->params->getRequired('key'); 68 | 69 | $form = new KeysForm(); 70 | $form->setRedirectUrl('aws/config/keys'); 71 | $form->setTitle(sprintf($this->translate('Edit Key %s'), $keyName)); 72 | $form->setIniConfig($this->Config('keys')); 73 | $form->setOnSuccess(function (KeysForm $form) use ($keyName) { 74 | try { 75 | $form->edit($keyName, array_map( 76 | function ($v) { 77 | return $v !== '' ? $v : null; 78 | }, 79 | $form->getValues() 80 | )); 81 | } catch (Exception $e) { 82 | $form->error($e->getMessage()); 83 | return false; 84 | } 85 | 86 | if ($form->save()) { 87 | Notification::success(sprintf(t('Key "%s" successfully updated'), $keyName)); 88 | return true; 89 | } 90 | 91 | return false; 92 | }); 93 | 94 | try { 95 | $form->load($keyName); 96 | $form->handleRequest(); 97 | } catch (NotFoundError $_) { 98 | $this->httpNotFound(sprintf($this->translate('Key "%s" not found'), $keyName)); 99 | } 100 | 101 | $this->view->form = $form; 102 | $this->render('form'); 103 | } 104 | 105 | public function createkeyAction() 106 | { 107 | $form = new KeysForm(); 108 | $form->setRedirectUrl('aws/config/keys'); 109 | $form->setTitle($this->translate('Create New Key')); 110 | $form->setIniConfig($this->Config('keys')); 111 | $form->setOnSuccess(function (KeysForm $form) { 112 | try { 113 | $form->add($form::transformEmptyValuesToNull($form->getValues())); 114 | } catch (Exception $e) { 115 | $form->error($e->getMessage()); 116 | return false; 117 | } 118 | 119 | if ($form->save()) { 120 | Notification::success(t('Key successfully created')); 121 | return true; 122 | } 123 | 124 | return false; 125 | }); 126 | $form->handleRequest(); 127 | 128 | $this->view->form = $form; 129 | $this->render('form'); 130 | } 131 | } -------------------------------------------------------------------------------- /application/forms/Config/KeysForm.php: -------------------------------------------------------------------------------- 1 | setName('form_config_aws_keys'); 33 | $this->setSubmitLabel($this->translate('Save Changes')); 34 | } 35 | 36 | /** 37 | * Populate the form with the given keys's config 38 | * 39 | * @param string $name 40 | * 41 | * @return $this 42 | * 43 | * @throws NotFoundError In case no key with the given name is found 44 | */ 45 | public function load($name) 46 | { 47 | if (! $this->config->hasSection($name)) { 48 | throw new NotFoundError('No key called "%s" found', $name); 49 | } 50 | 51 | $this->keyToLoad = $name; 52 | return $this; 53 | } 54 | 55 | /** 56 | * Add a new key 57 | * 58 | * The key to add is identified by the array-key `name'. 59 | * 60 | * @param array $data 61 | * 62 | * @return $this 63 | * 64 | * @throws InvalidArgumentException In case $data does not contain a key name 65 | * @throws IcingaException In case a key with the same name already exists 66 | */ 67 | public function add(array $data) 68 | { 69 | if (! isset($data['name'])) { 70 | throw new InvalidArgumentException('Key \'name\' missing'); 71 | } 72 | 73 | $keyName = $data['name']; 74 | if ($this->config->hasSection($keyName)) { 75 | throw new IcingaException( 76 | $this->translate('A key with the name "%s" does already exist'), 77 | $keyName 78 | ); 79 | } 80 | 81 | unset($data['name']); 82 | $this->config->setSection($keyName, $data); 83 | return $this; 84 | } 85 | 86 | /** 87 | * Edit an existing key 88 | * 89 | * @param string $name 90 | * @param array $data 91 | * 92 | * @return $this 93 | * 94 | * @throws NotFoundError In case no key with the given name is found 95 | */ 96 | public function edit($name, array $data) 97 | { 98 | if (! $this->config->hasSection($name)) { 99 | throw new NotFoundError('No key called "%s" found', $name); 100 | } 101 | 102 | $keyConfig = $this->config->getSection($name); 103 | if (isset($data['name'])) { 104 | if ($data['name'] !== $name) { 105 | $this->config->removeSection($name); 106 | $name = $data['name']; 107 | } 108 | 109 | unset($data['name']); 110 | } 111 | 112 | $keyConfig->merge($data); 113 | $this->config->setSection($name, $keyConfig); 114 | return $this; 115 | } 116 | 117 | /** 118 | * Remove a key 119 | * 120 | * @param string $name 121 | * 122 | * @return $this 123 | */ 124 | public function delete($name) 125 | { 126 | $this->config->removeSection($name); 127 | return $this; 128 | } 129 | 130 | /** 131 | * Create and add elements to this form 132 | * 133 | * @param array $formData 134 | */ 135 | public function createElements(array $formData) 136 | { 137 | $this->addElements([ 138 | [ 139 | 'text', 140 | 'name', 141 | [ 142 | 'required' => true, 143 | 'label' => $this->translate('Key Name'), 144 | 'description' => $this->translate( 145 | 'The name of this key that is used to differentiate it from others' 146 | ) 147 | ], 148 | ], 149 | [ 150 | 'text', 151 | 'access_key_id', 152 | [ 153 | 'required' => true, 154 | 'label' => $this->translate('Access Key ID'), 155 | 'description' => $this->translate('Your AWS access key') 156 | ] 157 | ], 158 | [ 159 | 'password', 160 | 'secret_access_key', 161 | [ 162 | 'required' => true, 163 | 'renderPassword' => true, 164 | 'label' => $this->translate('Access Key Secret'), 165 | 'description' => $this->translate('The access key\'s secret') 166 | ] 167 | ] 168 | ]); 169 | } 170 | 171 | /** 172 | * Populate the configuration of the key to load 173 | */ 174 | public function onRequest() 175 | { 176 | if ($this->keyToLoad) { 177 | $data = $this->config->getSection($this->keyToLoad)->toArray(); 178 | $data['name'] = $this->keyToLoad; 179 | $this->populate($data); 180 | } 181 | } 182 | 183 | /** 184 | * {@inheritdoc} 185 | */ 186 | public function isValidPartial(array $formData) 187 | { 188 | $isValidPartial = parent::isValidPartial($formData); 189 | 190 | $keyValidation = $this->getElement('key_validation'); 191 | if ($keyValidation !== null && $this->isValid($formData)) { 192 | $this->info($this->translate('The configuration has been successfully validated.')); 193 | } 194 | 195 | return $isValidPartial; 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /library/Aws/ProvidedHook/Director/ImportSource.php: -------------------------------------------------------------------------------- 1 | 'Auto Scaling Groups', 16 | 'lb' => 'Elastic Load Balancers', 17 | 'lbv2' => 'Elastic Load Balancers V2', 18 | 'ec2instance' => 'EC2 Instances', 19 | 'rdsinstance' => 'RDS Instances', 20 | 'route53records' => 'Route53 Records' 21 | ); 22 | 23 | protected $db; 24 | 25 | public function fetchData() 26 | { 27 | $keyName = $this->getSetting('aws_access_key'); 28 | $key = null; 29 | 30 | if ($keyName) { 31 | if ($keyName === 'IAM assume role') { 32 | $key = AssumeRole::create($this->getSetting('iam_assume_role'), 'director'); 33 | } else { 34 | $key = AwsKey::loadByName($keyName); 35 | } 36 | } 37 | 38 | $client = new AwsClient($key, $this->getSetting('aws_region')); 39 | 40 | switch ($this->getObjectType()) { 41 | case 'asg': 42 | return $client->getAutoscalingConfig(); 43 | case 'lb': 44 | return $client->getLoadBalancers(); 45 | case 'lbv2': 46 | return $client->getLoadBalancersV2(); 47 | case 'ec2instance': 48 | return $client->getEc2Instances(); 49 | case 'rdsinstance': 50 | return $client->getRdsInstances(); 51 | case 'route53records': 52 | return $client->getRoute53Records(); 53 | } 54 | } 55 | 56 | protected function getObjectType() 57 | { 58 | // Compat for old configs, asg used to be the only available type: 59 | $type = $this->getSetting('object_type', 'asg'); 60 | 61 | $validTypes = array_keys(static::$awsObjectTypes); 62 | 63 | if (! in_array($type, $validTypes)) { 64 | throw new ConfigurationError( 65 | 'Got no invalid AWS object type: "%s"', 66 | $type 67 | ); 68 | } 69 | 70 | return $type; 71 | } 72 | 73 | public function listColumns() 74 | { 75 | switch ($this->getObjectType()) { 76 | case 'asg': 77 | return array( 78 | 'name', 79 | 'launch_config', 80 | 'ctime', 81 | 'zones', 82 | 'desired_size', 83 | 'min_size', 84 | 'max_size', 85 | 'lb_names', 86 | 'health_check_type', 87 | 'tags', 88 | 'tags.Name', 89 | 'tags.aws:cloudformation:logical-id', 90 | 'tags.aws:cloudformation:stack-id', 91 | 'tags.aws:cloudformation:stack-name', 92 | ); 93 | case 'lb': 94 | return array( 95 | 'name', 96 | 'dnsname', 97 | 'scheme', 98 | 'zones', 99 | 'listeners', 100 | 'health_check', 101 | ); 102 | case 'lbv2': 103 | return array( 104 | 'name', 105 | 'dnsname', 106 | 'scheme', 107 | 'zones', 108 | 'type', 109 | 'scheme', 110 | 'state', 111 | 'security_groups' 112 | ); 113 | case 'rdsinstance': 114 | return array( 115 | 'name', 116 | 'port', 117 | 'fqdn', 118 | 'engine', 119 | 'version', 120 | 'security_groups', 121 | ); 122 | case 'ec2instance': 123 | return array( 124 | 'name', 125 | 'image', 126 | 'architecture', 127 | 'root_device_type', 128 | 'root_device_name', 129 | 'hypervisor', 130 | 'instance_type', 131 | 'virt_type', 132 | 'vpc_id', 133 | 'public_ip', 134 | 'public_dns', 135 | 'private_ip', 136 | 'private_dns', 137 | 'disabled', 138 | 'monitoring_state', 139 | 'security_groups', 140 | 'status', 141 | 'subnet_id', 142 | 'launch_time', 143 | 'tags', 144 | 'tags.Name', 145 | 'tags.aws:autoscaling:groupName', 146 | 'tags.aws:cloudformation:logical-id', 147 | 'tags.aws:cloudformation:stack-id', 148 | 'tags.aws:cloudformation:stack-name', 149 | ); 150 | case 'route53records': 151 | return [ 152 | 'name', 153 | 'recordname', 154 | 'type', 155 | 'records', 156 | 'ttl', 157 | 'private_zone', 158 | 'zone_name', 159 | 'zone_id', 160 | ]; 161 | } 162 | } 163 | 164 | public static function getDefaultKeyColumnName() 165 | { 166 | return 'name'; 167 | } 168 | 169 | public static function addSettingsFormFields(QuickForm $form) 170 | { 171 | $form->addElement('select', 'aws_region', array( 172 | 'label' => 'AWS region', 173 | 'required' => true, 174 | 'multiOptions' => $form->optionalEnum(AwsClient::enumRegions()), 175 | )); 176 | 177 | $form->addElement('select', 'aws_access_key', array( 178 | 'label' => 'AWS access method', 179 | 'required' => false, 180 | 'description' => $form->translate( 181 | 'Use IAM role credential, assume role or select your AWS key.' 182 | . ' This shows all keys from your keys.ini.' 183 | . ' Please check the documentation if you miss the keys in the list.' 184 | ), 185 | 'multiOptions' => $form->optionalEnum( 186 | AwsKey::enumKeyNames() 187 | + ['IAM assume role' => $form->translate('IAM assume role')], 188 | $form->translate( 189 | 'IAM role credentials' 190 | )), 191 | 'class' => 'autosubmit', 192 | )); 193 | 194 | /** @var ImportSourceForm $form */ 195 | if ($form->getSentOrObjectSetting('aws_access_key') === 'IAM assume role') { 196 | $form->addElement('text', 'iam_assume_role', [ 197 | 'label' => 'Assume role', 198 | 'required' => true 199 | ]); 200 | } 201 | 202 | $form->addElement('select', 'object_type', array( 203 | 'label' => 'Object type', 204 | 'required' => true, 205 | 'description' => $form->translate( 206 | 'AWS object type' 207 | ), 208 | 'multiOptions' => $form->optionalEnum( 209 | static::enumObjectTypes($form) 210 | ), 211 | 'class' => 'autosubmit', 212 | )); 213 | } 214 | 215 | protected static function enumObjectTypes(QuickForm $form) 216 | { 217 | static $enumerationTypes = null; 218 | 219 | if ($enumerationTypes === null) { 220 | $enumerationTypes = array(); 221 | foreach (static::$awsObjectTypes as $key => $label) { 222 | $enumerationTypes[$key] = $form->translate($label); 223 | } 224 | } 225 | 226 | return $enumerationTypes; 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /library/Aws/AwsClient.php: -------------------------------------------------------------------------------- 1 | region = $region; 27 | $this->key = $key; 28 | $this->prepareAwsLibs(); 29 | } 30 | 31 | public function getAutoscalingConfig() 32 | { 33 | $objects = array(); 34 | $client = $this->sdk()->createAutoScaling(); 35 | $res = $client->describeAutoScalingGroups([ 36 | 'MaxRecords' => 100 37 | ]); 38 | 39 | foreach ($res->get('AutoScalingGroups') as $entry) { 40 | 41 | $objects[] = $object = $this->extractAttributes( 42 | $entry, 43 | [ 44 | 'name' => 'AutoScalingGroupName', 45 | 'zones' => 'AvailabilityZones', 46 | 'lb_names' => 'LoadBalancerNames', 47 | 'health_check_type' => 'HealthCheckType', 48 | ], 49 | [ 50 | 'launch_config' => 'LaunchConfigurationName' 51 | ] 52 | ); 53 | 54 | $object->ctime = strtotime($entry['CreatedTime']); 55 | $object->desired_size = (int) $entry['DesiredCapacity']; 56 | $object->min_size = (int) $entry['MinSize']; 57 | $object->max_size = (int) $entry['MaxSize']; 58 | $this->extractTags($entry, $object); 59 | } 60 | 61 | return $this->sortByName($objects); 62 | } 63 | 64 | public function getLoadBalancers() 65 | { 66 | $client = $this->sdk()->createElasticLoadBalancing(); 67 | $res = $client->describeLoadBalancers(); 68 | $objects = array(); 69 | foreach ($res->get('LoadBalancerDescriptions') as $entry) { 70 | $objects[] = $object = $this->extractAttributes($entry, array( 71 | 'name' => 'LoadBalancerName', 72 | 'dnsname' => 'DNSName', 73 | 'scheme' => 'Scheme', 74 | 'zones' => 'AvailabilityZones', 75 | )); 76 | 77 | $object->health_check = $entry['HealthCheck']['Target']; 78 | 79 | $object->listeners = (object) array(); 80 | foreach ($entry['ListenerDescriptions'] as $l) { 81 | $listener = $l['Listener']; 82 | $object->listeners->{$listener['LoadBalancerPort']} = $this->extractAttributes( 83 | $listener, 84 | array( 85 | 'port' => 'LoadBalancerPort', 86 | 'protocol' => 'Protocol', 87 | 'instance_port' => 'InstancePort', 88 | 'instance_protocol' => 'InstanceProtocol', 89 | ) 90 | ); 91 | } 92 | } 93 | 94 | return $this->sortByName($objects); 95 | } 96 | 97 | public function getLoadBalancersV2() 98 | { 99 | $client = $this->sdk()->createElasticLoadBalancingV2(); 100 | $res = $client->describeLoadBalancers(); 101 | $objects = array(); 102 | 103 | foreach ($res['LoadBalancers'] as $entry) { 104 | $objects[] = $object = $this->extractAttributes($entry, array( 105 | 'name' => 'LoadBalancerName', 106 | 'dnsname' => 'DNSName', 107 | 'scheme' => 'Scheme', 108 | 'zones' => 'AvailabilityZones', 109 | 'type' => 'Type', 110 | 'scheme' => 'Scheme' 111 | ), array( 112 | 'security_groups' => 'SecurityGroups', 113 | 'arn' => 'LoadBalancerArn' 114 | )); 115 | 116 | $object->state = $entry['State']['Code']; 117 | } 118 | 119 | return $this->sortByName($objects); 120 | } 121 | 122 | public function getEc2Instances() 123 | { 124 | $client = $this->sdk()->createEc2(); 125 | $res = $client->describeInstances(); 126 | $objects = array(); 127 | foreach ($res->get('Reservations') as $reservation) { 128 | 129 | foreach ($reservation['Instances'] as $entry) { 130 | $objects[] = $object = $this->extractAttributes($entry, array( 131 | 'name' => 'InstanceId', 132 | 'image' => 'ImageId', 133 | 'architecture' => 'Architecture', 134 | 'hypervisor' => 'Hypervisor', 135 | 'virt_type' => 'VirtualizationType', 136 | ), array( 137 | 'vpc_id' => 'VpcId', 138 | 'root_device_type' => 'RootDeviceType', 139 | 'root_device_name' => 'RootDeviceName', 140 | 'public_ip' => 'PublicIpAddress', 141 | 'public_dns' => 'PublicDnsName', 142 | 'private_ip' => 'PrivateIpAddress', 143 | 'private_dns' => 'PrivateDnsName', 144 | 'instance_type' => 'InstanceType', 145 | 'subnet_id' => 'SubnetId' 146 | )); 147 | 148 | $object->disabled = $entry['State']['Name'] != 'running'; 149 | $object->monitoring_state = $entry['Monitoring']['State']; 150 | $object->status = $entry['State']['Name']; 151 | $object->launch_time = (string)$entry['LaunchTime']; 152 | $object->security_groups = []; 153 | 154 | foreach ($entry['SecurityGroups'] as $group) 155 | { 156 | $object->security_groups[] = $group['GroupName']; 157 | } 158 | 159 | $this->extractTags($entry, $object); 160 | } 161 | } 162 | 163 | return $this->sortByName($objects); 164 | } 165 | 166 | public function getRdsInstances() 167 | { 168 | $client = $this->sdk()->createRds(); 169 | $res = $client->describeDBInstances(); 170 | $objects = array(); 171 | foreach ($res['DBInstances'] as $entry) { 172 | $objects[] = $object = $this->extractAttributes($entry, array( 173 | 'name' => 'DBInstanceIdentifier', 174 | 'engine' => 'Engine', 175 | 'version' => 'EngineVersion', 176 | )); 177 | 178 | $object->port = $entry['Endpoint']['Port']; 179 | $object->fqdn = $entry['Endpoint']['Address']; 180 | $object->security_groups = []; 181 | 182 | foreach ($entry['VpcSecurityGroups'] as $group) 183 | { 184 | $object->security_groups[] = $group['VpcSecurityGroupId']; 185 | } 186 | 187 | $this->extractTags($entry, $object); 188 | } 189 | 190 | return $this->sortByName($objects); 191 | } 192 | 193 | public function getRoute53Records() 194 | { 195 | $client = $this->sdk()->createRoute53(); 196 | $zonesPaginator = $client->getPaginator('ListHostedZones', [ 197 | 'MaxItems' => '100' 198 | ]); 199 | $objects = []; 200 | foreach ($zonesPaginator as $zonesRs) { 201 | foreach ($zonesRs['HostedZones'] as $zone) { 202 | $resourcesPaginator = $client->getPaginator('ListResourceRecordSets', [ 203 | 'MaxItems' => '100', 204 | 'HostedZoneId' => $zone['Id'] 205 | ]); 206 | foreach ($resourcesPaginator as $resourceRs) { 207 | foreach ($resourceRs['ResourceRecordSets'] as $recordset) { 208 | $objects[] = $object = $this->extractAttributes($recordset, array( 209 | 'recordname' => 'Name', 210 | 'type' => 'Type' 211 | )); 212 | // 'Name' is not necessarily unique so we have to create a unique one 213 | if (array_key_exists('Weight', $recordset)) { 214 | $object->name = "{$recordset["Type"]}_{$recordset["Weight"]}_{$recordset["Name"]}"; 215 | } 216 | else { 217 | $object->name = "{$recordset["Type"]}_{$recordset["Name"]}"; 218 | } 219 | 220 | $object->private_zone = $zone['Config']['PrivateZone']; 221 | $object->zone_name = $zone['Name']; 222 | $object->zone_id = $zone['Id']; 223 | if (array_key_exists('ResourceRecords', $recordset)) { 224 | $object->records = $recordset['ResourceRecords']; 225 | } 226 | if (array_key_exists('TTL', $recordset)) { 227 | $object->ttl = $recordset['TTL']; 228 | } 229 | } 230 | // One would assume that the AWS paginators handle throttling, but they don't. Throttle to 4 req/s 231 | usleep(250000); 232 | } 233 | } 234 | } 235 | 236 | return $this->sortByName($objects); 237 | } 238 | 239 | public static function enumRegions() 240 | { 241 | return array( 242 | 'us-east-1' => 'US East (N. Virginia)', 243 | 'us-east-2' => 'US East (Ohio)', 244 | 'us-west-1' => 'US West (N. California)', 245 | 'us-west-2' => 'US West (Oregon)', 246 | 'af-south-1' => 'Africa (Cape Town)', 247 | 'ap-east-1' => 'Asia Pacific (Hong Kong)', 248 | 'ap-south-1' => 'Asia Pacific (Mumbai)', 249 | 'ap-northeast-3' => 'Asia Pacific (Osaka-Local)', 250 | 'ap-northeast-2' => 'Asia Pacific (Seoul)', 251 | 'ap-southeast-1' => 'Asia Pacific (Singapore)', 252 | 'ap-southeast-2' => 'Asia Pacific (Sydney)', 253 | 'ap-northeast-1' => 'Asia Pacific (Tokyo)', 254 | 'ca-central-1' => 'Canada (Central)', 255 | 'cn-north-1' => 'China (Beijing)', 256 | 'cn-northwest-1' => 'China (Ningxia)', 257 | 'eu-central-1' => 'EU (Frankfurt)', 258 | 'eu-west-1' => 'EU (Ireland)', 259 | 'eu-west-2' => 'EU (London)', 260 | 'eu-south-1' => 'EU (Milan)', 261 | 'eu-west-3' => 'EU (Paris)', 262 | 'eu-north-1' => 'EU (Stockholm)', 263 | 'me-south-1' => 'Middle East (Bahrain)', 264 | 'sa-east-1' => 'South America (São Paulo)', 265 | 'us-gov-east-1' => 'AWS GovCloud (US-East)', 266 | 'us-gov-west-1' => 'AWS GovCloud (US-West)', 267 | ); 268 | } 269 | 270 | protected function sortByName($objects) 271 | { 272 | usort($objects, array($this, 'compareName')); 273 | return $objects; 274 | } 275 | 276 | protected function extractAttributes($entry, $required, $optional = array(), $subkey = null) 277 | { 278 | $result = (object) array(); 279 | if ($subkey !== null) { 280 | $entry = $entry[$subkey]; 281 | } 282 | 283 | foreach ($required as $alias => $key) { 284 | $result->$alias = $entry[$key]; 285 | } 286 | 287 | foreach ($optional as $alias => $key) { 288 | if (array_key_exists($key, $entry)) { 289 | $result->$alias = $entry[$key]; 290 | } else { 291 | $result->$alias = null; 292 | } 293 | } 294 | 295 | return $result; 296 | } 297 | 298 | protected function extractTags($entry, $result) 299 | { 300 | $result->tags = (object) array(); 301 | if (! array_key_exists('Tags', $entry)) { 302 | return; 303 | } 304 | 305 | foreach ($entry['Tags'] as $t) { 306 | $result->tags->{$t['Key']} = $t['Value']; 307 | } 308 | } 309 | 310 | protected function compareName($a, $b) 311 | { 312 | return strcmp($a->name, $b->name); 313 | } 314 | 315 | /** 316 | * @return Sdk 317 | */ 318 | protected function sdk() 319 | { 320 | if ($this->sdk === null) { 321 | $this->initializeSdk(); 322 | } 323 | 324 | return $this->sdk; 325 | } 326 | 327 | protected function initializeSdk() 328 | { 329 | $params = array( 330 | 'version' => 'latest', 331 | 'region' => $this->region, 332 | ); 333 | 334 | if ($this->key instanceof AwsKey) { 335 | $params['credentials'] = $this->key->getCredentials(); 336 | } else if ($this->key instanceof AssumeRole) { 337 | $assumeRoleCredentials = new AssumeRoleCredentialProvider([ 338 | 'client' => new StsClient($params + [ 339 | 'credentials' => new InstanceProfileProvider() 340 | ]), 341 | 'assume_role_params' => $this->key->getParams() 342 | ]); 343 | $params['credentials'] = CredentialProvider::memoize($assumeRoleCredentials); 344 | } 345 | 346 | $config = Config::module('aws'); 347 | if ($proxy = $config->get('network', 'proxy')) { 348 | $params['request.options'] = array( 349 | 'proxy' => $proxy 350 | ); 351 | } 352 | 353 | if ($ca = $config->get('network', 'ssl_ca')) { 354 | $params['ssl.certificate_authority'] = $ca; 355 | } 356 | 357 | $this->sdk = new Sdk($params); 358 | } 359 | 360 | protected function prepareAwsLibs() 361 | { 362 | if (class_exists('\Aws\Sdk')) { 363 | return; 364 | } 365 | 366 | $autoloaderFiles = array( 367 | dirname(__DIR__) . '/vendor/aws/aws-autoloader.php', // manual sdk installation 368 | dirname(__DIR__) . '/vendor/autoload.php', // composer installation 369 | ); 370 | 371 | foreach ($autoloaderFiles as $file) { 372 | if (file_exists($file)) { 373 | require_once $file; 374 | } 375 | } 376 | 377 | if (! class_exists('\Aws\Sdk')) { 378 | throw new \RuntimeException('AWS SDK not found (Class \Aws\Sdk not found)'); 379 | } 380 | } 381 | } 382 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------