main.pm 18 KB

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