Beispiel #1
0
        /**
         * Setup everything before we begin the execute
         */
        public function __construct($config,$enable_output=true,$debug=false) {

                // DEFAULT_AWS_CACHE_SECONDS
                if(!isset($config['aws']['cache_seconds']) || empty($config['aws']['cache_seconds'])) {
                        $config['aws']['cache_seconds'] = NdJCloud::DEFAULT_AWS_CACHE_SECONDS;
                }

                // DEFAULT_MCRYPT_ALGORITHM
                if(!isset($config['mcrypt']['algorithm']) || empty($config['mcrypt']['algorithm'])) {
                        $config['mcrypt']['algorithm'] = NdJCloud::DEFAULT_MCRYPT_ALGORITHM;
                }

                // DEFAULT_MCRYPT_MODE
                if(!isset($config['mcrypt']['mode']) || empty($config['mcrypt']['mode'])) {
                        $config['mcrypt']['mode'] = NdJCloud::DEFAULT_MCRYPT_MODE;
                }

                // Set the config
                $this->config = $config;

                // NdJOut
                $this->Out = new NdJOut();

                // Set the output level
                if(!$enable_output) {
                        $this->Out->enabled_out_types = array('error');
                }

                // Check for dependancies and include AWSSDKforPHP
                if (! @include_once('AWSSDKforPHP/sdk.class.php') ) {
                        $this->Out->error('Missing AWS SDK for PHP - install via PEAR channel here http://pear.amazonwebservices.com/');
                        exit(1);
                }
                elseif(!function_exists('curl_init')) {
                        $this->Out->error('Missing PHP curl libaries, please install before using '.__CLASS__);
                        exit(1);
                } else {
					
                        // Create an EC2 class
                        $this->EC2 = new AmazonEC2(array('key'=>$this->config['aws']['access_key'],'secret'=>$this->config['aws']['secret_key']));
                        $this->EC2->set_cache_config(sys_get_temp_dir());
                        if(isset($this->config['ec2']['hostname'])) {
                                $this->EC2->allow_hostname_override(true);
                                $this->EC2->set_hostname($this->config['ec2']['hostname']);
                                $this->EC2->allow_hostname_override(false);
                        } else {
                                $this->EC2->set_region($this->__mapAwsRegion($this->config['ec2']['region']));
                        }

                        // Create an S3 class
                        $this->S3 = new AmazonS3(array('key'=>$this->config['aws']['access_key'],'secret'=>$this->config['aws']['secret_key']));
                        $this->S3->allow_hostname_override(false);
                        if(isset($this->config['s3']['hostname'])) {
                                $this->S3->allow_hostname_override(true);
                                $this->S3->set_hostname($this->config['s3']['hostname']);
                                $this->S3->allow_hostname_override(false);
                        } else {
                                $this->S3->set_region($this->__mapAwsRegion($this->config['s3']['region']));
                        }
                }

                // SystemCommand
                $this->SystemCommand = new NdJSystemCommand(&$this->debug);

                // Load each NdJCloud class
                foreach(get_declared_classes() as $class) {
                        if(preg_match("/^NdJCloud./",$class)) {
                                $name = str_replace('NdJCloud','',$class);
                                $this->$name = new $class(&$this);
                        }
                }
        }