smeserver-ddclient/root/usr/share/smanager/lib/SrvMngr/Controller/Ddclient.pm

1016 lines
33 KiB
Perl

package SrvMngr::Controller::Ddclient;
#----------------------------------------------------------------------
# heading : Network
# description : Dynamic Clients
# navigation : 6000 450
#
# name : ddclient, method : get, url : /ddclient, ctlact : Ddclient#main
# name : ddclient3, method : post, url : /ddclient3, ctlact : Ddclient#do_updateparams
# name : ddclient1, method : get, url : /ddclient1, ctlact : Ddclient#do_summary_domain
# name : ddclient2, method : get, url : /ddclient2, ctlact : Ddclient#do_summary_custom
# name : ddclient4, method : post, url : /ddclient4, ctlact : Ddclient#do_delete_domain
# name : ddclient5, method : get, url : /ddclient5, ctlact : Ddclient#do_update_domain
# name : ddclient6, method : get, url : /ddclient6, ctlact : Ddclient#do_create_custom
# name : ddclient7, method : post, url : /ddclient7, ctlact : Ddclient#do_create_custom_actual
# name : ddclient8, method : post, url : /ddclient8, ctlact : Ddclient#do_update_domain
#
# routes : end
#
# Documentation: https://wiki.contribs.org/Ddclient
#
#----------------------------------------------------------------------
#
# ddclient 3.9.1 Supportted services
#
#DynDNS.com - See http://www.dyndns.com for details on obtaining a free account.
#Hammernode - See http://www.hn.org for details on obtaining a free account.
#Zoneedit - See http://www.zoneedit.com for details.
#EasyDNS - See http://www.easydns.com for details.
#NameCheap - See http://www.namecheap.com for details
#DslReports - See http://www.dslreports.com for details
#Sitelutions - See http://www.sitelutions.com for details
#Loopia - See http://www.loopia.se for details
#Noip - See http://www.noip.com/ for details
#Freedns - See http://freedns.afraid.org/ for details
#ChangeIP - See http://www.changeip.com/ for details
#dtdns - See http://www.dtdns.com/ for details
#nsupdate - See nsupdate(1) and ddns-confgen(8) for details
#CloudFlare - See https://www.cloudflare.com/ for details
#Google - See http://www.google.com/domains for details
#Duckdns - See https://duckdns.org/ for details
#Freemyip - See https://freemyip.com for details
#woima.fi - See https://woima.fi/ for details
#Yandex - See https://domain.yandex.com/ for details
#DNS Made Easy - See https://dnsmadeeasy.com/ for details
#DonDominio - See https://www.dondominio.com for details
#NearlyFreeSpeech.net - See https://www.nearlyfreespeech.net/services/dns for details
#OVH - See https://www.ovh.com for details
#ClouDNS - See https://www.cloudns.net
# ddclient 3.11.1 Supported Services
# 1984:https://kb.1984hosting.com/doku.php?id=freedns
# changeip: https://changeip.com
# cloudflare: https://cloudflare.com
# cloudns: https://cloudns.com
# digitalocean: https://digitalocean.com
# dinahosting: https://dinahosting.com
# dnsexit: https://dnsexit.com/
# dnsmadeeasy: https://dnsmadeeasy.com
# domeneshop: https://domeneshop.com
# dondominio: https://dondominio.com
# dslreports: https://www.dslreports.com/
# duckdns: https://duckdns.com
# dyndns1:https://account.dyn.com/
# dyndns2: https://account.dyn.com/
# easydns: https://easydns.com
# enom: https://enom.com
# freedns: http://freedns.com
# freemyip: https://freemyip.com
# gandi: https://gandi.com
# godaddy: https://godaddy.com
# googledomains: https://googledomains.com
# hetzner: https://hetzner.com
# infomaniak: https://infomaniak.com
# keysystems: https://keysystems.com
# mythicdyn: https://www.mythic-beasts.com/support/api/dnsv2/dynamic-dns
# namecheap: https://namecheap.com
# nfsn: http://nfsn.com
# njalla: https://njalla.com
# noip: https://noip.com
# nsupdate: http://nsupdate.com
# ovh: https://ovh.com
# porkbun: https://porkbun.com
# regfishde: Cannot find link for this one
# sitelutions: https://sitelutions.com
# woima: http://woima.com
# yandex: https://yandex.com
# zoneedit: https://www.zoneedit.com/dynamic-dns/
use strict;
use warnings;
use Mojo::Base 'Mojolicious::Controller';
use constant FALSE => 0;
use constant TRUE => 1;
use Locale::gettext;
use SrvMngr::I18N;
use SrvMngr qw(theme_list init_session);
use Data::Dumper;
use esmith::util;
use esmith::HostsDB;
use esmith::AccountsDB;
our $db = esmith::ConfigDB->open();
our $adb = esmith::AccountsDB->open();
our $domaindb = esmith::ConfigDB->open('/home/e-smith/db/domains')
or die "Unable to open domains db";
our $edb;
$edb = esmith::ConfigDB->open('/home/e-smith/db/ddclient')
or $edb = esmith::ConfigDB->create('/home/e-smith/db/ddclient');
my %ddc_datas = ();
sub get_devices_names {
#
# Router/Firewall devices from which it can get ip address
#
my $devices = ( [
[ '2Wire 1701HG Gateway' => '2wire' ],
[ '3com 3c886a 56k Lan Modem' => '3com-3c886a' ],
[ '3com OfficeConnect Remote 812' => '3com-oc-remote812' ],
[ 'Alcatel Speed Touch 510' => 'alcatel-510' ],
[ 'Alcatel/Thomson SpeedTouch 530' => 'alcatel-530' ],
[ 'Alcatel Speed Touch Pro' => 'alcatel-stp' ],
[ 'Allnet 1298' => 'allnet-1298' ],
[ 'Cayman 3220-H DSL' => 'cayman-3220h' ],
[ 'D-Link DI-524' => 'dlink-524' ],
[ 'D-Link DI-604' => 'dlink-604' ],
[ 'dlink-614' => 'D-Link DI-614+' ],
[ 'e-tech' => 'E-tech Router' ],
[ 'elsa-lancom-dsl10' => 'ELSA LanCom DSL/10 DSL FW' ],
[ 'elsa-lancom-dsl10-ch01' => 'ELSA LanCom DSL/10 DSL FW (isdn ch01)' ],
[ 'elsa-lancom-dsl10-ch02' => 'ELSA LanCom DSL/10 DSL FW (isdn ch01)' ],
[ 'linksys' => 'Linksys FW' ],
[ 'linksys-rv042-wan1' => 'Linksys RV042 Dual Homed Router WAN Port 2' ],
[ 'linksys-rv042-wan2' => 'Linksys RV042 Dual Homed Router WAN Port 2' ],
[ 'linksys-ver2' => 'Linksys FW version 2' ],
[ 'linksys-ver3' => 'Linksys FW version 3' ],
[ 'linksys-wcg200' => 'Linksys WCG200 FW' ],
[ 'linksys-wrt854g' => 'Linksys WRT854G FW' ],
[ 'maxgate-ugate3x00' => 'MaxGate UGATE-3x00 FW' ],
[ 'netcomm-nb3' => 'NetComm NB3' ],
[ 'netgear-dg834g' => 'netgear-dg834g' ],
[ 'netgear-rp614' => 'Netgear RP614 FW' ],
[ 'netgear-rt3xx' => 'Netgear FW' ],
[ 'netgear-wgt624' => 'Netgear WGT624' ],
[ 'netgear-wpn824' => 'Netgear WPN824 FW' ],
[ 'netopia-r910' => 'Netopia R910 FW' ],
[ 'olitec-SX200' => 'olitec-SX200' ],
[ 'rtp300' => 'Linksys RTP300' ],
[ 'siemens-ss4200' => 'Siemens SpeedStream 4200' ],
[ 'sitecom-dc202' => 'Sitecom DC-202 FW' ],
[ 'smc-barricade' => 'SMC Barricade FW' ],
[ 'smc-barricade-7004vbr' => 'SMC Barricade FW (7004VBR model config)' ],
[ 'smc-barricade-7401bra' => 'SMC Barricade 7401BRA FW' ],
[ 'smc-barricade-alt' => 'SMC Barricade FW (alternate config)' ],
[ 'sohoware-nbg800' => 'SOHOWare BroadGuard NBG800' ],
[ 'sveasoft' => 'Sveasoft WRT54G/WRT54GS' ],
[ 'thomson-st536v6' => 'Thomson SpeedTouch 536v6' ],
[ 'thomson-tg782' => 'Thomson/Technicolor TG782' ],
[ 'vigor-2200usb' => 'Vigor 2200 USB' ],
[ 'watchguard-edge-x' => 'Watchguard Edge X FW' ],
[ 'watchguard-soho' => 'Watchguard SOHO FW' ],
[ 'westell-6100' => 'Westell C90-610015-06 DSL Router' ],
[ 'xsense-aero' => 'Xsense Aero' ]
] );
return $devices;
# Automatic loading of the devices from the ddclient program - I can't get this to pass the results successfully to the template
#my $output = `ddclient -list-devices`; # Run ddclient command to get devices output
#my @lines;
#foreach my $line (split /\n/, $output) {
#$line =~ s/\s+//; # Remove leading whitespace
#my ($field1, $field2) = split(' ', $line, 2);
#push @lines, [$field2, $field1];
#}
#return \@lines; # Return a reference to the lines array
}
sub get_web_services_names {
#
# Web Services from which it can get ip address
#
my $webservices = ( [
[ 'dyndns-http://checkip.dyndns.org/' => 'dyndns' ],
[ 'freedns-https://freedns.afraid.org/dynamic/check.php' => 'freedns' ],
[ 'googledomains-https://domains.google.com/checkip' => 'googledomains' ],
[ 'he-https://checkip.dns.he.net/' => 'he' ],
[ 'ip4only.me-https://ip4only.me/api/' => 'ip4only.me' ],
[ 'ip6only.me-https://ip6only.me/api/' => 'ip6only.me' ],
[ 'ipify-ipv4-https://api.ipify.org/' => 'ipify-ipv4' ],
[ 'ipify-ipv6-https://api6.ipify.org/' => 'ipify-ipv6' ],
[ 'loopia:-https://dns.loopia.se/checkip/checkip.php' => 'loopia' ],
[ 'myonlineportal-https://myonlineportal.net/checkip' => 'myonlineportal' ],
[ 'noip-ipv4-http://ip1.dynupdate.no-ip.com/' => 'noip-ipv4' ],
[ 'noip-ipv6-http://ip1.dynupdate6.no-ip.com/' => 'noip-ipv6' ],
[ 'nsupdate.info-ipv4-https://ipv4.nsupdate.info/myip' => 'nsupdate.info-ipv4' ],
[ 'nsupdate.info-ipv6-https://ipv6.nsupdate.info/myip' => 'nsupdate.info-ipv6' ],
[ 'zoneedit-https://dynamic.zoneedit.com/checkip.html' => 'zoneedit' ]
] );
return $webservices
#my $output = `ddclient -list-web-services`; # Run ddclient command to get web services output
#my @lines;
#foreach my $line (split /\n/, $output) {
#$line =~ s/\s+//; # Remove leading whitespace
#my ($field1, $field2) = split(' ', $line, 2);
#push @lines, [$field2, $field1];
#}
#return \@lines; # Return a reference to the lines array
}
sub get_dns_labels {
#
# dns service names
# Return array with translated results as well.
#
# Note that "new" ones willl not have any description / translation, this can be added to /usr/share/smanager/lib/SrvMngr/I18N/Modules/Ddclient
#
my $c = shift;
my $dnsservices = ( [
[ $c->l('1984') => '1984' ],
[ $c->l('changeip') => 'changeip' ],
[ $c->l('cloudflare') => 'cloudflare' ],
[ $c->l('cloudns') => 'cloudns' ],
[ $c->l('digitalocean') => 'digitalocean' ],
[ $c->l('dinahosting') => 'dinahosting' ],
[ $c->l('dnsexit') => 'dnsexit' ],
[ $c->l('dnsmadeeasy') => 'dnsmadeeasy' ],
[ $c->l('domeneshop') => 'domeneshop' ],
[ $c->l('dondominio') => 'dondominio' ],
[ $c->l('dslreports') => 'dslreports' ],
[ $c->l('duckdns') => 'duckdns' ],
[ $c->l('dyndns1') => 'dyndns1' ],
[ $c->l('dyndns2') => 'dyndns2' ],
[ $c->l('easydns') => 'easydns' ],
[ $c->l('enom') => 'enom' ],
[ $c->l('freedns') => 'freedns' ],
[ $c->l('freemyip') => 'freemyip' ],
[ $c->l('gandi') => 'gandi' ],
[ $c->l('godaddy') => 'godaddy' ],
[ $c->l('googledomains') => 'googledomains' ],
[ $c->l('hetzner') => 'hetzner' ],
[ $c->l('infomaniak') => 'infomaniak' ],
[ $c->l('keysystems') => 'keysystems' ],
[ $c->l('mythicdyn') => 'mythicdyn' ],
[ $c->l('namecheap') => 'namecheap' ],
[ $c->l('nfsn') => 'nfsn' ],
[ $c->l('njalla') => 'njalla' ],
[ $c->l('noip') => 'noip' ],
[ $c->l('nsupdate') => 'nsupdate' ],
[ $c->l('ovh') => 'ovh' ],
[ $c->l('porkbun') => 'porkbun' ],
[ $c->l('regfishde') => 'regfishde' ],
[ $c->l('sitelutions') => 'sitelutions' ],
[ $c->l('woima') => 'woima' ],
[ $c->l('yandex') => 'yandex' ],
[ $c->l('zoneedit') => 'zoneedit' ]
] );
return $dnsservices;
#my $output = `ddclient -list-protocols`; # Run ddclient command and capture the output
#my @protocols;
#foreach my $line (split /\n/, $output) {
#my ($protocol) = $line =~ /\s*(\S+)/;
#next unless $protocol; # Skip if protocol is empty or contains only whitespace
#my $custom_value = "$protocol.$c->l($protocol)"; # Additional column value using $c->l(protocol)
#push @protocols, [$custom_value, $protocol];
#}
#return \@protocols; # Return a reference to the protocols array
}
sub main {
#
# Initial page - full summary of parameters etc
# Initial para from the Wiki.
#
my $c = shift;
$ddc_datas{"first"} = 'DESCRIPTION';
do_display( $c, %ddc_datas );
}
sub do_display {
#
# Front Summary page
#
my $c = shift;
$c->app->log->info( $c->log_req );
my $title = $c->l('FORM_TITLE');
my $modul = '';
$ddc_datas{trt} = 'LIST';
my $trt = "LIST";
$ddc_datas{"params"} = get_params($c);
my @domains = get_domain_table($c);
my @FreeDomains = get_custom_table($c);
my $emptydom = ( scalar @domains == 0 );
my $emptycust = ( scalar @FreeDomains == 0 );
my $Labels = (
[
[ $c->l('SME external Interface') => "smeIF" ],
[ $c->l('SME configuration DB') => 'smeCMD' ],
[ $c->l('web') => 'web' ],
[ $c->l('Router/Firewall') => 'router' ],
[ $c->l('Interface') => 'if' ],
[ $c->l('IP') => 'ip' ],
[ $c->l('Command') => 'cmdv4' ]
]
);
$c->stash(
title => $title,
modul => $modul,
ddc_datas => \%ddc_datas,
domains => \@domains,
freedomains => \@FreeDomains,
methodlabels => $Labels,
dnslabels => get_dns_labels($c),
devices => get_devices_names($c),
webservices => get_web_services_names($c),
emptydom => $emptydom,
emptycust => $emptycust
);
$ddc_datas{'trt'} = $trt;
$c->stash( title => $title, modul => $modul, ddc_datas => \%ddc_datas );
$c->render( template => 'ddclient' );
}
sub do_updateparams {
#
# Called to update the parameters relating to the Ip address of the server
#
my $c = shift;
$ddc_datas{"first"} = '';
$ddc_datas{"success"} = pushParams($c);
do_display($c);
}
sub do_update_domain {
#
#Called to update/delete the ddclient for a specific inbuilt domain
#
my $c = shift;
my $title = $c->l("MODIFY_TITLE");
my $retmsg;
if ( $c->param("Route") eq "ddclient2" ) { #Route is hidden field
$retmsg = performModifyCustom($c);
}
else {
$retmsg = performModifyDomain($c);
}
$ddc_datas{"first"} = '';
if ( $retmsg eq "ok" ) {
my $dns = $c->param('dns');
my $domain = $c->param('domainname');
$ddc_datas{"success"} = $c->l( "SUCCESSFULLY_MODIFIED", $domain,
$c->l( '' . $dns ) );
do_display( $c, %ddc_datas );
}
else {
$ddc_datas{"error"} = $retmsg;
#Back to input panel to correct error
do_summary_domain($c);
}
}
sub do_create_custom {
#
# Create custom domain
#
my $c = shift;
my $title = $c->l("CREATE_TITLE");
my $modul = '';
my $trt = "NEW";
$ddc_datas{trt} = $trt;
$c->stash(
title => $title,
modul => $modul,
ddc_datas => \%ddc_datas,
dnslabels => get_dns_labels($c),
devices => get_devices_names($c),
webservices => get_web_services_names($c)
);
$c->render( template => 'ddclient' );
}
sub do_create_custom_actual {
my $c = shift;
$ddc_datas{"first"} = '';
my $retmsg = performCreateCustom($c);
if ( $retmsg eq "ok" ) {
my $dns = $c->param('dns');
my $domain = $c->param('domainname');
$ddc_datas{"success"} = $c->l( "SUCCESSFULLY_DELETED", $domain,
$c->l( '' . $dns ) );
do_display( $c, %ddc_datas );
}
else {
$ddc_datas{"error"} = $retmsg;
#Back to input panel to correct error
do_create_custom($c);
}
}
sub do_summary_custom {
#
# Display delete or modify panel for custom domain
#
my $c = shift;
my $title = $c->l("MODIFY_TITLE");
my $modul = '';
my $trt = $c->param("trt");
#Extract domain stuff from DB
my @results
= get_custom_table( $c, $c->param("Domain") ); #Returns just one row
$ddc_datas{"Domain_details"} = $results[0];
$ddc_datas{'trt'} = $trt;
$c->stash(
title => $title,
modul => $modul,
ddc_datas => \%ddc_datas,
dnslabels => get_dns_labels($c),
devices => get_devices_names($c),
webservices => get_web_services_names($c)
);
$c->render( template => 'ddclient' );
}
sub do_summary_domain {
#
# Display delete or modify panel for inbuilt domain
# param trt = MOD or DEL
#
my $c = shift;
my $title = $c->l("MODIFY_TITLE");
my $modul = '';
my $trt = $c->param("trt");
#Extract domain stuff from DB
my @results
= get_domain_table( $c, $c->param("Domain") ); #Returns just one row
$ddc_datas{"Domain_details"} = $results[0];
$ddc_datas{'trt'} = $trt;
$c->stash(
title => $title,
modul => $modul,
ddc_datas => \%ddc_datas,
dnslabels => get_dns_labels($c),
devices => get_devices_names($c),
webservices => get_web_services_names($c)
);
$c->render( template => 'ddclient' );
}
sub do_delete_domain {
#
# Actually clearout the inbuilt domain
# Return to initial page with message at the top.
#
my $c = shift;
my $route = $c->current_route;
my $title = $c->l("REMOVE_TITLE");
my $modul = '';
my $retmsg = "";
my $domain = $c->param("Domain");
$ddc_datas{"first"} = '';
#Delete it and return to front summary panel - depends on route domain or custom
if ( $c->param("Route") eq "ddclient2" ) { #Route is hidden field
$retmsg = performDeleteCustom( $c, $domain );
}
else {
$retmsg = performDeleteDomain( $c, $domain );
}
if ( $retmsg eq "ok" ) {
$ddc_datas{"success"} = $c->l( "SUCCESSFULLY_DELETED", $domain,
$c->l( '' . $c->param("dns") ) );
}
else { $ddc_datas{"error"} = $retmsg; }
do_display( $c, %ddc_datas );
}
sub do_delete_custom {
#
# Actually delete the custom domain
# Return to initial page with message at the top.
#
my $c = shift;
my $route = $c->current_route;
my $title = $c->l("REMOVE_TITLE");
my $modul = '';
my $retmsg = "";
my $domain = $c->param("Domain");
$ddc_datas{"first"} = '';
#Delete it and return to front summary panel - depends on route domain or custom
$retmsg = performDeleteCustom( $c, $domain );
if ( $retmsg eq "ok" ) {
$ddc_datas{"success"} = $c->l( "SUCCESSFULLY_DELETED", $domain );
}
else { $ddc_datas{"error"} = $retmsg; }
do_display( $c, %ddc_datas );
}
sub get_domain_table {
#
# Return full table of all domains OR just the details for the specified one
#
my ( $c, $findDomain ) = @_; #$c and domain to find
$findDomain = FALSE if ( scalar(@_) <= 1 );
my $key;
my @virtualDomains = ();
foreach my $domain ( $domaindb->get_all_by_prop( type => 'domain' ) ) {
$key = $domain->key;
push( @virtualDomains, $key );
}
my $numDomains = @virtualDomains;
if ( $numDomains == 0 ) { return () }
else {
my $domain;
my @virtualDomains2d = ();
foreach $domain ( sort @virtualDomains ) {
my %properties = $domaindb->get($domain)->props;
my $test = $domaindb->get($domain) || '';
my %extraprops;
if ( $test ne '' ) {
%extraprops = $domaindb->get($domain)->props;
}
my $content;
if ( $properties{'Content'} eq 'wwwpublic' ) {
$content = $c->l('PRIMARY_SITE');
}
else {
$content = $c->l( 'CONTENT', $properties{'Content'} );
}
my $public;
my %thisrow;
if ( $test eq '' ) {
%thisrow = (
"Domain" => $domain,
"Description" => $properties{'Description'},
"Content" => $content,
"dns" => "",
"Publication" => "",
"customprotocol" => "",
"customdns" => "",
"login" => "",
"password" => "",
"mx" => ""
);
push( @virtualDomains2d, \%thisrow );
}
else {
%thisrow = (
"Domain" => $domain,
"Description" => $properties{'Description'},
"Content" => $content,
"dns" => $extraprops{'dns'},
"Publication" => $c->l( '' . $extraprops{'dns'} ),
"customprotocol" => $properties{"customprotocol"},
"customdns" => $properties{"customdns"},
"login" => $properties{"login"},
"password" => $properties{"password"},
"mx" => $properties{"mx"},
);
push( @virtualDomains2d, \%thisrow );
}
if ($findDomain) {
if ( $domain eq $findDomain ) {
@virtualDomains2d = (); #Just return matching one
push( @virtualDomains2d, \%thisrow );
last;
}
} #Found the one needed
}
return @virtualDomains2d; #Return the lot
}
}
sub get_custom_table {
#
# Return full table of all domains OR just the details for the specified one
#
my ( $c, $findDomain ) = @_; #$c and domain to find
$findDomain = FALSE if ( scalar(@_) <= 1 );
my $key;
my @FreeDomains = ();
foreach my $domain ( $edb->get_all_by_prop( type => 'ddhost' ) ) {
$key = $domain->key;
push( @FreeDomains, $key );
}
my $numDomains = @FreeDomains;
my @freedomains2d = ();
if ( $numDomains > 0 ) {
foreach my $domain ( sort @FreeDomains ) {
my $vals = $edb->get($domain);
my $content = $vals->prop('desc');
my $publish = $vals->prop('dns');
my %thisrow = (
'Domain' => $domain,
"Description" => $content,
"dns" => $publish,
"Publication" => $c->l( '' . $publish )
, #msg ddc prefix for ddclient
"customprotocol" => $vals->prop("customprotocol"),
"customdns" => $vals->prop("customdns"),
"login" => $vals->prop("login"),
"password" => $vals->prop("password"),
"mx" => $vals->prop("mx"),
);
push( @freedomains2d, \%thisrow );
if ($findDomain) {
if ( $domain eq $findDomain ) {
@freedomains2d = (); #Just return matching one
push( @freedomains2d, \%thisrow );
last;
}
} #Found the one needed
}
}
return @freedomains2d;
}
sub get_params {
my $c = shift;
my $ddretrieve = $db->get('ddclient');
my $ExtIF = $db->get('ExternalInterface');
my $DeamonUpdate = $ddretrieve->prop('DeamonUpdate') || '300';
my $urlcheckip = $ddretrieve->prop('urlcheckip') || 'checkip.dyndns.org';
my $ssl = $ddretrieve->prop('SSL') || 'yes';
my $method = $ddretrieve->prop('method') || 'web';
my $Extinterface = $ddretrieve->prop('Extinterface') || '';
my $cmd = $ddretrieve->prop('cmd') || '';
my $forceIP = $ddretrieve->prop('ForceIP') || '';
my $fwlogin = $ddretrieve->prop('fwlogin') || '';
my $fwpassword = $ddretrieve->prop('fwpassword') || '';
my $res = {
"ssl" => $ssl,
"DeamonUpdate" => $DeamonUpdate,
"method" => $method,
"Extinterface" => $Extinterface,
"cmd" => $cmd,
"ForceIP" => $forceIP,
"urlcheckip" => $urlcheckip,
"FWlogin" => $fwlogin,
"FWpassword" => $fwpassword
};
return $res;
}
sub pushParams {
my $c = shift;
my $retrievedeamonupdate = $c->param('retrievedeamonupdate');
my $retrieverouter = $c->param('retrieverouter');
my $retrievewebservice = $c->param('retrievewebservice');
my $retrieveurlcheckip = $c->param('retrieveurlcheckip');
my $retrievessl = $c->param('retrievessl');
my $retrievemethod = $c->param('retrievemethod');
my $retrieveinterface = $c->param('retrieveinterface');
my $retrievecmd = $c->param('retrievecmd');
my $retrieveip = $c->param('retrieveip');
my $retrievefwlogin = $c->param('retrieverouterlogin');
my $retrievefwpassword = $c->param('retrieverouterpassword');
#print 1 / 0; #Crash
my $ddclient = $db->get('ddclient');
$ddclient->set_prop( 'urlcheckip' => $retrievewebservice || $retrieveurlcheckip );
$ddclient->set_prop( 'DeamonUpdate' => $retrievedeamonupdate );
$ddclient->set_prop( 'SSL' => $retrievessl );
$ddclient->set_prop( 'method' => $retrievemethod );
if ($retrievemethod eq 'router') {
$ddclient->set_prop( 'Extinterface' => $retrieverouter );
} else {
$ddclient->set_prop( 'Extinterface' => $retrieveinterface );
}
$ddclient->set_prop( 'cmd' => $retrievecmd );
$ddclient->set_prop( 'ForceIP' => $retrieveip );
$ddclient->set_prop( 'fwlogin' => $retrievefwlogin );
$ddclient->set_prop( 'fwpassword' => $retrievefwpassword );
$domaindb->reload();
system( "/sbin/e-smith/signal-event", "smeserver-ddclient-update" );
return $c->l('SUCCESSFULLY_MODIFIED_RETRIEVE_IP');
}
# We seem to be missing a Create Domain here
# sub performCreateDomain
sub performModifyDomain {
my $c = shift;
#------------------------------------------------------------
# Validate parameters and untaint them
#------------------------------------------------------------
my $domainName = $c->param('domainName');
if ( $domainName =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$domainName = $1;
}
else {
return $c->l( 'DOMAIN_NAME_VALIDATION_ERROR', $domainName );
}
my $domainLogin = $c->param('login');
if ( $domainLogin =~ /([\-\'\w][\-\'\w\s\.\@]*)$/ ) {
$domainLogin = $1;
}
else {
return $c->l( 'DOMAIN_LOGIN_VALIDATION_ERROR', $domainLogin );
}
my $domainPassword = $c->param('password');
if ( $domainPassword =~ /(.*)$/ ) {
$domainPassword = $1;
}
else {
return $c->l( 'DOMAIN_PASSWORD_VALIDATION_ERROR',
$domainPassword );
}
my $domainMX = $c->param('mx');
my $customDNS = $c->param('customdns');
my $customPROTOCOL = $c->param('customprotocol');
my $dns = $c->param('dns');
if ( $dns eq 'CUSTOMDNS' ) {
if ( $customDNS =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$customDNS = $1;
}
else
{
return $c->l( 'CUSTOMDNS_VALIDATION_ERROR', $domainName );
}
}
#------------------------------------------------------------
# Looks good. Find out if this domain has been taken
# or if the domain is a reserved to provide a secured webserver
# for a previous domain
#------------------------------------------------------------
# my $dns = $c->param ('dns');
my $dom = $domaindb->get($domainName);
$dom->set_prop( 'dns' => $dns );
$dom->set_prop( 'login' => $domainLogin );
$dom->set_prop( 'password' => $domainPassword );
$dom->set_prop( 'mx' => $domainMX );
$dom->set_prop( 'customdns' => $customDNS );
$dom->set_prop( 'customprotocol' => $customPROTOCOL );
$domaindb->reload();
system( "/sbin/e-smith/signal-event", "ddclient" );
return "ok";
}
sub performDeleteDomain {
my ( $c, $domain ) = @_;
#------------------------------------------------------------
# Attempt to delete domain
#------------------------------------------------------------
if ( $domain =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$domain = $1;
}
else {
return $c->l( 'ERROR_WHILE_REMOVING_DOMAIN', $domain );
}
my $value = $domaindb->get($domain);
unless ($value) {
return $c->l( 'NONEXISTENT_DOMAIN_ERROR', $domain );
}
my %properties = $value->props;
my $type = $properties{'type'};
if ( $type ne 'domain' ) {
return $c->l( 'NONEXISTENT_DOMAIN_ERROR', $domain );
}
my $evalue = $domaindb->get($domain);
$evalue->set_prop( 'dns' => '' );
$evalue->set_prop( 'login' => '' );
$evalue->set_prop( 'password' => '' );
$evalue->set_prop( 'customdns' => '' );
$evalue->set_prop( 'customprotocol' => '' );
$domaindb->reload();
system( "/sbin/e-smith/signal-event", "domain-modify" );
return "ok";
}
sub performCreateCustom {
my ($c) = shift;
#------------------------------------------------------------
# Validate parameters and untaint them
#------------------------------------------------------------
my $domainName = $c->param('domainName');
if ( $domainName =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$domainName = $1;
}
else {
return $c->l( 'DOMAIN_NAME_VALIDATION_ERROR', $domainName );
}
foreach my $domain ( $edb->get_all_by_prop( type => 'domain' ) ) {
my $key = $domain->key;
if ( $key eq $domainName ) {
return $c->l( 'DOMAIN_NAME_ALREADY_EXIST', $domainName );
}
}
foreach my $domain ( $domaindb->get_all_by_prop( type => 'ddhost' ) ) {
my $key = $domain->key;
if ( $key eq $domainName ) {
return $c->l( 'DOMAIN_NAME_ALREADY_EXIST', $domainName );
}
}
my $domainDesc = $c->param('desc');
my $domainLogin = $c->param('login');
if ( $domainLogin =~ /([\-\'\w][\-\'\w\s\.\@]*)$/ ) {
$domainLogin = $1;
}
else {
return $c->l( 'DOMAIN_LOGIN_VALIDATION_ERROR', $domainLogin );
}
my $domainPassword = $c->param('password');
if ( $domainPassword =~ /(.*)$/ ) {
$domainPassword = $1;
}
else {
return $c->l( 'DOMAIN_PASSWORD_VALIDATION_ERROR',
$domainPassword );
}
my $domainMX = $c->param('mx');
my $customDNS = $c->param('customdns');
my $customPROTOCOL = $c->param('customprotocol');
my $dns = $c->param('dns');
if ( $dns eq 'CUSTOMDNS' ) {
if ( $customDNS =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$customDNS = $1;
}
else {
return $c->l( 'CUSTOMDNS_VALIDATION_ERROR', $domainName );
}
}
#------------------------------------------------------------
# Looks good. Find out if this domain has been taken
# or if the domain is a reserved to provide a secured webserver
# for a previous domain
#------------------------------------------------------------
my %properties = ();
$properties{'type'} = 'ddhost';
$properties{'dns'} = $dns;
$properties{'login'} = $domainLogin;
$properties{'password'} = $domainPassword;
$properties{'mx'} = $domainMX;
$properties{'desc'} = $domainDesc;
$properties{'customdns'} = $customDNS;
$properties{'customprotocol'} = $customPROTOCOL;
$edb->new_record( $domainName, \%properties );
system( "/sbin/e-smith/signal-event", "domain-create" );
return "ok";
}
sub performModifyCustom {
my $c = shift;
#------------------------------------------------------------
# Validate parameters and untaint them
#------------------------------------------------------------
my $domainName = $c->param('domainName');
if ( $domainName =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$domainName = $1;
}
else {
return $c->l( 'DOMAIN_NAME_VALIDATION_ERROR', $domainName );
}
my $domainLogin = $c->param('login');
if ( $domainLogin =~ /([\-\'\w][\-\'\w\s\.\@]*)$/ ) {
$domainLogin = $1;
}
else {
return $c->l( 'DOMAIN_LOGIN_VALIDATION_ERROR', $domainLogin );
}
my $domainPassword = $c->param('password');
if ( $domainPassword =~ /(.*)$/ ) {
$domainPassword = $1;
}
else {
return $c->l( 'DOMAIN_PASSWORD_VALIDATION_ERROR',
$domainPassword );
}
my $domainMX = $c->param('mx');
my $customDNS = $c->param('customdns');
my $customPROTOCOL = $c->param('customprotocol');
my $dns = $c->param('dns');
if ( $dns eq 'CUSTOMDNS' ) {
if ( $customDNS =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$customDNS = $1;
}
else
{
return $c->l( 'CUSTOMDNS_VALIDATION_ERROR', $domainName );
}
}
#------------------------------------------------------------
# Looks good. Find out if this domain has been taken
# or if the domain is a reserved to provide a secured webserver
# for a previous domain
#------------------------------------------------------------
# my $dns = $c->param ('dns');
my $dom = $edb->get($domainName);
$dom->set_prop( 'dns' => $dns );
$dom->set_prop( 'login' => $domainLogin );
$dom->set_prop( 'password' => $domainPassword );
$dom->set_prop( 'mx' => $domainMX );
$dom->set_prop( 'customdns' => $customDNS );
$dom->set_prop( 'customprotocol' => $customPROTOCOL );
$domaindb->reload();
system( "/sbin/e-smith/signal-event", "domain-modify" );
return "ok";
}
sub performDeleteCustom {
my ( $c, $domain ) = @_;
#------------------------------------------------------------
# Attempt to delete domain
#------------------------------------------------------------
if ( $domain =~ /([a-zA-Z0-9\-\.]+)$/ ) {
$domain = $1;
}
else {
return $c->l( 'ERROR_WHILE_REMOVING_DOMAIN', $domain );
}
my $evalue = $edb->get($domain);
unless ($evalue) {
return $c->l( 'NONEXISTENT_DOMAIN_ERROR', $domain );
}
my %properties = $evalue->props;
my $type = $properties{'type'};
if ( $type ne 'ddhost' ) {
return $c->l( 'NONEXISTENT_DOMAIN_ERROR', $domain );
}
$evalue->delete;
$edb->reload();
system( "/sbin/e-smith/signal-event", "domain-delete" );
return "ok";
}
1;