1 ##############################################################################
3 # Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsibility of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # guarantees and support are strongly adviced to contract a Free Software
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ##############################################################################
33 from slapos
.recipe
.librecipe
import GenericBaseRecipe
35 class Recipe(GenericBaseRecipe
):
37 def _options(self
, options
):
38 options
['password'] = self
.generatePassword()
43 htpasswd_file
= self
.options
['htpasswd-file']
44 # Create or empty the file
45 open(htpasswd_file
, 'w').close()
46 path_list
.append(htpasswd_file
)
48 user
= self
.options
['user']
49 password
= self
.options
['password']
50 subprocess
.check_call([self
.options
['apache-htpasswd'],
55 htdocs_location
= self
.options
['htdocs']
56 if not (os
.path
.exists(htdocs_location
) and os
.listdir(htdocs_location
)):
58 os
.rmdir(htdocs_location
)
61 shutil
.copytree(self
.options
['source'], htdocs_location
)
64 php_ini
= self
.createFile(os
.path
.join(self
.options
['php-ini-dir'],
66 self
.substituteTemplate(self
.getTemplateFilename('php.ini.in'),
67 dict(tmp_directory
=self
.options
['tmp-dir']))
69 path_list
.append(php_ini
)
72 pid_file
=self
.options
['pid-file'],
73 lock_file
=self
.options
['lock-file'],
74 davlock_db
=self
.options
['davdb-lock'],
75 ip
=self
.options
['ip'],
76 port_webdav
=self
.options
['port_webdav'],
77 port_ajax
=self
.options
['port_ajax'],
78 error_log
=self
.options
['error-log'],
79 access_log
=self
.options
['access-log'],
80 document_root
=self
.options
['htdocs'],
81 modules_dir
=self
.options
['apache-modules-dir'],
82 mime_types
=self
.options
['apache-mime-file'],
83 server_root
=self
.options
['root'],
84 email_address
=self
.options
['email-address'],
85 htpasswd_file
=htpasswd_file
,
86 ssl_certificate
=self
.options
['cert-file'],
87 ssl_key
=self
.options
['key-file'],
88 php_ini_dir
=self
.options
['php-ini-dir']
92 for log
in [self
.options
['error-log'], self
.options
['access-log']]:
93 open(log
, 'a').close()
95 config_file
= self
.createFile(self
.options
['conf-file'],
96 self
.substituteTemplate(self
.getTemplateFilename('httpd.conf.in'),
99 path_list
.append(config_file
)
101 wrapper
= self
.createPythonScript(self
.options
['wrapper'],
102 'slapos.recipe.librecipe.execute.execute',
103 [self
.options
['apache-binary'], '-f', config_file
, '-DFOREGROUND'])
104 path_list
.append(wrapper
)
106 promise
= self
.createPythonScript(self
.options
['promise'],
107 __name__
+ '.promise',
108 dict(host
=self
.options
['ip'], port
=int(self
.options
['port_webdav']),
109 user
=self
.options
['user'], password
=self
.options
['password'])
111 path_list
.append(promise
)
119 password
= args
['password']
121 connection
= httplib
.HTTPSConnection(host
, port
)
122 auth
= base64
.b64encode('%s:%s' %
(user
, password
))
123 connection
.request('OPTIONS', '/',
125 Authorization
='Basic %s' % auth
,
128 connection
.getresponse()