PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/denwer/scripts/init.d/hosts.pl

https://bitbucket.org/n1kropol/denwer-codeigniter_2
Perl | 89 lines | 43 code | 16 blank | 30 comment | 4 complexity | e8a3427ac1aa6f183d393cfe2fa11d65 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. #!perl -w
  2. # +-------------------------------------------------------------------------+
  3. # | Джентльменский набор Web-разработчика |
  4. # | Версия: Денвер-3 2010-03-18 |
  5. # +-------------------------------------------------------------------------+
  6. # | Copyright (C) 2001-2010 Дмитрий Котеров. |
  7. # +-------------------------------------------------------------------------+
  8. # | Данный файл является частью комплекса программ "Денвер-3". Вы не можете |
  9. # | использовать его в коммерческих целях. Никакие другие ограничения не |
  10. # | накладываются. Если вы хотите внести изменения в исходный код, авторы |
  11. # | будут рады получить от вас комментарии и замечания. Приятной работы! |
  12. # +-------------------------------------------------------------------------+
  13. # | Домашняя страница: http://denwer.ru |
  14. # | Контакты: http://forum.dklab.ru/denwer |
  15. # +-------------------------------------------------------------------------+
  16. package Starters::Hosts;
  17. BEGIN { unshift @INC, "../lib"; }
  18. use Tools;
  19. use Installer;
  20. use ParseHosts;
  21. use VhostTemplate;
  22. use StartManager;
  23. # Path to hosts file.
  24. my $hostsPath=getHostsPath();
  25. # Read hosts.
  26. my $h=readBinFile($hostsPath);
  27. # First delete hosts which was added before.
  28. # We need it in case of doubled script running.
  29. my %log=readHostsLog();
  30. my $basedir = $CNF{apache_dir};
  31. my $httpd_conf = "$basedir/conf/httpd.conf";
  32. makeHostsWritable(1);
  33. StartManager::action
  34. $ARGV[0],
  35. PATH => [
  36. ],
  37. start => sub {
  38. ###
  39. ### START.
  40. ###
  41. print "ЋЎ­®ў«пҐ¬ $hostsPath...\n";
  42. if (scalar(keys %log)) {
  43. print " ЋвЄ в ЇаҐ¤л¤гйЁе Ё§¬Ґ­Ґ­Ё©... ";
  44. my %del=deleteHosts($h,%log);
  45. writeHostsLog(); # зЁбвЁ¬ ¦га­ «
  46. print "®в¬Ґ­Ґ­® е®бв®ў: ".scalar(keys %del)."\n";
  47. }
  48. # Add hosts from /home.
  49. my %dom = VhostTemplate::getAllVHosts_forHosts($httpd_conf);
  50. my %added = insertHosts($h,%dom);
  51. # warn join(", ", keys %added);
  52. # Add really added hosts to log.
  53. writeHostsLog(%added);
  54. # Save hosts.
  55. writeBinFile($hostsPath,$h);
  56. print " „®Ў ў«Ґ­® е®бв®ў: ".scalar(keys %added)."\n";
  57. },
  58. stop => sub {
  59. ###
  60. ### STOP.
  61. ###
  62. print "‚®ббв ­ ў«Ёў Ґ¬ $hostsPath...\n";
  63. my %del=deleteHosts($h,%log);
  64. writeHostsLog(); # clear log
  65. # Save hosts.
  66. if(eval { writeBinFile($hostsPath,$h); 1 }) {
  67. print " ѓ®в®ў®. ЋвЄ«о祭® е®бв®ў: ".scalar(keys %del)."\n";
  68. } else {
  69. print " ЌҐ¤®бв в®з­® ЇаЁўЁ«ҐЈЁ©, Їа®Їг饭®.\n";
  70. }
  71. },
  72. ;
  73. return 1 if caller;