| 54 | | if (eval "require $mod") { |
|---|
| 55 | | |
|---|
| 56 | | $mod -> import(); |
|---|
| 57 | | |
|---|
| 58 | | } else { |
|---|
| 59 | | |
|---|
| 60 | | print STDERR "\nCRITICAL ERROR: Module [$mod] WAS NOT FOUND !\n" ; |
|---|
| 61 | | |
|---|
| 62 | | $mod_err = '_on_'; |
|---|
| 63 | | |
|---|
| 64 | | if ($mod_missing eq '') { |
|---|
| 65 | | |
|---|
| 66 | | $mod_missing .= $mod; |
|---|
| 67 | | |
|---|
| 68 | | } else { |
|---|
| 69 | | |
|---|
| 70 | | $mod_missing .= ", $mod"; |
|---|
| 71 | | |
|---|
| 72 | | } |
|---|
| 73 | | } |
|---|
| 74 | | |
|---|
| 75 | | } |
|---|
| 76 | | |
|---|
| 77 | | if ($mod_err eq '_on_') { |
|---|
| 78 | | |
|---|
| 79 | | print STDERR "\nModules [$mod_missing] WAS NOT FOUND in your system...\n"; |
|---|
| 80 | | |
|---|
| 81 | | exit 1; |
|---|
| 82 | | |
|---|
| 83 | | } else { |
|---|
| 84 | | |
|---|
| 85 | | $| = 1; |
|---|
| 86 | | |
|---|
| 87 | | } |
|---|
| 88 | | } |
|---|
| 89 | | |
|---|
| 90 | | |
|---|
| 91 | | #$main::engine_debug = '_on_'; |
|---|
| 92 | | |
|---|
| 93 | | $main::cc_stdout = '/tmp/ispcp-cc.stdout'; |
|---|
| 94 | | |
|---|
| 95 | | $main::cc_stderr = '/tmp/ispcp-cc.stderr'; |
|---|
| 96 | | |
|---|
| 97 | | $main::el_sep = "\t#\t"; |
|---|
| 98 | | |
|---|
| 99 | | @main::el = (); |
|---|
| 100 | | |
|---|
| 101 | | |
|---|
| 102 | | sub push_el { |
|---|
| 103 | | |
|---|
| 104 | | my ($el, $sub_name, $msg) = @_; |
|---|
| 105 | | |
|---|
| 106 | | push @$el, "$sub_name".$main::el_sep."$msg"; |
|---|
| 107 | | |
|---|
| 108 | | if (defined($main::engine_debug)) { |
|---|
| 109 | | |
|---|
| 110 | | print STDOUT "DEBUG: push_el() sub_name: $sub_name, msg: $msg\n"; |
|---|
| 111 | | |
|---|
| 112 | | } |
|---|
| 113 | | |
|---|
| 114 | | |
|---|
| 115 | | } |
|---|
| 116 | | |
|---|
| 117 | | sub pop_el { |
|---|
| 118 | | |
|---|
| 119 | | my ($el) = @_; |
|---|
| 120 | | |
|---|
| 121 | | my $data = pop @$el; |
|---|
| 122 | | |
|---|
| 123 | | if (!defined($data)) { |
|---|
| 124 | | |
|---|
| 125 | | if (defined($main::engine_debug)) { |
|---|
| 126 | | |
|---|
| 127 | | print STDOUT "DEBUG: pop_el() Empty 'EL' Stack !\n"; |
|---|
| 128 | | |
|---|
| 129 | | } |
|---|
| 130 | | |
|---|
| 131 | | return undef; |
|---|
| 132 | | } |
|---|
| 133 | | |
|---|
| 134 | | my ($sub_name, $msg) = split(/$main::el_sep/, $data); |
|---|
| 135 | | |
|---|
| 136 | | if (defined($main::engine_debug)) { |
|---|
| 137 | | |
|---|
| 138 | | print STDOUT "DEBUG: pop_el() sub_name: $sub_name, msg: $msg\n"; |
|---|
| 139 | | |
|---|
| 140 | | } |
|---|
| 141 | | |
|---|
| 142 | | |
|---|
| 143 | | return $data; |
|---|
| 144 | | |
|---|
| 145 | | } |
|---|
| 146 | | |
|---|
| 147 | | |
|---|
| 148 | | sub dump_el { |
|---|
| 149 | | |
|---|
| 150 | | my ($el, $fname) = @_; |
|---|
| 151 | | |
|---|
| 152 | | my $res; |
|---|
| 153 | | |
|---|
| 154 | | if ($fname ne 'stdout') { |
|---|
| 155 | | |
|---|
| 156 | | $res = open(FP, ">", $fname); |
|---|
| 157 | | |
|---|
| 158 | | if (!defined($res)) { |
|---|
| 159 | | |
|---|
| 160 | | return 0; |
|---|
| 161 | | |
|---|
| 162 | | } |
|---|
| 163 | | |
|---|
| 164 | | } |
|---|
| 165 | | |
|---|
| 166 | | my $el_data = undef; |
|---|
| 167 | | |
|---|
| 168 | | # |
|---|
| 169 | | #if ($fname eq 'stdout') { |
|---|
| 170 | | # |
|---|
| 171 | | # print STDOUT "%-20s | %s\n", ' function', 'message'; |
|---|
| 172 | | # |
|---|
| 173 | | # print STDOUT "---------------------|---------------------------------------------------------------\n"; |
|---|
| 174 | | # |
|---|
| 175 | | #} else { |
|---|
| 176 | | # |
|---|
| 177 | | # print FP "%-20s | %s\n", ' function', 'message'; |
|---|
| 178 | | # |
|---|
| 179 | | # print FP "---------------------|---------------------------------------------------------------\n"; |
|---|
| 180 | | # |
|---|
| 181 | | #} |
|---|
| 182 | | # |
|---|
| 183 | | |
|---|
| 184 | | while (defined($el_data = pop_el(\@main::el))) { |
|---|
| 185 | | |
|---|
| 186 | | my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 187 | | |
|---|
| 188 | | if ($fname eq 'stdout') { |
|---|
| 189 | | |
|---|
| 190 | | printf STDOUT "%-30s | %s\n", $sub_name, $msg; |
|---|
| 191 | | |
|---|
| 192 | | } else { |
|---|
| 193 | | |
|---|
| 194 | | printf FP "%-30s | %s\n", $sub_name, $msg; |
|---|
| 195 | | |
|---|
| 196 | | } |
|---|
| 197 | | |
|---|
| 198 | | } |
|---|
| 199 | | |
|---|
| 200 | | close(FP); |
|---|
| 201 | | |
|---|
| 202 | | } |
|---|
| 203 | | |
|---|
| 204 | | # Global variables; |
|---|
| 205 | | |
|---|
| 206 | | $main::db_host = undef; |
|---|
| 207 | | |
|---|
| 208 | | $main::db_user = undef; |
|---|
| 209 | | |
|---|
| 210 | | $main::db_pwd = undef; |
|---|
| 211 | | |
|---|
| 212 | | $main::db_name = undef; |
|---|
| 213 | | |
|---|
| 214 | | @main::db_connect = (); |
|---|
| 215 | | |
|---|
| 216 | | $main::db = undef; |
|---|
| 217 | | |
|---|
| 218 | | # |
|---|
| 219 | | |
|---|
| 220 | | sub doSQL { |
|---|
| 221 | | |
|---|
| 222 | | my ($sql) = @_; |
|---|
| 223 | | |
|---|
| 224 | | my $qr = undef; |
|---|
| 225 | | |
|---|
| 226 | | push_el(\@main::el, 'doSQL()', 'Starting...'); |
|---|
| 227 | | |
|---|
| 228 | | if (!defined($sql) || ($sql eq '')) { |
|---|
| 229 | | |
|---|
| 230 | | push_el(\@main::el, 'doSQL()', 'ERROR: Undefined SQL query !'); |
|---|
| 231 | | |
|---|
| 232 | | return (-1, ''); |
|---|
| 233 | | |
|---|
| 234 | | } |
|---|
| 235 | | |
|---|
| 236 | | if (!defined($main::db) || !ref($main::db)) { |
|---|
| 237 | | |
|---|
| 238 | | $main::db = DBI -> connect(@main::db_connect, {PrintError => 0}); |
|---|
| 239 | | |
|---|
| 240 | | if ( !defined($main::db) ) { |
|---|
| 241 | | |
|---|
| 242 | | push_el( |
|---|
| 243 | | \@main::el, |
|---|
| 244 | | 'doSQL()', |
|---|
| 245 | | 'ERROR: Unable to connect SQL server !' |
|---|
| 246 | | ); |
|---|
| 247 | | |
|---|
| 248 | | return (-1, ''); |
|---|
| 249 | | |
|---|
| 250 | | } |
|---|
| 251 | | } |
|---|
| 252 | | |
|---|
| 253 | | if ($sql =~ /select/i) { |
|---|
| 254 | | |
|---|
| 255 | | $qr = $main::db -> selectall_arrayref($sql); |
|---|
| 256 | | |
|---|
| 257 | | } elsif ($sql =~ /show/i) { |
|---|
| 258 | | |
|---|
| 259 | | $qr = $main::db -> selectall_arrayref($sql); |
|---|
| 260 | | |
|---|
| 261 | | } else { |
|---|
| 262 | | |
|---|
| 263 | | $qr = $main::db -> do($sql); |
|---|
| 264 | | |
|---|
| 265 | | } |
|---|
| 266 | | |
|---|
| 267 | | if (defined($qr)) { |
|---|
| 268 | | |
|---|
| 269 | | push_el(\@main::el, 'doSQL()', 'Ending...'); |
|---|
| 270 | | |
|---|
| 271 | | return (0, $qr); |
|---|
| 272 | | |
|---|
| 273 | | } else { |
|---|
| 274 | | |
|---|
| 275 | | push_el(\@main::el, 'doSQL()', 'ERROR: Incorrect SQL Query -> '.$main::db -> errstr); |
|---|
| 276 | | |
|---|
| 277 | | return (-1, ''); |
|---|
| 278 | | |
|---|
| 279 | | } |
|---|
| 280 | | |
|---|
| 281 | | } |
|---|
| 282 | | |
|---|
| 283 | | sub setfmode { |
|---|
| 284 | | |
|---|
| 285 | | my ($fname, $fuid, $fgid, $fperms) = @_; |
|---|
| 286 | | |
|---|
| 287 | | push_el(\@main::el, 'setfmode()', 'Starting...'); |
|---|
| 288 | | |
|---|
| 289 | | if ( |
|---|
| 290 | | !defined($fname) || !defined($fuid) || |
|---|
| 291 | | !defined($fgid) || !defined($fperms) || |
|---|
| 292 | | $fname eq '' || $fuid eq '' || |
|---|
| 293 | | $fgid eq '' || $fperms eq '' |
|---|
| 294 | | ) |
|---|
| 295 | | { |
|---|
| 296 | | |
|---|
| 297 | | push_el( |
|---|
| 298 | | \@main::el, |
|---|
| 299 | | 'setfmode()', |
|---|
| 300 | | "ERROR: Undefined input data, fname: |$fname|, fuid: |$fuid|, fgid: |$fgid|, fperms: |$fperms| !" |
|---|
| 301 | | ); |
|---|
| 302 | | |
|---|
| 303 | | return -1; |
|---|
| 304 | | |
|---|
| 305 | | } |
|---|
| 306 | | |
|---|
| 307 | | if (! -e $fname) { |
|---|
| 308 | | |
|---|
| 309 | | push_el( |
|---|
| 310 | | \@main::el, |
|---|
| 311 | | 'setfmode()', |
|---|
| 312 | | "ERROR: File '$fname' does not exist !" |
|---|
| 313 | | ); |
|---|
| 314 | | |
|---|
| 315 | | return -1; |
|---|
| 316 | | } |
|---|
| 317 | | |
|---|
| 318 | | my @udata = (); |
|---|
| 319 | | |
|---|
| 320 | | my @gdata = (); |
|---|
| 321 | | |
|---|
| 322 | | my ($uid, $gid) = ($fuid, $fgid); |
|---|
| 323 | | |
|---|
| 324 | | if ($fuid =~ /^\d+$/) { |
|---|
| 325 | | |
|---|
| 326 | | $uid = $fuid; |
|---|
| 327 | | |
|---|
| 328 | | } elsif ($fuid ne '-1') { |
|---|
| 329 | | |
|---|
| 330 | | @udata = getpwnam($fuid); |
|---|
| 331 | | |
|---|
| 332 | | if (scalar(@udata) == 0) { |
|---|
| 333 | | |
|---|
| 334 | | push_el( |
|---|
| 335 | | \@main::el, |
|---|
| 336 | | 'setfmode()', |
|---|
| 337 | | "ERROR: Unknown user '$fuid' !" |
|---|
| 338 | | ); |
|---|
| 339 | | |
|---|
| 340 | | return -1; |
|---|
| 341 | | |
|---|
| 342 | | } |
|---|
| 343 | | |
|---|
| 344 | | $uid = $udata[2]; |
|---|
| 345 | | } |
|---|
| 346 | | |
|---|
| 347 | | if ($fgid =~ /^\d+$/) { |
|---|
| 348 | | |
|---|
| 349 | | $gid = $fgid; |
|---|
| 350 | | |
|---|
| 351 | | } elsif ($fgid ne '-1') { |
|---|
| 352 | | |
|---|
| 353 | | @gdata = getgrnam($fgid); |
|---|
| 354 | | |
|---|
| 355 | | if (scalar(@gdata) == 0) { |
|---|
| 356 | | |
|---|
| 357 | | push_el( |
|---|
| 358 | | \@main::el, |
|---|
| 359 | | 'setfmode()', |
|---|
| 360 | | "ERROR: Unknown group '$fgid' !" |
|---|
| 361 | | ); |
|---|
| 362 | | |
|---|
| 363 | | return -1; |
|---|
| 364 | | |
|---|
| 365 | | } |
|---|
| 366 | | |
|---|
| 367 | | $gid = $gdata[2]; |
|---|
| 368 | | } |
|---|
| 369 | | |
|---|
| 370 | | my $res = chmod ($fperms, $fname); |
|---|
| 371 | | |
|---|
| 372 | | if ($res != 1) { |
|---|
| 373 | | |
|---|
| 374 | | push_el( |
|---|
| 375 | | \@main::el, |
|---|
| 376 | | 'setfmode()', |
|---|
| 377 | | "ERROR: Can not change permissions of file '$fname' !" |
|---|
| 378 | | ); |
|---|
| 379 | | |
|---|
| 380 | | return -1; |
|---|
| 381 | | |
|---|
| 382 | | } |
|---|
| 383 | | |
|---|
| 384 | | $res = chown ($uid, $gid, $fname); |
|---|
| 385 | | |
|---|
| 386 | | if ($res != 1) { |
|---|
| 387 | | |
|---|
| 388 | | push_el( |
|---|
| 389 | | \@main::el, |
|---|
| 390 | | 'setfmode()', |
|---|
| 391 | | "ERROR: Can not change user/group of file '$fname' !" |
|---|
| 392 | | ); |
|---|
| 393 | | |
|---|
| 394 | | return -1; |
|---|
| 395 | | |
|---|
| 396 | | } |
|---|
| 397 | | |
|---|
| 398 | | push_el(\@main::el, 'setfmode()', 'Ending...'); |
|---|
| 399 | | |
|---|
| 400 | | return 0; |
|---|
| 401 | | |
|---|
| 402 | | } |
|---|
| 403 | | |
|---|
| 404 | | sub get_file { |
|---|
| 405 | | |
|---|
| 406 | | my ($fname) = @_; |
|---|
| 407 | | |
|---|
| 408 | | push_el(\@main::el, 'get_file()', 'Starting...'); |
|---|
| 409 | | |
|---|
| 410 | | if (!defined($fname) || ($fname eq '')) { |
|---|
| 411 | | |
|---|
| 412 | | push_el( |
|---|
| 413 | | \@main::el, |
|---|
| 414 | | 'get_file()', |
|---|
| 415 | | "ERROR: Undefined input data, fname: |$fname| !" |
|---|
| 416 | | ); |
|---|
| 417 | | |
|---|
| 418 | | return (-1, ''); |
|---|
| 419 | | |
|---|
| 420 | | } |
|---|
| 421 | | |
|---|
| 422 | | if (! -e $fname) { |
|---|
| 423 | | |
|---|
| 424 | | push_el( |
|---|
| 425 | | \@main::el, |
|---|
| 426 | | 'get_file()', |
|---|
| 427 | | "ERROR: File '$fname' does not exist !" |
|---|
| 428 | | ); |
|---|
| 429 | | |
|---|
| 430 | | return (-1, ''); |
|---|
| 431 | | |
|---|
| 432 | | } |
|---|
| 433 | | |
|---|
| 434 | | my $res = open(F, '<', $fname); |
|---|
| 435 | | |
|---|
| 436 | | if (!defined($res)) { |
|---|
| 437 | | |
|---|
| 438 | | push_el( |
|---|
| 439 | | \@main::el, |
|---|
| 440 | | 'get_file()', |
|---|
| 441 | | "ERROR: Can't open '$fname' for reading !" |
|---|
| 442 | | ); |
|---|
| 443 | | |
|---|
| 444 | | return (-1, ''); |
|---|
| 445 | | |
|---|
| 446 | | } |
|---|
| 447 | | |
|---|
| 448 | | my @fdata = <F>; |
|---|
| 449 | | |
|---|
| 450 | | close(F); |
|---|
| 451 | | |
|---|
| 452 | | my $line = join('', @fdata); |
|---|
| 453 | | |
|---|
| 454 | | push_el(\@main::el, 'get_file()', 'Ending...'); |
|---|
| 455 | | |
|---|
| 456 | | return (0, $line); |
|---|
| 457 | | |
|---|
| 458 | | } |
|---|
| 459 | | |
|---|
| 460 | | sub store_file { |
|---|
| 461 | | |
|---|
| 462 | | my ($fname, $fdata, $fuid, $fgid, $fperms) = @_; |
|---|
| 463 | | |
|---|
| 464 | | push_el(\@main::el, 'store_file()', 'Starting...'); |
|---|
| 465 | | |
|---|
| 466 | | if ( |
|---|
| 467 | | !defined($fname) || !defined($fuid) || |
|---|
| 468 | | !defined($fgid) || !defined($fperms) || |
|---|
| 469 | | $fname eq '' || $fuid eq '' || |
|---|
| 470 | | $fgid eq '' || $fperms eq '' |
|---|
| 471 | | ) |
|---|
| 472 | | { |
|---|
| 473 | | push_el( |
|---|
| 474 | | \@main::el, |
|---|
| 475 | | 'store_file()', |
|---|
| 476 | | "ERROR: Undefined input data, fname: |$fname|, fdata, fuid: '$fuid', fgid: '$fgid', fperms: '$fperms'" |
|---|
| 477 | | ); |
|---|
| 478 | | |
|---|
| 479 | | return -1; |
|---|
| 480 | | } |
|---|
| 481 | | |
|---|
| 482 | | my $res = open(F, '>', $fname); |
|---|
| 483 | | |
|---|
| 484 | | if (!defined($res)) { |
|---|
| 485 | | |
|---|
| 486 | | push_el( |
|---|
| 487 | | \@main::el, |
|---|
| 488 | | 'store_file()', |
|---|
| 489 | | "ERROR: Can't open file |$fname| for writing !" |
|---|
| 490 | | ); |
|---|
| 491 | | |
|---|
| 492 | | return -1; |
|---|
| 493 | | |
|---|
| 494 | | } |
|---|
| 495 | | |
|---|
| 496 | | print F $fdata; |
|---|
| 497 | | |
|---|
| 498 | | close(F); |
|---|
| 499 | | |
|---|
| 500 | | my ($rs, $rdata) = setfmode($fname, $fuid, $fgid, $fperms); |
|---|
| 501 | | |
|---|
| 502 | | return -1 if ($rs != 0); |
|---|
| 503 | | |
|---|
| 504 | | push_el(\@main::el, 'store_file()', 'Ending...'); |
|---|
| 505 | | |
|---|
| 506 | | return 0; |
|---|
| 507 | | |
|---|
| 508 | | } |
|---|
| 509 | | |
|---|
| 510 | | sub save_file { |
|---|
| 511 | | |
|---|
| 512 | | my ($fname, $fdata) = @_; |
|---|
| 513 | | |
|---|
| 514 | | push_el(\@main::el, 'save_file()', 'Starting...'); |
|---|
| 515 | | |
|---|
| 516 | | if ( !defined($fname) || $fname eq '' ) { |
|---|
| 517 | | push_el( |
|---|
| 518 | | \@main::el, |
|---|
| 519 | | 'save_file()', |
|---|
| 520 | | "ERROR: Undefined input data, fname: |$fname|, fdata" |
|---|
| 521 | | ); |
|---|
| 522 | | |
|---|
| 523 | | return -1; |
|---|
| 524 | | } |
|---|
| 525 | | |
|---|
| 526 | | my $res = open(F, '>', $fname); |
|---|
| 527 | | |
|---|
| 528 | | if (!defined($res)) { |
|---|
| 529 | | |
|---|
| 530 | | push_el( |
|---|
| 531 | | \@main::el, |
|---|
| 532 | | 'save_file()', |
|---|
| 533 | | "ERROR: Can't open file |$fname| for writing !" |
|---|
| 534 | | ); |
|---|
| 535 | | |
|---|
| 536 | | return -1; |
|---|
| 537 | | |
|---|
| 538 | | } |
|---|
| 539 | | |
|---|
| 540 | | print F $fdata; |
|---|
| 541 | | |
|---|
| 542 | | close(F); |
|---|
| 543 | | |
|---|
| 544 | | push_el(\@main::el, 'save_file()', 'Ending...'); |
|---|
| 545 | | |
|---|
| 546 | | return 0; |
|---|
| 547 | | |
|---|
| 548 | | } |
|---|
| 549 | | |
|---|
| 550 | | sub del_file { |
|---|
| 551 | | |
|---|
| 552 | | my ($fname) = @_; |
|---|
| 553 | | |
|---|
| 554 | | push_el(\@main::el, 'del_file()', 'Starting...'); |
|---|
| 555 | | |
|---|
| 556 | | if (!defined($fname) || ($fname eq '')) { |
|---|
| 557 | | |
|---|
| 558 | | push_el( |
|---|
| 559 | | \@main::el, |
|---|
| 560 | | 'del_file()', |
|---|
| 561 | | "ERROR: Undefined input data, fname: |$fname| !" |
|---|
| 562 | | ); |
|---|
| 563 | | |
|---|
| 564 | | return -1; |
|---|
| 565 | | |
|---|
| 566 | | } |
|---|
| 567 | | |
|---|
| 568 | | if (! -e $fname) { |
|---|
| 569 | | |
|---|
| 570 | | push_el( |
|---|
| 571 | | \@main::el, |
|---|
| 572 | | 'del_file()', |
|---|
| 573 | | "ERROR: File '$fname' does not exist !" |
|---|
| 574 | | ); |
|---|
| 575 | | |
|---|
| 576 | | return -1; |
|---|
| 577 | | |
|---|
| 578 | | } |
|---|
| 579 | | |
|---|
| 580 | | my $res = unlink ($fname); |
|---|
| 581 | | |
|---|
| 582 | | if ($res != 1) { |
|---|
| 583 | | |
|---|
| 584 | | push_el( |
|---|
| 585 | | \@main::el, |
|---|
| 586 | | 'del_file()', |
|---|
| 587 | | "ERROR: Can't unlink '$fname' !" |
|---|
| 588 | | ); |
|---|
| 589 | | |
|---|
| 590 | | return -1; |
|---|
| 591 | | |
|---|
| 592 | | } |
|---|
| 593 | | |
|---|
| 594 | | push_el(\@main::el, 'del_file()', 'Ending...'); |
|---|
| 595 | | |
|---|
| 596 | | return 0; |
|---|
| 597 | | |
|---|
| 598 | | } |
|---|
| 599 | | |
|---|
| 600 | | sub set_zone { |
|---|
| 601 | | my ($fdata, $data, $zone, $comment) = @_; |
|---|
| 602 | | |
|---|
| 603 | | my @fdata = split("\n", $fdata); |
|---|
| 604 | | |
|---|
| 605 | | my $bz = ''; |
|---|
| 606 | | my $az = ''; |
|---|
| 607 | | my $zs = 0; |
|---|
| 608 | | my $ze = 0; |
|---|
| 609 | | my $ll; |
|---|
| 610 | | my $curline; |
|---|
| 611 | | |
|---|
| 612 | | while(length($fdata) > 0) { |
|---|
| 613 | | $ll = index($fdata, "\n"); |
|---|
| 614 | | if( $ll < 0 ) { |
|---|
| 615 | | $ll = length( $fdata ); |
|---|
| 616 | | } else { |
|---|
| 617 | | $ll++; |
|---|
| 618 | | } |
|---|
| 619 | | $curline = substr( $fdata, 0, $ll ); |
|---|
| 620 | | $fdata = substr( $fdata, $ll ); |
|---|
| 621 | | |
|---|
| 622 | | if( $zs == 0 ) { |
|---|
| 623 | | if( index($curline, $comment."## START ISPCP ".$zone." ###") == 0 ) { |
|---|
| 624 | | $zs = 1; |
|---|
| 625 | | } else { |
|---|
| 626 | | $bz .= $curline; |
|---|
| 627 | | } |
|---|
| 628 | | } elsif( $ze == 0 ) { |
|---|
| 629 | | if( index($curline, $comment."## END ISPCP ".$zone." ###") == 0) { |
|---|
| 630 | | $ze = 1; |
|---|
| 631 | | } |
|---|
| 632 | | } elsif( $ze == 1 ) { |
|---|
| 633 | | $az .= $curline; |
|---|
| 634 | | } |
|---|
| 635 | | } |
|---|
| 636 | | |
|---|
| 637 | | return |
|---|
| 638 | | $bz.($zs == 1 ? "" : "\n"). |
|---|
| 639 | | $comment."## START ISPCP ".$zone." ###\n". |
|---|
| 640 | | $data."\n". |
|---|
| 641 | | $comment."## END ISPCP ".$zone." ###\n". |
|---|
| 642 | | $az; |
|---|
| 643 | | } |
|---|
| 644 | | |
|---|
| 645 | | sub get_zone { |
|---|
| 646 | | my ($fdata, $zone, $comment) = @_; |
|---|
| 647 | | |
|---|
| 648 | | my @fdata = split("\n", $fdata); |
|---|
| 649 | | |
|---|
| 650 | | my $zonecontent = ''; |
|---|
| 651 | | my $zs = 0; |
|---|
| 652 | | my $ze = 0; |
|---|
| 653 | | my $ll; |
|---|
| 654 | | my $curline; |
|---|
| 655 | | |
|---|
| 656 | | while(length($fdata) > 0) { |
|---|
| 657 | | $ll = index($fdata, "\n"); |
|---|
| 658 | | if( $ll < 0 ) { |
|---|
| 659 | | $ll = length( $fdata ); |
|---|
| 660 | | } else { |
|---|
| 661 | | $ll++; |
|---|
| 662 | | } |
|---|
| 663 | | $curline = substr( $fdata, 0, $ll ); |
|---|
| 664 | | $fdata = substr( $fdata, $ll ); |
|---|
| 665 | | |
|---|
| 666 | | if( $zs == 0 ) { |
|---|
| 667 | | if( index($curline, $comment."## START ISPCP ".$zone." ###") == 0 ) { |
|---|
| 668 | | $zs = 1; |
|---|
| 669 | | } |
|---|
| 670 | | } elsif( $ze == 0 ) { |
|---|
| 671 | | if( index($curline, $comment."## END ISPCP ".$zone." ###") == 0) { |
|---|
| 672 | | $ze = 1; |
|---|
| 673 | | } else { |
|---|
| 674 | | $zonecontent .= $curline; |
|---|
| 675 | | } |
|---|
| 676 | | } |
|---|
| 677 | | } |
|---|
| 678 | | |
|---|
| 679 | | return $zonecontent; |
|---|
| 680 | | } |
|---|
| 681 | | |
|---|
| 682 | | sub del_zone { |
|---|
| 683 | | my ($fdata, $zone, $comment) = @_; |
|---|
| 684 | | |
|---|
| 685 | | my @fdata = split("\n", $fdata); |
|---|
| 686 | | |
|---|
| 687 | | my $bz = ''; |
|---|
| 688 | | my $az = ''; |
|---|
| 689 | | my $zs = 0; |
|---|
| 690 | | my $ze = 0; |
|---|
| 691 | | my $ll; |
|---|
| 692 | | my $curline; |
|---|
| 693 | | |
|---|
| 694 | | while(length($fdata) > 0) { |
|---|
| 695 | | $ll = index($fdata, "\n"); |
|---|
| 696 | | if( $ll < 0 ) { |
|---|
| 697 | | $ll = length( $fdata ); |
|---|
| 698 | | } else { |
|---|
| 699 | | $ll++; |
|---|
| 700 | | } |
|---|
| 701 | | $curline = substr( $fdata, 0, $ll ); |
|---|
| 702 | | $fdata = substr( $fdata, $ll ); |
|---|
| 703 | | |
|---|
| 704 | | if( $zs == 0 ) { |
|---|
| 705 | | if( index($curline, $comment."## START ISPCP ".$zone." ###") == 0 ) { |
|---|
| 706 | | $zs = 1; |
|---|
| 707 | | } else { |
|---|
| 708 | | $bz .= $curline; |
|---|
| 709 | | } |
|---|
| 710 | | } elsif( $ze == 0 ) { |
|---|
| 711 | | if( index($curline, $comment."## END ISPCP ".$zone." ###") == 0) { |
|---|
| 712 | | $ze = 1; |
|---|
| 713 | | } |
|---|
| 714 | | } elsif( $ze == 1 ) { |
|---|
| 715 | | $az .= $curline; |
|---|
| 716 | | } |
|---|
| 717 | | } |
|---|
| 718 | | |
|---|
| 719 | | return $bz.$az; |
|---|
| 720 | | } |
|---|
| 721 | | |
|---|
| 722 | | sub sys_command { |
|---|
| 723 | | |
|---|
| 724 | | my ($cmd) = @_; |
|---|
| 725 | | |
|---|
| 726 | | push_el(\@main::el, 'sys_command()', 'Starting...'); |
|---|
| 727 | | |
|---|
| 728 | | my $result = system($cmd); |
|---|
| 729 | | |
|---|
| 730 | | my $exit_value = $? >> 8; |
|---|
| 731 | | |
|---|
| 732 | | my $signal_num = $? & 127; |
|---|
| 733 | | |
|---|
| 734 | | my $dumped_core = $? & 128; |
|---|
| 735 | | |
|---|
| 736 | | if ($exit_value == 0) { |
|---|
| 737 | | |
|---|
| 738 | | push_el(\@main::el, "sys_command('$cmd')", 'Ending...'); |
|---|
| 739 | | |
|---|
| 740 | | return 0; |
|---|
| 741 | | |
|---|
| 742 | | } else { |
|---|
| 743 | | |
|---|
| 744 | | push_el(\@main::el, 'sys_command()', "ERROR: External command '$cmd' returned '$exit_value' status !"); |
|---|
| 745 | | |
|---|
| 746 | | return -1; |
|---|
| 747 | | |
|---|
| 748 | | } |
|---|
| 749 | | |
|---|
| 750 | | } |
|---|
| 751 | | |
|---|
| 752 | | sub sys_command_rs { |
|---|
| 753 | | |
|---|
| 754 | | my ($cmd) = @_; |
|---|
| 755 | | |
|---|
| 756 | | push_el(\@main::el, 'sys_command_rs()', 'Starting...'); |
|---|
| 757 | | |
|---|
| 758 | | my $result = system($cmd); |
|---|
| 759 | | |
|---|
| 760 | | my $exit_value = $? >> 8; |
|---|
| 761 | | |
|---|
| 762 | | my $signal_num = $? & 127; |
|---|
| 763 | | |
|---|
| 764 | | my $dumped_core = $? & 128; |
|---|
| 765 | | |
|---|
| 766 | | push_el(\@main::el, 'sys_command_rs()', 'Ending...'); |
|---|
| 767 | | |
|---|
| 768 | | if ($exit_value == 0) { |
|---|
| 769 | | |
|---|
| 770 | | return 0; |
|---|
| 771 | | |
|---|
| 772 | | } else { |
|---|
| 773 | | |
|---|
| 774 | | |
|---|
| 775 | | return $exit_value; |
|---|
| 776 | | |
|---|
| 777 | | } |
|---|
| 778 | | |
|---|
| 779 | | } |
|---|
| 780 | | |
|---|
| 781 | | sub make_dir { |
|---|
| 782 | | |
|---|
| 783 | | my ($dname, $duid, $dgid, $dperms) = @_; |
|---|
| 784 | | |
|---|
| 785 | | my ($rs, $rdata) = ('', ''); |
|---|
| 786 | | |
|---|
| 787 | | push_el(\@main::el, 'make_dir()', 'Starting...'); |
|---|
| 788 | | |
|---|
| 789 | | if ( |
|---|
| 790 | | !defined($dname) || !defined($duid) || |
|---|
| 791 | | !defined($dgid) || !defined($dperms) || |
|---|
| 792 | | $dname eq '' || $duid eq '' || |
|---|
| 793 | | $dgid eq '' || $dperms eq '' |
|---|
| 794 | | ) |
|---|
| 795 | | { |
|---|
| 796 | | |
|---|
| 797 | | push_el(\@main::el, 'make_dir()', "ERROR: Undefined input data, dname: |$dname|, duid: |$duid|, dgid: |$dgid|, dperms: |$dperms| !"); |
|---|
| 798 | | |
|---|
| 799 | | return -1; |
|---|
| 800 | | |
|---|
| 801 | | } |
|---|
| 802 | | |
|---|
| 803 | | if ( -e $dname && -f $dname ) { |
|---|
| 804 | | |
|---|
| 805 | | push_el(\@main::el,'make_dir()', "'$dname' exists as file ! removing file first..."); |
|---|
| 806 | | |
|---|
| 807 | | return -1 if (del_file($dname) != 0); |
|---|
| 808 | | |
|---|
| 809 | | } |
|---|
| 810 | | |
|---|
| 811 | | if (!(-e $dname && -d $dname)) { |
|---|
| 812 | | |
|---|
| 813 | | push_el(\@main::el, 'make_dir()', "'$dname' doesn't exists as directory! creating..."); |
|---|
| 814 | | |
|---|
| 815 | | $rs = mkpath($dname); |
|---|
| 816 | | |
|---|
| 817 | | if (!$rs) { |
|---|
| 818 | | |
|---|
| 819 | | push_el(\@main::el, 'make_dir()', "ERROR: mkdir() returned '$rs' status !"); |
|---|
| 820 | | |
|---|
| 821 | | return -1; |
|---|
| 822 | | |
|---|
| 823 | | } |
|---|
| 824 | | |
|---|
| 825 | | } else { |
|---|
| 826 | | |
|---|
| 827 | | push_el(\@main::el, 'make_dir()', "'$dname' exists ! Setting its permissions..."); |
|---|
| 828 | | |
|---|
| 829 | | } |
|---|
| 830 | | |
|---|
| 831 | | return -1 if (setfmode($dname, $duid, $dgid, $dperms) != 0); |
|---|
| 832 | | |
|---|
| 833 | | push_el(\@main::el, 'make_dir()', 'Ending...'); |
|---|
| 834 | | |
|---|
| 835 | | return 0; |
|---|
| 836 | | } |
|---|
| 837 | | |
|---|
| 838 | | sub del_dir { |
|---|
| 839 | | |
|---|
| 840 | | my ($dname) = @_; |
|---|
| 841 | | |
|---|
| 842 | | push_el(\@main::el, 'make_dir()', 'Starting...'); |
|---|
| 843 | | |
|---|
| 844 | | if (!defined($dname) || ($dname eq '')) { |
|---|
| 845 | | |
|---|
| 846 | | push_el(\@main::el, 'make_dir()', "ERROR: Undefined input data, dname: |$dname| !"); |
|---|
| 847 | | |
|---|
| 848 | | return -1; |
|---|
| 849 | | |
|---|
| 850 | | } |
|---|
| 851 | | |
|---|
| 852 | | push_el(\@main::el, 'make_dir()', "Trying to remove '$dname'..."); |
|---|
| 853 | | |
|---|
| 854 | | return -1 if (sys_command("rm -rf $dname") != 0); |
|---|
| 855 | | |
|---|
| 856 | | push_el(\@main::el, 'make_dir()', 'Ending...'); |
|---|
| 857 | | |
|---|
| 858 | | return 0; |
|---|
| 859 | | |
|---|
| 860 | | } |
|---|
| 861 | | |
|---|
| 862 | | sub gen_rand_num { |
|---|
| 863 | | |
|---|
| 864 | | my ($len) = @_; |
|---|
| 865 | | |
|---|
| 866 | | push_el(\@main::el, 'gen_rand_num()', 'Starting...'); |
|---|
| 867 | | |
|---|
| 868 | | if (!defined($len) || ($len eq '')) { |
|---|
| 869 | | |
|---|
| 870 | | push_el(\@main::el, 'gen_rand_num()', "ERROR: Undefined input data, len: |$len| !"); |
|---|
| 871 | | |
|---|
| 872 | | return (-1, ''); |
|---|
| 873 | | |
|---|
| 874 | | } |
|---|
| 875 | | |
|---|
| 876 | | if (!(0 < $len && $len < 11)) { |
|---|
| 877 | | |
|---|
| 878 | | push_el(\@main::el, 'gen_rand_num()', "ERROR: Input data length '$len' out of limits [1, 10] !"); |
|---|
| 879 | | |
|---|
| 880 | | return (-1, ''); |
|---|
| 881 | | |
|---|
| 882 | | } |
|---|
| 883 | | |
|---|
| 884 | | my @rand_data = ('A'..'Z', 'a'..'z', '0'..'9', '.', '/'); |
|---|
| 885 | | |
|---|
| 886 | | my ($i, $rdata) = ('', ''); |
|---|
| 887 | | |
|---|
| 888 | | for ($i = 0; $i < $len; $i++) { |
|---|
| 889 | | |
|---|
| 890 | | $rdata .= $rand_data[ rand() * ($#rand_data + 1) ]; |
|---|
| 891 | | |
|---|
| 892 | | } |
|---|
| 893 | | |
|---|
| 894 | | push_el(\@main::el, 'gen_rand_num()', 'Ending...'); |
|---|
| 895 | | |
|---|
| 896 | | return (0, $rdata); |
|---|
| 897 | | |
|---|
| 898 | | } |
|---|
| 899 | | |
|---|
| 900 | | sub gen_sys_rand_num { |
|---|
| 901 | | |
|---|
| 902 | | my ($len) = @_; |
|---|
| 903 | | |
|---|
| 904 | | push_el(\@main::el, 'gen_sys_rand_num()', 'Starting...'); |
|---|
| 905 | | |
|---|
| 906 | | if (!defined($len) || ($len eq '')) { |
|---|
| 907 | | |
|---|
| 908 | | push_el(\@main::el, 'gen_sys_rand_num()', "ERROR: Undefined input data, len: |$len| !"); |
|---|
| 909 | | |
|---|
| 910 | | return (-1, ''); |
|---|
| 911 | | |
|---|
| 912 | | } |
|---|
| 913 | | |
|---|
| 914 | | if (0 >= $len ) { |
|---|
| 915 | | |
|---|
| 916 | | push_el(\@main::el, 'gen_sys_rand_num()', "ERROR: Input data length '$len' is zero or negative !"); |
|---|
| 917 | | |
|---|
| 918 | | return (-1, ''); |
|---|
| 919 | | |
|---|
| 920 | | } |
|---|
| 921 | | |
|---|
| 922 | | my $rs = open(F, '<', '/dev/random'); |
|---|
| 923 | | |
|---|
| 924 | | if (!defined($rs)) { |
|---|
| 925 | | |
|---|
| 926 | | push_el(\@main::el, 'gen_sys_rand_num()', "ERROR: Couldn't open the pseudo-random characters generator"); |
|---|
| 927 | | |
|---|
| 928 | | return (-1, ''); |
|---|
| 929 | | |
|---|
| 930 | | } |
|---|
| 931 | | |
|---|
| 932 | | my ($i, $rdata, $rc, $rci) = (0, undef, undef, undef); |
|---|
| 933 | | |
|---|
| 934 | | while ($i < $len) { |
|---|
| 935 | | |
|---|
| 936 | | read(F, $rc, 1); |
|---|
| 937 | | |
|---|
| 938 | | $rci = ord($rc); |
|---|
| 939 | | |
|---|
| 940 | | next if ($rci <= 32 || $rci >= 125 || $rci == 92 ); |
|---|
| 941 | | |
|---|
| 942 | | $rdata .= $rc; |
|---|
| 943 | | $rc = undef; |
|---|
| 944 | | $i++; |
|---|
| 945 | | |
|---|
| 946 | | } |
|---|
| 947 | | |
|---|
| 948 | | close(F); |
|---|
| 949 | | |
|---|
| 950 | | push_el(\@main::el, 'gen_sys_rand_num()', 'Ending...'); |
|---|
| 951 | | |
|---|
| 952 | | return (0, $rdata); |
|---|
| 953 | | |
|---|
| 954 | | } |
|---|
| 955 | | |
|---|
| 956 | | sub crypt_md5_data { |
|---|
| 957 | | |
|---|
| 958 | | my ($data) = @_; |
|---|
| 959 | | |
|---|
| 960 | | push_el(\@main::el, 'crypt_md5_data()', 'Starting...'); |
|---|
| 961 | | |
|---|
| 962 | | if (!defined($data) || $data eq '') { |
|---|
| 963 | | |
|---|
| 964 | | push_el(\@main::el, 'crypt_md5_data()', "ERROR: Undefined input data, data: |$data| !"); |
|---|
| 965 | | |
|---|
| 966 | | return (-1, ''); |
|---|
| 967 | | |
|---|
| 968 | | } |
|---|
| 969 | | |
|---|
| 970 | | my ($rs, $rdata) = gen_rand_num(2); |
|---|
| 971 | | |
|---|
| 972 | | return (-1, '') if ($rs != 0); |
|---|
| 973 | | |
|---|
| 974 | | $rdata = unix_md5_crypt($data, $rdata); |
|---|
| 975 | | |
|---|
| 976 | | push_el(\@main::el, 'crypt_md5_data()', 'Ending...'); |
|---|
| 977 | | |
|---|
| 978 | | return (0, $rdata); |
|---|
| 979 | | |
|---|
| 980 | | } |
|---|
| 981 | | |
|---|
| 982 | | sub crypt_data { |
|---|
| 983 | | |
|---|
| 984 | | my ($data) = @_; |
|---|
| 985 | | |
|---|
| 986 | | push_el(\@main::el, 'crypt_data()', 'Starting...'); |
|---|
| 987 | | |
|---|
| 988 | | if (!defined($data) || $data eq '') { |
|---|
| 989 | | |
|---|
| 990 | | push_el(\@main::el, 'crypt_data()', "ERROR: Undefined input data, data: |$data| !"); |
|---|
| 991 | | |
|---|
| 992 | | return (-1, ''); |
|---|
| 993 | | |
|---|
| 994 | | } |
|---|
| 995 | | |
|---|
| 996 | | my ($rs, $rdata) = gen_rand_num(2); |
|---|
| 997 | | |
|---|
| 998 | | return (-1, '') if ($rs != 0); |
|---|
| 999 | | |
|---|
| 1000 | | $rdata = crypt($data, $rdata); |
|---|
| 1001 | | |
|---|
| 1002 | | push_el(\@main::el, 'crypt_data()', 'Ending...'); |
|---|
| 1003 | | |
|---|
| 1004 | | return (0, $rdata); |
|---|
| 1005 | | |
|---|
| 1006 | | } |
|---|
| 1007 | | |
|---|
| 1008 | | sub get_tag { |
|---|
| 1009 | | |
|---|
| 1010 | | my ($bt, $et, $src) = @_; |
|---|
| 1011 | | |
|---|
| 1012 | | push_el(\@main::el, 'get_tag()', "Starting..."); |
|---|
| 1013 | | |
|---|
| 1014 | | if ( |
|---|
| 1015 | | !defined($bt) || !defined($et) || |
|---|
| 1016 | | !defined($src) || $bt eq '' || |
|---|
| 1017 | | $et eq '' || $src eq '' |
|---|
| 1018 | | ) |
|---|
| 1019 | | { |
|---|
| 1020 | | |
|---|
| 1021 | | push_el(\@main::el, 'get_tag()', "ERROR: Undefined intput data, bt: |$bt|, et: |$et|, src !"); |
|---|
| 1022 | | |
|---|
| 1023 | | return (-1, ''); |
|---|
| 1024 | | |
|---|
| 1025 | | } |
|---|
| 1026 | | |
|---|
| 1027 | | my ($bt_len, $et_len, $src_len) = ( |
|---|
| 1028 | | length($bt), |
|---|
| 1029 | | length($et), |
|---|
| 1030 | | length($src) |
|---|
| 1031 | | ); |
|---|
| 1032 | | |
|---|
| 1033 | | # |
|---|
| 1034 | | #return ('_e03_', $main::strerr{'_e03_'}) |
|---|
| 1035 | | # |
|---|
| 1036 | | #if ($bt_len > $src_len || $et_len > $src_len); |
|---|
| 1037 | | # |
|---|
| 1038 | | |
|---|
| 1039 | | if ($bt eq $et) { |
|---|
| 1040 | | |
|---|
| 1041 | | |
|---|
| 1042 | | # Let's search for ...$tag... ; |
|---|
| 1043 | | |
|---|
| 1044 | | # $bt == $et == $tag ; |
|---|
| 1045 | | |
|---|
| 1046 | | |
|---|
| 1047 | | my $tag = $bt; |
|---|
| 1048 | | |
|---|
| 1049 | | my $tag_pos = index($src, $tag); |
|---|
| 1050 | | |
|---|
| 1051 | | if ($tag_pos < 0) { |
|---|
| 1052 | | |
|---|
| 1053 | | push_el(\@main::el, 'get_tag()', "ERROR: '$bt' eq '$et', missing '$bt' in src !"); |
|---|
| 1054 | | |
|---|
| 1055 | | return (-4, ''); |
|---|
| 1056 | | |
|---|
| 1057 | | } else { |
|---|
| 1058 | | |
|---|
| 1059 | | push_el(\@main::el, 'get_tag()', 'Ending...'); |
|---|
| 1060 | | |
|---|
| 1061 | | return (0, $tag); |
|---|
| 1062 | | |
|---|
| 1063 | | } |
|---|
| 1064 | | |
|---|
| 1065 | | } else { |
|---|
| 1066 | | |
|---|
| 1067 | | if ($bt_len + $et_len > $src_len) { |
|---|
| 1068 | | |
|---|
| 1069 | | push_el(\@main::el, 'get_tag()', "ERROR: len($bt) + len($et) > len(src) !"); |
|---|
| 1070 | | |
|---|
| 1071 | | return (-1, ''); |
|---|
| 1072 | | |
|---|
| 1073 | | } |
|---|
| 1074 | | |
|---|
| 1075 | | |
|---|
| 1076 | | # Let's search for ...$bt...$et... ; |
|---|
| 1077 | | |
|---|
| 1078 | | |
|---|
| 1079 | | my ($bt_pos, $et_pos) = (index($src, $bt), index($src, $et)); |
|---|
| 1080 | | |
|---|
| 1081 | | if ($bt_pos < 0 || $et_pos < 0) { |
|---|
| 1082 | | |
|---|
| 1083 | | push_el(\@main::el, 'get_tag()', "ERROR: '$bt' ne '$et', '$bt' or '$et' missing in src !"); |
|---|
| 1084 | | |
|---|
| 1085 | | return (-5, ''); |
|---|
| 1086 | | |
|---|
| 1087 | | } |
|---|
| 1088 | | |
|---|
| 1089 | | if ($et_pos < $bt_pos + $bt_len) { |
|---|
| 1090 | | |
|---|
| 1091 | | push_el(\@main::el, 'get_tag()', "ERROR: '$bt' ne '$et', '$et' overlaps '$bt' in src !"); |
|---|
| 1092 | | |
|---|
| 1093 | | return (-1, ''); |
|---|
| 1094 | | |
|---|
| 1095 | | } |
|---|
| 1096 | | |
|---|
| 1097 | | push_el(\@main::el, 'get_tag()', 'Ending...'); |
|---|
| 1098 | | |
|---|
| 1099 | | my $tag_len = $et_pos + $et_len - $bt_pos; |
|---|
| 1100 | | |
|---|
| 1101 | | return (0, substr($src, $bt_pos, $tag_len)); |
|---|
| 1102 | | |
|---|
| 1103 | | } |
|---|
| 1104 | | |
|---|
| 1105 | | } |
|---|
| 1106 | | |
|---|
| 1107 | | sub repl_tag { |
|---|
| 1108 | | |
|---|
| 1109 | | my ($bt, $et, $src, $rwith) = @_; |
|---|
| 1110 | | |
|---|
| 1111 | | push_el(\@main::el, 'repl_tag()', "Starting..."); |
|---|
| 1112 | | |
|---|
| 1113 | | if (!defined ($rwith)) { |
|---|
| 1114 | | |
|---|
| 1115 | | push_el(\@main::el, 'repl_tag()', "ERROR: Undefined input data, rwith: |$rwith| !"); |
|---|
| 1116 | | |
|---|
| 1117 | | return (-1, ''); |
|---|
| 1118 | | |
|---|
| 1119 | | } |
|---|
| 1120 | | |
|---|
| 1121 | | my ($rs, $rdata) = get_tag($bt, $et, $src); |
|---|
| 1122 | | |
|---|
| 1123 | | return $rs if ($rs != 0); |
|---|
| 1124 | | |
|---|
| 1125 | | my $tag = $rdata; |
|---|
| 1126 | | |
|---|
| 1127 | | my ($tag_pos, $tag_len) = (index($src, $tag), length($tag)); |
|---|
| 1128 | | |
|---|
| 1129 | | if ($rwith eq '') { |
|---|
| 1130 | | |
|---|
| 1131 | | substr($src, $tag_pos, $tag_len, ''); |
|---|
| 1132 | | |
|---|
| 1133 | | } else { |
|---|
| 1134 | | |
|---|
| 1135 | | substr($src, $tag_pos, $tag_len, $rwith); |
|---|
| 1136 | | |
|---|
| 1137 | | } |
|---|
| 1138 | | |
|---|
| 1139 | | push_el(\@main::el, 'repl_tag()', "Ending..."); |
|---|
| 1140 | | |
|---|
| 1141 | | return (0, $src); |
|---|
| 1142 | | } |
|---|
| 1143 | | |
|---|
| 1144 | | sub add_tag { |
|---|
| 1145 | | |
|---|
| 1146 | | my ($bt, $et, $src, $adata) = @_; |
|---|
| 1147 | | |
|---|
| 1148 | | push_el(\@main::el, 'add_tag()', "Starting..."); |
|---|
| 1149 | | |
|---|
| 1150 | | if (!defined($adata) || $adata eq '') { |
|---|
| 1151 | | |
|---|
| 1152 | | push_el(\@main::el, 'add_tag()', "ERROR: Undefined input data, adata: |$adata| !"); |
|---|
| 1153 | | |
|---|
| 1154 | | return (-1, ''); |
|---|
| 1155 | | } |
|---|
| 1156 | | |
|---|
| 1157 | | my ($rs, $rdata) = get_tag($bt, $et, $src); |
|---|
| 1158 | | |
|---|
| 1159 | | return ($rs, '') if ($rs != 0); |
|---|
| 1160 | | |
|---|
| 1161 | | my $rwith = ''; |
|---|
| 1162 | | |
|---|
| 1163 | | if ($bt eq $et) { |
|---|
| 1164 | | |
|---|
| 1165 | | $rwith = "$adata$bt"; |
|---|
| 1166 | | |
|---|
| 1167 | | } else { |
|---|
| 1168 | | |
|---|
| 1169 | | $rwith = "$adata$bt$et"; |
|---|
| 1170 | | |
|---|
| 1171 | | } |
|---|
| 1172 | | |
|---|
| 1173 | | ($rs, $rdata) = repl_tag($bt, $et, $src, $rwith); |
|---|
| 1174 | | |
|---|
| 1175 | | return (-1, '') if ($rs != 0); |
|---|
| 1176 | | |
|---|
| 1177 | | push_el(\@main::el, 'add_tag()', "Ending..."); |
|---|
| 1178 | | |
|---|
| 1179 | | return (0, $rdata); |
|---|
| 1180 | | } |
|---|
| 1181 | | |
|---|
| 1182 | | sub del_tag { |
|---|
| 1183 | | |
|---|
| 1184 | | my ($bt, $et, $src) = @_; |
|---|
| 1185 | | |
|---|
| 1186 | | push_el(\@main::el, 'del_tag()', "Starting..."); |
|---|
| 1187 | | |
|---|
| 1188 | | my ($rs, $rdata) = get_tag($bt, $et, $src); |
|---|
| 1189 | | |
|---|
| 1190 | | return ($rs, '') if ($rs != 0); |
|---|
| 1191 | | |
|---|
| 1192 | | ($rs, $rdata) = repl_tag($bt, $et, $src, ''); |
|---|
| 1193 | | |
|---|
| 1194 | | return (-1, '') if ($rs != 0); |
|---|
| 1195 | | |
|---|
| 1196 | | push_el(\@main::el, 'del_tag()', "Ending..."); |
|---|
| 1197 | | |
|---|
| 1198 | | return (0, $rdata); |
|---|
| 1199 | | |
|---|
| 1200 | | } |
|---|
| 1201 | | |
|---|
| 1202 | | sub get_var { |
|---|
| 1203 | | |
|---|
| 1204 | | my ($var, $src) = @_; |
|---|
| 1205 | | |
|---|
| 1206 | | push_el(\@main::el, 'get_var()', "Starting..."); |
|---|
| 1207 | | |
|---|
| 1208 | | my ($rs, $rdata) = get_tag($var, $var, $src); |
|---|
| 1209 | | |
|---|
| 1210 | | return ($rs, '') if ($rs != 0); |
|---|
| 1211 | | |
|---|
| 1212 | | push_el(\@main::el, 'get_var()', "Ending..."); |
|---|
| 1213 | | |
|---|
| 1214 | | return (0, $rdata); |
|---|
| 1215 | | |
|---|
| 1216 | | } |
|---|
| 1217 | | |
|---|
| 1218 | | sub repl_var { |
|---|
| 1219 | | |
|---|
| 1220 | | my ($var, $src, $rwith) = @_; |
|---|
| 1221 | | |
|---|
| 1222 | | my ($rs, $rdata, $result) = (0, $src, ''); |
|---|
| 1223 | | |
|---|
| 1224 | | push_el(\@main::el, 'repl_var()', "Starting..."); |
|---|
| 1225 | | |
|---|
| 1226 | | while ($rs == 0) { |
|---|
| 1227 | | |
|---|
| 1228 | | $result = $rdata; |
|---|
| 1229 | | |
|---|
| 1230 | | ($rs, $rdata) = repl_tag($var, $var, $rdata, $rwith); |
|---|
| 1231 | | |
|---|
| 1232 | | return -1 if ($rs != 0 && $rs != -4); |
|---|
| 1233 | | |
|---|
| 1234 | | } |
|---|
| 1235 | | |
|---|
| 1236 | | push_el(\@main::el, 'repl_var()', "Ending..."); |
|---|
| 1237 | | |
|---|
| 1238 | | return (0, $result); |
|---|
| 1239 | | } |
|---|
| 1240 | | |
|---|
| 1241 | | sub add_var { |
|---|
| 1242 | | |
|---|
| 1243 | | my ($var, $src, $adata) = @_; |
|---|
| 1244 | | |
|---|
| 1245 | | push_el(\@main::el, 'add_var()', "Starting..."); |
|---|
| 1246 | |
|---|