Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
various layout corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbunsch committed Sep 22, 2009
1 parent 5f49a70 commit 112a548
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 67 deletions.
4 changes: 3 additions & 1 deletion lib/actions/images.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Images

get '/:project/images' do
@@images ||= @ec2.describe_images.find_all{|x| x[:aws_image_type] == 'machine'}
@@images ||= @ec2.describe_images_by_owner('self')
# @@images ||= @ec2.describe_images_by_executable_by('self')
# @@images ||= @ec2.describe_images.find_all{|x| x[:aws_image_type] == 'machine'}
@i386 = @@images.find_all{|x| x[:aws_architecture] == 'i386'}.sort {|x,y| x[:aws_location] <=> y[:aws_location] }
@x86_64 = @@images.find_all{|x| x[:aws_architecture] == 'x86_64'}.sort {|x,y| x[:aws_location] <=> y[:aws_location] }
erb :images
Expand Down
13 changes: 4 additions & 9 deletions lib/actions/s3.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# S3

get '/:project/buckets' do
@buckets = @s3.buckets.map{|b| { :name => b.name, :location => (b.location != '' ? b.location : 'US') } }
erb :buckets
Expand All @@ -21,13 +20,9 @@

get '/:project/bucket/:bucket_name/keys' do
@bucket = @s3.bucket(params[:bucket_name])
@keys = @bucket.keys
@keys = @bucket.keys.collect { |key|
{ :link => "http://#{params[:bucket_name]}.s3.amazonaws.com/#{key}",
:name => key.name }
}
erb :s3_keys
end

