/usr/bin/musetup is in museekd 1:0.2+svn20100315.r1208-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 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 376 377 378 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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 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 | #! /usr/bin/env python
import os, sys
DATADIR = os.path.realpath(sys.argv[0])
for i in range(2):
DATADIR = os.path.split(DATADIR)[0]
DEFAULT_TEMPLATE = os.path.join(DATADIR, 'share', 'museek', 'museekd', 'config.xml.tmpl')
if not os.path.exists(DEFAULT_TEMPLATE):
t_path = os.path.join('/usr', 'share', 'museek', 'museekd', 'config.xml.tmpl')
if os.path.exists(t_path):
DEFAULT_TEMPLATE = t_path
DEFAULT_CONFIG = os.path.join('~', '.museekd', 'config.xml')
from xml.dom import minidom
import time, stat, string, pwd
config = {}
def readDomain(node):
domain = {}
child = node.firstChild
while child:
if child.nodeName == u'key':
id = child.getAttribute('id')
if child.firstChild:
domain[id] = child.firstChild.nodeValue
else:
domain[id] = ''
child = child.nextSibling
return domain
def readConfig(path = 'config.xml'):
global config
doc = minidom.parse(path)
root = doc.firstChild
node = root.firstChild
while node:
if node.nodeName == u'domain':
id = node.getAttribute('id')
config[id] = readDomain(node)
node = node.nextSibling
def readTemplate(path = 'config.xml.tmpl', config_path = 'config.xml'):
global config
readConfig(path)
if config_path.rfind('.') > config_path.rfind('/'):
config_path = '.'.join(config_path.split('.')[:-1])
user = pwd.getpwuid(os.getuid())[0]
for domain in config.values():
for key in domain.keys():
value = domain[key].replace('$(USER)', user).replace('$(CONFIG)', config_path)
del domain[key]
key = key.replace('$(USER)', user).replace('$(CONFIG)', config_path)
domain[key] = value
def writeConfig(path = 'newconfig.xml'):
global config
doc = minidom.Document()
root = doc.appendChild(doc.createElement('museekd'))
for i in config.keys():
root.appendChild(doc.createTextNode('\n '))
domain = root.appendChild(doc.createElement('domain'))
domain.setAttribute('id', i)
for j in config[i].keys():
domain.appendChild(doc.createTextNode('\n '))
key = domain.appendChild(doc.createElement('key'))
key.setAttribute('id', j)
v = config[i][j]
if v:
key.appendChild(doc.createTextNode(v.encode( "utf-8" )))
domain.appendChild(doc.createTextNode('\n '))
root.appendChild(doc.createTextNode('\n'))
try:
os.makedirs(os.path.split(path)[0])
except OSError:
pass
f = open(path, 'w')
doc.writexml(f)
f.close()
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
print
print 'Configuration updated. Don\'t forget to restart museekd.'
print
def choice(max):
print
print 'Pick a number, any number: ',
line = sys.stdin.readline().strip()
print
try:
choice = int(line)
except:
print 'I said, a number.. when did \'%s\' become a number?' % line
time.sleep(3)
return -1
if choice not in range(max+1):
print 'I know I said any number, but a number which actually\nhas an action assigned to it might be a wiser choice'
time.sleep(3)
return -1
return choice
def port_choice(default):
print 'Port [%s]: ' % (default),
s = sys.stdin.readline().strip()
print
if s:
try:
port = int(s)
return s
except:
print 'Ports are usually numbers'
time.sleep(3)
return default
def string_choice(title, default):
print '%s [%s]: ' % (title, default),
s = sys.stdin.readline().strip()
if s:
return s
return default
def path_choice(default):
print 'Path: ',
s = sys.stdin.readline().strip()
return os.path.expanduser(s)
def server():
global config
if not config.has_key('server'):
config['server'] = {}
_server = config['server'].get('host', 'server.slsknet.org')
_port = config['server'].get('port', '2242')
_username = config['server'].get('username', '')
_password = config['server'].get('password', '')
print
print
print 'Soulseek server setup'
print
print '1. Server:', _server
print '2. Port: ', _port
print
print '3. Username:', _username
print '4. Password:', '*' * len(_password)
print
print '0. Leave this menu'
c = choice(4)
if c == 0:
return 1
elif c == 1:
config['server']['host'] = string_choice('Server', _server)
elif c == 2:
config['server']['port'] = port_choice(_port)
elif c == 3:
config['server']['username'] = string_choice('Username', _username)
elif c == 4:
config['server']['password'] = string_choice('Password', _password)
return 0
def connectmode():
print
print
print 'Peer connect mode setup'
print
print '1. Active'
print ' (use this if your client port can\'t be reached'
print ' from the outside world, think firewalls / routers)'
print
print '2. Passive'
print ' (use this if you can receive direct connections on'
print ' your client port from the outside world)'
print
print ' Passive is usually a good choice.'
print
print '0. Don\'t change this setting'
c = choice(2)
if c == -1:
return 0
elif c == 1:
config['clients']['connectmode'] = 'active'
elif c == 2:
config['clients']['connectmode'] = 'passive'
return 1
def buddyshares():
print
print 'Special Shares List for Buddies'
print
print "Note: If you want to share all the files in your \"Normal\" shares"
print "within the special shares, you will have to add them."
print
print '1. True'
print ' (use this if your want to have a seperate list for'
print ' buddies that includes file normal users will not get)'
print
print '2. False'
print ' (use this if you want everyone to get have access'
print ' to a single \"Normal\" shares list)'
print
print '0. Don\'t change this setting'
c = choice(2)
if c == -1:
return 0
elif c == 1:
config['transfers']['have_buddy_shares'] = 'true'
elif c == 2:
config['transfers']['have_buddy_shares'] = 'false'
return 1
def portrange():
global config
if not config.has_key('clients.bind'):
config['clients.bind'] = {}
_first = config['clients.bind'].get('first', '2234')
_last = config['clients.bind'].get('last', '2240')
if not config.has_key('clients'):
config['clients'] = {}
_mode = config['clients'].get('connectmode', 'active')
print
print
print 'Client port range setup'
print
print '1. First port to try: ', _first
print '2. Last port to try: ', _last
print
print '3. Connection mode: ', _mode
print
print '0. Leave this menu'
c = choice(3)
if c == 1:
config['clients.bind']['first'] = port_choice(_first)
elif c == 2:
config['clients.bind']['last'] = port_choice(_last)
elif c == 3:
while not connectmode(): pass
else:
return 1
return 0
def dirs():
if not config.has_key('transfers'):
config['transfers'] = {}
_complete = config['transfers'].get('download-dir', '~/downloads')
_incomplete = config['transfers'].get('incomplete-dir', '')
print
print
print 'Incomplete and completed download setup'
print 'Please input the full directory path, or use ~/ for your home directory'
print
print '1. Completed downloads:', _complete
print '2. Incomplete downloads:', _incomplete
print ' (if this is empty, completed download dirs will be used)'
print
print '0. Leave this menu'
c = choice(2)
if c == 1:
config['transfers']['download-dir'] = path_choice(_complete)
elif c == 2:
config['transfers']['incomplete-dir'] = path_choice(_incomplete)
else:
return 1
return 0
def charsets():
if not config.has_key('encoding'):
config['encoding'] = {}
_network = config['encoding'].get('network', 'UTF-8')
_filesystem = config['encoding'].get('filesystem', 'LATIN1')
print
print
print 'Network and filesystem character set setup'
print
print '1. Network character set: ', _network
print ' (Make the world a better place, use UTF-8!)'
print
print '2. Filesystem character set:', _filesystem
print ' (latin1 is usually a good choice)'
print
print '0. Leave this menu'
c = choice(2)
if c == 1:
config['encoding']['network'] = string_choice('Character set', _network)
elif c == 2:
config['encoding']['filesystem'] = string_choice('Character set', _filesystem)
else:
return 1
return 0
def new_iface():
print
print
print 'New interface listener setup'
print
print '1. Add TCP socket listener'
print '2. Add UNIX socket listener'
print
print '0. Don\'t add a new interface listener'
c = choice(2)
if c == -1:
return 0
elif c == 1:
host = string_choice('Local address to bind to (empty = all)', '')
port = port_choice('')
if not port:
print 'A port is a requirement to be able to bind...'
time.sleep(3)
return 0
config['interfaces.bind'][host + ':' + port] = ''
elif c == 2:
path = string_choice('Path + filename of UNIX socket', '')
if not path:
return 0
if path[0] != '/':
print 'UNIX socket pathnames have to be absolute'
time.sleep(3)
return 0
config['interfaces.bind'][path] = ''
return 1
def ifaces():
if not config.has_key('interfaces'):
config['interfaces'] = {}
_password = config['interfaces'].get('password', '')
if not config.has_key('interfaces.bind'):
config['interfaces.bind'] = {}
_ifaces = config['interfaces.bind'].keys()
_ifaces.sort()
print
print
print 'Interface listener setup'
print
print '1. Interface password', '*' * len(_password)
print
print '2. Add new interface listener'
print
ix = 2
for i in _ifaces:
ix = ix + 1
print '%i. Delete interface listener' % (ix), i
if not _ifaces:
print '(no interface listeners defined)'
print
print '0. Leave this menu'
c = choice(ix)
if c == 0:
return 1
elif c == 1:
config['interfaces']['password'] = string_choice('Password', _password)
elif c == 2:
while not new_iface(): pass
elif c != -1:
del config['interfaces.bind'][_ifaces[c - 3]]
return 0
def escapeCommand(filename):
"""Escapes special characters for command execution"""
escaped = ""
for ch in filename:
if ch not in string.ascii_letters+string.digits+"/":
escaped += "\\"
escaped += ch
return escaped
def shares(config_path):
if not os.path.exists(config_path):
print "Need config file to build shares, creating..."
writeConfig(config_path)
r = os.popen('muscan -c %s -l' % escapeCommand(config_path)).read()
_shared = [i for i in r.split("\n") if i]
print
print
print 'Shared directories setup'
print ' Note: these options work immediately and without confirmation'
print
print '1. Rescan shares incrementally'
print '2. Rescan shares from scratch'
print
print '3. Add shared directory'
print
ix = 3
for dir in _shared:
ix = ix + 1
print '%i. Remove %s' % (ix, dir)
print
print '0. Leave this menu'
c = choice(ix)
if c == 0:
return 1
elif c == 1:
print
print 'Please wait patiently while rescanning shares...'
os.system('muscan -c %s' % escapeCommand(config_path))
elif c == 2:
print
print 'Please wait patiently while rescanning shares...'
os.system('muscan -c %s -r' % escapeCommand(config_path))
elif c == 3:
dir = string_choice('Path', '')
if dir:
dir = os.path.expanduser(dir)
if dir[-1:] == "/":
dir = dir[:-1]
print dir
print 'Please wait patiently while rescanning shares...'
os.system('muscan -c %s -s %s' % (escapeCommand(config_path), escapeCommand(dir)))
else:
os.system('muscan -c %s -u %s' % (escapeCommand(config_path), escapeCommand(_shared[c - 4])))
return 0
def bshares(config_path):
if not os.path.exists(config_path):
print "Need config file to build shares, creating..."
writeConfig(config_path)
r = os.popen('muscan -c %s -b -l' % escapeCommand(config_path)).read()
_shared = [i for i in r.split("\n") if i]
_have_buddy_shares = config['transfers'].get('have_buddy_shares', '')
print
print
print 'Special Buddy-only Shared directories setup'
print ' Note: these options work immediately and without confirmation'
print
print '1. Rescan shares incrementally'
print '2. Rescan shares from scratch'
print
print '3. Special list for buddies:', _have_buddy_shares
print
print '4. Add shared directory'
print
ix = 4
for dir in _shared:
ix = ix + 1
print '%i. Remove %s' % (ix, dir)
print
print '0. Leave this menu'
c = choice(ix)
if c == 0:
return 1
elif c == 1:
print
print 'Please wait patiently while rescanning shares...'
os.system('muscan -c %s -b' % escapeCommand(config_path))
elif c == 2:
print
print 'Please wait patiently while rescanning shares...'
os.system('muscan -c %s -b -r' % escapeCommand(config_path))
elif c == 3:
while not buddyshares(): pass
elif c == 4:
dir = string_choice('Path', '')
if dir:
dir = os.path.expanduser(dir)
if dir[-1:] == "/":
dir = dir[:-1]
print dir
print 'Please wait patiently while rescanning shares...'
os.system('muscan -c %s -b -s %s' % (escapeCommand(config_path), escapeCommand(dir)))
else:
os.system('muscan -c %s -b -u %s' % (escapeCommand(config_path), escapeCommand(_shared[c - 5])))
return 0
def save(config_path):
print
print
print 'Leave museek setup'
print
print '1. Save changes'
print '2. Don\'t save changes'
print
print '0. Don\'t leave museek setup'
c = choice(2)
if c == -1:
return 0
elif c == 0:
return 1
elif c == 1:
writeConfig(config_path)
return 2
def main(config_path):
print
print 'Museek daemon setup'
print
print "Settings that must be set for museekd to run: \nServer, Username, Password, Interface Password, Download Dir"
print
print '1. Soulseek server'
print '2. Peer connections'
print '3. Interface listeners'
print '4. Network and filesystem character sets'
print '5. Download and incomplete file directory'
print
print '6. Shared directories'
print "7. Buddy-Only Shared directories"
print
print '0. Exit museek setup'
c = choice(7)
if c == -1:
return 0
elif c == 1:
while not server(): pass
elif c == 2:
while not portrange(): pass
elif c == 3:
while not ifaces(): pass
elif c == 4:
while not charsets(): pass
elif c == 5:
while not dirs(): pass
elif c == 6:
while not shares(config_path): pass
elif c == 7:
while not bshares(config_path): pass
else:
while 1:
c = save(config_path)
if c == 1:
return 0
elif c == 2:
return 1
return 0
if '--help' in sys.argv or len(sys.argv) > 2:
print
print 'Syntax: %s [path]' % sys.argv[0]
print
print '\'path\' is the filename of the configuration file to edit.'
print
sys.exit(1)
if len(sys.argv) == 2:
path = sys.argv[1]
else:
path = DEFAULT_CONFIG
path = os.path.expanduser(path)
try:
readConfig(path)
except:
print
print "Warning: couldn't load configuration, loading template"
print
readTemplate(DEFAULT_TEMPLATE, path)
try:
while not main(path): pass
except Exception, e:
print "\nAborting musetup..."
|