# Path: RapacheCore/PluginBase.py
# class PluginBaseObject():
# 
#     def __init__(self, path):
#             
#         # The path to the plugin
#         self.path = path
#     
#         # module this plugin works with
#         self.module = ""
#         
#         # Define what additional config should be read from vhost file
#         self.vhosts_config = {  } # 0 value | 1 options
#         
#         # Number set when plugin UI is added to notebook
#         self._tab_number = -1
#     
#     def is_module_enabled(self):
#         if self.module:
#             module = ModuleModel(self.module)
#             module.load()
#             #print "STATUS : " + self.module + " - " + str( module.is_enabled())
#             return module.is_enabled()
#         return True
#         
#     def is_enabled(self):
#         enabled = self.is_module_enabled()
#         
#         #TODO: Method of activating / deactivating plugins
#         
#         return enabled
#         
#     # Add item to tools menu
#     def init_main_window(self, MainWindow):
#         return None
#         
#         
#     # Customise the module properties window
#     def load_module_properties(self, notebook, module):
#         return True
# 
#     # Perform action on module properties save
#     def save_module_properties(self, module):
#         return True
# 
# 
# 
# 
# 
# 
#     # Init the vhost propertis window
#     def init_vhost_properties(self, notebook):
#         return None, None, None
# 
#     # Tab recives focus load properties from vhost object
#     def load_vhost_properties(self,  vhost):
#         return True
#         
#     # Tab blurs update vhost object with changes
#     def update_vhost_properties(self, vhost):
#         return True, ""
#         
#     # Perform action on vhost properties save, return false if validation fails
#     def save_vhost_properties(self, vhost):
#         return True, ""
# 
# Path: RapacheCore/Shell.py
# class CommandLogEntry:
# class CommandHandler:
#     def __init__(self, command):
#     def __init__(self, ssh_server="localhost", ssh_port=None, ssh_username=None, ssh_password=None):
#     def __get_backup_path(self, path):
#     def get_backup_files(self, path):
#     def read_file_version(self, path, date_stamp):
#     def create_backup(self, path, new_content):
#     def read_file(self, path):
#     def write_file(self, path, content, backup=True):
#     def listdir(self, path):
#     def create_complete_path ( self, complete_path ):
#     def exists(self, path):
#     def readlink(self, path):
#     def move(self, source, destination):
#     def __get_password(self, description, prompt="Password: "):
#     def __sudo_popen (self, command, password ): 
#     def is_auth_needed (self):        
#     def execute(self, command, description = None ):
#     def __output (self, command, returncode, output, error ):
#     def sudo_reset (self):
#     def ask_password(self, description = "Super user priviledges are required to perform this operation"):
#     def sudo_execute(self, command, description = "Super user priviledges are required to perform this operation"):
#     def sudo_read_file(self, path):
#     def sudo_exists(self, path):
#     def sudo_listdir(self, path):


import os
     import pygtk
    import gtk
    import gtk.glade
from RapacheCore.PluginBase import PluginBaseObject
from RapacheCore import Shell
from htpasswd import Htpasswd
from user_credentials import UserCredentials
        self.treeview_users.append_column(column)

        self.entry_location.set_text(self.default_location)
        self.users.load(Shell.command.read_file(self.default_location))
        self.entry_warning_message.set_text("Enter your password")
        

        self.update_users()
        
        icon_theme = gtk.icon_theme_get_default()
        pixbuf = icon_theme.lookup_icon("gtk-dialog-authentication", 24, 0).load_icon()

        return hbox_auth_basic, "Basic Security", pixbuf

    # Customise the vhost properties window
    def load_vhost_properties(self, vhost):
        self.users_active = []
        self.checkbutton_enable_auth_basic.set_active(False)
        
        ds = vhost.config.Directory.search(  [vhost.get_document_root()]  )

        if len(  ds    ) > 0:
            d = ds[0]
            if d.AuthType:
                self.checkbutton_enable_auth_basic.set_active(d.AuthType.value.lower() == "basic")
                
            # only load if value changes
            if d.AuthUserFile:
                if d.AuthUserFile.value != self.entry_location.get_text():
                    self.entry_location.set_text(d.AuthUserFile.value)

