164 | | sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf won't be used ! Move it to /etc instead.\n") |
165 | | sys.stderr.write("PyKota installation will continue anyway, but the software won't run until you put a proper configuration file in /etc\n") |
166 | | else : |
167 | | sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf will not be used !\nThe file /etc/pykota.conf will be used instead.\n") |
168 | | elif not os.path.isfile("/etc/pykota.conf") : |
169 | | # no configuration file, first installation it seems. |
170 | | if os.path.isfile("conf/pykota.conf.sample") : |
171 | | answer = raw_input("Do you want to install conf/pykota.conf.sample as /etc/pykota.conf (y/N) ? ") |
172 | | if answer[0:1].upper() == 'Y' : |
173 | | try : |
174 | | shutil.copy("conf/pykota.conf.sample", "/etc/pykota.conf") |
175 | | except IOError : |
176 | | sys.stderr.write("WARNING : Problem while installing /etc/pykota.conf, please do it manually.\n") |
177 | | else : |
178 | | sys.stdout.write("Configuration file /etc/pykota.conf installed.\nDon't forget to adapt /etc/pykota.conf to your needs.\n") |
| 176 | sys.stderr.write("WARNING : Configuration file /etc/pykota.conf won't be used ! Move it to /etc/pykota/ instead.\n") |
| 177 | sys.stderr.write("PyKota installation will continue anyway,\nbut the software won't run until you put a proper configuration file in /etc/pykota/\n") |
| 178 | dummy = raw_input("Please press ENTER when you have read the message above. ") |
| 179 | else : |
| 180 | # first installation |
| 181 | if os.path.isfile("conf/pykota.conf.sample") : |
| 182 | answer = raw_input("Do you want to install\n\tconf/pykota.conf.sample as /etc/pykota/pykota.conf (y/N) ? ") |
| 183 | if answer[0:1].upper() == 'Y' : |
| 184 | try : |
| 185 | shutil.copy("conf/pykota.conf.sample", "/etc/pykota/pykota.conf") |
| 186 | shutil.copy("conf/pykotadmin.conf.sample", "/etc/pykota/pykotadmin.conf") |
| 187 | except IOError, msg : |
| 188 | sys.stderr.write("WARNING : Problem while installing sample configuration files in /etc/pykota/, please do it manually.\n%s\n" % msg) |
| 189 | else : |
| 190 | sys.stdout.write("Configuration file /etc/pykota/pykota.conf and /etc/pykota/pykotadmin.conf installed.\nDon't forget to adapt these files to your needs.\n") |
| 191 | else : |
| 192 | sys.stderr.write("WARNING : PyKota won't run without a configuration file !\n") |
180 | | sys.stderr.write("WARNING : PyKota won't run without a configuration file !\n") |
181 | | else : |
182 | | # Configuration file already exists. Check if this is an old version or not |
183 | | # if the 'method: lazy' line is present, then the configuration file |
184 | | # has to be updated. |
185 | | oldconf = ConfigParser.ConfigParser() |
186 | | oldconf.read(["/etc/pykota.conf"]) |
187 | | try : |
188 | | if oldconf.get("global", "method", raw=1).lower().strip() == "lazy" : |
189 | | sys.stdout.write("You have got an OLD PyKota configuration file !\n") |
190 | | sys.stdout.write("The 'method' statement IS NOT SUPPORTED ANYMORE\nand was replaced with the 'accounter' statement.\n") |
191 | | sys.stdout.write("You have to manually set an 'accounter' statement,\neither globally or for each printer.\n") |
192 | | sys.stdout.write("Please read the sample configuration file conf/pykota.conf.sample\n") |
193 | | sys.stdout.write("to learn how to MANUALLY apply the modifications needed,\nafter the installation is done.\n") |
194 | | sys.stdout.write("If you don't do this, then PyKota will stop working !\n") |
195 | | answer = raw_input("Please, press ENTER when you'll have read the above paragraph.") |
196 | | except ConfigParser.NoOptionError : |
197 | | # New configuration file, OK |
198 | | pass |
| 194 | # Problem ? |
| 195 | sys.stderr.write("WARNING : PyKota's sample configuration file cannot be found.\nWhat you have downloaded seems to be incomplete,\nor you are not in the pykota directory.\nPlease double check, and restart the installation procedure.\n") |
| 196 | dummy = raw_input("Please press ENTER when you have read the message above. ") |
| 197 | else : |
| 198 | # already at 1.14 or above, nothing to be done. |
| 199 | pass |
| 200 | |
| 201 | # Second stage, we will fail if onfiguration is incorrect for security reasons |
| 202 | from pykota.config import PyKotaConfig,PyKotaConfigError |
| 203 | try : |
| 204 | conf = PyKotaConfig("/etc/pykota/") |
| 205 | except PyKotaConfigError, msg : |
| 206 | sys.stedrr.write("%s\nINSTALLATION ABORTED !\nPlease restart installation.\n" % msg) |
| 207 | sys.exit(-1) |
| 208 | else : |
| 209 | hasadmin = conf.getGlobalOption("storageadmin", ignore=1) |
| 210 | hasadminpw = conf.getGlobalOption("storageadminpw", ignore=1) |
| 211 | hasuser = conf.getGlobalOption("storageuser", ignore=1) |
| 212 | if hasadmin or hasadminpw : |
| 213 | sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf doesn't contain the Quota Storage Administrator's name and optional password.\n") |
| 214 | sys.stderr.write("Please put these in a [global] section in /etc/pykota/pykotadmin.conf\n") |
| 215 | sys.stderr.write("Then replace these values with 'storageuser' and 'storageuserpw' in /etc/pykota/pykota.conf\n") |
| 216 | sys.stderr.write("These two fields were re-introduced to allow any user to read to his own quota, without allowing them to modify it.\n") |
| 217 | sys.stderr.write("You can look at the conf/pykota.conf.sample and conf/pykotadmin.conf.sample files for examples.\n") |
| 218 | sys.stderr.write("YOU HAVE TO DO THESE MODIFICATIONS MANUALLY, AND RESTART THE INSTALLATION.\n") |
| 219 | sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n") |
| 220 | sys.exit(-1) |
| 221 | if not hasuser : |
| 222 | sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf contains the Quota Storage Normal User's name and optional password.\n") |
| 223 | sys.stderr.write("Please put these in a [global] section in /etc/pykota/pykota.conf\n") |
| 224 | sys.stderr.write("These fields are respectively named 'storageuser' and 'storageuserpw'.\n") |
| 225 | sys.stderr.write("These two fields were re-introduced to allow any user to read to his own quota, without allowing them to modify it.\n") |
| 226 | sys.stderr.write("You can look at the conf/pykota.conf.sample and conf/pykotadmin.conf.sample files for examples.\n") |
| 227 | sys.stderr.write("YOU HAVE TO DO THESE MODIFICATIONS MANUALLY, AND RESTART THE INSTALLATION.\n") |
| 228 | sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n") |
| 229 | sys.exit(-1) |
| 230 | |
| 231 | sb = conf.getStorageBackend() |
| 232 | if (sb.get("storageadmin") is None) or (sb.get("storageuser") is None) : |
| 233 | sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf contains the Quota Storage Normal User's name and optional password which gives READONLY access to the Print Quota DataBase,") |
| 234 | sys.stderr.write("and that /etc/pykota/pykotadmin.conf contains the Quota Storage Administrator's name and optional password which gives READ/WRITE access to the Print Quota DataBase.\n") |
| 235 | sys.stderr.write("Your configuration doesn't seem to be OK, please modify your configuration files in /etc/pykota/\n") |
| 236 | sys.stderr.write("AND RESTART THE INSTALLATION.\n") |
| 237 | sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n") |
| 238 | sys.exit(-1) |
| 239 | |
| 240 | # change files permissions |
| 241 | os.chmod("/etc/pykota/pykota.conf", 0644) |
| 242 | os.chmod("/etc/pykota/pykotadmin.conf", 0640) |
| 243 | |
| 244 | # WARNING MESSAGE |
| 245 | sys.stdout.write("WARNING : IF YOU ARE UPGRADING FROM A PRE-1.14 TO 1.14 OR ABOVE\n") |
| 246 | sys.stdout.write("AND USE THE POSTGRESQL BACKEND, THEN YOU HAVE TO MODIFY YOUR\n") |
| 247 | sys.stdout.write("DATABASE SCHEMA USING initscripts/postgresql/upgrade-to-1.14.sql\n") |
| 248 | sys.stdout.write("PLEASE READ DOCUMENTATION IN initscripts/postgresql/ TO LEARN HOW TO DO.\n") |
| 249 | sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION.\n\n") |
| 250 | dummy = raw_input("Please press ENTER when you have read the message above. ") |