Commit 3b6f367e authored by Tomas Hlavacek's avatar Tomas Hlavacek

Move config file to an arbitrary path.

Implement loading of config.py from arbitrary path. The file potentially
contains sensitive material like passwords, usernames, list of routers
etc. and should be placed outside the www root directory.
parent 2de45733
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# Router config file
config_file = '/etc/ulg/config.py'
# HTML presentation settings # HTML presentation settings
header = 'Universal looking glass test header' header = 'Universal looking glass test header'
refresh_interval = 5 # interval of html refresh refresh_interval = 5 # interval of html refresh
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
import os, sys import os, sys
import random import random
import config
import defaults import defaults
import ulgmodel import ulgmodel
...@@ -33,6 +32,8 @@ import re ...@@ -33,6 +32,8 @@ import re
import time import time
import traceback import traceback
config = ulgmodel.import_config()
def testRouterCommand(router=0,command=0,params=[]): def testRouterCommand(router=0,command=0,params=[]):
r = config.routers[router] r = config.routers[router]
......
...@@ -24,11 +24,12 @@ import time, datetime ...@@ -24,11 +24,12 @@ import time, datetime
import pickle import pickle
import re import re
import config
import defaults import defaults
import ulgmodel import ulgmodel
config = ulgmodel.import_config()
### ULG cron script ### ULG cron script
SESSION_FILE_REGEX='^ulg-.*\.session$' SESSION_FILE_REGEX='^ulg-.*\.session$'
......
...@@ -32,12 +32,13 @@ import md5 ...@@ -32,12 +32,13 @@ import md5
import time import time
import random import random
import config
import defaults import defaults
import ulgmodel import ulgmodel
import whois import whois
config = ulgmodel.import_config()
IPV4_ANNOTATE_REGEXP = '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(/[0-9]{1,2})?)' IPV4_ANNOTATE_REGEXP = '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(/[0-9]{1,2})?)'
ipv4_annotate_regexp = re.compile(IPV4_ANNOTATE_REGEXP) ipv4_annotate_regexp = re.compile(IPV4_ANNOTATE_REGEXP)
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# Imports # Imports
import os import os
import re import re
import sys
from time import localtime, strftime from time import localtime, strftime
from genshi.template import TemplateLoader from genshi.template import TemplateLoader
from genshi.core import Markup from genshi.core import Markup
...@@ -49,6 +50,14 @@ def debug(message): ...@@ -49,6 +50,14 @@ def debug(message):
if(defaults.debug): if(defaults.debug):
log('DEBUG:' + message) log('DEBUG:' + message)
def import_config():
path, filename = os.path.split(defaults.config_file)
filename, ext = os.path.splitext(filename)
sys.path.append(path)
module = __import__(filename)
reload(module)
del sys.path[-1]
return module
def annotateAS(asn): def annotateAS(asn):
return asn+' | '+whois.lookup_as_name(asn) return asn+' | '+whois.lookup_as_name(asn)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment