File Coverage

blib/lib/Win32/WindowsMedia.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Win32::WindowsMedia;
2              
3 1     1   22614 use warnings;
  1         3  
  1         30  
4 1     1   6 use strict;
  1         2  
  1         38  
5 1     1   406 use Win32::OLE qw( in with HRESULT );
  0            
  0            
6             use Win32::OLE::Const "Windows Media Services Server Object Model and Plugin 9.0 Type Library";
7             use Win32::WindowsMedia::BaseVariables;
8              
9             =head1 NAME
10              
11             Win32::WindowsMedia - Base Module for Provisiong and control for Windows Media Services
12              
13             =head1 VERSION
14              
15             Version 0.258
16              
17             =cut
18              
19             our $VERSION = '0.258';
20              
21             =head1 SYNOPSIS
22              
23             This is a module to control Windows Media services for a Windows 2003/2008 server. This is a
24             complete change to the pre-alpha releases (0.15 and 0.16) as all functions are now in one module.
25             To create a Windows Media control instance do the following
26              
27             use Win32::WindowsMedia;
28             use strict;
29              
30             my $main =new Win32::WindowsMedia;
31              
32             my $create_server = $main->Server_Create("127.0.0.1");
33              
34             The $create_server variable should return 1 on success or 0 on failure. You can then call the other
35             functions against the main object, an example would be
36              
37             my $publishing_point = $main->Publishing_Point_Create( "127.0.0.1","andrew", "push:*", "broadcast" );
38              
39             If you can create objects for multiple addresses (need to be in the same domain) you call the functions
40             against the specific IPs. Most uses of the module will be against the local instance of Windows Media which
41             should be 127.0.0.1
42              
43             =head1 Server FUNCTIONS
44              
45             =item C<< Server_Create >>
46              
47             This function create an instance to communicate with the Windows Media Server running. You
48             can specify an IP address, however 99% of the time it should be one of the local interface
49             IPs or localhost(127.0.0.1). It does not matter which IP is used as Windows Media services
50             is not bound to a specific IP.
51              
52             Server_Create( "" );
53              
54             Example of Use
55              
56             my $result = $main->Server_Create("127.0.0.1");
57              
58             On success $result will return 1, on failure 0. If there is a failure error is set and can be retrieved.
59              
60             =item C<< Server_Destroy >>
61              
62             This function destroys an instance created to communicate with the Windows Media Server running. You
63             must specify the IP address used to create the instance.
64              
65             Server_Destroy( "" );
66              
67             Example of Use
68              
69             my $result = $main->Server_Destroy("127.0.0.1");
70              
71             On success $result will return 1, on failure 0. If there is a failure, error is set and can be retrieved.
72              
73             =head1 Control FUNCTIONS
74              
75             =item C<< Publishing_Point_Create >>
76              
77             This function creates a new publishing point on the Windows Media server specified. You need to specify
78             the publishing point, the URL to use ( see example ) and also the type ( again see example ). This function
79             is called through eval ( do not worry if you have no idea what this means ). If the URL specified is invalid
80             Windows Media services will attempt to resolve it and return an invalid callback via OLE. This causes any
81             scripts to stop without warning thus eval catches this nicely.
82              
83             Publishing_Point_Create( "", "", "", "" );
84              
85             Publishing point name - Can be any alphanumeric and _ characters
86             URL - can be one of push:* , or http:/// for relay
87             Type - Can be one of OnDemand, Broadcast, CacheProxyOnDemand, CacheProxyBroadcast
88              
89             Example of Use
90              
91             my $result = $main->Publishing_Point_Create("127.0.0.1","andrew","push:*","broadcast");
92              
93             On success $result will return 1, on failure 0. If there is a failure, error is set and can be retrieved.
94              
95             =item C<< Publishing_Point_Remove >>
96              
97             This function removes the publishing point name specified. You need to specify the IP and the publishing
98             point name.
99              
100             Publishing_Point_Remove( "", "" );
101              
102             my $result = $main->Publishing_Point_Remove("127.0.0.1","andrew");
103              
104             On success $result will return 1, on failure 0. If there is a failure, error is set and can be retrieved.
105              
106             =item C<< Publishing_Point_Start >>
107              
108             This function is only required if the publishing point in question is not using Push and auto start is off.
109              
110             Publishing_Point_Start( "", "" );
111              
112             Example of Use
113              
114             my $result = $main->Publishing_Point_Start("127.0.0.1","andrew");
115              
116             On success $result will return 1, on failure 0. If there is a failure, error is set and can be retrieved.
117              
118             =item C<< Publishing_Point_Stop >>
119              
120             This can be used on all types of publishing points and causes the source to be disconnected. If auto start
121             is configured on the publishing point will not stop for long, max 30 seconds. If auto start on client
122             connection it will be stopped until a client reconnects.
123              
124             Publishing_Point_Stop( "", "" );
125              
126             Example of Use
127              
128             my $result = $main->Publishing_Point_Stop("127.0.0.1","andrew");
129              
130             On success $result will return 1, on failure 0. If there is a failure, error is set and can be retrieved.
131              
132             =item C<< Publishing_Point_List >>
133              
134             This function returns an array of the currently provisioned publishing point names. You *may* find at least
135             two which do not show up in the Windows Media adminitration panel. These are for proxy and cache use and
136             should be ignored. You can optionally specify a partial match name which will then only return those
137             publishing points that match.
138              
139             Publishing_Point_List( "", "" );
140              
141             Example of Use
142              
143             my @publishing_point = $main->Publishing_Point_List( "127.0.0.1", "*");
144              
145             The above will return all publishing points defined.
146              
147             =item C<< Publishing_Point_Authorization_ACL_Add >>
148              
149             This function adds a username to the authorization list allowed to connect to this stream. The defaults
150             are dependent on the Parent configuration, but you can change them at this level. In order to make a change
151             you must first delete a user, you can not add them again ( their previous entry will remain so adding them
152             again with a different mask will not have any effect ).
153              
154             Publishing_Point_Authorization_ACL_Add ("","","
155              
156             The is made up of a username as the key and their mask being comma seperated entries made
157             up from UserAccessSettings function. The allowable entries are
158              
159             ACCESSINIT
160             ReadDeny
161             WriteDeny
162             CreateDeny
163             AllDeny
164             UNKNOWN
165             ReadAllow
166             WriteAllow
167             CreateAllow
168             AllAllow
169              
170             To build an entry use the following
171              
172             my %user_list = (
173             'Username' => 'ReadAllow,WriteAllow'
174             'username2' => 'ReadAllow'
175             );
176              
177             This would allow the user 'Username' to read and write to the stream ( so push ), and also allow user 'username2' to
178             read from the stream ( so listen ).
179              
180             You must remember the server must have these usernames configured, or accessable otherwise it will fail (silently). You
181             can specify a username in a domain, such if the server is configured in a domain, and do to so requires you to put the domain
182             before the username. To change 'Username' to be part of a domain it should be changed to 'domain\\Username' where 'domain'
183             is the name of the domain the user is in. Note the double \ is required.
184              
185             There is a SPECIAL user called 'Everyone' ( well it is a user defined on the server by default ) and is configured so
186             that if added to the publishing point it allows anyone to listen. If you do not want to use username/password for encoders
187             to connect you need to remove and then re-add Everyone with permissions of ReadAllow,WriteAllow.
188              
189             Example of Use
190              
191             my %user_list = ( 'Everyone' => 'ReadAllow,WriteAllow');
192             $main->Publishing_Point_Authorization_ACL_Remove( "127.0.0.1", "publishing_point", \%user_list);
193             $main->Publishing_Point_Authorization_ACL_Add( "127.0.0.1", "publishing_point", \%user_list);
194              
195             This will remove the username Everyone from the ACL then add it back in with read and write permissions.
196              
197             =item C<< Publishing_Point_Authorization_ACL_Remove >>
198              
199             This function removes a username from the authorization list allowed to connect to this stream. The defaults
200             are dependent on the Parent configuration, but you can change them at this level.
201              
202             Publishing_Point_Authorization_ACL_Remove ("","","
203              
204             Example of Use
205              
206             my %user_list = ( 'Everyone' => 'ReadAllow,WriteAllow');
207             $main->Publishing_Point_Authorization_ACL_Remove( "127.0.0.1", "publishing_point", \%user_list);
208              
209             =item C<< Publishing_Point_Authorization_ACL_List >>
210              
211             This function lists the usernames and their permissions currently defined on the publishing point. The function
212             requires pointer to a hash which is populated with the username as the key and the value is the numerical value
213             of the access mask.
214              
215             Publishing_Point_Authorization_ACL_List ("","","
216              
217             Example of Use
218              
219             my %user_list;
220             $main->Publishing_Point_Authorization_ACL_List( "127.0.0.1", "publishing_point", \%user_list);
221              
222             =item C<< Publishing_Point_Log_Set >>
223              
224             This function sets up the logging facility for the publishing point named. You should only set the variables
225             you need and leave the others as default.
226              
227             Publishing_Point_Log_Set( "","","
228              
229             Example of Use
230              
231             my %log_settings =
232             (
233             'Template' => 'D:\Andrew\logs-.log',
234             'Cycle' => 'Month',
235             'UseLocalTime' => 'Yes',
236             'UseBuffering' => 'Yes',
237             'UseUnicode' => 'Yes',
238             'V4Compat' => 'No',
239             'MaxSize' => 0,
240             'RoleFilter' => 'SHAMROCK',
241             'LoggedEvents' => 'Player,Local'
242             );
243              
244             $main->Publishing_Point_Log_Set("127.0.0.1","publishing_point",\%log_settings);
245              
246             Cycle can be one of None Size Month Week Day Hour
247              
248             MaxSize is in Mbytes and only used when Cycle is Size
249              
250             LoggedEvents can be None Player Distribution Local Remote Filter seperated by a comma (,)
251              
252             You can also use FreeSpaceQuota. This has a default of 10, which means 10Mbytes. The attribute means
253             how much free space should be available for logging to work.
254              
255             =item C<< Publishing_Point_Log_Enable >>
256              
257             This function turns on the logging plugin. If you make changes using Publishing_Point_Log_Set you need
258             to call Publishing_Point_Log_Disable and then Publishing_Point_Log_Enable for them to take effect.
259              
260             Publishing_Point_Log_Enable("","");
261              
262             Example of Use
263              
264             $main->Publishing_Point_Log_Enable("127.0.0.1","publishing_point");
265              
266             =item C<< Publishing_Point_Log_Disable >>
267              
268             This function turns off the logging plugin. If you make changes using Publishing_Point_Log_Set you need
269             to call Publishing_Point_Log_Disable and then Publishing_Point_Log_Enable for them to take effect.
270              
271             Publishing_Point_Log_Disable("","");
272              
273             Example of Use
274              
275             $main->Publishing_Point_Log_Disable("127.0.0.1","publishing_point");
276              
277             =item C<< Publishing_Point_Log_Cycle >>
278              
279             This function cycles the log file immediately rather than waiting for the log time.
280              
281             Publishing_Point_Log_Cycle("","");
282              
283             Example Of Use
284              
285             $main->Publishing_Point_Log_Cycle("127.0.0.1","publishing_point");
286              
287             =item C<< Publishing_Point_Authorization_IPAddress_Add >>
288              
289             =item C<< Publishing_Point_Authorization_IPAddress_Remove >>
290              
291             =item C<< Publishing_Point_Authorization_IPAddress_Get >>
292              
293             =item C<< Publishing_Point_General_Set >>
294              
295             =item C<< Publishing_Point_General_Get >>
296              
297             =item C<< Publishing_Point_Players_Get >>
298              
299             =item C<< Server_CoreVariable_Get >>
300              
301             =head1 Playlist FUNCTIONS
302              
303             =item C<< Playlist_Jump_To_Event >>
304              
305             This function jumps to a specific section of the current playlist. You need to make sure the playlist
306             you are using is constructed correctly for this to work. You have to specify the server IP, publishing
307             point name and position in the playlist (known as event). If any of the entries are incorrect or the
308             playlist is not correct it will FAIL to jump and return no error.
309              
310             Playlist_Jump_To_Event( "", "", "" );
311              
312             Example of Use
313              
314             my $result = $main->Playlist_Jump_To_Event("127.0.0.1","andrew","position2");
315              
316             On success $result will return 1, on failure 0. If there is a failure, error is set and can be retrieved.
317             If an incorrect event, publishing point or IP are specified no error is usually returned.
318              
319             =cut
320              
321             sub new {
322              
323             my $self = {};
324             bless $self;
325              
326             my ( $class , $attr ) =@_;
327              
328             while (my($field, $val) = splice(@{$attr}, 0, 2))
329             { $self->{_GLOBAL}{$field}=$val; }
330              
331             $self->{_GLOBAL}{'STATUS'}="OK";
332              
333             return $self;
334             }
335              
336             sub Server_Create
337             {
338             my $self = shift;
339             my $server_ip = shift;
340             if ( !$server_ip )
341             {
342             $self->set_error("IP Address of Windows Media Server required");
343             return 0;
344             }
345             my $server_object = new Win32::OLE( [ $server_ip , "WMSServer.Server" ] );
346             if ( !$server_object )
347             {
348             $self->set_error("OLE Object Failed To Initialise");
349             # need to add error capture here
350             return 0;
351             }
352             $self->{_GLOBAL}{'Server'}{$server_ip}=$server_object;
353             return 1;
354             }
355              
356             sub Server_Destroy
357             {
358             my ( $self ) = shift;
359             my ( $server_ip ) = shift;
360             if ( !$server_ip )
361             {
362             $self->set_error("IP Address of Windows Media Server required");
363             return 0;
364             }
365             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
366             {
367             $self->set_error("IP Address Specified Has No Server");
368             return 0;
369             }
370              
371             undef $self->{_GLOBAL}{'Server'}{$server_ip};
372             delete $self->{_GLOBAL}{'Server'}{$server_ip};
373             return 1;
374             }
375              
376              
377             sub Server_ExportXML
378             {
379             my $self = shift;
380             my $server_ip = shift;
381             my $filename = shift;
382             if ( !$server_ip )
383             { $self->set_error("IP Address of Windows Media Server required");
384             return 0; }
385             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
386             { $self->set_error("IP Address Specified Has No Server");
387             return 0; }
388             if ( !$filename )
389             { $self->set_error("Filename Not Specified");
390             return 0; }
391              
392             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
393              
394             $server_object->ExportXML($filename);
395             return 1;
396             }
397              
398             # Playlist functions go here.
399              
400             sub Playlist_Jump_To_Event
401             {
402             my $self = shift;
403             my $server_ip = shift;
404             my $publishing_point_name = shift;
405             my $event_name = shift;
406             if ( !$server_ip )
407             { $self->set_error("IP Address of Windows Media Server required");
408             return 0; }
409             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
410             { $self->set_error("IP Address Specified Has No Server");
411             return 0; }
412              
413             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
414              
415             if ( !$server_object->PublishingPoints($publishing_point_name) )
416             {
417             $self->set_error("Publishing Point Not Defined");
418             return 0;
419             }
420              
421             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
422             if ( $publishing_point->{BroadCastStatus}!=2 )
423             {
424             $self->set_error("Publishing Point Not Active");
425             return 0;
426             }
427              
428             my $publishing_point_playlist = $publishing_point->{SharedPlaylist};
429             if ( !$publishing_point_playlist )
430             {
431             $self->set_error("Playlist not defined");
432             return 0;
433             }
434              
435             my $error = $publishing_point_playlist->FireEvent( $event_name );
436             return 1;
437             }
438              
439             sub Publishing_Point_Authorization_ACL_Enable
440             {
441             my $self = shift;
442             my $server_ip = shift;
443             my $publishing_point_name = shift;
444             if ( !$server_ip )
445             { $self->set_error("IP Address of Windows Media Server required");
446             return 0; }
447             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
448             { $self->set_error("IP Address Specified Has No Server");
449             return 0; }
450             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
451             if ( !$server_object->PublishingPoints($publishing_point_name) )
452             { $self->set_error("Publishing Point Not Defined"); return 0; }
453             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
454             my $User_Control = $publishing_point->EventHandlers("WMS Publishing Points ACL Authorization");
455             ${$User_Control}{'Enabled'}=1;
456             return 1;
457             }
458              
459             sub Publishing_Point_Authorization_ACL_Disable
460             {
461             my $self = shift;
462             my $server_ip = shift;
463             my $publishing_point_name = shift;
464             if ( !$server_ip )
465             { $self->set_error("IP Address of Windows Media Server required");
466             return 0; }
467             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
468             { $self->set_error("IP Address Specified Has No Server");
469             return 0; }
470             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
471             if ( !$server_object->PublishingPoints($publishing_point_name) )
472             { $self->set_error("Publishing Point Not Defined"); return 0; }
473             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
474             my $User_Control = $publishing_point->EventHandlers("WMS Publishing Points ACL Authorization");
475             ${$User_Control}{'Enabled'}=0;
476             return 1;
477             }
478              
479              
480             sub Publishing_Point_Authorization_ACL_Add
481             {
482             my $self = shift;
483             my $server_ip = shift;
484             my $publishing_point_name = shift;
485             my $limit_parameters = shift;
486             if ( !$server_ip )
487             { $self->set_error("IP Address of Windows Media Server required");
488             return 0; }
489             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
490             { $self->set_error("IP Address Specified Has No Server");
491             return 0; }
492              
493             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
494             if ( !$server_object->PublishingPoints($publishing_point_name) )
495             { $self->set_error("Publishing Point Not Defined"); return 0; }
496             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
497             my $limit_variables = Win32::WindowsMedia::BaseVariables->UserAccessSettings();
498             my $User_Control = $publishing_point->EventHandlers("WMS Publishing Points ACL Authorization");
499             my $User_Custom = $User_Control->CustomInterface();
500             my $User_List = $User_Custom->AccessControlList();
501             foreach my $user ( keys %{$limit_parameters} )
502             {
503             my $user_mask = ${$limit_parameters}{$user};
504             my $user_value;
505             foreach my $mask_name ( split(/,/,$user_mask) )
506             {
507             foreach my $limit_names ( keys %{$limit_variables} )
508             {
509             if ( $mask_name=~/${$limit_variables}{$limit_names}/i )
510             {
511             if ( $mask_name=~/^AllowAll$/i || $mask_name=~/^DenyAll$/i )
512             { $user_value=$limit_names; }
513             else
514             { $user_value+=$limit_names; }
515             }
516             }
517             }
518             my $add_user=$User_List->Add( $user, $user_value );
519             }
520             return 1;
521             }
522              
523             sub Publishing_Point_Authorization_ACL_List
524             {
525             my $self = shift;
526             my $server_ip = shift;
527             my $publishing_point_name = shift;
528             my $users_configured = shift;
529             if ( !$server_ip )
530             { $self->set_error("IP Address of Windows Media Server required");
531             return 0; }
532             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
533             { $self->set_error("IP Address Specified Has No Server");
534             return 0; }
535              
536             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
537             if ( !$server_object->PublishingPoints($publishing_point_name) )
538             { $self->set_error("Publishing Point Not Defined"); return 0; }
539             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
540             my $User_Control = $publishing_point ->EventHandlers("WMS Publishing Points ACL Authorization");
541             my $User_Custom = $User_Control->CustomInterface();
542             my $User_List = $User_Custom->AccessControlList();
543             for ($a=0;$a< ${$User_List}{'Count'}; $a++)
544             {
545             my $info= ${$User_List}{$a};
546             my $name = ${$info}{'Trustee'};
547             my $user_mask = ${$info}{'AccessMask'};
548             ${$users_configured}{$name}=$user_mask;
549             }
550             return 1;
551             }
552              
553             sub Publishing_Point_Authorization_ACL_Remove
554             {
555             my $self = shift;
556             my $server_ip = shift;
557             my $publishing_point_name = shift;
558             my $limit_parameters = shift;
559              
560             if ( !$server_ip )
561             { $self->set_error("IP Address of Windows Media Server required");
562             return 0; }
563              
564             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
565             { $self->set_error("IP Address Specified Has No Server");
566             return 0; }
567              
568             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
569              
570             if ( !$server_object )
571             { $self->set_error("Server Object Not Set"); return 0; }
572              
573             if ( !$server_object->PublishingPoints($publishing_point_name) )
574             { $self->set_error("Publishing Point Not Defined"); return 0; }
575              
576             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
577             my $User_Control = $publishing_point ->EventHandlers("WMS Publishing Points ACL Authorization");
578             my $User_Custom = $User_Control->CustomInterface();
579             my $User_List = $User_Custom->AccessControlList();
580             foreach my $user ( keys %{$limit_parameters} )
581             {
582             my $add_user=$User_List->Remove( $user );
583             }
584             return 1;
585             }
586              
587             sub Publishing_Point_Authorization_IPAddress_Add
588             {
589             my $self = shift;
590             my $server_object = shift;
591             my $publishing_point_name = shift;
592             my $ip_list_type = shift;
593             my $limit_parameters = shift;
594             if ( !$server_object )
595             { $self->set_error("Server Object Not Set"); return 0; }
596             if ( !$server_object->PublishingPoints($publishing_point_name) )
597             { $self->set_error("Publishing Point Not Defined"); return 0; }
598             if ( $ip_list_type!~/^AllowIP$/ && $ip_list_type!~/^DisallowIP$/ )
599             { $self->set_error("AllowIP or DisallowIP are the only valid types requested '$ip_list_type'"); return 0; }
600             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
601             my $IP_Control = $publishing_point ->EventHandlers("WMS IP Address Authorization");
602             my $IP_Custom = $IP_Control->CustomInterface();
603             my $IPList = ${$IP_Custom}{$ip_list_type};
604             foreach my $entry (@{$limit_parameters})
605             {
606             # Probably need to put some IP address and mask checking
607             # in here so not to pass crap to the WindowsMediaService as it appears
608             # to go a little screwy if you do.
609             my ( $address, $netmask ) = (split(/,/,$entry))[0,1];
610             $IPList->Add( $address, $netmask );
611             }
612             return 1;
613             }
614              
615             sub Publishing_Point_Authorization_IPAddress_Remove
616             {
617             my $self = shift;
618             my $server_object = shift;
619             my $publishing_point_name = shift;
620             my $ip_list_type = shift;
621             my $limit_parameters = shift;
622             if ( !$server_object )
623             { $self->set_error("Server Object Not Set"); return 0; }
624             if ( !$server_object->PublishingPoints($publishing_point_name) )
625             { $self->set_error("Publishing Point Not Defined"); return 0; }
626             if ( $ip_list_type!~/^AllowIP/ && $ip_list_type!~/^DisallowIP/ )
627             { $self->set_error("AllowIP or DisallowIP are the only valid types requested '$ip_list_type'"); return 0; }
628             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
629             my $IP_Control = $publishing_point ->EventHandlers("WMS IP Address Authorization");
630             my $IP_Custom = $IP_Control->CustomInterface();
631             my $IPList = ${$IP_Custom}{$ip_list_type};
632             if ( ${$IPList}{'Count'}>0 )
633             {
634             foreach my $address (@{$limit_parameters})
635             {
636             for ( $a=0; $a<${$IPList}{'Count'}; $a++ )
637             {
638             my $ip_entry = ${$IPList}{$a};
639             if ( ${$ip_entry}{'Address'}=~/$address/ )
640             {
641             $IPList->Remove ($a);
642             }
643             }
644             }
645             }
646             return 1;
647             }
648              
649             sub Publishing_Point_General_Set
650             {
651             my $self = shift;
652             my $server_object = shift;
653             my $publishing_point_name = shift;
654             my %limit_parameters = shift;
655             if ( !$server_object )
656             { $self->set_error("Server Object Not Set"); return 0; }
657             if ( !$server_object->PublishingPoints($publishing_point_name) )
658             { $self->set_error("Publishing Point Not Defined"); return 0; }
659             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
660             my $limit_variables = Win32::WindowsMedia::BaseVariables->PublishingPointGeneral();
661             foreach my $limit_name ( keys %limit_parameters )
662             {
663             if ( ${$limit_variables}{$limit_name} )
664             { $publishing_point->{ ${$limit_variables}{$limit_name} }=$limit_parameters{$limit_name}; }
665             }
666             return 1;
667             }
668              
669             sub Publishing_Point_General_Get
670             {
671             my $self = shift;
672             my $server_object = shift;
673             my $publishing_point_name = shift;
674             my $limit_values = shift;
675             if ( !$server_object )
676             { $self->set_error("Server Object Not Set"); return 0; }
677             if ( !$server_object->PublishingPoints($publishing_point_name) )
678             { $self->set_error("Publishing Point Not Defined"); return 0; }
679             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
680             my $limit_variables = Win32::WindowsMedia::BaseVariables->PublishingPointGeneral();
681             foreach my $limit_name ( keys %{$limit_variables} )
682             { ${$limit_values}{$limit_name}=${$publishing_point}{$limit_name}; }
683             return 1;
684             }
685              
686             sub Publishing_Point_Limits_Set
687             {
688             my $self = shift;
689             my $server_object = shift;
690             my $publishing_point_name = shift;
691             my %limit_parameters = shift;
692             if ( !$server_object )
693             { $self->set_error("Server Object Not Set"); return 0; }
694             if ( !$server_object->PublishingPoints($publishing_point_name) )
695             { $self->set_error("Publishing Point Not Defined"); return 0; }
696             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
697             my $Limits = $publishing_point->{Limits};
698             my $limit_variables = Win32::WindowsMedia::BaseVariables->PublishingPointLimits();
699             foreach my $limit_name ( keys %limit_parameters )
700             {
701             if ( ${$limit_variables}{$limit_name} )
702             { $Limits->{ ${$limit_variables}{$limit_name} }=$limit_parameters{$limit_name}; }
703             }
704             return 1;
705             }
706              
707             sub Publishing_Point_Limits_Get
708             {
709             my $self = shift;
710             my $server_object = shift;
711             my $publishing_point_name = shift;
712             my $limit_values = shift;
713             if ( !$server_object )
714             { $self->set_error("Server Object Not Set"); return 0; }
715             if ( !$server_object->PublishingPoints($publishing_point_name) )
716             { $self->set_error("Publishing Point Not Defined"); return 0; }
717             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
718             my $Limits = $publishing_point->{Limits};
719             my $limit_variables = Win32::WindowsMedia::BaseVariables->PublishingPointLimits();
720             foreach my $limit_name ( keys %{$limit_variables} )
721             { ${$limit_values}{$limit_name}=${$Limits}{$limit_name}; }
722             return 1;
723             }
724              
725             sub Publishing_Point_Start
726             {
727             my $self = shift;
728             my $server_ip = shift;
729             my $publishing_point_name = shift;
730             if ( !$server_ip )
731             {
732             $self->set_error("IP Address of Windows Media Server required");
733             return 0;
734             }
735             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
736             {
737             $self->set_error("IP Address Specified Has No Server");
738             return 0;
739             }
740             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
741             if ( !$server_object )
742             { $self->set_error("Server Object Not Set"); return 0; }
743             if ( !$server_object->PublishingPoints($publishing_point_name) )
744             { $self->set_error("Publishing Point Not Defined"); return 0; }
745             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
746             #if ( ${$publishing_point}{'Path'}=~/^push:\*/i )
747             # { $self->set_error("Push Publishing Points Can Not Be Started"); return 0; }
748             $publishing_point->Start();
749             return 1;
750             }
751              
752             sub Publishing_Point_Stop
753             {
754             my $self = shift;
755             my $server_ip = shift;
756             my $publishing_point_name = shift;
757             if ( !$server_ip )
758             {
759             $self->set_error("IP Address of Windows Media Server required");
760             return 0;
761             }
762             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
763             {
764             $self->set_error("IP Address Specified Has No Server");
765             return 0;
766             }
767             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
768             if ( !$server_object )
769             { $self->set_error("Server Object Not Set"); return 0; }
770             if ( !$server_object->PublishingPoints($publishing_point_name) )
771             { $self->set_error("Publishing Point Not Defined"); return 0; }
772             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
773             #if ( ${$publishing_point}{'Path'}=~/^push:\*/i )
774             # { $self->set_error("Push Publishing Points Can Not Be Stopped"); return 0; }
775             $publishing_point->Stop();
776             return 1;
777             }
778              
779             sub Publishing_Point_Remove
780             {
781             my $self = shift;
782             my $server_ip = shift;
783             my $publishing_point_name = shift;
784             if ( !$server_ip )
785             {
786             $self->set_error("IP Address of Windows Media Server required");
787             return 0;
788             }
789             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
790             {
791             $self->set_error("IP Address Specified Has No Server");
792             return 0;
793             }
794             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
795              
796             if ( !$server_object )
797             { $self->set_error("Server Object Not Set"); return 0; }
798             if ( !$server_object->PublishingPoints($publishing_point_name) )
799             { $self->set_error("Publishing Point Not Defined"); return 0; }
800             my $publishing_points = $server_object->PublishingPoints;
801             my $publishing_point_del = $publishing_points->Remove(
802             $publishing_point_name
803             );
804             undef $publishing_points;
805             if ( !$publishing_point_del )
806             { $self->set_error("Publishing Point Remove Error"); return 0; }
807             return 1;
808             }
809              
810             sub Publishing_Point_Create
811             {
812             my $self = shift;
813             my $server_ip = shift;
814             my $publishing_point_name = shift;
815             my $publishing_point_url = shift;
816             my $publishing_point_type = shift;
817              
818             # type can be a name or number,
819             # 'OnDemand', 'Broadcast', 'CacheProxyOnDemand', 'CacheProxyBroadcast'
820             my $real_pub_point_type=0;
821             if ( !$server_ip )
822             {
823             $self->set_error("IP Address of Windows Media Server required");
824             return 0;
825             }
826             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
827             {
828             $self->set_error("IP Address Specified Has No Server");
829             return 0;
830             }
831             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
832              
833             my $limit_variables = Win32::WindowsMedia::BaseVariables->PublishingPointType();
834             foreach my $pub_type ( keys %{$limit_variables} )
835             {
836             if ( ${$limit_variables}{$pub_type}=~/$publishing_point_type/i )
837             {
838             $real_pub_point_type=$pub_type;
839             }
840             }
841              
842             if ( !$real_pub_point_type )
843             {
844             my $publishing_point_types;
845             foreach my $pub_type ( keys %{$limit_variables} )
846             { $publishing_point_types.="${$limit_variables}{$pub_type},"; }
847             chop($publishing_point_types);
848             $self->set_error("Invalid Publishing Point Type Specified must be one of $publishing_point_types");
849             undef $publishing_point_types;
850             return 0;
851             }
852              
853             $publishing_point_url="push:*" if !$publishing_point_url;
854              
855             if ( $publishing_point_name!~/^[0-9a-zA-Z\-_]+$/ )
856             {
857             $self->set_error("Publishing Point Name Invalid");
858             return 0;
859             }
860              
861             if ( length($publishing_point_name)<3 )
862             {
863             $self->set_error("Publishing Point Name Too Short");
864             return 0;
865             }
866              
867             if ( !$server_object )
868             {
869             $self->set_error("Server Object Not Set");
870             return 0;
871             }
872              
873             if ( $server_object->PublishingPoints($publishing_point_name) )
874             {
875             $self->set_error("Publishing Point Already Defined");
876             return 0;
877             }
878              
879             my $publishing_points = $server_object->PublishingPoints;
880              
881             # We need to eval this with a timer, why you might asked,
882             # well you can figure it out.
883              
884             my $publishing_point_new;
885             eval {
886             local $SIG{ALRM} = sub { die "Broken"; };
887             alarm 5;
888             $publishing_point_new = $publishing_points->Add(
889             $publishing_point_name,
890             $real_pub_point_type,
891             $publishing_point_url );
892             alarm 0;
893             };
894              
895             if ( !$publishing_point_new )
896             {
897             $self->set_error("Publishing Point Creation Failed");
898             return 0;
899             }
900              
901             undef $publishing_points;
902              
903             return $publishing_point_new;
904             }
905              
906             sub Publishing_Point_Path
907             {
908             my $self = shift;
909             my $server_ip = shift;
910             my $publishing_point_name = shift;
911             my $path = shift;
912             my $stop = $self->Publishing_Point_Stop($server_ip,$publishing_point_name);
913             if ( !$stop )
914             { return 0; }
915             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
916             if ( !$server_object )
917             { $self->set_error("Server Object Not Set"); return 0; }
918             if ( !$server_object->PublishingPoints($publishing_point_name) )
919             { $self->set_error("Publishing Point Not Defined"); return 0; }
920             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
921             ${$publishing_point}{'Path'} =$path;
922             return 1;
923             }
924              
925             sub Publishing_Point_List
926             {
927             my $self = shift;
928             my $server_ip = shift;
929             my $publishing_point_name = shift;
930             my (@found_publishing_points);
931             if ( !$server_ip )
932             {
933             $self->set_error("IP Address of Windows Media Server required");
934             return 0;
935             }
936             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
937             {
938             $self->set_error("IP Address Specified Has No Server");
939             return 0;
940             }
941             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
942             if ( !$server_object )
943             { $self->set_error("Server Object Not Set"); return 0; }
944              
945             for ( $a=0; $a< $server_object->PublishingPoints->{'length'}; $a++ )
946             {
947             if ( $server_object->PublishingPoints->{$a}->{'Name'}=~/$publishing_point_name/ig )
948             { push @found_publishing_points, $server_object->PublishingPoints->{$a}->{'Name'}; }
949             }
950              
951             return @found_publishing_points;
952             }
953              
954             sub Publishing_Point_Authorization_IPAddress_Get
955             {
956             my $self = shift;
957             my $server_object = shift;
958             my $publishing_point_name = shift;
959             my $ip_list_type = shift;
960             my $limit_values = shift;
961             if ( !$server_object )
962             { $self->set_error("Server Object Not Set"); return 0; }
963              
964             if ( !$server_object->PublishingPoints($publishing_point_name) )
965             { $self->set_error("Publishing Point Not Defined"); return 0; }
966              
967             if ( $ip_list_type!~/^AllowIP/ || $ip_list_type!~/^DisallowIP/ )
968             { $self->set_error("AllowIP or DisallowIP are the only valid types"); return 0; }
969              
970             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
971             my $IP_Control = $publishing_point ->EventHandlers("WMS IP Address Authorization");
972             my $IP_Custom = $IP_Control->CustomInterface();
973             my $IPList = ${$IP_Custom}{$ip_list_type};
974             # variables should be 'Address' and 'Mask'
975             if ( ${$IPList}{'Count'} > 0 )
976             {
977             for ($a=0; $a<${$IPList}{'Count'}; $a++ )
978             {
979             my $ip_entry = ${$IPList}{$a};
980             foreach my $variable ( keys %{$ip_entry} )
981             {
982             ${$limit_values}{$a}{$variable}=${$ip_entry}{$variable};
983             }
984             }
985             }
986             return 1;
987             }
988              
989              
990             sub Publishing_Point_Players_Get
991             {
992             my $self = shift;
993             my $server_object = shift;
994             my $publishing_point_name = shift;
995             my $limit_values = shift;
996             if ( !$server_object )
997             {
998             $self->set_error("Server Object Not Set");
999             return 0;
1000             }
1001              
1002             if ( !$server_object->PublishingPoints($publishing_point_name) )
1003             {
1004             $self->set_error("Publishing Point Not Defined");
1005             return 0;
1006             }
1007              
1008             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
1009             my $players = $publishing_point ->{Players};
1010             my $player_status = Win32::WindowsMedia::BaseVariables->PlayerStatus();
1011             if ( ${$players}{'Count'}>0 )
1012             {
1013             for ( $a=0; $a<${$players}{'Count'}; $a++ )
1014             {
1015             my $ip_client = ${$players}{$a};
1016             foreach my $variable ( keys %{$ip_client} )
1017             {
1018             ${$limit_values}{$a}{$variable}= ${$ip_client}{$variable};
1019             }
1020             ${$limit_values}{$a}{'Status'}=${$player_status}{ ${$limit_values}{$a}{'Status'} };
1021             }
1022             }
1023             return 1;
1024             }
1025              
1026             sub Publishing_Point_Log_Cycle
1027             {
1028             my ( $self ) = shift;
1029             my ( $server_ip ) = shift;
1030             my ( $publishing_point_name ) = shift;
1031             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
1032             {
1033             $self->set_error("IP Address Specified Has No Server");
1034             return 0;
1035             }
1036             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
1037             if ( !$server_object )
1038             {
1039             $self->set_error("OLE Object Failed To Initialise");
1040             # need to add error capture here
1041             return 0;
1042             }
1043             if ( !$server_object->PublishingPoints($publishing_point_name) )
1044             {
1045             $self->set_error("Publishing Point Not Defined");
1046             return 0;
1047             }
1048             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
1049             my $log_plugin=$publishing_point->EventHandlers("WMS Client Logging");
1050             my $log_custom =$log_plugin->CustomInterface();
1051             $log_custom->CycleNow();
1052             return 1;
1053             }
1054              
1055              
1056             sub Publishing_Point_Log_Set
1057             {
1058             my ( $self ) = shift;
1059             my ( $server_ip ) = shift;
1060             my ( $publishing_point_name ) = shift;
1061             my ( $template ) = shift;
1062              
1063             my ( $real_log_type );
1064              
1065             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
1066             {
1067             $self->set_error("IP Address Specified Has No Server");
1068             return 0;
1069             }
1070             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
1071             if ( !$server_object )
1072             {
1073             $self->set_error("OLE Object Failed To Initialise");
1074             # need to add error capture here
1075             return 0;
1076             }
1077             if ( !$server_object->PublishingPoints($publishing_point_name) )
1078             {
1079             $self->set_error("Publishing Point Not Defined");
1080             return 0;
1081             }
1082             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
1083              
1084             my $log_plugin=$publishing_point->EventHandlers("WMS Client Logging");
1085              
1086             my $log_custom =$log_plugin->CustomInterface();
1087              
1088             my $limit_variables = Win32::WindowsMedia::BaseVariables->ServerLogCycle();
1089             foreach my $log_type ( keys %{$limit_variables} )
1090             {
1091             if ( ${$limit_variables}{$log_type}=~/${$template}{'Cycle'}/i )
1092             {
1093             ${$template}{'Cycle'}=$log_type;
1094             }
1095             }
1096              
1097              
1098             my $option_transform = Win32::WindowsMedia::BaseVariables->Return_Yes_No();
1099              
1100             ${$log_custom}{'Template'}=${$template}{'Template'};
1101             ${$log_custom}{'Cycle'}=${$template}{'Cycle'};
1102             ${$log_custom}{'UseLocalTime'}=${$option_transform}{ ${$template}{'UseLocalTime'} };
1103             ${$log_custom}{'UseBuffering'}=${$option_transform}{ ${$template}{'UseBuffering'} };
1104             ${$log_custom}{'UseUnicode'}=${$option_transform}{ ${$template}{'UseUnicode'} };
1105             ${$log_custom}{'V4Compat'}=${$option_transform}{ ${$template}{'V4Compat'} };
1106              
1107             ${$log_custom}{'MaxSize'}=${$template}{'MaxSize'};
1108             ${$log_custom}{'RoleFilter'}=${$template}{'RoleFilter'};
1109              
1110             if ( ${$template}{'FreeSpaceQuota'} )
1111             { ${$log_custom}{'MaxSize'}=${$template}{'FreeSpaceQuota'}; }
1112              
1113             if ( ${$template}{'LoggedEvents'} )
1114             {
1115             my $log_value=0;
1116             my $log_variables = Win32::WindowsMedia::BaseVariables->ServerLogType();
1117             foreach my $log_entry ( split(/,/,${$template}{'LoggedEvents'}) )
1118             {
1119             foreach my $limit_names ( keys %{$log_variables} )
1120             {
1121             if ( $log_entry=~/${$log_variables}{$limit_names}/i )
1122             { $log_value+=$limit_names; }
1123             }
1124             }
1125             ${$log_custom}{'LoggedEvents'}=$log_value;
1126             }
1127              
1128             return 1;
1129             }
1130              
1131             sub Publishing_Point_Log_Disable
1132             {
1133             my ( $self ) = shift;
1134             my ( $server_ip ) = shift;
1135             my ( $publishing_point_name ) = shift;
1136             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
1137             {
1138             $self->set_error("IP Address Specified Has No Server");
1139             return 0;
1140             }
1141             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
1142             if ( !$server_object )
1143             {
1144             $self->set_error("OLE Object Failed To Initialise");
1145             # need to add error capture here
1146             return 0;
1147             }
1148             if ( !$server_object->PublishingPoints($publishing_point_name) )
1149             {
1150             $self->set_error("Publishing Point Not Defined");
1151             return 0;
1152             }
1153              
1154             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
1155              
1156             my $log_plugin=$publishing_point->EventHandlers("WMS Client Logging");
1157              
1158             ${$log_plugin}{'Enabled'}=0;
1159              
1160             return 1;
1161             }
1162              
1163             sub Publishing_Point_Log_Enable
1164             {
1165             my ( $self ) = shift;
1166             my ( $server_ip ) = shift;
1167             my ( $publishing_point_name ) = shift;
1168              
1169             if ( !$self->{_GLOBAL}{'Server'}{$server_ip} )
1170             {
1171             $self->set_error("IP Address Specified Has No Server");
1172             return 0;
1173             }
1174             my ( $server_object ) = $self->{_GLOBAL}{'Server'}{$server_ip};
1175             if ( !$server_object )
1176             {
1177             $self->set_error("OLE Object Failed To Initialise");
1178             # need to add error capture here
1179             return 0;
1180             }
1181             if ( !$server_object->PublishingPoints($publishing_point_name) )
1182             {
1183             $self->set_error("Publishing Point Not Defined");
1184             return 0;
1185             }
1186              
1187              
1188             my $publishing_point = $server_object->PublishingPoints( $publishing_point_name );
1189              
1190             my $log_plugin=$publishing_point->EventHandlers("WMS Client Logging");
1191              
1192             ${$log_plugin}{'Enabled'}=1;
1193              
1194             return 1;
1195             }
1196              
1197             sub Server_CoreVariable_Get
1198             {
1199             my $self = shift;
1200             my $server_object = shift;
1201             my $corevariable = shift;
1202             if ( !$server_object )
1203             {
1204             $self->set_error("Server Object Not Set");
1205             return 0;
1206             }
1207              
1208             if ( !$corevariable )
1209             {
1210             $self->set_error("Variable Name Required");
1211             return 0;
1212             }
1213              
1214             my $variable_names = Win32::WindowsMedia::BaseVariables->CoreVariableNames();
1215              
1216             foreach my $name ( keys %{$variable_names} )
1217             {
1218             if ( $name=~/$corevariable/i )
1219             {
1220             my $type = ${$variable_names}{$name};
1221             if ( $type!~/^read/i )
1222             {
1223             $self->set_error("Variable Name Not Value");
1224             return 0;
1225             }
1226             my $value = $server_object->{$name};
1227             return $value;
1228             }
1229             }
1230             $self->set_error("Variable Name Not Found");
1231             return 0;
1232             }
1233              
1234             sub set_error
1235             {
1236             my $self = shift;
1237             my $error = shift;
1238             $self->{_GLOBAL}{'STATUS'} = $error;
1239             return 1;
1240             }
1241              
1242             sub get_error
1243             {
1244             my $self = shift;
1245             return $self->{_GLOBAL}{'STATUS'};
1246             }
1247              
1248              
1249             =head1 AUTHOR
1250              
1251             Andrew S. Kennedy, C<< >>
1252              
1253             =head1 BUGS
1254              
1255             Please report any bugs or feature requests to
1256             C, or through the web interface at
1257             L.
1258             I will be notified, and then you'll automatically be notified of progress on
1259             your bug as I make changes.
1260              
1261             =head1 SUPPORT
1262              
1263             L
1264              
1265             =item * Search CPAN
1266              
1267             L
1268              
1269             =head1 ACKNOWLEDGEMENTS
1270              
1271             =head1 COPYRIGHT & LICENSE
1272              
1273             Copyright 2008 Andrew S. Kennedy, all rights reserved.
1274              
1275             This program is free software; you can redistribute it and/or modify it
1276             under the same terms as Perl itself.
1277              
1278             =cut
1279              
1280             1; # End of Win32::WindowsMedia