Class: Yast::HttpServerClass
- Inherits:
-
Module
- Object
- Module
- Yast::HttpServerClass
- Defined in:
- ../../src/modules/HttpServer.rb
Instance Method Summary (collapse)
-
- (Hash) AutoPackages
Return required packages for auto-installation.
-
- (Hash) Export
Dump the http-server settings to a single map (For use by autoinstallation.).
-
- (Hash{String => Object}) find_known_module(known_modules, mod)
For module name find description map in known_modules.
-
- (Boolean) Import(s)
Get all http-server settings from the first parameter (For use by autoinstallation.).
- - (Object) isWizardMode
- - (Object) main
-
- (Object) Modified
Data was modified?.
-
- (Object) Read
Read all http-server settings.
- - (Object) setWizardMode(w_mode)
-
- (Object) Summary
Create a textual summary for the current configuration.
-
- (Object) Write
Write all http-server settings.
Instance Method Details
- (Hash) AutoPackages
Return required packages for auto-installation
795 796 797 798 799 800 801 802 803 804 805 806 807 808 |
# File '../../src/modules/HttpServer.rb', line 795 def AutoPackages if !Package.InstalledAny( ["apache2-prefork", "apache2-metuxmpm", "apache2-worker"] ) # add a default MPM - prefork because of the PHP4 compatibility @required_packages = Convert.convert( Builtins.union(@required_packages, ["apache2-prefork"]), :from => "list", :to => "list <string>" ) end { "install" => @required_packages, "remove" => [] } end |
- (Hash) Export
Dump the http-server settings to a single map (For use by autoinstallation.)
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File '../../src/modules/HttpServer.rb', line 639 def Export known_modules = YaST::HTTPDData.GetKnownModules enabled_modules = YaST::HTTPDData.GetModuleList Builtins.y2milestone("Enabled modules: %1", enabled_modules) # walk over the known modules modules = Builtins.maplist(known_modules) do |desc| { "name" => Ops.get_string(desc, "name", ""), "change" => Ops.get(desc, "default") == "1" ? # default is true Builtins.contains(enabled_modules, Ops.get_string(desc, "name", "")) ? "nochange" : "disable" : # default is false Builtins.contains(enabled_modules, Ops.get_string(desc, "name", "")) ? "enable" : "nochange", "default" => Ops.get_string(desc, "default", "1") } end # filter out not changed modules = Builtins.filter(modules) do |desc| Ops.get(desc, "change") != "nochange" end # store the user defined ones Builtins.foreach(enabled_modules) do |mod| if find_known_module(known_modules, mod) == nil # user-defined modules = Builtins.add( modules, { "name" => mod, "change" => "enable", "userdefined" => true } ) end end # hosts hosts = [] #listmap (string host, YaST::HTTPDData::GetHostsList(), ``( # $[ "KEY":host, "VALUE":YaST::HTTPDData::GetHost(host) ] # )); Builtins.foreach(YaST::HTTPDData.GetHostsList) do |host| hosts = Builtins.add( hosts, { "KEY" => host, "VALUE" => YaST::HTTPDData.GetHost(host) } ) end Builtins.y2milestone("Hosts: %1", hosts) result = { "version" => "2.9", "modules" => modules, "hosts" => hosts, "Listen" => YaST::HTTPDData.GetCurrentListen, "service" => YaST::HTTPDData.GetService } @configured = true deep_copy(result) end |
- (Hash{String => Object}) find_known_module(known_modules, mod)
For module name find description map in known_modules
500 501 502 503 504 505 506 507 508 509 510 511 |
# File '../../src/modules/HttpServer.rb', line 500 def find_known_module(known_modules, mod) known_modules = deep_copy(known_modules) res = nil Builtins.foreach(known_modules) do |i| if Ops.get_string(i, "name", "") == mod res = deep_copy(i) raise Break end end deep_copy(res) end |
- (Boolean) Import(s)
Get all http-server settings from the first parameter (For use by autoinstallation.)
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File '../../src/modules/HttpServer.rb', line 517 def Import(s) s = deep_copy(s) YaST::HTTPDData.InitializeDefaults version = Ops.get_string(s, "version", "unknown") # setup modules Builtins.foreach(Ops.get_list(s, "modules", [])) do |desc| mod = Ops.get_string(desc, "name", "") if Builtins.size(mod) == 0 # translators: warning in autoyast loading the configuration description. Report.Warning( _("Module description does not have a name specified, ignoring.") ) next end change_string = Ops.get_string(desc, "change", "nochange") # get the default defaultstatus = Ops.get_string(desc, "default") if change_string != "nochange" if !Builtins.contains(["enable", "disable"], change_string) # translators: warning in autoyast loading the configuration description. Report.Warning( Builtins.sformat( _("Unknown change of a module for autoinstallation: %1"), change_string ) ) next end # just change the status YaST::HTTPDData.ModifyModuleList([mod], change_string == "enable") else # check against the current default if defaultstatus != nil && Ops.get( find_known_module(YaST::HTTPDData.GetKnownModules, mod), "default" ) != defaultstatus # translators: warning in autoyast loading the configuration description. Report.Warning( Builtins.sformat( _( "Default value for module %1 does not match.\nThis can cause inconsistent module configuration." ), mod ) ) end end end # setup listen listen = Ops.get_list(s, "Listen", []) Builtins.foreach(listen) do |l| if !Builtins.haskey(l, "PORT") # translators: error in autoyast loading the configuration description. Report.Error(_("Listen statement without port found.")) else YaST::HTTPDData.CreateListen( Builtins.tointeger(Ops.get_string(l, "PORT", "0")), Builtins.tointeger(Ops.get_string(l, "PORT", "0")), Ops.get_string(l, "ADDRESS", "") ) end end # setup hosts default_server = nil Builtins.foreach(Ops.get_list(s, "hosts", [])) do |row| # "main" defines the default server configured in # /etc/apache2/default-server.conf. This has already been # defined in YaPI::HTTPD and has to be updated only. # With the CreateHost call an own entry in /etc/apache2/vhosts.d # will be generated. # (bnc#893100) if row["KEY"] == "main" default_server = row else value = row["VALUE"] || [] key_split = row["KEY"].split("/") if value.none? {|item| item["KEY"] == "HostIP"} && key_split.size > 1 # Set HostIP which is given in the KEY (e.g. *:443/sleposbuilder3.suse.cz.conf) # values in order to set VirtualHost in /etc/apache2/vhosts.d/<hostname> # (bnc#895127) host_ip = key_split.first value << {"KEY" => "HostIP", "VALUE" => host_ip} end YaST::HTTPDData.CreateHost( row["KEY"] || "", value ) end end # Every YaST::HTTPDData.CreateHost resets the NameVirtualHost # entry in default-server.conf. I do not really know the # reason for, but in that case it is not intent (schubi). # So, the default server will be modified AFTER all other # hosts have been created to get the correct NameVirtualHost entry if default_server YaST::HTTPDData.ModifyHost( default_server["KEY"], default_server["VALUE"] || [] ) end # setup service if Builtins.haskey(s, "service") YaST::HTTPDData.ModifyService(Ops.get_boolean(s, "service", false)) end @modified = false @configured = true true end |
- (Object) isWizardMode
81 82 83 84 85 86 87 88 89 90 91 |
# File '../../src/modules/HttpServer.rb', line 81 def isWizardMode if {} == SCR.Read( path(".target.stat"), Ops.add(Directory.vardir, "/http_server") ) return true else return false end end |
- (Object) main
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File '../../src/modules/HttpServer.rb', line 16 def main Yast.import "UI" textdomain "http-server" Yast.import "YaPI::HTTPD" Yast.import "YaST::HTTPDData" Yast.import "NetworkInterfaces" Yast.import "Progress" Yast.import "Report" Yast.import "Package" Yast.import "Service" Yast.import "Summary" Yast.import "Message" Yast.import "Directory" Yast.import "Popup" Yast.import "DnsServerAPI" Yast.import "NetworkService" Yast.import "SuSEFirewall" Yast.import "Confirm" Yast.import "SuSEFirewallServices" Yast.import "FileChanges" # Abort function # return boolean return true if abort @AbortFunction = nil # Required packages @required_packages = ["apache2"] # Data was modified? @modified = false @configured = false @proposal_valid = false # Write only, used during autoinstallation. # Don't run services and SuSEconfig, it's all done at one place. @write_only = false @configured_dns = false Yast.include self, "http-server/routines.rb" # Mapping of IPs to network devices @ip2device = {} @files_to_check = [ "/etc/sysconfig/apache2", "/etc/apache2/default-server.conf", "/etc/apache2/httpd.conf", "/etc/apache2/listen.conf", "/etc/apache2/vhosts.d/yast2_vhosts.conf" ] end |
- (Object) Modified
Data was modified?
76 77 78 79 |
# File '../../src/modules/HttpServer.rb', line 76 def Modified Builtins.y2debug("modified=%1", @modified) @modified end |
- (Object) Read
Read all http-server settings
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File '../../src/modules/HttpServer.rb', line 114 def Read # HttpServer read dialog caption caption = _("Initializing HTTP Server Configuration") steps = 4 # We do not set help text here, because it was set outside Progress.New( caption, " ", steps, [ # translators: progress stage _("Check the environment"), # translators: progress stage _("Read Apache2 configuration"), # translators: progress stage _("Read network configuration") ], [ # translators: progress step _("Checking the environment..."), # translators: progress step _("Reading Apache2 configuration..."), # translators: progress step _("Reading network configuration..."), # translators: progress finished _("Finished") ], "" ) # check the environment return false if !Confirm.MustBeRoot return false if !NetworkService.RunningNetworkPopup return false if !NetworkService.ConfirmNetworkManager Progress.NextStep # check rpms required = deep_copy(@required_packages) if !Package.InstalledAny( ["apache2-prefork", "apache2-metuxmpm", "apache2-worker"] ) # add a default MPM - prefork because of the PHP4 compatibility required = Convert.convert( Builtins.union(required, ["apache2-prefork"]), :from => "list", :to => "list <string>" ) end if !Package.InstallAllMsg( required, # notification about package needed 1/2 _( "<p>To configure the HTTP server, the <b>%1</b> packages must be installed.</p>" ) + # notification about package needed 2/2 _("<p>Do you want to install it now?</p>") ) if !Package.Available("apache2") # translators: error popup before aborting the module Popup.Error( Builtins.sformat( _( "The package %1 is not available.\n" + "\n" + "Configuration cannot continue\n" + "\n" + "without installing the package." ), "apache2" ) ) else # translators: error popup before aborting the module Popup.Error(Message.CannotContinueWithoutPackagesInstalled) end return false end Progress.NextStep # check httpd.conf if SCR.Read(path(".target.lstat"), "/etc/apache2/httpd.conf") == {} # translators: error message, %1 is the file name of expected configuration file Report.Error( Builtins.sformat( _("The configuration file '%1' does not exist."), "/etc/apache2/httpd.conf" ) ) return false end # check sysconfig if SCR.Read(path(".target.lstat"), "/etc/sysconfig/apache2") == {} if SCR.Execute( path(".target.bash"), "cp /var/adm/fillup-templates/sysconfig.apache2 /etc/sysconfig/apache2" ) != 0 # translators:: error message Report.Error(Message.CannotWriteSettingsTo("/etc/sysconfig/apache2")) return false end end # check listen.conf if SCR.Read(path(".target.lstat"), "/etc/apache2/listen.conf") == {} # translators: warning message, %1 is the file name of expected configuration file Report.Warning( Builtins.sformat( _("The configuration file '%1' does not exist."), "/etc/apache2/listen.conf" ) ) # create empty file if !SCR.Write(path(".target.string"), "/etc/apache2/listen.conf", "") # translators:: error message Report.Error( Message.CannotWriteSettingsTo("/etc/apache2/listen.conf") ) return false end end old_progress = Progress.set(false) #off(); SuSEFirewall.Read if Package.Installed("bind") if Ops.greater_than( Builtins.size( Convert.to_map( SCR.Read( path(".target.stat"), Ops.add(Directory.vardir, "/dns_server") ) ) ), 0 ) if Service.Status("named") == 0 @configured_dns = true if DnsServerAPI.Read else Builtins.y2milestone( _("There is no DNS server running on this machine.") ) end else Builtins.y2warning("DNS server is not correctly configured via YaST.") end else Builtins.y2warning("Package bind is not installed.") end Builtins.y2internal("DNS running and configured: %1", @configured_dns) Progress.set(old_progress) #on(); # read current settings from httpd.conf and sysconfig Progress.NextStage # read hosts YaST::HTTPDData.ReadHosts YaST::HTTPDData.ReadListen YaST::HTTPDData.ReadModules YaST::HTTPDData.ReadService return false if !FileChanges.CheckFiles(@files_to_check) # check the modules RPMs modules = YaST::HTTPDData.GetModuleList Builtins.y2milestone("Testing packages for %1", modules) Builtins.foreach(modules) do |mod| pkgs = YaST::HTTPDData.GetPackagesForModule(mod) if Ops.greater_than(Builtins.size(pkgs), 0) Yast.import "Package" Builtins.y2milestone("Checking packages %1 for module %2", pkgs, mod) res = Builtins.find(pkgs) { |pkg| !Package.Installed(pkg) } if res != nil Builtins.y2milestone( "Packages not installed (missing %1), setting %2 as disabled", res, mod ) YaST::HTTPDData.ModifyModuleList([mod], false) end end end Progress.NextStage # read current settings for firewall and network old_progress = Progress.set(false) #off(); NetworkInterfaces.Read # generate the map: static IP -> device @ip2device = { "127.0.0.1" => "loopback" } devs = NetworkInterfaces.Locate("BOOTPROTO", "static") Builtins.foreach(devs) do |dev| # use also additional addresses (#264393) Builtins.foreach(NetworkInterfaces.GetIP(dev)) do |ip| Ops.set(@ip2device, ip, dev) if ip != nil && ip != "" end end # add DHCP ones, if we can find out the current IP devs = NetworkInterfaces.Locate("BOOTPROTO", "dhcp") Builtins.foreach(devs) do |dev| output = Convert.to_map( SCR.Execute( path(".target.bash_output"), Ops.add("/sbin/ifconfig ", dev), { "LC_MESSAGES" => "C" } ) ) if Ops.get_integer(output, "exit", -1) == 0 # lookup the correct line first line = Builtins.splitstring( Ops.get_string(output, "stdout", ""), "\n" ) addr = nil Builtins.foreach(line) do |ln| if Builtins.regexpmatch(ln, "^[ \t]*inet addr:") addr = Builtins.regexpsub( ln, "^[ \t]*inet addr:([0-9\\.]+)[ \t]*", "\\1" ) Builtins.y2milestone("Found addr: %1", addr) raise Break end end Ops.set(@ip2device, addr, dev) if addr != nil && addr != "" end end Builtins.y2milestone( "Mapping of IP addresses and network devices: %1", @ip2device ) Progress.set(old_progress) #on(); # translators: progress step ProgressNextStage(_("Finished")) return false if Abort() @modified = false @configured = true true end |
- (Object) setWizardMode(w_mode)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File '../../src/modules/HttpServer.rb', line 93 def setWizardMode(w_mode) if w_mode == true SCR.Execute( path(".target.bash"), Builtins.sformat("rm %1%2", Directory.vardir, "/http_server") ) Builtins.y2milestone("Set wizard mode on") else SCR.Write( path(".target.string"), Ops.add(Directory.vardir, "/http_server"), "" ) Builtins.y2milestone("Set wizard mode off") end nil end |
- (Object) Summary
Create a textual summary for the current configuration
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
# File '../../src/modules/HttpServer.rb', line 703 def Summary nc = Summary.NotConfigured summary = "" if @configured # "Listen on " information (interfaces, port) summary = Summary.AddLine(summary, _("<h3>Listen On</h3>")) port = "80" interfaces = "127.0.0.1" Builtins.foreach(YaST::HTTPDData.GetCurrentListen) do |listens| port = Ops.get_string(listens, "PORT", "80") if Ops.get_string(listens, "ADDRESS", "") == "" interfaces = "all" else interfaces = Ops.add( interfaces, Ops.get_string(listens, "ADDRESS", "") ) end end summary = Summary.AddLine( summary, Ops.add(Ops.add(interfaces, ", port "), port) ) # "Default host" information summary = Summary.AddLine(summary, _("<h3>Default Host</h3>")) serv_name = "" doc_root = "" ssl = false Builtins.foreach(YaST::HTTPDData.GetHost("default")) do |params| if Ops.get_string(params, "KEY", "") == "ServerName" serv_name = Ops.get_string(params, "VALUE", "") end if Ops.get_string(params, "KEY", "") == "DocumentRoot" doc_root = Ops.get_string(params, "VALUE", "") end if Ops.get_string(params, "KEY", "") == "SSL" && Ops.get_string(params, "VALUE", "") != "0" ssl = true end end #translators: assiciation server name with document root summary = Summary.AddLine( summary, Ops.add(Ops.add(serv_name, _(" in ")), doc_root) ) #translators: whether SSL is enabled or disabled summary = Summary.AddLine( summary, "SSL " + (ssl ? _("enabled") : _("disabled")) ) # the same information as in default host but for other virtual hosts summary = Summary.AddLine(summary, _("<h3>Virtual Hosts</h3>")) Builtins.foreach(YaST::HTTPDData.GetHostsList) do |host| next if host == "default" Builtins.foreach(YaST::HTTPDData.GetHost(host)) do |params| if Ops.get_string(params, "KEY", "") == "ServerName" serv_name = Ops.get_string(params, "VALUE", "") end if Ops.get_string(params, "KEY", "") == "DocumentRoot" doc_root = Ops.get_string(params, "VALUE", "") end if Ops.get_string(params, "KEY", "") == "SSL" && Ops.get_string(params, "VALUE", "") != "0" ssl = true end end #translators: assiciation server name with document root summary = Summary.AddLine( summary, Ops.add( Ops.add( Ops.add(Ops.add(serv_name, _(" in ")), doc_root), #translators: whether SSL is enabled or disable ", SSL " ), ssl ? _("enabled") : _("disabled") ) ) end else summary = Summary.AddLine(summary, nc) end [summary, []] end |
- (Object) Write
Write all http-server settings
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File '../../src/modules/HttpServer.rb', line 379 def Write # HttpServer read dialog caption caption = _("Saving HTTP Server Configuration") steps = 3 # We do not set help text here, because it was set outside Progress.New( caption, " ", steps, [ # translators: progress stage 1/3 _("Write the Apache2 settings"), YaST::HTTPDData.GetService ? # translators: progress stage 2/3 _("Enable Apache2 service") : # translators: progress stage 3/3 _("Disable Apache2 service") ], [ # translators: progress step 1/3 _("Writing the settings..."), YaST::HTTPDData.GetService ? # translators: progress step 2/3 _("Enabling Apache2 service...") : # translators: progress step 3/3 _("Disabling Apache2 service..."), # translators: progress finished _("Finished") ], "" ) # write Apache2 settings rpms = YaPI::HTTPD.GetModulePackages # install required RPMs for modules Package.InstallAllMsg( rpms, _( "The enabled modules require\n" + "installation of some of these additional packages:\n" + "%1\n" + "Install them now?\n" ) ) # write httpd.conf # write hosts YaST::HTTPDData.WriteHosts Progress.NextStage Yast.import "SuSEFirewall" old_progress = Progress.set(false) # off(); # always adapt firewall if YaST::HTTPDData.WriteListen(false) == nil # FIXME: show popup Builtins.y2error("Writing listen failed, firewall problems?") end # Firewall ports = [] Builtins.foreach(YaST::HTTPDData.GetCurrentListen) do |row| ports = Builtins.add(ports, Ops.get_string(row, "PORT", "")) end SuSEFirewallServices.SetNeededPortsAndProtocols( "service:apache2", { "tcp_ports" => ports, "udp_ports" => [] } ) SuSEFirewall.Write DnsServerAPI.Write if @configured_dns Progress.set(old_progress) YaST::HTTPDData.WriteModuleList # in autoyast, quit here # Wrong, service still has to be enabled... # if( write_only ) return true; Progress.NextStage if !YaST::HTTPDData.WriteService(@write_only) # translators: error message Report.Error(Message.CannotAdjustService("apache2")) end if YaST::HTTPDData.GetService # this will reload the configuration and start httpd if !Service.Restart("apache2") # translators: error message Report.Error(Message.CannotAdjustService("apache2")) end else if !Service.Stop("apache2") # translators: error message Report.Error(Message.CannotAdjustService("apache2")) end end # configuration test # map<string, any> test = (map<string, any>)SCR::Execute(.target.bash_output, "apache2ctl conftest"); #y2internal("test %1", test); Builtins.foreach(@files_to_check) do |file| FileChanges.StoreFileCheckSum(file) end # translators: progress finished ProgressNextStage(_("Finished")) return false if Abort() true end |