#!/usr/bin/python
import macro
import index_view
import authorization


def read_conf():
    f = open(macro.dcmm_conf_file)
    items = {}

    content = f.readline()
    while content:
        str_no_comment = content.split('#')
        key_value = str_no_comment[0].split()
        if len(key_value) != 2:
            continue
        items[key_value[0]] = key_value[1]
        content = f.readline()

    return items


def index_handler():
    if not authorization.is_Authorized():
        authorization.send_unauth()
        return

    cfg_itm = read_conf()

    print index_view.get_html(cfg_itm, 200)

index_handler()
'''
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'
'''
