Skip to content

Instantly share code, notes, and snippets.

View jasonlyles's full-sized avatar

Jason Lyles jasonlyles

View GitHub Profile
#! /bin/sh
echo "Installing play framework..."
cd /usr/lib
curl -O http://downloads.typesafe.com/play/2.2.6/play-2.2.6.zip
yum -y install unzip
unzip play-2.2.6.zip
rm -f play-2.2.6.zip
export PATH=$PATH:/usr/lib/play-2.2.6
cd play-2.2.6
chmod a+x play
require 'win32ole'
#PUTS-ing Route table
ole = WIN32OLE.connect("winmgmts://")
query = "select * from Win32_IP4RouteTable"
puts "Network Address\t\tNetmask\t\tGateway Address\t\tMetric"
ole.ExecQuery(query).each do |route|
puts "#{route.Destination}\t\t#{route.Mask}\t\t#{route.NextHop}\t\t#{route.Metric1}"
end
#data_getter.rb
require 'server'
localhost = Server.new
#server.rb
<form action="/servers" class="new_server" id="new_server" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="985c45f4eb511084ddee29d0cfc3e00c0405b410" /></div>
<p>
<label for="server_hostname">Hostname</label><br />
<input id="server_hostname" name="server[hostname]" size="30" type="text" />
</p>
<p>
<label for="server_ip_address">Ip address</label><br />
<input id="server_ip_address" name="server[ip_address]" size="30" type="text" />
class RouteTable
attr_accessor :table
end
class ServersController < ApplicationController
# GET /servers
# GET /servers.xml
before_filter :login_required, :except => [:new, :edit, :create, :update]
protect_from_forgery :except => [:new, :edit, :create, :update]
def index
require 'will_paginate'
params = {'server[ip_address]' => localhost.ip_address, 'server[hostname]' => localhost.hostname,
'server[param_1]' => localhost.registry_user_base_dir, 'server[default_gateway]' => localhost.default_gateway,
'server[param_2]' => localhost.registry_sql_connect, 'server[netmask]' => localhost.netmask, 'server[route_table]' =>
route_table, 'server[os]' => localhost.os, 'server[build_date]' => localhost.build_date, 'server[service_pack]' =>
localhost.service_pack, 'server[subnet]' => localhost.subnet, 'server[persistent_route_table]' => persistent_route_table}
#old way
#x = Net::HTTP.post_form(URI.parse('http://report1.atbackup.local/servers/create'),params)
#new way
url = URI.parse('http://report1.atbackup.local/servers/create')
req = Net::HTTP::Post.new(url.path)
req.content_type='text/xml'
req.body = "<?xml version='1.0' encoding='UTF-8'?><server><hostname>#{localhost.hostname}</hostname><netmask>#{localhost.netmask}</netmask></server>"
res = Net::HTTP.new(url.host, url.port).start{|http| http.request(req)}
puts res.code
puts res.body
def run_pulse_run
@id = params[:id]
@timeout = params[:timeout]
result = ''
#Adding a timeout on my end in hopes of keeping this page from crashing the mongrel
begin
status = Timeout::timeout(@timeout.to_i) do
#And adding a rescue for Mongrel timeouts, just to be safe
begin
result = PulseRunner.run_pulse_test(@id,@timeout)
#This file is smtp_tls.rb
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args(user, secret) if user || secret
module DataRepair
class DateValueArray
def self.fill_in_the_gaps(start_date,end_date,date_array,*value_array_temp)
date_array = date_array.reverse
value_array = []
value_array_temp.each{|v|value_array << v.reverse}
dates,values = [],[]
val_index = 0
num_of_values = ((Time.parse(end_date) - Time.parse(start_date)) / 86400).to_i + 1
num_of_values.times do |i|