| 1 | #!/usr/bin/env python |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2005-2006 Insecure.Com LLC. |
|---|
| 4 | # Copyright (C) 2007-2008 Adriano Monteiro Marques |
|---|
| 5 | # |
|---|
| 6 | # Author: Adriano Monteiro Marques <adriano@umitproject.org> |
|---|
| 7 | # Rodolfo da Silva Carvalho <rodolfo@umitproject.org> |
|---|
| 8 | # |
|---|
| 9 | # This program is free software; you can redistribute it and/or modify |
|---|
| 10 | # it under the terms of the GNU General Public License as published by |
|---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | # (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # This program is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # GNU General Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You should have received a copy of the GNU General Public License |
|---|
| 20 | # along with this program; if not, write to the Free Software |
|---|
| 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 22 | |
|---|
| 23 | import sys |
|---|
| 24 | import os |
|---|
| 25 | import os.path |
|---|
| 26 | import re |
|---|
| 27 | |
|---|
| 28 | from distutils.core import setup |
|---|
| 29 | from distutils.command.install import install |
|---|
| 30 | from distutils.command.sdist import sdist |
|---|
| 31 | from distutils.command.build import build |
|---|
| 32 | from distutils import log, dir_util |
|---|
| 33 | |
|---|
| 34 | from glob import glob |
|---|
| 35 | from stat import * |
|---|
| 36 | |
|---|
| 37 | from umitWeb.Version import VERSION |
|---|
| 38 | from utils import msgfmt |
|---|
| 39 | # Directories for POSIX operating systems |
|---|
| 40 | # These are created after a "install" or "py2exe" command |
|---|
| 41 | # These directories are relative to the installation or dist directory |
|---|
| 42 | # Ex: python setup.py install --prefix=/tmp/umit |
|---|
| 43 | # Will create the directory /tmp/umit with the following directories |
|---|
| 44 | pixmaps_dir = os.path.join('share', 'pixmaps', 'umit') |
|---|
| 45 | icons_dir = os.path.join('share', 'icons', 'umit') |
|---|
| 46 | locale_dir = os.path.join('share', 'locale') |
|---|
| 47 | config_dir = os.path.join('share', 'umit', 'config') |
|---|
| 48 | docs_dir = os.path.join('share', 'doc', 'umit') |
|---|
| 49 | misc_dir = os.path.join('share', 'umit', 'misc') |
|---|
| 50 | sql_dir = os.path.join('share', 'umit', 'sql') |
|---|
| 51 | media_dir = os.path.join('share', 'umit', 'umitweb_media') |
|---|
| 52 | templates_dir = os.path.join('share', 'umit', 'templates') |
|---|
| 53 | |
|---|
| 54 | def extension_find(result, dirname, fnames, suffix): |
|---|
| 55 | files = [] |
|---|
| 56 | for f in fnames: |
|---|
| 57 | p = os.path.join(dirname, f) |
|---|
| 58 | if os.path.isfile(p) and f.endswith(suffix): |
|---|
| 59 | files.append(p) |
|---|
| 60 | |
|---|
| 61 | if files: |
|---|
| 62 | result.append((dirname, files)) |
|---|
| 63 | |
|---|
| 64 | def mo_find(result, dirname, fnames): |
|---|
| 65 | return extension_find(result, dirname, fnames, ".mo") |
|---|
| 66 | |
|---|
| 67 | def po_find(result, dirname, fnames): |
|---|
| 68 | return extension_find(result, dirname, fnames, ".po") |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | ############################################################################### |
|---|
| 72 | # Installation variables |
|---|
| 73 | |
|---|
| 74 | svg = glob(os.path.join('share', 'pixmaps', '*.svg')) |
|---|
| 75 | data_files = [ (pixmaps_dir, glob(os.path.join(pixmaps_dir, '*.svg')) + |
|---|
| 76 | glob(os.path.join(pixmaps_dir, '*.png')) + |
|---|
| 77 | glob(os.path.join(pixmaps_dir, '*.xpm')) + |
|---|
| 78 | glob(os.path.join(pixmaps_dir, 'umit.o*'))), |
|---|
| 79 | |
|---|
| 80 | (config_dir, [os.path.join(config_dir, 'umitweb.conf')] + |
|---|
| 81 | [os.path.join(config_dir, 'scan_profile.usp')] + |
|---|
| 82 | [os.path.join(config_dir, 'umit_version')] + |
|---|
| 83 | [os.path.join(config_dir, 'umitng.db')] + |
|---|
| 84 | [os.path.join(config_dir, |
|---|
| 85 | 'timeline-settings.conf')] + |
|---|
| 86 | [os.path.join(config_dir, |
|---|
| 87 | 'tl_colors_evt_std.conf')] + |
|---|
| 88 | [os.path.join(config_dir, |
|---|
| 89 | 'scheduler-schemas.conf')] + |
|---|
| 90 | [os.path.join(config_dir, |
|---|
| 91 | 'scheduler-profiles.conf')] + |
|---|
| 92 | [os.path.join(config_dir, 'scheduler.log')] + |
|---|
| 93 | [os.path.join(config_dir, 'smtp-schemas.conf')] + |
|---|
| 94 | glob(os.path.join(config_dir, '*.xml'))+ |
|---|
| 95 | glob(os.path.join(config_dir, '*.txt'))), |
|---|
| 96 | |
|---|
| 97 | # umitDB SQL |
|---|
| 98 | (sql_dir, glob(os.path.join("umitDB/sql", "*.sql"))), |
|---|
| 99 | |
|---|
| 100 | (misc_dir, glob(os.path.join(misc_dir, '*.dmp'))), |
|---|
| 101 | |
|---|
| 102 | # Radialnet |
|---|
| 103 | (os.path.join(pixmaps_dir, 'radialnet', 'application'), |
|---|
| 104 | glob(os.path.join(pixmaps_dir, 'radialnet', 'application', |
|---|
| 105 | '*.png'))), |
|---|
| 106 | (os.path.join(pixmaps_dir, 'radialnet', 'icons'), |
|---|
| 107 | glob(os.path.join(pixmaps_dir, 'radialnet', 'icons','*.png'))), |
|---|
| 108 | |
|---|
| 109 | # Network Inventory |
|---|
| 110 | (os.path.join(pixmaps_dir, 'networkinventory'), |
|---|
| 111 | glob(os.path.join(pixmaps_dir, 'networkinventory', '*.png'))), |
|---|
| 112 | |
|---|
| 113 | # InterfaceEditor |
|---|
| 114 | (os.path.join(pixmaps_dir, 'uie'), |
|---|
| 115 | glob(os.path.join(pixmaps_dir, 'uie', '*.png'))), |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | (icons_dir, glob(os.path.join('share', 'icons', 'umit', |
|---|
| 119 | '*.ico'))+ |
|---|
| 120 | glob(os.path.join('share', 'icons', 'umit', |
|---|
| 121 | '*.png'))), |
|---|
| 122 | |
|---|
| 123 | (docs_dir, glob(os.path.join(docs_dir, '*.html'))+ |
|---|
| 124 | glob(os.path.join(docs_dir, |
|---|
| 125 | 'comparing_results', '*.xml'))+ |
|---|
| 126 | glob(os.path.join(docs_dir, |
|---|
| 127 | 'profile_editor', '*.xml'))+ |
|---|
| 128 | glob(os.path.join(docs_dir, |
|---|
| 129 | 'scanning', '*.xml'))+ |
|---|
| 130 | glob(os.path.join(docs_dir, |
|---|
| 131 | 'searching', '*.xml'))+ |
|---|
| 132 | glob(os.path.join(docs_dir, |
|---|
| 133 | 'wizard', '*.xml'))+ |
|---|
| 134 | glob(os.path.join(docs_dir, 'scheduler', '*.xml')) + |
|---|
| 135 | glob(os.path.join(docs_dir, 'smtpsetup', '*.xml')) + |
|---|
| 136 | glob(os.path.join(docs_dir, |
|---|
| 137 | 'screenshots', '*.png'))), |
|---|
| 138 | |
|---|
| 139 | (templates_dir, |
|---|
| 140 | glob(os.path.join(templates_dir, "*.html"))), |
|---|
| 141 | |
|---|
| 142 | (os.path.join(templates_dir, "html"), |
|---|
| 143 | glob(os.path.join(templates_dir, "html", "*.html"))), |
|---|
| 144 | |
|---|
| 145 | (os.path.join(media_dir, "js"), |
|---|
| 146 | glob(os.path.join(media_dir, 'js', '*.js'))), |
|---|
| 147 | |
|---|
| 148 | (os.path.join(media_dir, "css"), |
|---|
| 149 | glob(os.path.join(media_dir, 'css', '*.css'))), |
|---|
| 150 | |
|---|
| 151 | (os.path.join(media_dir, "images"), |
|---|
| 152 | glob(os.path.join(media_dir, 'images', '*.jpg'))+ |
|---|
| 153 | glob(os.path.join(media_dir, 'images', '*.gif'))+ |
|---|
| 154 | glob(os.path.join(media_dir, 'images', '*.png')))] |
|---|
| 155 | |
|---|
| 156 | # Add i18n files to data_files list |
|---|
| 157 | os.path.walk(locale_dir, mo_find, data_files) |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | ############################################################################## |
|---|
| 161 | # Distutils subclasses |
|---|
| 162 | |
|---|
| 163 | class umit_build(build): |
|---|
| 164 | |
|---|
| 165 | def delete_mo_files(self): |
|---|
| 166 | """ Remove *.mo files """ |
|---|
| 167 | tmp = [] |
|---|
| 168 | os.path.walk(locale_dir, mo_find, tmp) |
|---|
| 169 | for (path, t) in tmp: |
|---|
| 170 | os.remove(t[0]) |
|---|
| 171 | |
|---|
| 172 | def build_mo_files(self): |
|---|
| 173 | """Build mo files from po and put it into LC_MESSAGES """ |
|---|
| 174 | tmp = [] |
|---|
| 175 | os.path.walk(locale_dir, po_find, tmp) |
|---|
| 176 | for (path, t) in tmp: |
|---|
| 177 | full_path = os.path.join(path , "LC_MESSAGES", "umit.mo") |
|---|
| 178 | self.mkpath(os.path.dirname(full_path)) |
|---|
| 179 | self.announce("Compiling %s -> %s" % (t[0],full_path)) |
|---|
| 180 | msgfmt.make(t[0], full_path, False) |
|---|
| 181 | # like guess |
|---|
| 182 | os.path.walk(locale_dir, mo_find, data_files) |
|---|
| 183 | |
|---|
| 184 | def run(self): |
|---|
| 185 | self.delete_mo_files() |
|---|
| 186 | self.build_mo_files() |
|---|
| 187 | build.run(self) |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | class umit_install(install): |
|---|
| 191 | |
|---|
| 192 | def run(self): |
|---|
| 193 | # Add i18n files to data_files list |
|---|
| 194 | os.path.walk(locale_dir, mo_find, data_files) |
|---|
| 195 | install.run(self) |
|---|
| 196 | |
|---|
| 197 | self.set_perms() |
|---|
| 198 | self.set_modules_path() |
|---|
| 199 | self.fix_paths() |
|---|
| 200 | self.create_uninstaller() |
|---|
| 201 | self.finish_banner() |
|---|
| 202 | |
|---|
| 203 | def create_uninstaller(self): |
|---|
| 204 | uninstaller_filename = os.path.join( |
|---|
| 205 | self.install_scripts, "uninstall_umit") |
|---|
| 206 | uninstaller = """#!/usr/bin/env python |
|---|
| 207 | import os, os.path, sys |
|---|
| 208 | |
|---|
| 209 | print |
|---|
| 210 | print '%(line)s Uninstall UmitWeb %(version)s %(line)s' |
|---|
| 211 | print |
|---|
| 212 | |
|---|
| 213 | answer = raw_input('Are you sure that you want to completly uninstall \ |
|---|
| 214 | Umit %(version)s? (yes/no) ') |
|---|
| 215 | |
|---|
| 216 | if answer != 'yes' and answer != 'y': |
|---|
| 217 | sys.exit(0) |
|---|
| 218 | |
|---|
| 219 | print |
|---|
| 220 | print '%(line)s Uninstalling Umit %(version)s... %(line)s' |
|---|
| 221 | print |
|---|
| 222 | """ % {'version':VERSION, 'line':'-'*10} |
|---|
| 223 | |
|---|
| 224 | for output in self.get_outputs(): |
|---|
| 225 | uninstaller += "print 'Removing %s...'\n" % output |
|---|
| 226 | uninstaller += "if os.path.exists('%s'): os.remove('%s')\n" % \ |
|---|
| 227 | (output, output) |
|---|
| 228 | |
|---|
| 229 | uninstaller += "print 'Removing uninstaller itself...'\n" |
|---|
| 230 | uninstaller += "os.remove('%s')\n" % uninstaller_filename |
|---|
| 231 | |
|---|
| 232 | uninstaller_file = open(uninstaller_filename, 'w') |
|---|
| 233 | uninstaller_file.write(uninstaller) |
|---|
| 234 | uninstaller_file.close() |
|---|
| 235 | |
|---|
| 236 | # Set exec bit for uninstaller |
|---|
| 237 | mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777 |
|---|
| 238 | os.chmod(uninstaller_filename, mode) |
|---|
| 239 | |
|---|
| 240 | def set_modules_path(self): |
|---|
| 241 | umit = os.path.join(self.install_scripts, "umitwebserver") |
|---|
| 242 | modules = self.install_lib |
|---|
| 243 | |
|---|
| 244 | re_sys = re.compile("^import sys$") |
|---|
| 245 | |
|---|
| 246 | ufile = open(umit, "r") |
|---|
| 247 | ucontent = ufile.readlines() |
|---|
| 248 | ufile.close() |
|---|
| 249 | |
|---|
| 250 | uline = None |
|---|
| 251 | for line in xrange(len(ucontent)): |
|---|
| 252 | if re_sys.match(ucontent[line]): |
|---|
| 253 | uline = line + 1 |
|---|
| 254 | break |
|---|
| 255 | |
|---|
| 256 | ucontent.insert(uline, "sys.path.insert(0,'%s')\n" % modules ) |
|---|
| 257 | |
|---|
| 258 | ufile = open(umit, "w") |
|---|
| 259 | ufile.writelines(ucontent) |
|---|
| 260 | ufile.close() |
|---|
| 261 | |
|---|
| 262 | def set_perms(self): |
|---|
| 263 | re_bin = re.compile("(bin)") |
|---|
| 264 | for output in self.get_outputs(): |
|---|
| 265 | if re_bin.findall(output): |
|---|
| 266 | continue |
|---|
| 267 | |
|---|
| 268 | if os.path.isdir(output): |
|---|
| 269 | os.chmod(output, S_IRWXU | \ |
|---|
| 270 | S_IRGRP | \ |
|---|
| 271 | S_IXGRP | \ |
|---|
| 272 | S_IROTH | \ |
|---|
| 273 | S_IXOTH) |
|---|
| 274 | else: |
|---|
| 275 | os.chmod(output, S_IRWXU | \ |
|---|
| 276 | S_IRGRP | \ |
|---|
| 277 | S_IROTH) |
|---|
| 278 | |
|---|
| 279 | def fix_paths(self): |
|---|
| 280 | interesting_paths = {"CONFIG_DIR":config_dir, |
|---|
| 281 | "DOCS_DIR":docs_dir, |
|---|
| 282 | "LOCALE_DIR":locale_dir, |
|---|
| 283 | "MISC_DIR":misc_dir, |
|---|
| 284 | "PIXMAPS_DIR":pixmaps_dir, |
|---|
| 285 | "ICONS_DIR":icons_dir, |
|---|
| 286 | "MEDIA_DIR":"umitweb_media", |
|---|
| 287 | "TEMPLATES_DIR":"templates", |
|---|
| 288 | "UMIT_ICON":"umit_48.ico"} |
|---|
| 289 | |
|---|
| 290 | pcontent = "" |
|---|
| 291 | paths_file = os.path.join("umitCore", "BasePaths.py") |
|---|
| 292 | installed_files = self.get_outputs() |
|---|
| 293 | |
|---|
| 294 | # Finding where the Paths.py file was installed. |
|---|
| 295 | for f in installed_files: |
|---|
| 296 | if re.findall("(%s)" % re.escape(paths_file), f): |
|---|
| 297 | paths_file = f |
|---|
| 298 | pf = open(paths_file) |
|---|
| 299 | pcontent = pf.read() |
|---|
| 300 | pf.close() |
|---|
| 301 | break |
|---|
| 302 | |
|---|
| 303 | for path in interesting_paths: |
|---|
| 304 | for f in installed_files: |
|---|
| 305 | result = re.findall("(.*%s)" %\ |
|---|
| 306 | re.escape(interesting_paths[path]), |
|---|
| 307 | f) |
|---|
| 308 | if len(result) == 1: |
|---|
| 309 | result = result[0] |
|---|
| 310 | pcontent = re.sub("%s\s+=\s+.+" % path, |
|---|
| 311 | "%s = \"%s\"" % (path, result), |
|---|
| 312 | pcontent) |
|---|
| 313 | break |
|---|
| 314 | |
|---|
| 315 | pf = open(paths_file, "w") |
|---|
| 316 | pf.write(pcontent) |
|---|
| 317 | pf.close() |
|---|
| 318 | |
|---|
| 319 | def finish_banner(self): |
|---|
| 320 | print |
|---|
| 321 | print "%s Thanks for using Umit %s %s" % \ |
|---|
| 322 | ("#"*10, VERSION, "#"*10) |
|---|
| 323 | print |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | class umit_sdist(sdist): |
|---|
| 327 | |
|---|
| 328 | def read_manifest_no_mo(self): |
|---|
| 329 | """Read Manifest without mo file.""" |
|---|
| 330 | for line in open(self.manifest): |
|---|
| 331 | if not line: |
|---|
| 332 | break |
|---|
| 333 | |
|---|
| 334 | if line[-1] == '\n': |
|---|
| 335 | line = line[:-1] |
|---|
| 336 | if line.find('umit.mo') != -1: |
|---|
| 337 | self.filelist.files.remove(line) |
|---|
| 338 | |
|---|
| 339 | def run(self): |
|---|
| 340 | from distutils.filelist import FileList |
|---|
| 341 | self.keep_temp = 1 |
|---|
| 342 | #Rewrite: sdist.run(self) |
|---|
| 343 | self.manifest = "MANIFEST" |
|---|
| 344 | self.filelist = FileList() |
|---|
| 345 | self.check_metadata() |
|---|
| 346 | self.get_file_list() |
|---|
| 347 | ## Exclude mo files: |
|---|
| 348 | self.read_manifest_no_mo() |
|---|
| 349 | if self.manifest_only: |
|---|
| 350 | return |
|---|
| 351 | self.make_distribution() |
|---|
| 352 | |
|---|
| 353 | self.finish_banner() |
|---|
| 354 | |
|---|
| 355 | def finish_banner(self): |
|---|
| 356 | print |
|---|
| 357 | print "%s The packages for UmitWeb %s are in ./dist %s" % \ |
|---|
| 358 | ("#" * 10, VERSION, "#" * 10) |
|---|
| 359 | print |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | ##################### Umit banner ######################## |
|---|
| 363 | print |
|---|
| 364 | print "%s UmitWeb for Linux %s %s" % ("#" * 10, VERSION, "#" * 10) |
|---|
| 365 | print |
|---|
| 366 | ########################################################## |
|---|
| 367 | |
|---|
| 368 | setup(name = 'umitweb', |
|---|
| 369 | license = 'GNU GPL (version 2 or later)', |
|---|
| 370 | url = 'http://www.umitproject.org', |
|---|
| 371 | download_url = 'http://www.umitproject.org', |
|---|
| 372 | author = 'Adriano Monteiro, Cleber Rodrigues & Rodolfo Carvalho', |
|---|
| 373 | author_email = 'adriano@umitproject.org, cleber@globalred.com.br, rodolfo@umitproject.org', |
|---|
| 374 | maintainer = 'Adriano Monteiro', |
|---|
| 375 | maintainer_email = 'adriano@gmail.com', |
|---|
| 376 | description = """Umit is a network scanning frontend, developed in \ |
|---|
| 377 | Python and GTK and was started with the sponsoring of Google's Summer \ |
|---|
| 378 | of Code.""", |
|---|
| 379 | long_description = """The project goal is to develop a network scanning \ |
|---|
| 380 | frontend that is really useful for advanced users and easy to be used by \ |
|---|
| 381 | newbies. With Umit, a network admin could create scan profiles for faster and \ |
|---|
| 382 | easier network scanning or even compare scan results to easily see any \ |
|---|
| 383 | changes. A regular user will also be able to construct powerful scans with \ |
|---|
| 384 | Umit command creator wizards.""", |
|---|
| 385 | version = VERSION, |
|---|
| 386 | scripts = ['umitwebserver', 'umit_scheduler.py'], |
|---|
| 387 | packages = [ |
|---|
| 388 | 'umitCore', 'umitCore.radialnet', 'umitDB', 'umitWeb', 'umitWeb.views', 'umitWeb.views.html', |
|---|
| 389 | 'umitInventory', 'umitPlugin', 'umitInterfaceEditor', 'umitInterfaceEditor.selectborder', |
|---|
| 390 | 'higwidgets', 'utils'], |
|---|
| 391 | data_files = data_files, |
|---|
| 392 | cmdclass = { |
|---|
| 393 | "install": umit_install, |
|---|
| 394 | "build": umit_build, |
|---|
| 395 | "sdist": umit_sdist}) |
|---|