main.pm 19 KB

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