Customising snapshot to remove options

Hi,

I'm trying to see if there's a simple way to customise Snapshot so that it has hardcoded AWS details (bucket name, folder). We want to use this on customer sites and don't want the plugin to list other buckets or contents of other folders. This works with the AWS policy applied but it means the plugin cannot be setup (no where to manually enter the bucket name).

We'd also like to remove the other, unsupported, options (Dropbox etc).

Any help appreciated.

  • PC

    Hey there,

    Greetings and thanks for posting on the forums.

    It will need some custom modification to do all of that. The destination files are located here : snapshot\lib\destinations

    snapshot\lib\snapshot_admin_destinations_lib.php

    However, just to make sure they are the right files and folders, I have asked our lead developer @Paul to chime in and advise :slight_smile:

    Cheers
    PC
    Sales &Support

  • andrew_mayberry

    Actually I found that simply removing the destination folders for dropbox etc, work and the enumeration simply listed the remaining (supported) options. Awesome.

    Now I'd like to change this:

    function get_buckets() {
    
    				try {
    					$buckets = $this->aws_connection->list_buckets();
    				} catch (Exception $e) {
    					$this->error_array['errorStatus'] 		= true;
    					$this->error_array['errorArray'][] 		= "Error: Could not list buckets :". $e->getMessage();
    					return false;
    				}
    
    				if (($buckets->status < 200) || ($buckets->status >= 300)) {
    					$this->error_array['errorStatus'] 		= true;
    					$this->error_array['errorArray'][] 		= "Error: Could not list buckets :". $buckets->body->Message;
    					return false;
    				}
    
    				if ((!isset($buckets->body->Buckets->Bucket)) || ( count($buckets->body->Buckets->Bucket) < 1)) {
    					$this->error_array['errorStatus'] 		= true;
    					$this->error_array['errorArray'][] 		= "Error: No Buckets found";
    					return false;
    			  	}
    
    				$this->error_array['responseArray'][0] = '';
    				foreach ($buckets->body->Buckets->Bucket as $bucket) {
    					$this->error_array['responseArray'][0] .= '<option value="'. $bucket->Name .'" ';
    
    					if ($this->destination_info['bucket'] == $bucket->Name) {
    						$this->error_array['responseArray'][0] .= ' selected="selected" ';
    					}
    					$this->error_array['responseArray'][0] .= '>'. $bucket->Name .'</option>';
    				}
    				return true;
    			}

    to simply return our predefined bucket (skipping the enumeration as it will fail). Likewise, we want to hardcode the s3 object prefix to the site base url. e.g. the module will be forced to use <predefined s3 bucket-name>/mysite.com/*.

    We create a S3 policy which restricts CRUD operations to the same path and define that within the plugin. This way no access to other website data backups is permitted, and if the customer leaves us, we can simply change the policy to 'Deny'.

    I hope this makes sense? :slight_smile:

  • Paul

    @andrew_mayberry,

    Is there no way simply to have the function above return the bucket name we want? (non-php dev here :grinning: And likewise, hardcode the path to the site domain url?

    No and yes.

    No, this is the way Snapshot is written. So far you have been the only person asking for this. So not something which was planned in the implementation.

    Yes, Well in coding anything is possible. But at the moment I'm dealing with a few other bug and cannot drop those issues to look into this. If you can hold off a day of so I'll try and provide a recommendation on a solution.

  • Paul

    @andrew_mayberry,

    Looking into this request this afternoon. I think the best solution is to add your values to the load_class_destination() of the index.php within the AWS folder.

    So if you load up that index.php file into an editor then go to line 342 where the function starts. You can remove all of the content and replace with the following:

    function load_class_destination($d_info) {
    
    	$this->destination_info['type'] 		= "aws"; // ALWAYS aws. Do not change.
    	$this->destination_info['name'] 		= "Your name for the destination. "; // Change this if you want.
    	$this->destination_info['awskey'] 		= ""; // Your AWS Access Key ID
    	$this->destination_info['secretkey'] 	= ""; // Your AWS Access Key Secret
    	$this->destination_info['ssl'] 			= "yes"; // Can be 'yes' or 'no'
    	$this->destination_info['region'] 		= AmazonS3::REGION_US_E1; 		// See line 81 for values
    	$this->destination_info['storage'] 		= AmazonS3::STORAGE_STANDARD;	// See line 92 for values
    	$this->destination_info['acl'] 			= AmazonS3::ACL_PRIVATE;		// See line 97 for values
    	$this->destination_info['bucket'] 		= ""; // YOUR Bucket name here.
    	$this->destination_info['directory'] 	= ""; // Directory within the Bucket
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.