main.pm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. package eyelib::main;
  2. #
  3. # Copyright (C) Roman Dmitiriev, rnd@rajven.ru
  4. #
  5. use utf8;
  6. use strict;
  7. use English;
  8. use FindBin '$Bin';
  9. use lib "$Bin";
  10. use base 'Exporter';
  11. use vars qw(@EXPORT @ISA);
  12. use eyelib::config;
  13. use Socket;
  14. use IO::Select;
  15. use IO::Handle;
  16. use Crypt::CBC;
  17. use MIME::Base64;
  18. our @ISA = qw(Exporter);
  19. our @EXPORT = qw(
  20. eye_version
  21. log_file
  22. write_to_file
  23. wrlog
  24. log_session
  25. log_warning
  26. log_info
  27. log_debug
  28. log_error
  29. log_verbose
  30. log_die
  31. in_array
  32. timestamp
  33. do_exec
  34. do_exec_ref
  35. do_exit
  36. sendEmail
  37. IsNotRun
  38. IsMyPID
  39. Add_PID
  40. Remove_PID
  41. IsNotLocked
  42. IsMyLock
  43. Add_Lock
  44. Remove_Lock
  45. DefHash
  46. read_file
  47. uniq
  48. strim
  49. trim
  50. is_integer
  51. is_float
  52. run_in_parallel
  53. translit
  54. crypt_string
  55. decrypt_string
  56. netdev_set_auth
  57. );
  58. BEGIN
  59. {
  60. our $eye_version = "2.4.14";
  61. #---------------------------------------------------------------------------------------------------------
  62. sub log_file {
  63. return if (!$_[0]);
  64. return if (!$_[1]);
  65. return if (!$_[2]);
  66. open (LG,">>$_[0]") || die("Error open log file $_[0]!!! die...");
  67. my ($sec,$min,$hour,$mday,$mon,$year) = (localtime())[0,1,2,3,4,5];
  68. $mon += 1; $year += 1900;
  69. my @msg = split("\n",$_[2]);
  70. foreach my $row (@msg) {
  71. next if (!$row);
  72. printf LG "%04d%02d%02d-%02d%02d%02d %s [%d] %s\n",$year,$mon,$mday,$hour,$min,$sec,$_[1],$$,$row;
  73. }
  74. close (LG);
  75. if ($< ==0) {
  76. my $uid = getpwnam $log_owner_user;
  77. my $gid = getgrnam $log_owner_user;
  78. if (!$gid) { $gid=getgrnam "root"; }
  79. if (!$uid) { $uid=getpwnam "root"; }
  80. chown $uid, $gid, $_[0];
  81. chmod oct("0660"), $_[0];
  82. }
  83. }
  84. #---------------------------------------------------------------------------------------------------------
  85. sub write_to_file {
  86. return if (!$_[0]);
  87. return if (!$_[1]);
  88. my $f_name = shift;
  89. my $cmd = shift;
  90. my $append = shift;
  91. if ($append) {
  92. open (LG,">>$f_name") || die("Error open file $f_name!!! die...");
  93. } else {
  94. open (LG,">$f_name") || die("Error open file $f_name!!! die...");
  95. }
  96. binmode(LG,':utf8');
  97. if (ref($cmd) eq 'ARRAY') {
  98. foreach my $row (@$cmd) {
  99. next if (!$row);
  100. print LG $row."\n";
  101. }
  102. } else {
  103. my @msg = split("\n",$cmd);
  104. foreach my $row (@msg) {
  105. next if (!$row);
  106. print LG $row."\n";
  107. }
  108. }
  109. close (LG);
  110. }
  111. #---------------------------------------------------------------------------------------------------------
  112. sub wrlog {
  113. my $level = shift;
  114. my $string = shift;
  115. my $PRN_LEVEL = 'INFO:';
  116. if ($level == $W_INFO) { log_info($string); }
  117. if ($level == $W_ERROR) { $PRN_LEVEL = 'ERROR:'; log_error($string); }
  118. if ($level == $W_DEBUG) { $PRN_LEVEL = 'DEBUG'; log_debug($string); }
  119. my @msg = split("\n",$string);
  120. foreach my $row (@msg) {
  121. next if (!$row);
  122. print $PRN_LEVEL.' '.$row."\n";
  123. }
  124. }
  125. #---------------------------------------------------------------------------------------------------------
  126. sub log_session { log_file($LOG_COMMON,"SESSION:",$_[0]) if ($log_enable); }
  127. #---------------------------------------------------------------------------------------------------------
  128. sub log_info { log_file($LOG_COMMON,"INFO:",$_[0]) if ($log_enable); }
  129. #---------------------------------------------------------------------------------------------------------
  130. sub log_verbose { log_file($LOG_COMMON,"VERBOSE:",$_[0]) if ($log_enable); }
  131. #---------------------------------------------------------------------------------------------------------
  132. sub log_warning { log_file($LOG_COMMON,"WARN:",$_[0]) if ($log_enable); }
  133. #---------------------------------------------------------------------------------------------------------
  134. sub log_debug { log_file($LOG_DEBUG,"DEBUG:",$_[0]) if $debug; }
  135. #---------------------------------------------------------------------------------------------------------
  136. sub log_error { log_file($LOG_ERR,"ERROR:",$_[0]) if ($log_enable); }
  137. #---------------------------------------------------------------------------------------------------------
  138. sub log_die {
  139. wrlog($W_ERROR,$_[0]);
  140. my $worktime = time()-$BASETIME;
  141. log_info("Script work $worktime sec.");
  142. sendEmail("$HOSTNAME - $MY_NAME die! ","Process: $MY_NAME aborted with error:\n$_[0]");
  143. die ($_[0]);
  144. }
  145. #---------------------------------------------------------------------------------------------------------
  146. sub timestamp {
  147. my $worktime = time()-$BASETIME;
  148. log_info("TimeStamp: $worktime sec.");
  149. }
  150. #---------------------------------------------------------------------------------------------------------
  151. sub in_array {
  152. my $arr = shift;
  153. my @tmp = ();
  154. if (ref($arr)=~'ARRAY') { @tmp = @{$arr}; } else { push(@tmp,$arr); }
  155. my $value = shift;
  156. my %num = map { $_, 1 } @tmp;
  157. return $num{$value} || 0;
  158. }
  159. #---------------------------------------------------------------------------------------------------------.
  160. sub do_exec_ref {
  161. my $ret = `$_[0] 2>&1`;
  162. my $res = $?;
  163. my %result;
  164. chomp($ret);
  165. $result{output}=$ret;
  166. $result{status}=$res;
  167. log_debug("Run: $_[0] Output:\n$ret\nResult code: $res");
  168. if ($res eq "0") { log_info("Run: $_[0] - $ret"); } else { log_error("Run: $_[0] - $ret"); }
  169. return %result;
  170. }
  171. #---------------------------------------------------------------------------------------------------------
  172. sub do_exec {
  173. my $ret = `$_[0]`;
  174. my $res = $?;
  175. log_debug("Run: $_[0] Output:\n$ret\nResult code: $res");
  176. if ($res eq "0") {
  177. log_info("Run: $_[0] - $ret");
  178. } else {
  179. $ret = "Error";
  180. log_error("Run: $_[0] - $ret");
  181. }
  182. return $ret;
  183. }
  184. #---------------------------------------------------------------------------------------------------------
  185. sub do_exit {
  186. my $worktime = time()-$BASETIME;
  187. my $code;
  188. if ($_[0]) { $code = $_[0]; } else { $code = 0; }
  189. log_info("Script work $worktime sec. Exit code: $code");
  190. exit $code;
  191. }
  192. #---------------------------------------------------------------------------------------------------------
  193. sub sendEmail {
  194. my ($subject, $message, $crf) = @_;
  195. return if (!$send_email);
  196. my $sendmail = '/sbin/sendmail';
  197. open(MAIL, "|$sendmail -oi -t");
  198. print MAIL "From: $sender_email\n";
  199. print MAIL "To: $admin_email\n";
  200. print MAIL "Subject: $subject\nMIME-Version: 1.0\nContent-Language: ru\nContent-Type: text/html; charset=utf-8\nContent-Transfer-Encoding: 8bit\n\n";
  201. print MAIL '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
  202. print MAIL '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
  203. print MAIL "<head><title>$subject </title></head><body>\n";
  204. my @msg = split("\n",$message);
  205. foreach my $row (@msg) {
  206. if ($crf) { print MAIL "$row<br>"; } else { print MAIL "$row\n"; };
  207. }
  208. print MAIL "</body></html>\n";
  209. close(MAIL);
  210. log_info("Send email from $sender_email to $admin_email with subject: $subject");
  211. log_debug("Body:\n$message");
  212. }
  213. #---------------------------------------------------------------------------------------------------------
  214. ### Check few run script
  215. sub IsNotRun {
  216. my $pname = shift;
  217. my $lockfile = $pname.".pid";
  218. # if pid file not exists - OK
  219. log_debug("Check what pid file $lockfile exists.");
  220. if (! -e $lockfile) { log_debug("pid file not found. Continue."); return 1; }
  221. open (FF,"<$lockfile") or log_die("can't open file $lockfile: $!");
  222. my $lockid = <FF>;
  223. close(FF);
  224. chomp($lockid);
  225. # If the process ID belongs to the current program - OK
  226. if ($lockid eq $$) { log_debug("pid file found, but owner is this process. Continue. "); return 1; }
  227. # if owner of this process ID not exists - OK
  228. my $process_count = `ps -p $lockid | grep \'$lockid\' | wc -l`;
  229. chomp($process_count);
  230. log_debug("Process count with id $lockid is $process_count");
  231. if ($process_count==0) { log_debug("pid file found, but owner process not found. Remove lock file and continue. "); unlink $lockfile; return 1; }
  232. log_debug("Another proceess with name $MY_NAME pid: $lockid already worked. ");
  233. return 0;
  234. }
  235. #---------------------------------------------------------------------------------------------------------
  236. sub IsMyPID {
  237. my $pname = shift;
  238. my $lockfile = $pname.".pid";
  239. log_debug("Check what pid file $lockfile exists.");
  240. if (! -e $lockfile) { log_debug("pid file not found. Continue."); return 1; }
  241. open (FF,"<$lockfile") or log_die "can't open file $lockfile: $!";
  242. my $lockid = <FF>;
  243. close(FF);
  244. chomp($lockid);
  245. if ($lockid eq $$) { log_debug("pid file is my. continue."); return 1; }
  246. log_debug("Another proceess with name $MY_NAME pid: $lockid already worked. ");
  247. return 0;
  248. }
  249. #---------------------------------------------------------------------------------------------------------
  250. sub Add_PID {
  251. my $pname = shift;
  252. my $lockfile = $pname.".pid";
  253. log_debug("Try create lock file $lockfile");
  254. open (FF,">$lockfile") or log_die "can't open file $lockfile: $!";
  255. flock(FF,2) or log_die "can't flock $lockfile: $!";
  256. print FF $$;
  257. close(FF);
  258. log_debug("Ok.");
  259. return 1;
  260. }
  261. #---------------------------------------------------------------------------------------------------------
  262. sub Remove_PID {
  263. my $pname = shift;
  264. my $lockfile = $pname.".pid";
  265. log_debug("Check what pid file $lockfile exists.");
  266. if (! -e $lockfile) { log_debug("pid file not exists. Continue."); return 1; }
  267. unlink $lockfile or return 0;
  268. log_debug("pid file $lockfile removed.");
  269. return 1;
  270. }
  271. #---------------------------------------------------------------------------------------------------------
  272. sub IsNotLocked {
  273. my $lockfile = $_[0] . ".lock";
  274. log_debug("Check what lock file $lockfile exists.");
  275. if (! -e $lockfile) { log_debug("lock file not found. Continue."); return 1; }
  276. open (FF,"<$lockfile") or log_die "can't open file $lockfile: $!";
  277. my $lockid = <FF>;
  278. close(FF);
  279. chomp($lockid);
  280. if ($lockid eq $$) { log_debug("lock file found, but it is owner is this process. Continue. "); return 1; }
  281. my $process_count = `ps -p $lockid | grep \'$lockid\' | wc -l`;
  282. if ($process_count lt 1) { log_debug("lock file found, but owner process not found. Remove lock file and continue. "); unlink $lockfile; return 1; }
  283. log_debug("Another proceess with pid: $lockid already use $_[0]");
  284. return 0;
  285. }
  286. #---------------------------------------------------------------------------------------------------------
  287. sub IsMyLock {
  288. my $lockfile = $_[0] . ".lock";
  289. log_debug("Check what lock file $lockfile exists.");
  290. if (! -e $lockfile) { log_debug("lock file not found. Continue."); return 0; }
  291. open (FF,"<$lockfile") or log_die "can't open file $lockfile: $!";
  292. my $lockid = <FF>;
  293. close(FF);
  294. chomp($lockid);
  295. if ($lockid eq $$) { log_debug("lock file found, but it is owner is this process. Continue. "); return 1; }
  296. log_debug("file $_[0] used by process with pid: $lockid");
  297. return 0;
  298. }
  299. #---------------------------------------------------------------------------------------------------------
  300. sub Add_Lock {
  301. if (!IsNotLocked($_[0])) { return 0; }
  302. my $lockfile = $_[0] . ".lock";
  303. open (FF,">$lockfile") or log_die "can't open file $lockfile: $!";
  304. flock(FF,2) or log_die "can't flock $lockfile: $!";
  305. print FF $$;
  306. close(FF);
  307. log_debug("Create lock file for $_[0]");
  308. return 1;
  309. }
  310. #---------------------------------------------------------------------------------------------------------
  311. sub Remove_Lock {
  312. if (!IsNotLocked($_[0])) { return 0; }
  313. my $lockfile = $_[0] . ".lock";
  314. if (! -e $lockfile) { return 1; }
  315. unlink $lockfile or return 0;
  316. log_debug("Lock file for $_[0] removed");
  317. return 1;
  318. }
  319. #---------------------------------------------------------------------------------------------------------
  320. sub DefHash {
  321. my $hash=$_[0];
  322. my $num_list = $_[1];
  323. my %num_keys;
  324. if ($num_list) {
  325. my @ret_num = split(' ',$num_list);
  326. %num_keys = map { $_, 1 } @ret_num;
  327. }
  328. foreach my $key (keys %$hash) {
  329. my $null_value = "";
  330. $null_value = 0 if (defined $num_keys{$key});
  331. $hash->{$key}=$null_value if (!defined($hash->{$key}));
  332. }
  333. return $hash;
  334. }
  335. #---------------------------------------------------------------------------------------------------------
  336. sub read_file {
  337. my $filename = shift;
  338. return if (!$filename);
  339. return if (!-e $filename);
  340. open (FF,"<$filename") or die "unable to open file $filename!" ;
  341. my @tmp=<FF>;
  342. close(FF);
  343. chomp(@tmp);
  344. return @tmp;
  345. }
  346. #---------------------------------------------------------------------------------------------------------
  347. sub uniq (\@) {
  348. my @tmp = @{(shift)};
  349. if (scalar(@tmp) eq 0) { return @tmp; }
  350. chomp(@tmp);
  351. my %newlist = map { $_, 1 } @tmp;
  352. return keys %newlist;
  353. }
  354. #---------------------------------------------------------------------------------------------------------
  355. sub strim {
  356. my $str=shift;
  357. return if (!$str);
  358. #$str =~ s/.*[^[:print:]]+//g;
  359. #$str =~ s/[^[:print:]]+//g;
  360. #$str =~ s/[^(a-z|A-Z|0-9|\:|\-|\s|\.)]//g;
  361. #$str =~ s/[:^print:]//g;
  362. $str =~ s/[^[:ascii:]]//g;
  363. $str =~ s/^\s+//g;
  364. $str =~ s/\s+$//g;
  365. return $str;
  366. }
  367. #---------------------------------------------------------------------------------------------------------
  368. sub trim {
  369. my $str=shift;
  370. return if (!$str);
  371. $str =~ s/\n/ /g;
  372. $str =~ s/^\s+//g;
  373. $str =~ s/\s+$//g;
  374. return $str;
  375. }
  376. #---------------------------------------------------------------------------------------------------------
  377. sub is_integer {
  378. defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
  379. }
  380. #---------------------------------------------------------------------------------------------------------
  381. sub is_float {
  382. defined $_[0] && $_[0] =~ /^[+-]?\d+(\.\d+)?$/;
  383. }
  384. #---------------------------------------------------------------------------------------------------------
  385. sub run_in_parallel(\@) {
  386. my @commands = @{(shift)};
  387. my @result = ();
  388. return @result if (!@commands or !scalar(@commands));
  389. my $count = scalar(@commands);
  390. my $start = 0;
  391. while ($start<=$count-1) {
  392. my @run_list=();
  393. my $select = IO::Select->new();
  394. my $stop = $start + $parallel_process_count;
  395. $stop=$count-1 if ($stop >=$count);
  396. for (my $index = $start; $index <=$stop; $index++) {
  397. next if (!$commands[$index]);
  398. my $cmd=$commands[$index];
  399. log_info("Starting ".$cmd);
  400. my ($hchild, $hparent, $childid);
  401. socketpair($hchild, $hparent, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!";
  402. $childid = fork;
  403. die "cannot fork" if($childid == -1);
  404. # redirect child Input|Output
  405. unless($childid) {
  406. open STDIN, "<&", $hparent;
  407. open STDOUT, ">&", $hparent;
  408. open STDERR, ">&", $hparent;
  409. close $hparent;
  410. close $hchild;
  411. $select->remove($_) and close $_ for($select->handles);
  412. exec "/bin/nice -n 15 ".$cmd;
  413. }
  414. close $hparent;
  415. $select->add($hchild);
  416. }
  417. while (my @ready = $select->can_read) {
  418. next if (!@ready or !scalar(@ready));
  419. for my $read(@ready) {
  420. if($read->eof || $read->error) {
  421. # child exit
  422. $select->remove($read);
  423. close $read;
  424. next;
  425. }
  426. if(defined(my $str = <$read>)) {
  427. log_info("Read:".$str);
  428. push(@result,$str);
  429. }
  430. }
  431. }
  432. $start = $stop+1;
  433. }
  434. return (@result);
  435. }
  436. #---------------------------------------------------------------------------------
  437. sub translit {
  438. my $textline=shift;
  439. return if (!$textline);
  440. $textline =~ s/А/A/g; $textline =~ s/а/a/g;
  441. $textline =~ s/Б/B/g; $textline =~ s/б/b/g;
  442. $textline =~ s/В/V/g; $textline =~ s/в/v/g;
  443. $textline =~ s/Г/G/g; $textline =~ s/г/g/g;
  444. $textline =~ s/Д/D/g; $textline =~ s/д/d/g;
  445. $textline =~ s/Е/E/g; $textline =~ s/е/e/g;
  446. $textline =~ s/Ё/E/g; $textline =~ s/ё/e/g;
  447. $textline =~ s/Ж/Zh/g; $textline =~ s/ж/zh/g;
  448. $textline =~ s/З/Z/g; $textline =~ s/з/z/g;
  449. $textline =~ s/И/I/g; $textline =~ s/и/i/g;
  450. $textline =~ s/Й/I/g; $textline =~ s/й/i/g;
  451. $textline =~ s/К/K/g; $textline =~ s/к/k/g;
  452. $textline =~ s/Л/L/g; $textline =~ s/л/l/g;
  453. $textline =~ s/М/M/g; $textline =~ s/м/m/g;
  454. $textline =~ s/Н/N/g; $textline =~ s/н/n/g;
  455. $textline =~ s/О/O/g; $textline =~ s/о/o/g;
  456. $textline =~ s/П/P/g; $textline =~ s/п/p/g;
  457. $textline =~ s/Р/R/g; $textline =~ s/р/r/g;
  458. $textline =~ s/ТС/T-S/g; $textline =~ s/Тс/T-s/g; $textline =~ s/тс/t-s/g;
  459. $textline =~ s/С/S/g; $textline =~ s/с/s/g;
  460. $textline =~ s/Т/T/g; $textline =~ s/т/t/g;
  461. $textline =~ s/У/U/g; $textline =~ s/у/u/g;
  462. $textline =~ s/Ф/F/g; $textline =~ s/ф/f/g;
  463. $textline =~ s/Х/Kh/g; $textline =~ s/х/kh/g;
  464. $textline =~ s/Ц/Ts/g; $textline =~ s/ц/ts/g;
  465. $textline =~ s/Ч/Ch/g; $textline =~ s/ч/ch/g;
  466. $textline =~ s/Ш/Sh/g; $textline =~ s/ш/sh/g;
  467. $textline =~ s/Щ/Shch/g; $textline =~ s/щ/shch/g;
  468. #$textline =~ s/Ь/'/g; $textline =~ s/ь/'/g;
  469. #$textline =~ s/Ъ/''/g; $textline =~ s/ъ/''/g;
  470. $textline =~ s/Ь//g; $textline =~ s/ь//g;
  471. $textline =~ s/Ъ//g; $textline =~ s/ъ//g;
  472. $textline =~ s/Ы/Y/g; $textline =~ s/ы/y/g;
  473. $textline =~ s/Э/E/g; $textline =~ s/э/e/g;
  474. $textline =~ s/Ю/Yu/g; $textline =~ s/ю/yu/g;
  475. $textline =~ s/Я/Ya/g; $textline =~ s/я/ya/g;
  476. return $textline;
  477. }
  478. #---------------------------------------------------------------------------------
  479. sub netdev_set_auth {
  480. my $device = shift;
  481. $device->{login}=$config_ref{router_login} if (!$device->{login});
  482. $device->{password}=$config_ref{router_password} if (!$device->{password});
  483. $device->{password}=decrypt_string($device->{password});
  484. $device->{enable_password}='';
  485. #$device->{enable_password}=$device->{passowrd};
  486. $device->{proto} = 'ssh' if ($device->{protocol} eq '0');
  487. $device->{proto} = 'telnet' if ($device->{protocol} eq '1');
  488. $device->{port} = $device->{control_port} if ($device->{control_port});
  489. return $device;
  490. }
  491. #---------------------------------------------------------------------------------
  492. sub decrypt_string {
  493. my $crypted_string = shift;
  494. return if (!$crypted_string);
  495. my $cipher_handle = Crypt::CBC->new(
  496. {
  497. 'key' => $config_ref{encryption_key},
  498. 'cipher' => 'Cipher::AES',
  499. 'iv' => $config_ref{encryption_iv},
  500. 'literal_key' => 1,
  501. 'header' => 'none',
  502. keysize => 128 / 8
  503. }
  504. );
  505. my $result = $cipher_handle->decrypt(decode_base64($crypted_string));
  506. return $result;
  507. }
  508. #---------------------------------------------------------------------------------
  509. sub crypt_string {
  510. my $simple_string = shift;
  511. return if (!$simple_string);
  512. my $cipher_handle = Crypt::CBC->new(
  513. {
  514. 'key' => $config_ref{encryption_key},
  515. 'cipher' => 'Cipher::AES',
  516. 'iv' => $config_ref{encryption_iv},
  517. 'literal_key' => 1,
  518. 'header' => 'none',
  519. keysize => 128 / 8
  520. }
  521. );
  522. my $result = encode_base64($cipher_handle->encrypt($simple_string));
  523. return $result;
  524. }
  525. #---------------------------------------------------------------------------------
  526. #log_file($LOG_COMMON,"INFO:","----------------------------------------------------------------------------------------");
  527. #log_file($LOG_COMMON,"INFO:","Run script $0. Pid: $$ Pid file: $SPID.pid");
  528. #log_file($LOG_COMMON,"INFO:","User uid: $< Effective uid: $>");
  529. #log_file($LOG_COMMON,"INFO:","Status:");
  530. #log_file($LOG_COMMON,"INFO:","Logging enabled: $log_enable");
  531. #log_file($LOG_COMMON,"INFO:","Logging debug: $debug");
  532. 1;
  533. }