diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/images/rails.png | bin | 0 -> 6646 bytes | |||
| -rw-r--r-- | app/assets/javascripts/application.js | 15 | ||||
| -rw-r--r-- | app/assets/javascripts/finger.js | 2 | ||||
| -rw-r--r-- | app/assets/stylesheets/application.css | 13 | ||||
| -rw-r--r-- | app/assets/stylesheets/finger.css | 4 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 3 | ||||
| -rw-r--r-- | app/controllers/finger_controller.rb | 38 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/finger_helper.rb | 2 | ||||
| -rw-r--r-- | app/mailers/.gitkeep | 0 | ||||
| -rw-r--r-- | app/models/.gitkeep | 0 | ||||
| -rw-r--r-- | app/models/finger.rb | 6 | ||||
| -rw-r--r-- | app/views/finger/index.html.erb | 38 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 14 |
14 files changed, 137 insertions, 0 deletions
diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png Binary files differnew file mode 100644 index 0000000..d5edc04 --- /dev/null +++ b/app/assets/images/rails.png diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..1145f9f --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,15 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD +// GO AFTER THE REQUIRES BELOW. +// +//= require jquery +//= require_tree . + diff --git a/app/assets/javascripts/finger.js b/app/assets/javascripts/finger.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/finger.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..3192ec8 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,13 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + */ diff --git a/app/assets/stylesheets/finger.css b/app/assets/stylesheets/finger.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/finger.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..bf99b83 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery +end diff --git a/app/controllers/finger_controller.rb b/app/controllers/finger_controller.rb new file mode 100644 index 0000000..823e2a7 --- /dev/null +++ b/app/controllers/finger_controller.rb @@ -0,0 +1,38 @@ +class FingerController < ApplicationController + + http_basic_authenticate_with :name => "dumpfm", :password => "jazzcup", :except => :create + + def create + @finger = Finger.new() + @finger.remote_addr = request.remote_ip + @finger.nick = params[:nick] + @finger.token = params[:token] + + @lookup = Finger.where(:token => @finger.token, :nick => @finger.nick).first + + if @lookup + render :json => { 'status' => @lookup.banned ? 'KO' : 'OK' } + elsif @finger.save + render :json => { 'status' => 'OK' } + else + render :json => { 'status' => 'ERROR' } + end + end + + def index + @fingers = Finger.all + end + + def ban + @finger = Finger.find(params[:id]) + + @finger.banned = (params[:banned] == "true") + + if @finger.save + render :json => { 'status' => 'OK' } + else + render :json => { 'status' => 'ERROR' } + end + end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/finger_helper.rb b/app/helpers/finger_helper.rb new file mode 100644 index 0000000..d835a6b --- /dev/null +++ b/app/helpers/finger_helper.rb @@ -0,0 +1,2 @@ +module FingerHelper +end diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/mailers/.gitkeep diff --git a/app/models/.gitkeep b/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/models/.gitkeep diff --git a/app/models/finger.rb b/app/models/finger.rb new file mode 100644 index 0000000..20a4238 --- /dev/null +++ b/app/models/finger.rb @@ -0,0 +1,6 @@ +class Finger < ActiveRecord::Base + attr_accessible :token, :nick, :remote_addr, :banned + + validates :nick, presence: true + validates :token, presence: true +end diff --git a/app/views/finger/index.html.erb b/app/views/finger/index.html.erb new file mode 100644 index 0000000..a1a2f32 --- /dev/null +++ b/app/views/finger/index.html.erb @@ -0,0 +1,38 @@ +<style> +td,th { min-width: 100px; text-align: left } +tr[data-banned=true], tr.banned { background: red; color: white; } +</style> +<table cellspacing=0> + <tr> + <td></td> + <th>id</th> + <th>nick</th> + <th>hash</th> + <th>ip</th> + </tr> +<% @fingers.each do |finger| %> + <tr data-id="<%= finger.id %>" data-banned="<%= finger.banned %>"> + <td><button><%= finger.banned ? "BANNED" : "BAN?" %></button></td> + <td><%= finger.id %></td> + <td><%= finger.nick %></td> + <td><%= finger.token %></td> + <td><%= finger.remote_addr %></td> + </tr> +<% end %> + +</table> + +<script> +$("button").click(function(){ + var $tr = $(this).closest("tr") + var data = $tr.data() + data.banned = ! data.banned + $tr.data("banned", data.banned) + $tr.toggleClass("banned", data.banned) + $tr.attr("data-banned", null) + $(this).html( data.banned ? "BANNED" : "BAN?" ) + $.post("/finger/ban", data, function(){ + console.log("ok") + }) +}) +</script>
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..1506bc8 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> +<head> + <title>Fingerprint</title> + <%= stylesheet_link_tag "application", :media => "all" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> +</head> +<body> + +<%= yield %> + +</body> +</html> |