# Path: RapacheCore/PluginBase.py
# class PluginBaseObject():
# 
#     def __init__(self, path):
#             
#         # The path to the plugin
#         self.path = path
#     
#         # module this plugin works with
#         self.module = ""
#         
#         # Define what additional config should be read from vhost file
#         self.vhosts_config = {  } # 0 value | 1 options
#         
#         # Number set when plugin UI is added to notebook
#         self._tab_number = -1
#     
#     def is_module_enabled(self):
#         if self.module:
#             module = ModuleModel(self.module)
#             module.load()
#             #print "STATUS : " + self.module + " - " + str( module.is_enabled())
#             return module.is_enabled()
#         return True
#         
#     def is_enabled(self):
#         enabled = self.is_module_enabled()
#         
#         #TODO: Method of activating / deactivating plugins
#         
#         return enabled
#         
#     # Add item to tools menu
#     def init_main_window(self, MainWindow):
#         return None
#         
#         
#     # Customise the module properties window
#     def load_module_properties(self, notebook, module):
#         return True
# 
#     # Perform action on module properties save
#     def save_module_properties(self, module):
#         return True
# 
# 
# 
# 
# 
# 
#     # Init the vhost propertis window
#     def init_vhost_properties(self, notebook):
#         return None, None, None
# 
#     # Tab recives focus load properties from vhost object
#     def load_vhost_properties(self,  vhost):
#         return True
#         
#     # Tab blurs update vhost object with changes
#     def update_vhost_properties(self, vhost):
#         return True, ""
#         
#     # Perform action on vhost properties save, return false if validation fails
#     def save_vhost_properties(self, vhost):
#         return True, ""
# 
# Path: RapacheCore/Shell.py
# class CommandLogEntry:
# class CommandHandler:
#     def __init__(self, command):
#     def __init__(self, ssh_server="localhost", ssh_port=None, ssh_username=None, ssh_password=None):
#     def __get_backup_path(self, path):
#     def get_backup_files(self, path):
#     def read_file_version(self, path, date_stamp):
#     def create_backup(self, path, new_content):
#     def read_file(self, path):
#     def write_file(self, path, content, backup=True):
#     def listdir(self, path):
#     def create_complete_path ( self, complete_path ):
#     def exists(self, path):
#     def readlink(self, path):
#     def move(self, source, destination):
#     def __get_password(self, description, prompt="Password: "):
#     def __sudo_popen (self, command, password ): 
#     def is_auth_needed (self):        
#     def execute(self, command, description = None ):
#     def __output (self, command, returncode, output, error ):
#     def sudo_reset (self):
#     def ask_password(self, description = "Super user priviledges are required to perform this operation"):
#     def sudo_execute(self, command, description = "Super user priviledges are required to perform this operation"):
#     def sudo_read_file(self, path):
#     def sudo_exists(self, path):
#     def sudo_listdir(self, path):


# Path: plugins/basic_authentication/plugin.py
import os
     import pygtk
    import gtk
    import gtk.glade
from RapacheCore.PluginBase import PluginBaseObject
from RapacheCore import Shell
from htpasswd import Htpasswd
from user_credentials import UserCredentials

        self.treeview_users.append_column(column)

        self.entry_location.set_text(self.default_location)
        self.users.load(Shell.command.read_file(self.default_location))
        self.entry_warning_message.set_text("Enter your password")
        

        self.update_users()
        
        icon_theme = gtk.icon_theme_get_default()
        pixbuf = icon_theme.lookup_icon("gtk-dialog-authentication", 24, 0).load_icon()

        return hbox_auth_basic, "Basic Security", pixbuf

    # Customise the vhost properties window
    def load_vhost_properties(self, vhost):
        self.users_active = []
        self.checkbutton_enable_auth_basic.set_active(False)
        
        ds = vhost.config.Directory.search(  [vhost.get_document_root()]  )

        if len(  ds    ) > 0:
            d = ds[0]
            if d.AuthType:
                self.checkbutton_enable_auth_basic.set_active(d.AuthType.value.lower() == "basic")
                
            # only load if value changes
            if d.AuthUserFile:
                if d.AuthUserFile.value != self.entry_location.get_text():
                    self.entry_location.set_text(d.AuthUserFile.value)

                    content = Shell.command.read_file(self.entry_location.get_text())