get '/:project/bucket/*/key/*' do
bucket_name = request.path_info.split('/')[2]
key_name = request.path_info.split('/')[4]
@bucket = @s3.bucket(bucket_name)
send_data(@bucket.get(key_name))
end
3 changes: 2 additions & 1 deletion lib/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def time_ago_or_time_stamp(from_time, to_time = Time.now, include_seconds = true
end

def table(collection, *columns)
raise 'Collection element is not a hash' if collection.first.class != Hash
return '' if collection.size == 0
raise 'Collection element is not a Hash' if collection.first.class != Hash
if columns == []
# auto load a list of keys
first = collection.first
Expand Down
7 changes: 6 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ table.list th { background-color: #D3EDEE; color: #4F6B83; font-size: 0.7em; pad
table.list th.short { width: 130px; }
table.list td { background-color: #fff; text-align: left; font-size:0.9em; padding: 5px; vertical-align: top;}
table.list td.options { width: 200px; }
table.list tr.alt td { background-color: #F5FAFA; }
table.list tr.alt td { background-color: #F5FAFA; }

form { margin-bottom: 10px; padding: 5px; background-color: #eee;}
form select,
form input { border:1px solid #999; }
form input { padding: 1px; font-size: 0.9em; position: relative; top: -1px;}
9 changes: 7 additions & 2 deletions snail.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env ruby

# first, check required files so any user gets instant notification that something is wrong
CONFIG_FILE = "config/snail.yml"
def abort(msg); puts msg; exit(1); end
abort('Could not find config/snail.yml file.') if !File.exists?(CONFIG_FILE)

require 'rubygems'
# make sure we're using the right version of gems
gem 'sinatra', :version => '0.9.4'
Expand All @@ -15,7 +20,7 @@
Dir["lib/actions/*.rb"].each { |x| load x }

# set s3_config
config_file = YAML.load_file("config/snail.yml")
config_file = YAML.load_file(CONFIG_FILE)
set :config, config_file
set :projects, config_file.keys

Expand All @@ -27,7 +32,7 @@
@ec2 = RightAws::Ec2.new(config['aws_key'], config['aws_secret'])
@s3 = RightAws::S3.new(config['aws_key'], config['aws_secret'])
else
redirect '/projects' if first != 'projects' and !File.exists?("public#{request.path}")
redirect '/projects' if first != 'projects' and !File.exists?("public#{request.path}") and !request.path.include?('__sinatra__')
end
end

Expand Down
2 changes: 1 addition & 1 deletion views/_layout_footer.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
snail (<a href="http://github.com/moomerman/snail/tree/master" target="_new">on github</a>)
snail (<a href="http://github.com/marcinbunsch/snail/tree/master" target="_new">on github</a>)
12 changes: 6 additions & 6 deletions views/buckets.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<form action="/<%= @project %>/buckets" method="post">
<input type="text" name="bucket[name]" value="" />
<select name="bucket[location]">
<option value="eu">EU</option>
<option value="us">US</option>
Name: <input type="text" name="bucket[name]" value="" />
Location: <select name="bucket[location]">
<option value="eu">Europe</option>
<option value="us">United States</option>
</select>
<input type="submit">
<input type="submit" value="Create">
</form>
<%= table(@buckets) do |bucket|
result = link_to('view', "/#{@project}/bucket/#{bucket[:name]}/keys")
result << ' ' + link_to('delete', "/#{@project}/bucket/#{bucket[:name]}/delete")
result << ' | ' + link_to('destroy', "/#{@project}/bucket/#{bucket[:name]}/delete", :onclick => "return confirm('Are you sure you want to delete bucket #{bucket[:name]}?')")
end %>
19 changes: 3 additions & 16 deletions views/groups.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,9 @@
) %>
<br/><br/>

<% group[:aws_perms].each do |perm| %>
<% if perm[:group] %>
Allow <%= perm[:owner] %> <%= perm[:group] %>
<%= link_to(
'revoke',
"/group/#{group[:aws_group_name]}/revoke?group=#{perm[:group]}&owner=#{perm[:owner]}"
)%>
<% else %>
Allow <%= perm[:protocol].upcase %> IPs:<%= perm[:cidr_ips] %> Port:<%= perm[:from_port] %>:<%= perm[:to_port] %>
<%= link_to(
'revoke',
"/group/#{group[:aws_group_name]}/revoke?from=#{perm[:from_port]}&to=#{perm[:to_port]}&protocol=#{perm[:protocol]}&ip=#{perm[:cidr_ips]}"
)%>
<% end %>
<br/>
<% end %>
<%= table(group[:aws_perms]) %>



<%= link_to'+ Add new rule', '#', :onclick => "$('#add_rule_#{group[:aws_group_name]}').toggle()" %>

Expand Down
19 changes: 4 additions & 15 deletions views/images.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div>
<div style="float:right">
<form action="/images/search" method="GET">
<form action="/<%= @project %>/images/search" method="GET">
Search: <input type="text" name="query" value="<%= params[:query] %>">
<%= link_to 'All', '/images' %>
</form>
Expand All @@ -18,24 +18,13 @@
<br clear="all"/>
</div>


<div id="i386">
<% @i386.each_with_index do |machine, i| %>
<div class="image<% if i % 2 == 1%> odd<% end %>">
<b><%= machine[:aws_location].gsub('.manifest.xml', '').gsub('.img', '').gsub('/image', '').gsub('-', ' ') %></b>
<small>owner: <%= link_to machine[:aws_owner], "/images/search/#{machine[:aws_owner]}" %></small>
<%= link_to image_tag('add.png', :alt => 'Launch Instance'), "/images/#{machine[:aws_id]}/launch" %>
</div>
<% end %>
<%= table(@i386, :aws_owner, :aws_location) { |machine| link_to image_tag('add.png', :alt => 'Launch Instance'), "/images/#{machine[:aws_id]}/launch" } %>
</div>

<div id="x86_64" style="display:none">
<% @x86_64.each_with_index do |machine, i| %>
<div class="image<% if i % 2 == 1%> odd<% end %>">
<b><%= machine[:aws_location].gsub('.manifest.xml', '').gsub('.img', '').gsub('/image', '').gsub('-', ' ') %></b>
<small>owner: <%= link_to machine[:aws_owner], "/images/search/#{machine[:aws_owner]}" %></small>
<%= link_to image_tag('add.png', :alt => 'Launch Instance'), "/images/#{machine[:aws_id]}/launch" %>
</div>
<% end %>
<%= table(@x86_64, :aws_owner, :aws_location) { |machine| link_to image_tag('add.png', :alt => 'Launch Instance'), "/images/#{machine[:aws_id]}/launch" } %>
</div>

<a href="#top">top</a>
Expand Down
5 changes: 3 additions & 2 deletions views/instances.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<% @title = 'Instances' %>

<%= table(@instances, :aws_state, :aws_instance_id, :aws_availability_zone, :aws_instance_type, :aws_groups) %>
<br />
<% unless @instances.empty? %>

<div id="instances">
Expand Down Expand Up @@ -43,6 +44,6 @@
<% else %>

<p><i>You have no current instances.</i></p>
<p><%= link_to 'Choose an image', '/images' %> to launch a new instance.</p>
<p><%= link_to 'Choose an image', "/#{@project}/images" %> to launch a new instance.</p>

<% end %>
13 changes: 5 additions & 8 deletions views/keys.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
<p><%= link_to image_tag('add.png', :alt => 'Create a new Key Pair'), '#',:onclick => "$('#add_key').toggle()" %> Create a new SSH Key Pair</p>
<br/>
<div id="add_key">
<form action="/key" method="POST">
<form action="/<%= @project %>/key" method="POST">
Name <input name="key_name" type="text"/>
<input type="submit" value="create"/> <%= link_to 'Cancel', '#', :onclick => "$('#add_key').toggle()" %>
</form>
</div>

<% @keys.each do |key| %>
<b><%= key[:aws_key_name] %></b> <small><%= key[:aws_fingerprint] %></small>
<%= link_to(
image_tag('minus.png', :alt => 'Delete Key Pair'),
"/key/#{key[:aws_key_name]}/delete", :onclick => "return confirm('Delete Key: Are you sure?')"
) %><br/>
<% end %>
<%= table(@keys, :aws_key_name) { |key| link_to(
image_tag('minus.png', :alt => 'Delete Key Pair'),
"/key/#{key[:aws_key_name]}/delete", :onclick => "return confirm('Delete Key: Are you sure?')"
)} %>
6 changes: 1 addition & 5 deletions views/s3_keys.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<table>
<% @keys.each do |key| %>
<tr><td><%= key.name %></td><td><%= link_to('link', key.public_link) %> <%= link_to 'download', "/#{@project}/bucket/#{@bucket.name}/key/#{key.name}" %></td></tr>
<% end %>
</table>
<%= table(@keys) { |key| link_to('link', key[:link]) } %>

0 comments on commit 112a548

Please sign in to comment.