diff --git a/db/up/icecast.sql b/db/up/icecast.sql index a04a62df8..fc0c2a2d9 100644 --- a/db/up/icecast.sql +++ b/db/up/icecast.sql @@ -13,7 +13,7 @@ CREATE TABLE icecast_limits ( queue_size INTEGER NOT NULL DEFAULT 102400, -- does not appear to be used - client_timeout INTEGER DEFAULT 10, + client_timeout INTEGER DEFAULT 30, -- The maximum time (in seconds) to wait for a request to come in once -- the client has made a connection to the server. @@ -35,23 +35,23 @@ CREATE TABLE icecast_limits ( ); -create table icecast_admin_authentications ( +CREATE TABLE icecast_admin_authentications ( id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), -- The unencrypted password used by sources to connect to icecast2. - -- The default username for all source connections is 'source' but - -- this option allows to specify a default password. This and the username + -- The DEFAULT username for all source connections is 'source' but + -- this option allows to specify a DEFAULT password. This and the username -- can be changed in the individual mount sections. - source_password VARCHAR(64) NOT NULL DEFAULT 'icejam321', + source_password VARCHAR(64) NOT NULL, -- Used in the master server as part of the authentication when a slave requests - -- the list of streams to relay. The default username is 'relay' - relay_user VARCHAR(64) NOT NULL DEFAULT 'relay', - relay_password VARCHAR(64) NOT NULL DEFAULT 'jkrelayhack', + -- the list of streams to relay. The DEFAULT username is 'relay' + relay_user VARCHAR(64) NOT NULL, + relay_password VARCHAR(64) NOT NULL, --The username/password used for all administration functions. - admin_user VARCHAR(64) NOT NULL DEFAULT 'jkadmin', - admin_password VARCHAR(64) NOT NULL DEFAULT 'jKadmin123', + admin_user VARCHAR(64) NOT NULL, + admin_password VARCHAR(64) NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP @@ -60,294 +60,282 @@ create table icecast_admin_authentications ( --contains all the settings for listing a stream on any of the Icecast2 YP Directory servers. -- Multiple occurances of this section can be specified in order to be listed on multiple directory servers. -create table icecast_directories ( +CREATE TABLE icecast_directories ( id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), - yp_url_timeout INTEGER not null default 15, - yp_url VARCHAR(1024) not null UNIQUE default 'http://dir.xiph.org/cgi-bin/yp-cgi', + yp_url_timeout INTEGER NOT NULL DEFAULT 15, + yp_url VARCHAR(1024) NOT NULL UNIQUE, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create table icecast_servermiscs ( - id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), - -- This is the DNS name or IP address that will be used for the stream directory lookups or possibily - -- the playlist generation if a Host header is not provided. While localhost is shown as an example, - -- in fact you will want something that your listeners can use. - hostname VARCHAR(256) not null default 'concertsvr.jamkazam.com', - --This sets the location string for this icecast instance. It will be shown e.g in the web interface. - location VARCHAR(128) not null default 'earth', - --This should contain contact details for getting in touch with the server administrator. - admin VARCHAR(128) not null default 'icemaster@localhost', - -- This flag turns on the icecast2 fileserver from which static files can be served. - -- All files are served relative to the path specified in the configuration - -- setting. By default the setting is enabled so that requests for the images - -- on the status page are retrievable. - fileserve INTEGER not null default 1, - -- This optional setting allows for the administrator of the server to override the - -- default server identification. The default is icecast followed by a version number - -- and most will not care to change it however this setting will change that. - server_id VARCHAR(128) not null default 'icecast 2.3', - - - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); - -create table icecast_listen_sockets ( +CREATE TABLE icecast_listen_sockets ( id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), -- The TCP port that will be used to accept client connections. - port INTEGER not null default 8001, + port INTEGER NOT NULL DEFAULT 8001, -- An optional IP address that can be used to bind to a specific network card. -- If not supplied, then it will bind to all interfaces. - bind_address VARCHAR(128), + bind_address VARCHAR(1024), - shoutcast_mount VARCHAR(128) default NULL, - shoutcast_compat INTEGER not null default 0, + shoutcast_mount VARCHAR(1024), + shoutcast_compat INTEGER, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create table icecast_mastersvr_relays ( - id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), - - -- ip address of the master icecast server and port number - master_server VARCHAR(128) not null, - master_server_port INTEGER not null, - --The interval (in seconds) that the Relay Server will poll the Master Server for any new mountpoints to relay. - master_update_interval INTEGER not null default 120, - - -- This is the relay username on the master server. It is used to query the server for a list of - -- mountpoints to relay. If not specified then 'relay' is used - master_username VARCHAR(64) not null default 'relay', - master_password VARCHAR(64) not null, - - --Global on-demand setting for relays. Because you do not have individual relay options when - -- using a master server relay, you still may want those relays to only pull the stream when - -- there is at least one listener on the slave. The typical case here is to avoid surplus - -- bandwidth costs when no one is listening. - relays_on_demand INTEGER default 0, - - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP - --make sure this combo is unique - --CONSTRAINT serverID UNIQUE KEY (master_server,master_server_port) -); - -create table icecast_relays ( +CREATE TABLE icecast_relays ( id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), -- ip address of server we are relaying from and port number - server VARCHAR(128) not null, - port INTEGER not null default 8001, + server VARCHAR(1024) NOT NULL, + port INTEGER NOT NULL DEFAULT 8001, -- mount at server. eg /example.ogg - mount VARCHAR(128) not null, + mount VARCHAR(1024) NOT NULL, -- eg /different.ogg - local_mount VARCHAR(128) not null default '/relaymout.ogg', + local_mount VARCHAR(1024), -- eg joe. could be null - username VARCHAR(64) not null default 'jkicerelayusr' , + username VARCHAR(64), -- user password - password VARCHAR(64) not null default 'jkicerelaypwd' , - relay_shoutcast_metadata INTEGER default 0, + password VARCHAR(64), + relay_shoutcast_metadata BOOLEAN DEFAULT FALSE, --- relay only if we have someone wanting to listen - on_demand INTEGER default 0, + on_demand BOOLEAN DEFAULT TRUE, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create TABLE icecast_user_authentications( +CREATE TABLE icecast_user_authentications( id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), --"htpasswd or url" -- real name is type - stype VARCHAR(16) DEFAULT 'url' , + authentication_type VARCHAR(16) DEFAULT 'url', -- these are for httpasswd - filename VARCHAR(256) default NULL, - allow_duplicate_users INTEGER DEFAULT 1, + filename VARCHAR(1024), + allow_duplicate_users BOOLEAN, -- these options are for url -- eg value="http://myauthserver.com/stream_start.php" - mount_add VARCHAR(256) DEFAULT 'http://icecastauth.jamkazam.com/stream_start.php', + mount_add VARCHAR(1024), --value="http://myauthserver.com/stream_end.php" - mount_remove VARCHAR(256) default 'http://icecastauth.jamkazam.com/stream_end.php', + mount_remove VARCHAR(1024), --value="http://myauthserver.com/listener_joined.php" - listener_add VARCHAR(256) default 'http://icecastauth.jamkazam.com/listener_joined.php', + listener_add VARCHAR(1024), --value="http://myauthserver.com/listener_left.php" - listener_remove VARCHAR(256) default 'http://icecastauth.jamkazam.com/listener_left.php', + listener_remove VARCHAR(1024), -- value="user" - username VARCHAR(64) default 'jkuser', + username VARCHAR(64), -- value="pass" - password VARCHAR(64) DEFAULT 'jkhackpass', + password VARCHAR(64), -- value="icecast-auth-user: 1" - auth_header VARCHAR(64) default 'icecast-auth-user: 1', + auth_header VARCHAR(64) DEFAULT 'icecast-auth-user: 1', -- value="icecast-auth-timelimit:" - timelimit_header VARCHAR(64) default 'icecast-auth-timelimit:', + timelimit_header VARCHAR(64) DEFAULT 'icecast-auth-timelimit:', created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create table icecast_mounts ( +CREATE UNLOGGED TABLE icecast_mounts ( id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), -- eg/example-complex.ogg - mount_name VARCHAR(128) UNIQUE NOT NULL, - username VARCHAR(64) NOT NULL DEFAULT 'jamsource', - password VARCHAR(64) NOT NULL DEFAULT 'jamhackmesourcepwd', - max_listeners INTEGER NOT NULL DEFAULT 4, - max_listener_duration INTEGER NOT NULL DEFAULT 3600, + mount_name VARCHAR(1024) UNIQUE NOT NULL, + username VARCHAR(64), + password VARCHAR(64), + max_listeners INTEGER DEFAULT 4, + max_listener_duration INTEGER DEFAULT 3600, -- dump of the stream coming through on this mountpoint. -- eg /tmp/dump-example1.ogg - dump_file VARCHAR(256) DEFAULT NULL, - + dump_file VARCHAR(1024), -- intro music to play -- This optional value specifies a mountpoint that clients are automatically moved to -- if the source shuts down or is not streaming at the time a listener connects. - intro VARCHAR(256) NOT NULL DEFAULT '/intro.ogg', - fallback_mount VARCHAR(256) NOT NULL DEFAULT '/sourcedown.ogg', + intro VARCHAR(1024), + fallback_mount VARCHAR(1024), -- When enabled, this allows a connecting source client or relay on this mountpoint -- to move listening clients back from the fallback mount. - fallback_override INTEGER DEFAULT 1, + fallback_override BOOLEAN DEFAULT TRUE, -- When set to 1, this will cause new listeners, when the max listener count for the mountpoint -- has been reached, to move to the fallback mount if there is one specified. - fallback_when_full INTEGER DEFAULT 1, + fallback_when_full BOOLEAN DEFAULT TRUE, --For non-Ogg streams like MP3, the metadata that is inserted into the stream often -- has no defined character set. - charset VARCHAR(256) NOT NULL DEFAULT 'ISO8859-1', - -- possilble values are -1, 0, 1 + charset VARCHAR(1024) DEFAULT 'ISO8859-1', + -- possible values are -1, 0, 1 -- real name is public but this is reserved word in ruby - publicc INTEGER DEFAULT 1, + is_public INTEGER DEFAULT 0, - stream_name VARCHAR(256) NOT NULL DEFAULT 'My Jamkazam Audio Stream', - stream_description VARCHAR(256) NOT NULL DEFAULT 'My JK audio description', + stream_name VARCHAR(1024), + stream_description VARCHAR(10000), -- direct to user page - stream_url VARCHAR(256) NOT NULL DEFAULT 'http://wwww.jamakazam.com#user_id', + stream_url VARCHAR(1024), -- get this from the session info - genre VARCHAR(64) NOT NULL DEFAULT 'Unknown', - bitrate integer NOT NULL default 92, + genre VARCHAR(256), + bitrate INTEGER, -- real name is type but this is reserved name in ruby - mtype VARCHAR(64) NOT NULL DEFAULT 'application/ogg' , - subtype VARCHAR(64) NOT NULL DEFAULT 'vorbis', + mime_type VARCHAR(64) NOT NULL DEFAULT 'application/ogg' , + subtype VARCHAR(64) NOT NULL DEFAULT 'vorbis', + + -- This optional setting allows for providing a burst size which overrides the + -- DEFAULT burst size as defined in limits. The value is in bytes. + burst_size INTEGER, + mp3_metadata_interval INTEGER, + -- Enable this to prevent this mount from being shown on the xsl pages. -- This is mainly for cases where a local relay is configured and you do -- not want the source of the local relay to be shown - hidden INTEGER DEFAULT 1, - - -- This optional setting allows for providing a burst size which overrides the - -- default burst size as defined in limits. The value is in bytes. - burst_size INTEGER DEFAULT 65536, - mp3_metadata_interval INTEGER DEFAULT 4096, + hidden BOOLEAN DEFAULT TRUE, --called when the source connects or disconnects. The scripts are called with the name of the mount - on_connect VARCHAR(256) DEFAULT '/home/icecast/bin/source-start', - on_disconnect VARCHAR(256) DEFAULT '/home/icecast/bin/source-end', + on_connect VARCHAR(1024), + on_disconnect VARCHAR(1024), - user_authentication_id varchar(64) DEFAULT NULL references icecast_user_authentications(id), + -- references icecast_user_authentications(id) + authentication_id varchar(64) DEFAULT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create table icecast_paths ( +CREATE TABLE icecast_paths ( id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), - basedir VARCHAR(256) NOT NULL DEFAULT './', - logdir VARCHAR(256) NOT NULL DEFAULT './logs', - pidfile VARCHAR(256) NOT NULL DEFAULT './icecast.pid', - webroot VARCHAR(256) NOT NULL DEFAULT './web', - adminroot VARCHAR(256) NOT NULL DEFAULT './admin', - allow_ip VARCHAR(256) NOT NULL DEFAULT '/path/to/ip_allowlist', - deny_ip VARCHAR(256) NOT NULL DEFAULT '/path_to_ip_denylist', - --real name is alias but alias is reserved in ruby - aliass VARCHAR(256) DEFAULT 'source="/foo" dest="/bar"', + base_dir VARCHAR(1024) NOT NULL DEFAULT './', + log_dir VARCHAR(1024) NOT NULL DEFAULT './logs', + pid_file VARCHAR(1024) NOT NULL DEFAULT './icecast.pid', + web_root VARCHAR(1024) NOT NULL DEFAULT './web', + admin_root VARCHAR(1024) NOT NULL DEFAULT './admin', + allow_ip VARCHAR(1024), + deny_ip VARCHAR(1024), + alias_source VARCHAR(1024), + alias_dest VARCHAR(1024), created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create table icecast_loggings ( - id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), - accesslog VARCHAR(256) NOT NULL DEFAULT 'access.log', - errorlog VARCHAR(256) NOT NULL DEFAULT 'error.log', - playlistlog VARCHAR(256) NOT NULL DEFAULT 'playlist.log', - -- 4 Debug, 3 Info, 2 Warn, 1 Error - loglevel INTEGER NOT NULL DEFAULT 4 , +CREATE TABLE icecast_loggings ( + id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), + access_log VARCHAR(1024) NOT NULL DEFAULT 'access.log', + error_log VARCHAR(1024) NOT NULL DEFAULT 'error.log', + playlist_log VARCHAR(1024), + -- 4 Debug, 3 Info, 2 Warn, 1 Error + log_level INTEGER NOT NULL DEFAULT 3 , + log_archive BOOLEAN, + -- 10 meg log file by default + log_size INTEGER DEFAULT 10000, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create table icecast_securities ( - id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), - - chroot INTEGER NOT NULL DEFAULT 0, - changeowner_user VARCHAR(64) DEFAULT 'nobody', - changeowner_group VARCHAR(64) DEFAULT 'nogroup', - - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +CREATE TABLE icecast_securities ( + id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(), + chroot BOOLEAN NOT NULL DEFAULT FALSE, + change_owner_user VARCHAR(64), + change_owner_group VARCHAR(64), + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -create TABLE icecast_servers( +CREATE TABLE icecast_master_server_relays( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + + -- ip address of the master icecast server and port number + master_server VARCHAR(1024) NOT NULL, + master_server_port INTEGER NOT NULL DEFAULT 8001, + --The interval (in seconds) that the Relay Server will poll the Master Server for any new mountpoints to relay. + master_update_interval INTEGER NOT NULL DEFAULT 120, + -- This is the relay username on the master server. It is used to query the server for a list of + -- mountpoints to relay. If not specified then 'relay' is used + master_username VARCHAR(64) NOT NULL, + master_password VARCHAR(64) NOT NULL, + + --Global on-demand setting for relays. Because you do not have individual relay options when + -- using a master server relay, you still may want those relays to only pull the stream when + -- there is at least one listener on the slave. The typical case here is to avoid surplus + -- bandwidth costs when no one is listening. + relays_on_demand BOOLEAN NOT NULL DEFAULT TRUE, + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE icecast_servers ( id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), --use this to mark the server configuration as needing to be regenerated - config_changed INTEGER DEFAULT 0, + config_changed BOOLEAN DEFAULT FALSE, + limit_id VARCHAR(64) REFERENCES icecast_limits(id), + admin_auth_id VARCHAR(64) REFERENCES icecast_admin_authentications(id), + directory_id VARCHAR(64) REFERENCES icecast_directories(id), + master_relay_id VARCHAR(64) REFERENCES icecast_master_server_relays(id), + path_id VARCHAR(64) REFERENCES icecast_paths(id), + logging_id VARCHAR(64) REFERENCES icecast_loggings(id), + security_id VARCHAR(64) REFERENCES icecast_securities(id), - limit_id VARCHAR(64) REFERENCES icecast_limits(id), - adminauth_id VARCHAR(64) REFERENCES icecast_admin_authentications(id), - directory_id VARCHAR(64) REFERENCES icecast_directories(id), - misc_id VARCHAR(64) REFERENCES icecast_servermiscs(id), - master_relay_id VARCHAR(64) REFERENCES icecast_mastersvr_relays(id), - - /* relay_ids VARCHAR(64) REFERENCES icecast_serverrelays(id), - mount_ids VARCHAR(64) REFERENCES icecast_servermounts(id), - socket_ids VARCHAR(64) REFERENCES icecast_serversockets(id) , - */ + -- This is the DNS name or IP address that will be used for the stream directory lookups or possibily + -- the playlist generation if a Host header is not provided. While localhost is shown as an example, + -- in fact you will want something that your listeners can use. + hostname VARCHAR(1024) NOT NULL, + --This sets the location string for this icecast instance. It will be shown e.g in the web interface. + location VARCHAR(1024) NOT NULL, + --This should contain contact details for getting in touch with the server administrator. + admin_email VARCHAR(1024) NOT NULL DEFAULT 'admin@jamkazam.com', + -- This flag turns on the icecast2 fileserver from which static files can be served. + -- All files are served relative to the path specified in the configuration + -- setting. By DEFAULT the setting is enabled so that requests for the images + -- on the status page are retrievable. + fileserve BOOLEAN NOT NULL DEFAULT TRUE, + -- This optional setting allows for the administrator of the server to override the + -- DEFAULT server identification. The DEFAULT is icecast followed by a version number + -- and most will not care to change it however this setting will change that. + server_id VARCHAR(1024), created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); - -CREATE TABLE icecast_servermounts ( +CREATE TABLE icecast_server_mounts ( id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), - mount_id VARCHAR(64) REFERENCES icecast_mounts(id) ON DELETE CASCADE, - server_id VARCHAR(64) REFERENCES icecast_servers(id) ON DELETE CASCADE, + --REFERENCES icecast_mounts(id) ON DELETE CASCADE, + icecast_mount_id VARCHAR(64), + icecast_server_id VARCHAR(64) REFERENCES icecast_servers(id) ON DELETE CASCADE, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -ALTER TABLE icecast_servermounts ADD CONSTRAINT server_mount_uniqkey UNIQUE (server_id, mount_id); +ALTER TABLE icecast_server_mounts ADD CONSTRAINT server_mount_uniqkey UNIQUE (icecast_mount_id, icecast_server_id); -CREATE TABLE icecast_serverrelays ( +CREATE TABLE icecast_server_relays ( id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), - relay_id VARCHAR(64) REFERENCES icecast_relays(id) ON DELETE CASCADE, - server_id VARCHAR(64) REFERENCES icecast_servers(id) ON DELETE CASCADE, + icecast_relay_id VARCHAR(64) REFERENCES icecast_relays(id) ON DELETE CASCADE, + icecast_server_id VARCHAR(64) REFERENCES icecast_servers(id) ON DELETE CASCADE, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -ALTER TABLE icecast_serverrelays ADD CONSTRAINT server_relay_uniqkey UNIQUE (server_id, relay_id); +ALTER TABLE icecast_server_relays ADD CONSTRAINT server_relay_uniqkey UNIQUE (icecast_relay_id, icecast_server_id); -CREATE TABLE icecast_serversockets ( +CREATE TABLE icecast_server_sockets ( id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), - socket_id VARCHAR(64) REFERENCES icecast_listen_sockets(id) ON DELETE CASCADE, - server_id VARCHAR(64) REFERENCES icecast_servers(id) ON DELETE CASCADE, + icecast_listen_socket_id VARCHAR(64) REFERENCES icecast_listen_sockets(id) ON DELETE CASCADE, + icecast_server_id VARCHAR(64) REFERENCES icecast_servers(id) ON DELETE CASCADE, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -ALTER TABLE icecast_serversockets ADD CONSTRAINT server_socket_uniqkey UNIQUE (server_id, socket_id); +ALTER TABLE icecast_server_sockets ADD CONSTRAINT server_socket_uniqkey UNIQUE (icecast_listen_socket_id, icecast_server_id); diff --git a/ruby/Gemfile b/ruby/Gemfile index c60e7fca3..ca3ab001a 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -30,6 +30,7 @@ gem 'resque' gem 'resque-retry' gem 'resque-failed-job-mailer' #, :path => "/Users/seth/workspace/resque_failed_job_mailer" gem 'oj' +gem 'builder' if devenv gem 'jam_db', :path=> "../db/target/ruby_package" diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index b756eadb8..b9dbfbdbf 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -99,13 +99,13 @@ require "jam_ruby/models/icecast_directory" require "jam_ruby/models/icecast_limit" require "jam_ruby/models/icecast_listen_socket" require "jam_ruby/models/icecast_logging" -require "jam_ruby/models/icecast_mastersvr_relay" +require "jam_ruby/models/icecast_master_server_relay" require "jam_ruby/models/icecast_mount" require "jam_ruby/models/icecast_path" require "jam_ruby/models/icecast_relay" -require "jam_ruby/models/icecast_sercurity" +require "jam_ruby/models/icecast_security" require "jam_ruby/models/icecast_server" -require "jam_ruby/models/icecast_servermisc" +#require "jam_ruby/models/icecast_servermisc" require "jam_ruby/models/icecast_user_authentication" include Jampb diff --git a/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb b/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb index 0e1a57808..dc84bb3b4 100644 --- a/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb +++ b/ruby/lib/jam_ruby/models/icecast_admin_authentication.rb @@ -1,102 +1,23 @@ -module JAmXml - def jdumpXml (hash, nm, ident=1, output=$stdout, child=nil) - - tb = "\t" - tbs = tb * ident - - unless ident <= 0 - tbse = tb * (ident-1) - output.puts "#{tbse}<#{nm}>" - end - - hash.each do |key, val| - #puts "attrib: key=#{key} val=#{val}" - - el = key - if !key.nil? && !key.empty? - el = key.gsub(/_/, '-') - end - - - sv = val - if val.to_s.empty? - #skip ??? - next if val.to_s.empty? - else - if val.instance_of? String - #encode the string to be xml safe - sv = CGI.escapeHTML(val) - end - end - - if key.empty? - output.puts "#{tbs}<#{sv}/>" - else - output.puts "#{tbs}<#{el}>#{sv}" - end - end - - if !child.nil? - if child.kind_of? Array - child.each { |x| x.dumpXml(ident+1,output)} - else - child.dumpXml(ident+1,output) - end - end - unless ident <= 0 - output.puts "#{tbse}" - end - end - - def jMakeStrXmlSafe(val) - sv = val - if val.to_s.empty? - #skip ??? - sv ="" - else - if val.instance_of? String - #encode the string to be xml safe - sv = CGI.escapeHTML(val) - end - end - return sv - end -end - - - module JamRuby class IcecastAdminAuthentication < ActiveRecord::Base - include JAmXml - attr_accessible :source_password, :relay_user, :relay_password, :admin_user, :admin_password - #myattr_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' + has_many :servers, :class_name => "JamRuby::IcecastServer", :inverse_of => :admin_auth, :foreign_key => "admin_auth_id" validates :source_password, presence: true, length: {minimum: 5} validates :admin_password, presence: true, length: {minimum: 5} + validates :relay_user, presence: true, length: {minimum: 5} + validates :relay_password, presence: true, length: {minimum: 5} + validates :admin_user, presence: true, length: {minimum: 5} - def dumpXml (ident=1, output=$stdout) - hash = Hash["source_password" => self.source_password, - "relay_user" => self.relay_user, - "relay_password" => self.relay_password, - "admin_user" => self.admin_user, - "admin_password" => self.admin_password] + def dumpXml (builder) - self.jdumpXml(hash,"authentication", ident,output) + builder.tag! 'authentication' do |auth| + auth.tag! 'source-password', source_password + auth.tag! 'admin-user', admin_user + auth.tag! 'relay-user', relay_user + auth.tag! 'relay-password', relay_password + auth.tag! 'admin-password', admin_password + end 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 79f0f012a..d2672fa00 100644 --- a/ruby/lib/jam_ruby/models/icecast_directory.rb +++ b/ruby/lib/jam_ruby/models/icecast_directory.rb @@ -1,17 +1,20 @@ module JamRuby class IcecastDirectory < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' + has_many :servers, :class_name => "JamRuby::IcecastServer", :inverse_of => :directory, :foreign_key => "directory_id" - attr_accessible :yp_url_timeout, :yp_url - validates :yp_url_timeout, numericality: {only_integer: true}, length: {in: 1..30} + validates :yp_url_timeout, presence: true, numericality: {only_integer: true}, length: {in: 1..30} + validates :yp_url, presence: true - def dumpXml (ident=1, output=$stdout) - hash = Hash["yp_url_timeout" => self.yp_url_timeout, - "yp_url" => self.yp_url] - self.jdumpXml(hash, "directory", ident, output) + def dumpXml (builder) + + builder.tag! 'directory' do |dir| + dir.tag! 'yp-url-timeout', yp_url_timeout + dir.tag! 'yp-url', yp_url + end end + + 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 b3670b8bd..da0d4b9d2 100644 --- a/ruby/lib/jam_ruby/models/icecast_limit.rb +++ b/ruby/lib/jam_ruby/models/icecast_limit.rb @@ -1,37 +1,28 @@ module JamRuby class IcecastLimit < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' + has_many :servers, class_name: 'JamRuby::IcecastServer', inverse_of: :limit, foreign_key: 'limit_id' - attr_accessible :clients, :sources, :queue_size, :client_timeout, :header_timeout, :source_timeout, :burst_size + validates :clients, presence: true, numericality: {only_integer: true}, length: {in: 1..15000} + validates :sources, presence: true, numericality: {only_integer: true}, length: {in:1..10000} + validates :queue_size, presence: true, numericality: {only_integer: true} + validates :client_timeout, presence: true, numericality: {only_integer: true} + validates :header_timeout, presence: true, numericality: {only_integer: true} + validates :source_timeout, presence: true, numericality: {only_integer: true} + validates :burst_size, presence: true, numericality: {only_integer: true} - validates :clients, numericality: {only_integer: true}, length: {in: 1..15000} + def dumpXml (builder) - - after_initialize :init - - - def init - 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 dumpXml (ident=1, output=$stdout) - hash = Hash["clients" => self.clients, - "sources" => self.sources, - "queue_size" => self.queue_size, - "client_timeout" => self.client_timeout, - "header_timeout" => self.header_timeout] - hash.merge! "source_timeout" => self.source_timeout, - "burst_size" => self.burst_size - self.jdumpXml(hash, "limits", ident, output) + builder.tag! 'limits' do |limits| + limits.tag! 'clients', clients + limits.tag! 'sources', sources + limits.tag! 'queue-size', queue_size + limits.tag! 'client-timeout', client_timeout + limits.tag! 'header-timeout', header_timeout + limits.tag! 'source-timeout', source_timeout + limits.tag! 'burst-on-connect', 1 + limits.tag! 'burst-size', burst_size + end 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 65d721b1a..eef194d34 100644 --- a/ruby/lib/jam_ruby/models/icecast_listen_socket.rb +++ b/ruby/lib/jam_ruby/models/icecast_listen_socket.rb @@ -1,21 +1,19 @@ module JamRuby class IcecastListenSocket < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - - attr_accessible :port, :bind_address, :shoutcast_mount, :shoutcast_compat belongs_to :server, :class_name => "JamRuby::IcecastServer" , :inverse_of => :sockets + has_and_belongs_to_many :servers, :class_name => "JamRuby::IcecastServer", :join_table => "icecast_server_sockets" - def dumpXml (ident=1, output=$stdout) - hash = Hash["port" => self.port, - "bind_address" => self.bind_address, - "shoutcast_mount" => self.shoutcast_mount, - "shoutcast_compat" => self.shoutcast_compat] + validates :port, presence: true, numericality: {only_integer: true}, length: {in: 1..65535} + validates :shoutcast_compat, :inclusion => {:in => [nil, true, false]} - self.jdumpXml(hash, "listen-socket", ident, output) + def dumpXml (builder) + builder.tag! 'listen-socket' do |listen| + listen.tag! 'port', port + listen.tag! 'bind-address', bind_address if bind_address + listen.tag! 'shoutcast-mount', shoutcast_mount if shoutcast_mount + listen.tag! 'shoutcast-compat', shoutcast_compat ? 1 : 0 unless shoutcast_compat.nil? + end 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 45cd97401..cf10c6256 100644 --- a/ruby/lib/jam_ruby/models/icecast_logging.rb +++ b/ruby/lib/jam_ruby/models/icecast_logging.rb @@ -1,20 +1,23 @@ module JamRuby class IcecastLogging < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - attr_accessible :accesslog, :errorlog, :playlistlog, :loglevel + has_many :servers, :class_name => "JamRuby::IcecastServer", :inverse_of => :logging, :foreign_key => "logging_id" - def dumpXml (ident=1, output=$stdout) - - hash = Hash["accesslog" => self.accesslog, - "errorlog" => self.errorlog, - "loglevel" => self.loglevel, - "playlistlog" => self.playlistlog] - - self.jdumpXml(hash, "logging", ident, output) + validates :access_log, presence: true + validates :error_log, presence: true + validates :log_level, :inclusion => {:in => [1, 2, 3, 4]} + validates :log_archive, :inclusion => {:in => [nil, true, false]} + validates :log_size, numericality: {only_integer: true}, if: lambda {|m| m.log_size.present?} + def dumpXml(builder) + builder.tag! 'logging' do |log| + log.tag! 'accesslog', access_log + log.tag! 'errorlog', error_log + log.tag! 'playlistlog', playlist_log if playlist_log + log.tag! 'logsize', log_size if log_size + log.tag! 'logarchive', log_archive ? '1' : '0' unless log_archive.nil? + log.tag! 'loglevel', log_level + end end - end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_master_server_relay.rb b/ruby/lib/jam_ruby/models/icecast_master_server_relay.rb new file mode 100644 index 000000000..3e99a5a19 --- /dev/null +++ b/ruby/lib/jam_ruby/models/icecast_master_server_relay.rb @@ -0,0 +1,22 @@ +module JamRuby + class IcecastMasterServerRelay < ActiveRecord::Base + + has_many :servers, :class_name => "JamRuby::IcecastServer", :inverse_of => :master_relay, :foreign_key => "master_relay_id" + + validates :master_server, presence: true, length: {minimum: 1} + validates :master_server_port, presence: true, numericality: {only_integer: true}, length: {in: 1..65535} + validates :master_update_interval, presence: true, numericality: {only_integer: true}, length: {in: 1..1200} + validates :master_username, presence: true, length: {minimum: 5} + validates :master_password, presence: true, length: {minimum: 5} + validates :relays_on_demand, :inclusion => {:in => [true, false]} + + def dumpXml(builder) + builder.tag! 'master-server', master_server + builder.tag! 'master-server-port', master_server_port + builder.tag! 'master-update-interval', master_update_interval + builder.tag! 'master-username', master_username + builder.tag! 'master-password', master_password + builder.tag! 'relays-on-demand', relays_on_demand ? '1' : '0' + 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 deleted file mode 100644 index 8cb9bd3a9..000000000 --- a/ruby/lib/jam_ruby/models/icecast_mastersvr_relay.rb +++ /dev/null @@ -1,18 +0,0 @@ -module JamRuby - class IcecastMastersvrRelay < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - attr_accessible :master_server, :master_server_port, :master_username, :master_password, :relays_on_demand - validates :master_password, :master_username, presence: true - - def dumpXml (ident=0, output=$stdout) - hash = Hash["master_server" => self.master_server, - "master_server_port" => self.master_server_port, - "master_username" => self.master_username, - "master_password" => self.master_password, - "relays_on_demand" => self.relays_on_demand] - - self.jdumpXml(hash, "masterrelay", ident, output) - 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 91b5873a6..5b938707e 100644 --- a/ruby/lib/jam_ruby/models/icecast_mount.rb +++ b/ruby/lib/jam_ruby/models/icecast_mount.rb @@ -1,64 +1,65 @@ module JamRuby class IcecastMount < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - attr_accessible :mount_name, :username, :password, :max_listeners, :max_listener_duration, :dump_file - attr_accessible :intro, :fallback_mount, :fallback_override, :fallback_when_full, :charset - attr_accessible :publicc, :stream_name, :stream_description, :stream_url, :genre, :bitrate - attr_accessible :mtype, :subtype, :hidden, :burst_size, :mp3_metadata_interval, :on_connect, :on_disconnect + belongs_to :authentication, class_name: "JamRuby::IcecastUserAuthentication", inverse_of: :mount + has_and_belongs_to_many :servers, :class_name => "JamRuby::IcecastServer", :join_table => "icecast_server_mounts" validates :mount_name, presence: true - validates :username, presence: true - validates :password, presence: true + validates :username, length: {minimum: 5}, if: lambda {|m| m.username.present?} + validates :password, length: {minimum: 5}, if: lambda {|m| m.password.present?} + validates :max_listeners, length: {in: 1..15000}, if: lambda {|m| m.max_listeners.present?} + validates :max_listener_duration, length: {in: 1..3600 * 48}, if: lambda {|m| m.max_listener_duration.present?} + validates :fallback_override, :inclusion => {:in => [true, false]} , if: lambda {|m| m.fallback_mount.present?} + validates :fallback_when_full, :inclusion => {:in => [true, false]} , if: lambda {|m| m.fallback_mount.present?} + validates :is_public, presence: true, :inclusion => {:in => [-1, 0, 1]} + validates :stream_name, presence: true + validates :stream_description, presence: true + validates :stream_url, presence: true + validates :genre, presence: true + validates :bitrate, numericality: {only_integer: true}, if: lambda {|m| m.bitrate.present?} + validates :mime_type, presence: true + validates :subtype, presence: true + validates :burst_size, numericality: {only_integer: true}, if: lambda {|m| m.burst_size.present?} + validates :mp3_metadata_interval, numericality: {only_integer: true}, if: lambda {|m| m.mp3_metadata_interval.present?} + validates :hidden, presence: true, :inclusion => {:in => [true, false]} - #has_one :authentication, :class_name => "IcecastUserAuthentication" - has_one :authentication, :class_name => "IcecastUserAuthentication" - belongs_to :servermount, :class_name => "JamRuby::IcecastServermount" , :inverse_of => :mount - def dumpXml (ident=1, output=$stdout) - hash = Hash["mount_name" => self.mount_name, - "username" => self.username, - "password" => self.password, - "max_listeners" => self.max_listeners, - "max_listener_duration" => self.max_listener_duration, - "dump_file" => self.dump_file, + def dumpXml(builder) + builder.tag! 'mount' do |mount| + mount.tag! 'mount-name', mount_name + mount.tag! 'username', username if username + mount.tag! 'password', password if password + mount.tag! 'max-listeners', max_listeners if max_listeners + mount.tag! 'max-listener-duration', max_listener_duration if max_listener_duration + mount.tag! 'dump-file', dump_file if dump_file + mount.tag! 'intro', intro if intro + mount.tag! 'fallback-mount', fallback_mount if fallback_mount + mount.tag! 'fallback-override', fallback_override ? '1' : '0' unless fallback_override.nil? + mount.tag! 'fallback-when-full', fallback_when_full ? '1' : '0' unless fallback_when_full.nil? + mount.tag! 'charset', charset if charset + mount.tag! 'public', is_public + mount.tag! 'stream-name', stream_name if stream_name + mount.tag! 'stream-description', stream_description if stream_description + mount.tag! 'stream-url', stream_url if stream_url + mount.tag! 'genre', genre if genre + mount.tag! 'bitrate', bitrate if bitrate + mount.tag! 'type', mime_type + mount.tag! 'subtype', subtype + mount.tag! 'burst-size', burst_size if burst_size + mount.tag! 'mp3-metadata-interval', mp3_metadata_interval if mp3_metadata_interval + mount.tag! 'hidden', hidden ? '1' : '0' + mount.tag! 'on-connect', on_connect if on_connect + mount.tag! 'on-disconnect', on_disconnect if on_disconnect - "intro" => self.intro, - "fallback_mount" => self.fallback_mount, - "fallback_override" => self.fallback_override, - "fallback_when_full" => self.fallback_when_full, - "charset" => self.charset, - - "public" => self.publicc, - "stream_name" => self.stream_name, - "stream_description" => self.stream_description, - "stream_url" => self.stream_url, - "genre" => self.genre, - "bitrate" => self.bitrate, - - "type" => self.mtype, - "subtype" => self.subtype, - "hidden" => self.hidden, - "burst_size" => self.burst_size, - "mp3_metadata_interval" => self.mp3_metadata_interval, - "on_connect" => self.on_connect, - "on_disconnect" => self.on_disconnect - ] - - self.jdumpXml(hash, "mount", ident, output, self.authentication) - end - - def getMediaUrl - if !self.servermount.nil? - @server = self.servermount.server - @misc = @server.misc - url = "http://" + @misc.hostname + self.mount_name - return url; - else - raise ("Undefined severid") + authentication.dumpXml(builder) if authentication end end + + def get_media_url + raise "Unassociated server to mount" if self.server_mount.nil? + + "http://" + server_mount.server.hostname + self.mount_name + 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 19edb23ab..682f55165 100644 --- a/ruby/lib/jam_ruby/models/icecast_path.rb +++ b/ruby/lib/jam_ruby/models/icecast_path.rb @@ -1,25 +1,26 @@ module JamRuby class IcecastPath < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - attr_accessible :basedir, :logdir, :pidfile, :webroot, :adminroot, :allow_ip, :deny_ip, :aliass + has_many :servers, :class_name => "JamRuby::IcecastServer", :inverse_of => :path, :foreign_key => "path_id" - def dumpXml (ident=1, output=$stdout) + validates :base_dir, presence: true + validates :log_dir, presence: true + validates :pid_file, presence: true + validates :web_root, presence: true + validates :admin_root, presence: true - a = "alias #{self.aliass}" - hash = Hash["basedir" => self.basedir, - "logdir" => self.logdir, - "pidfile" => self.pidfile, - "webroot" => self.webroot, - "adminroot" => self.adminroot, + def dumpXml (builder) - "allow_ip" => self.allow_ip, - "deny_ip" => self.deny_ip, - "" => a, - ] - self.jdumpXml(hash, "paths", ident, output) + builder.tag! 'paths' do |paths| + paths.tag! 'basedir', base_dir + paths.tag! 'logdir', log_dir + paths.tag! 'pidfile', pid_file + paths.tag! 'webroot', web_root + paths.tag! 'adminroot', admin_root + paths.tag! 'allow-ip', allow_ip if allow_ip + paths.tag! 'deny-ip', deny_ip if deny_ip + paths.tag! 'alias', :source => alias_source, :dest => alias_dest if alias_source + end 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 74f693f57..978997a06 100644 --- a/ruby/lib/jam_ruby/models/icecast_relay.rb +++ b/ruby/lib/jam_ruby/models/icecast_relay.rb @@ -1,35 +1,25 @@ module JamRuby class IcecastRelay < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - attr_accessible :server, :port, :mount, :local_mount, :username, :password, :relay_shoutcast_metadata, :on_demand + has_and_belongs_to_many :servers, :class_name => "JamRuby::IcecastServer", :join_table => "icecast_server_relays" - validates :port, numericality: {only_integer: true}, length: {in: 1..65000} + validates :port, presence: true, numericality: {only_integer: true}, length: {in: 1..65535} validates :mount, presence: true validates :server, presence: true - validates :local_mount, presence: true - validates :username, presence: true - validates :password, presence: true + validates :relay_shoutcast_metadata, :inclusion => {:in => [true, false]} + validates :on_demand, presence: true, :inclusion => {:in => [true, false]} - belongs_to :sserver, :class_name => "JamRuby::IcecastServerrelay" - - - def dumpXml (ident=1, output=$stdout) - - hash = Hash["server" => self.server, - "port" => self.port, - "mount" => self.mount, - "local_mount" => self.local_mount, - "username" => self.username, - - "password" => self.password, - "relay_shoutcast_metadata" => self.relay_shoutcast_metadata, - "on_demand" => self.on_demand - ] - self.jdumpXml(hash, "relay", ident, output) + def dumpXml (builder) + builder.tag! 'relay' do |listen| + listen.tag! 'server', server + listen.tag! 'port', port + listen.tag! 'mount', mount + listen.tag! 'local-mount', local_mount if local_mount + listen.tag! 'username', username if username + listen.tag! 'password', password if password + listen.tag! 'relay-shoutcast-metadata', relay_shoutcast_metadata ? 1 : 0 + listen.tag! 'on-demand', on_demand ? 1 : 0 + end end - - end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_security.rb b/ruby/lib/jam_ruby/models/icecast_security.rb new file mode 100644 index 000000000..6a9c1ca56 --- /dev/null +++ b/ruby/lib/jam_ruby/models/icecast_security.rb @@ -0,0 +1,20 @@ +module JamRuby + class IcecastSecurity < ActiveRecord::Base + + has_many :servers, :class_name => "JamRuby::IcecastServer", :inverse_of => :security, :foreign_key => "security_id" + + validates :chroot, :inclusion => {:in => [true, false]} + + def dumpXml(builder) + builder.tag! 'security' do |security| + security.tag! 'chroot', chroot ? '1' : '0' + if change_owner_user + security.tag! 'changeowner' do + security.tag! 'user', change_owner_user + security.tag! 'group', change_owner_group + end + end + end + 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 deleted file mode 100644 index 3a8dafef8..000000000 --- a/ruby/lib/jam_ruby/models/icecast_sercurity.rb +++ /dev/null @@ -1,41 +0,0 @@ -module JamRuby - class IcecastSecurity < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - - attr_accessible :chroot, :changeowner_user, :changeowner_group - - validates :chroot, numericality: {only_integer: true}, length: {in: 0..1} - - - def dumpXml (ident=1, output=$stdout) - - tb = "\t" - tbs = tb * (ident) - tbs2 = tb * (ident+1) - tbse = tb * (ident-1) - if tbse.empty? || tbse.nil? - tbse="" - end - - - nm = "security" - output.puts "#{tbse}<#{nm}>" - - output.puts "#{tbs}#{self.chroot}" - output.puts "#{tbs}" - - v = jMakeStrXmlSafe(self.changeowner_user) - output.puts "#{tbs2}#{v}" - - v = jMakeStrXmlSafe(self.changeowner_group) - output.puts "#{tbs2}#{v}" - - output.puts "#{tbs}" - - output.puts "#{tbse}" - - 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 c753e44e0..f872a6481 100644 --- a/ruby/lib/jam_ruby/models/icecast_server.rb +++ b/ruby/lib/jam_ruby/models/icecast_server.rb @@ -1,77 +1,63 @@ module JamRuby class IcecastServer < ActiveRecord::Base - include JAmXml - self.primary_key = 'id' - has_one :limit, :class_name => "JamRuby::IcecastLimit" , foreign_key: "id" - has_one :adminauth, :class_name => "JamRuby::IcecastAdminAuthentication" , foreign_key: "id" - has_one :directory, :class_name => "JamRuby::IcecastDirectory" , foreign_key: "id" - has_one :misc, :class_name => "JamRuby::IcecastServermisc" , foreign_key: "id" + belongs_to :limit, :class_name => "JamRuby::IcecastLimit", foreign_key: 'limit_id', :inverse_of => :servers + belongs_to :admin_auth, :class_name => "JamRuby::IcecastAdminAuthentication", foreign_key: 'admin_auth_id', :inverse_of => :servers + belongs_to :directory, :class_name => "JamRuby::IcecastDirectory", foreign_key: 'directory_id', :inverse_of => :servers + belongs_to :master_relay, :class_name => "JamRuby::IcecastMasterServerRelay", foreign_key: 'master_relay_id', :inverse_of => :servers + belongs_to :path, :class_name => "JamRuby::IcecastPath", foreign_key: 'path_id', :inverse_of => :servers + belongs_to :logging, :class_name => "JamRuby::IcecastLogging", foreign_key: 'logging_id', :inverse_of => :servers + belongs_to :security, :class_name => "JamRuby::IcecastSecurity", foreign_key: 'security_id', :inverse_of => :servers - has_one :master_relay, :class_name => "JamRuby::IcecastMastersvrRelay" , foreign_key: "id" + has_and_belongs_to_many :mounts, :class_name => "JamRuby::IcecastMount", :join_table => "icecast_server_mounts" + has_and_belongs_to_many :listen_sockets, :class_name => "JamRuby::IcecastListenSocket", :join_table => "icecast_server_sockets" + has_and_belongs_to_many :relays, :class_name => "JamRuby::IcecastRelay", :join_table => "icecast_server_relays" - has_many :smounts, :class_name => "JamRuby::IcecastServermount" - has_many :mounts, :class_name => "JamRuby::IcecastMount", :through => :smounts + validates :config_changed, :inclusion => {:in => [true, false]} + validates :hostname, presence: true + validates :location, presence: true + validates :admin_email, presence: true + validates :fileserve, :inclusion => {:in => [true, false]} + validates :server_id, presence: true - has_many :ssockets, :class_name => "JamRuby::IcecastServersocket" - has_many :sockets, :class_name => "JamRuby::IcecastListenSocket" ,:through => :ssockets + validates :limit, presence: true + validates :admin_auth, presence: true + validates :path, presence: true + validates :logging, presence: true + validates :security, presence: true + validates :listen_sockets, length: {minimum: 1} - has_many :srelays, :class_name => "JamRuby::IcecastServerrelay" , :inverse_of => :server - has_many :relays, :class_name => "JamRuby::IcecastRelay" , :through => :srelays + def dumpXml (output=$stdout, indent=1) + builder = ::Builder::XmlMarkup.new(:target => output, :indent => indent) - has_one :path, :class_name => "JamRuby::IcecastPath" , foreign_key: "id" - has_one :logging, :class_name => "JamRuby::IcecastLogging" , foreign_key: "id" - has_one :security, :class_name => "JamRuby::IcecastSecurity" , foreign_key: "id" + builder.tag! 'icecast' do |icecast| + icecast.tag! 'hostname', hostname + icecast.tag! 'location', location + icecast.tag! 'admin', admin_email + icecast.tag! 'fileserve', fileserve ? 1 : 0 + icecast.tag! 'server-id', server_id - def dumpXml (ident=1, output=$stdout) - ident += 1 - unless self.limit.nil? - self.limit.dumpXml(ident,output) + limit.dumpXml(builder) unless limit.nil? + admin_auth.dumpXml(builder) unless admin_auth.nil? + directory.dumpXml(builder) unless directory.nil? + master_relay.dumpXml(builder) unless master_relay.nil? + path.dumpXml(builder) unless path.nil? + logging.dumpXml(builder) unless logging.nil? + security.dumpXml(builder) unless security.nil? + + relays.each do |relay| + relay.dumpXml(builder) + end + + listen_sockets.each do |listen_socket| + listen_socket.dumpXml(builder) + end + + mounts.each do |mount| + mount.dumpXml(builder) + end end - unless self.adminauth.nil? - self.adminauth.dumpXml(ident,output) - end - - unless self.directory.nil? - self.directory.dumpXml(ident,output) - end - - unless self.misc.nil? - self.misc.dumpXml(ident,output) - end - - unless self.master_relay.nil? - self.master_relay.dumpXml(ident,output) - end - - - unless self.path.nil? - self.path.dumpXml(ident,output) - end - - unless self.logging.nil? - self.logging.dumpXml(ident,output) - end - - unless self.security.nil? - self.security.dumpXml(ident,output) - end - - - self.relays.each do |rl| - sock.rl(ident,output) - end - - self.sockets.each do |sock| - sock.dumpXml(ident,output) - end - - self.mounts.each do |mount| - mount.dumpXml(ident,output) - end - end - end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_servermount.rb b/ruby/lib/jam_ruby/models/icecast_server_mount.rb similarity index 64% rename from ruby/lib/jam_ruby/models/icecast_servermount.rb rename to ruby/lib/jam_ruby/models/icecast_server_mount.rb index 633bc6af2..ec48dd2ea 100644 --- a/ruby/lib/jam_ruby/models/icecast_servermount.rb +++ b/ruby/lib/jam_ruby/models/icecast_server_mount.rb @@ -1,14 +1,12 @@ module JamRuby - class IcecastServermount < ActiveRecord::Base + class IcecastServerMount < ActiveRecord::Base self.primary_key = 'id' - belongs_to :mount, :class_name => "JamRuby::IcecastMount" , :inverse_of => :servermount + belongs_to :mount, :class_name => "JamRuby::IcecastMount" , :inverse_of => :server_mount belongs_to :server, :class_name => "JamRuby::IcecastServer" validates :server_id, :presence => true - validates :mount_id, :presence => true - - + validates :mount_id, :presence => true end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/icecast_serverrelay.rb b/ruby/lib/jam_ruby/models/icecast_server_relay.rb similarity index 83% rename from ruby/lib/jam_ruby/models/icecast_serverrelay.rb rename to ruby/lib/jam_ruby/models/icecast_server_relay.rb index 14b80220c..a80bd8dde 100644 --- a/ruby/lib/jam_ruby/models/icecast_serverrelay.rb +++ b/ruby/lib/jam_ruby/models/icecast_server_relay.rb @@ -1,5 +1,5 @@ module JamRuby - class IcecastServerrelay < ActiveRecord::Base + class IcecastServerRelay < ActiveRecord::Base self.primary_key = 'id' diff --git a/ruby/lib/jam_ruby/models/icecast_serversocket.rb b/ruby/lib/jam_ruby/models/icecast_server_socket.rb similarity index 55% rename from ruby/lib/jam_ruby/models/icecast_serversocket.rb rename to ruby/lib/jam_ruby/models/icecast_server_socket.rb index c677e23d2..dde090f3c 100644 --- a/ruby/lib/jam_ruby/models/icecast_serversocket.rb +++ b/ruby/lib/jam_ruby/models/icecast_server_socket.rb @@ -1,14 +1,13 @@ module JamRuby - class IcecastServersocket < ActiveRecord::Base + class IcecastServerSocket < ActiveRecord::Base self.primary_key = 'id' - belongs_to :socket, :class_name => "JamRuby::IcecastListenSocket" , foreign_key: "id" - belongs_to :server, :class_name => "JamRuby::IcecastServer" , foreign_key: "id" + belongs_to :socket, :class_name => "JamRuby::IcecastListenSocket" + belongs_to :server, :class_name => "JamRuby::IcecastServer" validates :socket_id, :presence => true validates :server_id, :presence => true - 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 cdc2b2c95..c88c34a7d 100644 --- a/ruby/lib/jam_ruby/models/icecast_servermisc.rb +++ b/ruby/lib/jam_ruby/models/icecast_servermisc.rb @@ -1,14 +1,6 @@ module JamRuby - class IcecastServermisc < ActiveRecord::Base - include JAmXml + class IcecastServerMisc < ActiveRecord::Base self.primary_key = 'id' - attr_accessible :hostname, :location, :admin, :fileserve, :server_id - - - def dumpXml (ident=0, output=$stdout) - - 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 a28056bae..538d82efd 100644 --- a/ruby/lib/jam_ruby/models/icecast_user_authentication.rb +++ b/ruby/lib/jam_ruby/models/icecast_user_authentication.rb @@ -1,77 +1,41 @@ module JamRuby class IcecastUserAuthentication < ActiveRecord::Base - include JAmXml - 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 + has_one :mount, class_name: 'JamRuby::IcecastMount', inverse_of: :authentication + + validates :authentication_type, presence: true, :inclusion => {:in => ["url", "htpasswd"]} + validates :allow_duplicate_users, :inclusion => {:in => [true, false]}, if: :htpasswd_auth? + validates :username, length: {minimum: 5}, if: :url_auth? + validates :password, length: {minimum: 5}, if: :url_auth? + validates :mount_add, presence: true, if: :url_auth? + validates :mount_remove, presence: true, if: :url_auth? + validates :listener_add, presence: true, if: :url_auth? + validates :listener_remove, presence: true, if: :url_auth? + validates :auth_header, presence: true, if: :url_auth? + validates :timelimit_header, presence: true, if: :url_auth? - - validates :stype, presence: true - - def dumpXml (ident=1, output=$stdout) - - tb = "\t" - tbs = tb * (ident) - tbse = tb * (ident-1) - if tbse.empty? || tbse.nil? - tbse="" + def dumpXml (builder) + builder.tag! 'authentication', type: authentication_type do |auth| + auth.tag! 'option', name: 'mount_add', value: mount_add if mount_add + auth.tag! 'option', name: 'mount_remove', value: mount_remove if mount_remove + auth.tag! 'option', name: 'username', value: username if username + auth.tag! 'option', name: 'password', value: password if password + auth.tag! 'option', name: 'listener_add', value: listener_add if listener_add + auth.tag! 'option', name: 'listener_remove', value: listener_remove if listener_remove + auth.tag! 'option', name: 'auth_header', value: auth_header if auth_header + auth.tag! 'option', name: 'timelimit_header', value: timelimit_header if timelimit_header end - - if self.stype.nil? - return - elsif self.stype.empty? - return - elsif self.stype == "htpasswd" - nm = "" - - output.puts "#{tbse}#{nm}" - fname = jMakeStrXmlSafe(self.filename) - - output.puts "#{tbs}