diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 306042a5a..a9b28bb59 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -14,6 +14,7 @@ require "postgres-copy" require "geokit-rails" require "postgres_ext" require 'builder' +require 'cgi' require "jam_ruby/constants/limits" require "jam_ruby/constants/notification_types" diff --git a/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb b/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb index 3abd1696c..8ff23f631 100644 --- a/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb +++ b/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb @@ -1,9 +1,95 @@ + +module JSONable + module ClassMethods + attr_accessor :attributes + + def attr_accessor *attrs + self.attributes = Array attrs + super + end + end + + def self.included(base) + base.extend(ClassMethods) + end + + def as_json options = {} + serialized = Hash.new + self.class.attributes.each do |attribute| + serialized[attribute] = self.public_send attribute + end + serialized + end + + def to_json *a + as_json.to_json *a + end + + def jdumpXml (ovb, nm, ident=1, output=$stdout) + + v = JSON.generate ovb + #puts "#{v}" + + hash = JSON.parse(v) + #puts "#{hash}" + + tb = "\t" + tbs = tb * ident + tbse = tb * (ident-1) + + output.puts "#{tbse}<#{nm}>" + hash.each do |key, val| + #puts "attrib: key=#{key} val=#{val}" + + el = key + if key.present? + el = key.gsub(/_/, '-') + end + + + sv = val + if val.to_s.empty? + #skip ??? + else + if val.instance_of? String + #encode the string to be xml safe + sv = CGI.escapeHTML(val) + end + end + output.puts "#{tbs}<#{el}>#{sv}" + end + puts "#{tbse}" + end +end + + + module JamRuby class IcecastAdminAuthentication < ActiveRecord::Base + include JSONable + attr_accessible :source_password, :relay_user, :relay_password, :admin_user, :admin_password + attr_accessor :source_password, :relay_user, :relay_password, :admin_user, :admin_password + + after_initialize :init + + protected + def init + #set only if nil + self.source_password ||= "UndefinedSourcePassword" + self.admin_password ||= "JKAminPw" + end + + public self.primary_key = 'id' - validates :source_password, length: {minimum: 5} + validates :source_password, presence: true, length: {minimum: 5} + validates :admin_password, presence: true, length: {minimum: 5} + + def dumpXml (ident=1, output=$stdout) + self.jdumpXml(self,"authentication", ident,output) + end + end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_directory.rb b/ruby/lib/jam_ruby/models/icecast_directory.rb index 7d5fd4b45..f86a7f7c9 100644 --- a/ruby/lib/jam_ruby/models/icecast_directory.rb +++ b/ruby/lib/jam_ruby/models/icecast_directory.rb @@ -3,7 +3,8 @@ module JamRuby self.primary_key = 'id' - + attr_accessible :yp_url_timeout, :yp_url + attr_accessor :yp_url_timeout, :yp_url end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_limit.rb b/ruby/lib/jam_ruby/models/icecast_limit.rb index 006ee6e69..e55afc142 100644 --- a/ruby/lib/jam_ruby/models/icecast_limit.rb +++ b/ruby/lib/jam_ruby/models/icecast_limit.rb @@ -1,12 +1,34 @@ module JamRuby class IcecastLimit < ActiveRecord::Base + include JSONable self.primary_key = 'id' + attr_accessible :clients, :sources, :queue_size, :client_timeout, :header_timeout, :source_timeout, :burst_size + #attr_accessor :clients, :sources, :queue_size, :client_timeout, :header_timeout, :source_timeout, :burst_size + + #validates :clients, numericality: {only_integer: true}, length: {in: 1..15000} validates :clients, numericality: {only_integer: true} - def dumpXml() + after_initialize :init + self[:clients] + def init + puts "Init self.client #{self.clients}" + self.clients ||= 10000 + self.sources ||= 1000 + self.queue_size ||= 102400 + self.client_timeout ||= 30 + self.header_timeout ||= 15 + self.source_timeout ||= 10 + self.burst_size ||= 65536 + end + + def setclients(val) + @clients = val + end + def dumpXml (ident=1, output=$stdout) + self.jdumpXml(self, "limits", ident, output) end end diff --git a/ruby/lib/jam_ruby/models/icecast_listen_socket.rb b/ruby/lib/jam_ruby/models/icecast_listen_socket.rb index f6d13f7c0..b4e1741f8 100644 --- a/ruby/lib/jam_ruby/models/icecast_listen_socket.rb +++ b/ruby/lib/jam_ruby/models/icecast_listen_socket.rb @@ -3,6 +3,13 @@ module JamRuby self.primary_key = 'id' + attr_accessible :port, :bind_address, :shoutcast_mount, :shoutcast_compat + attr_accessor :port, :bind_address, :shoutcast_mount, :shoutcast_compat + + def dumpXml() + + end + end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_logging.rb b/ruby/lib/jam_ruby/models/icecast_logging.rb index 457afc2a2..a2aa1cc88 100644 --- a/ruby/lib/jam_ruby/models/icecast_logging.rb +++ b/ruby/lib/jam_ruby/models/icecast_logging.rb @@ -3,7 +3,12 @@ module JamRuby self.primary_key = 'id' + attr_accessible :accesslog, :errorlog, :playlistlog, :loglevel + attr_accessor :accesslog, :errorlog, :playlistlog, :loglevel + def dumpXml() + + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_mastersvr_relay.rb b/ruby/lib/jam_ruby/models/icecast_mastersvr_relay.rb index 2ff4239f0..cd949c3d2 100644 --- a/ruby/lib/jam_ruby/models/icecast_mastersvr_relay.rb +++ b/ruby/lib/jam_ruby/models/icecast_mastersvr_relay.rb @@ -2,6 +2,11 @@ module JamRuby class IcecastMastersvrRelay < ActiveRecord::Base self.primary_key = 'id' + attr_accessible :master_server, :master_server_port, :master_username, :master_password, :relays_on_demand + attr_accessible :master_server, :master_server_port, :master_username, :master_password, :relays_on_demand + def dumpXml() + + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_mount.rb b/ruby/lib/jam_ruby/models/icecast_mount.rb index 6627f3ddd..47731cbf1 100644 --- a/ruby/lib/jam_ruby/models/icecast_mount.rb +++ b/ruby/lib/jam_ruby/models/icecast_mount.rb @@ -3,7 +3,22 @@ module JamRuby self.primary_key = 'id' + attr_accessible :mount_name, :username, :password, :max_listeners, :max_listener_duration, :dump_file + attr_accessor :mount_name, :username, :password, :max_listeners, :max_listener_duration, :dump_file + + attr_accessible :intro, :fallback_mount, :fallback_override, :fallback_when_full, :charset + attr_accessor :intro, :fallback_mount, :fallback_override, :fallback_when_full, :charset + + attr_accessible :publicc, :stream_name, :stream_description, :stream_url, :genre, :bitrate + attr_accessor :publicc, :stream_name, :stream_description, :stream_url, :genre, :bitrate + + attr_accessible :mtype, :subtype, :hidden, :burst_size, :mp3_metadata_interval, :on_connect, :on_disconnect + attr_accessor :mtype, :subtype, :hidden, :burst_size, :mp3_metadata_interval, :on_connect, :on_disconnect + has_one :authentication, :class_name => "IcecastUserAuthentication" + def dumpXml() + + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_path.rb b/ruby/lib/jam_ruby/models/icecast_path.rb index 434d7839c..a6f01e122 100644 --- a/ruby/lib/jam_ruby/models/icecast_path.rb +++ b/ruby/lib/jam_ruby/models/icecast_path.rb @@ -3,7 +3,12 @@ module JamRuby self.primary_key = 'id' + attr_accessible :basedir, :logdir, :pidfile, :webroot, :adminroot, :allow_ip, :deny_ip, :aliass + attr_accessor :basedir, :logdir, :pidfile, :webroot, :adminroot, :allow_ip, :deny_ip, :aliass + def dumpXml() + + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_relay.rb b/ruby/lib/jam_ruby/models/icecast_relay.rb index e0228df0f..19d9b275d 100644 --- a/ruby/lib/jam_ruby/models/icecast_relay.rb +++ b/ruby/lib/jam_ruby/models/icecast_relay.rb @@ -3,6 +3,12 @@ module JamRuby self.primary_key = 'id' + attr_accessible :server, :port, :mount, :local_mount, :username, :password, :relay_shoutcast_metadata, :on_demand + attr_accessor :server, :port, :mount, :local_mount, :username, :password, :relay_shoutcast_metadata, :on_demand + + def dumpXml() + + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_sercurity.rb b/ruby/lib/jam_ruby/models/icecast_sercurity.rb index 510fd95c3..318c055ed 100644 --- a/ruby/lib/jam_ruby/models/icecast_sercurity.rb +++ b/ruby/lib/jam_ruby/models/icecast_sercurity.rb @@ -3,7 +3,12 @@ module JamRuby self.primary_key = 'id' + attr_accessible :chroot, :changeowner_user, :changeowner_group + attr_accessor :chroot, :changeowner_user, :changeowner_group + def dumpXml() + + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_server.rb b/ruby/lib/jam_ruby/models/icecast_server.rb index f015f35ac..8f837edc8 100644 --- a/ruby/lib/jam_ruby/models/icecast_server.rb +++ b/ruby/lib/jam_ruby/models/icecast_server.rb @@ -14,5 +14,10 @@ module JamRuby has_one :path, :class_name => "JamRuby::IcecastPath" has_one :logging, :class_name => "JamRuby::IcecastLogging" has_one :security, :class_name => "JamRuby::IceCastSecurity" + + def dumpXml() + + end + end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_servermisc.rb b/ruby/lib/jam_ruby/models/icecast_servermisc.rb index d620f032e..881a1c811 100644 --- a/ruby/lib/jam_ruby/models/icecast_servermisc.rb +++ b/ruby/lib/jam_ruby/models/icecast_servermisc.rb @@ -3,5 +3,12 @@ module JamRuby self.primary_key = 'id' + attr_accessible :hostname, :location, :admin, :fileserve, :server_id + attr_accessor :hostname, :location, :admin, :fileserve, :server_id + + def dumpXml() + + end + end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_user_authentication.rb b/ruby/lib/jam_ruby/models/icecast_user_authentication.rb index ec6974093..12d4f1520 100644 --- a/ruby/lib/jam_ruby/models/icecast_user_authentication.rb +++ b/ruby/lib/jam_ruby/models/icecast_user_authentication.rb @@ -3,6 +3,15 @@ module JamRuby self.primary_key = 'id' + attr_accessible :stype, :filename, :allow_duplicate_users, :mount_add, :mount_remove, + :listener_add, :listener_remove, :username, :password, :auth_header, :timelimit_header + attr_accessor :stype, :filename, :allow_duplicate_users, :mount_add, :mount_remove, + :listener_add, :listener_remove, :username, :password, :auth_header, :timelimit_header + + + def dumpXml() + + end end end \ No newline at end of file diff --git a/ruby/spec/jam_ruby/models/icecast_admin_authentication_spec.rb b/ruby/spec/jam_ruby/models/icecast_admin_authentication_spec.rb index d5cd83588..a87bd7dcf 100644 --- a/ruby/spec/jam_ruby/models/icecast_admin_authentication_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_admin_authentication_spec.rb @@ -5,11 +5,21 @@ describe IcecastAdminAuthentication do let(:admin) { IcecastAdminAuthentication.new } before(:all) do - + admin.source_password = "GoodJob@" end it "save" do - admin.save.should be_true + admin.save! + #puts "source password #{admin.source_password}" + #puts "id #{admin.id}" + #puts admin.errors + #puts admin.inspect + #puts admin.to_yaml + #puts JSON.pretty_generate admin + puts admin.dumpXml (1) + #puts admin.errors.inspect + admin.errors.any?.should be_false end + end diff --git a/ruby/spec/jam_ruby/models/icecast_directory_spec.rb b/ruby/spec/jam_ruby/models/icecast_directory_spec.rb index e69de29bb..8e04dbf3a 100644 --- a/ruby/spec/jam_ruby/models/icecast_directory_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_directory_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe IcecastDirectory do + + let(:idir) { IcecastDirectory.new } + + before(:all) do + + end + + it "save" do + idir.save.should be_true + end + +end diff --git a/ruby/spec/jam_ruby/models/icecast_limit_spec.rb b/ruby/spec/jam_ruby/models/icecast_limit_spec.rb index aa3c34bdf..da1dee4bf 100644 --- a/ruby/spec/jam_ruby/models/icecast_limit_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_limit_spec.rb @@ -9,11 +9,19 @@ describe IcecastLimit do end it "save" do - limit.save.should be_true + limit.clients = 9999 + limit.save + puts limit.inspect + #limit.dumpXml + limit.errors.any?.should be_false + v = IcecastLimit.find(limit.id) + puts v.inspect end - it "non-integer clients should be checked" do - limit.clients = "a" + it "non-integer clients should be checked" do + limit.setclients 'a' + puts limit.clients + puts limit.inspect limit.save.should be_false limit.errors[:clients].should == ['is not a number'] end diff --git a/ruby/spec/jam_ruby/models/icecast_listen_socket_spec.rb b/ruby/spec/jam_ruby/models/icecast_listen_socket_spec.rb index e69de29bb..f7bd08e2d 100644 --- a/ruby/spec/jam_ruby/models/icecast_listen_socket_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_listen_socket_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe IcecastListenSocket do + + let(:iobj) { IcecastListenSocket.new } + + before(:all) do + + end + + it "save" do + iobj.save.should be_true + end + +end diff --git a/ruby/spec/jam_ruby/models/icecast_logging_spec.rb b/ruby/spec/jam_ruby/models/icecast_logging_spec.rb index e69de29bb..fa0d67b4c 100644 --- a/ruby/spec/jam_ruby/models/icecast_logging_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_logging_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe IcecastLogging do + + let(:iobj) { IcecastLogging.new } + + before(:all) do + + end + + it "save" do + iobj.save.should be_true + end + +end \ No newline at end of file diff --git a/ruby/spec/jam_ruby/models/icecast_mastersvr_relay_spec.rb b/ruby/spec/jam_ruby/models/icecast_mastersvr_relay_spec.rb index e69de29bb..90a1001f5 100644 --- a/ruby/spec/jam_ruby/models/icecast_mastersvr_relay_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_mastersvr_relay_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe IcecastMastersvrRelay do + + let(:iobj) { IcecastMastersvrRelay.new } + + before(:all) do + + end + + + it "should not save" do + iobj.save.should be_false + iobj.errors[:master_server].should_equal "is required" + end + + it "should save" do + iobj.master_server = "test.www.com" + iobj.master_server_port = 7111 + iobj.master_username = "hack" + iobj.master_password = "hackme" + iobj.save.should be_true + end + +end \ No newline at end of file diff --git a/ruby/spec/jam_ruby/models/icecast_mount_spec.rb b/ruby/spec/jam_ruby/models/icecast_mount_spec.rb index e69de29bb..0dba3b94f 100644 --- a/ruby/spec/jam_ruby/models/icecast_mount_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_mount_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe IcecastMount do + + let(:iobj) { IcecastMount.new } + + before(:all) do + + end + + it "save" do + iobj.save.should be_true + end + +end \ No newline at end of file diff --git a/ruby/spec/jam_ruby/models/icecast_path_spec.rb b/ruby/spec/jam_ruby/models/icecast_path_spec.rb index e69de29bb..15015e93a 100644 --- a/ruby/spec/jam_ruby/models/icecast_path_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_path_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe IcecastPath do + + let(:iobj) { IcecastPath.new } + + before(:all) do + + end + + it "save" do + iobj.save.should be_true + end + +end \ No newline at end of file diff --git a/ruby/spec/jam_ruby/models/icecast_relay_spec.rb b/ruby/spec/jam_ruby/models/icecast_relay_spec.rb index e69de29bb..b81d47c18 100644 --- a/ruby/spec/jam_ruby/models/icecast_relay_spec.rb +++ b/ruby/spec/jam_ruby/models/icecast_relay_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe IcecastRelay do + + let(:iobj) { IcecastRelay.new } + + before(:all) do + + end + + it "save" do + :iobj.save.should be_true + end + +end \ No newline at end of file