+sub enable{
+ my ($param) = @_;
+
+ modify_configs($param->{name}, $param->{source},4);
+}
+
+sub disable{
+ my ($param) = @_;
+
+ modify_configs($param->{name}, $param->{source},2);
+}
+
+sub modify_configs{
+ my ($name, $sou, $op) = @_;
+
+ $name = $name ? $name : "default";
+
+ my $cfg = read_from_config("$CONFIG_PATH$CONFIG");
+
+ my $source = parse_target($sou);
+
+ my $change_configs = sub {
+ my ($path, $name, $cfg, $op) = @_;
+
+ die "Source does not exist!\n" unless $cfg->{$path} ;
+
+ die "Sync Name does not exist!\n" unless $cfg->{$path}->{$name};
+
+ my $source = $cfg->{$path}->{$name}->{source_ip} ? "$cfg->{$path}->{$name}->{source_ip}:" : '';
+
+ $source .= $cfg->{$path}->{$name}->{source_pool} if $cfg->{$path}->{$name}->{source_pool};
+ $source .= $cfg->{$path}->{$name}->{source_path} ? $cfg->{$path}->{$name}->{source_path} :'';
+
+ my $dest = $cfg->{$path}->{$name}->{dest_ip} ? $cfg->{$path}->{$name}->{dest_ip} :"";
+ $dest .= $cfg->{$path}->{$name}->{dest_pool} if $cfg->{$path}->{$name}->{dest_pool};
+ $dest .= $cfg->{$path}->{$name}->{dest_path} ? $cfg->{$path}->{$name}->{dest_path} :'';
+
+ if($op == 1){
+ delete $cfg->{$path}->{$name};
+
+ delete $cfg->{$path} if keys%{$cfg->{$path}} == 0;
+
+ write_to_config($cfg);
+ }
+ if($op == 1 || $op == 2) {
+
+ if ($op == 2) {
+
+ $cfg->{$path}->{$name}->{status} = "stoped";
+
+ write_to_config($cfg);
+ }
+ write_to_cron($cfg);
+ } elsif($op == 4) {
+ my $job = {};
+
+ $cfg->{$path}->{$name}->{status} = "ok";
+
+ write_to_config($cfg);
+
+ write_to_cron($cfg);
+ }
+ };
+
+
+ if ($source->{vmid}) {
+ my $path = $source->{vmid};
+
+ &$change_configs($path, $name, $cfg, $op)
+ } else {
+ my $path = $source->{pool};
+ $path .= $source->{path} if $source->{path};
+
+ &$change_configs($path, $name, $cfg, $op);
+ }
+}
+