API-ISPManager

 view release on metacpan or  search on metacpan

lib/API/ISPManager.pm  view on Meta::CPAN


    return '' unless $params &&
        ref $params eq 'HASH' && %$params ;

    my $result = join '&', map { "$_=$params->{$_}" } sort keys %$params;
    warn $result if $DEBUG;

    return $result;
}

# Kill slashes at start / end string
# STATIC(STRING:input_string)
sub kill_start_end_slashes {
    my $str = shift;

    for ($str) {
        s/^\/+//sgi;
        s/\/+$//sgi;
    }
    
    return $str;
}

lib/API/ISPManager.pm  view on Meta::CPAN

        $params->{host};

    my $host       = delete $params->{host};
    my $path       = delete $params->{path}        || '';
    my $allow_http = delete $params->{allow_http}  || '';

    unless ($path) {
        $path = 'manager';
    }

    $path = kill_start_end_slashes($path);
    $host = kill_start_end_slashes($host);

    my $query_path = ( $allow_http ? 'http' : 'https' ) . "://$host/$path/ispmgr?";

    return %$params ? $query_path . mk_query_string($params) : '';
}


# Make request to server and get answer
# STATIC (STRING: query_string)
sub mk_query_to_server {

lib/API/ISPManager/misc.pm  view on Meta::CPAN

use strict;
use warnings;

use API::ISPManager;

sub reload {
    my $params = shift;

    my $server_answer = API::ISPManager::query_abstract(
        params      => $params,
        func        => 'restart',
    );

    if ( $server_answer && $server_answer->{elem} && ref $server_answer->{elem} eq 'HASH' ) {
        return { data =>  $server_answer->{elem} };
    }

    return $server_answer;
}

sub usrparam {

t/01-test.t  view on Meta::CPAN


$a = 'mk_query_string';
is( API::ISPManager::mk_query_string( {  }  ), '', $a );
is( API::ISPManager::mk_query_string( ''    ), '', $a );
is( API::ISPManager::mk_query_string( undef ), '', $a );
is( API::ISPManager::mk_query_string( { aaa => 111, bbb => 222 } ), 'aaa=111&bbb=222', $a );
is( API::ISPManager::mk_query_string( { bbb => 222, aaa => 111 } ), 'aaa=111&bbb=222', $a );
is( API::ISPManager::mk_query_string( [ ] ), '', $a );
is( API::ISPManager::mk_query_string( { dddd => 'dfdf' } ), 'dddd=dfdf', $a );

my $kill_start_end_slashes_test = {
    '////aaa////' => 'aaa',
    'bbb////'     => 'bbb',
    '////ccc'     => 'ccc', 
    ''            => '',
};

for (keys %$kill_start_end_slashes_test) {
    is(
        API::ISPManager::kill_start_end_slashes ($_),
        $kill_start_end_slashes_test->{$_},
        'kill_start_end_slashes'
    );
}

$a = 'mk_full_query_string';
is( API::ISPManager::mk_full_query_string( {
        host => $test_host, 
    } ), 
    '',
    $a
);

t/01-test.t  view on Meta::CPAN

    username => $ENV{username} || 'root',
    password => $ENV{password},
    host     => $test_host,
    path     => 'manager',
);

### Services

my $fake_services = <<DOC;
<?xml version="1.0" encoding="UTF-8"?>
<doc><elem><name>HTTP</name><proc>apache2</proc><autostart/><count>33</count><active/></elem><elem><name>FTP</name><proc>proftpd</proc><autostart/><count>1</count><active/></elem><elem><name>DNS</name><proc>named</proc><autostart/><count>1</count><ac...
DOC

is_deeply( API::ISPManager::services::get( { %correct_params }, $fake_services ), {
        'data' => {
            'FTP' => {
                'count' => '1',
                'proc' => 'proftpd',
                'autostart' => {},
                'active' => {}
            },
            'HTTP' => {
                'count' => '33',
                'proc' => 'apache2',
                'autostart' => {},
                'active' => {}
            },
            'SMTP' => {
                'count' => '1',
                'proc' => 'exim4',
                'autostart' => {},
                'active' => {}
            },
            'MySQL' => {
                'count' => '3',
                'proc' => 'mysqld',
                'autostart' => {}
            },
            'POP3' => {
                'count' => '2',
                'proc' => 'dovecot',
                'autostart' => {},
                'active' => {}
             },
            'DNS' => {
                'count' => '1',
                'proc' => 'named',
                'autostart' => {},
                'active' => {}
            }
        }
    },
    'services test'
);


### Services end



( run in 0.298 second using v1.01-cache-2.11-cpan-0d8aa00de5b )