# 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
    def update_users(self):
        self.treeview_users_store = gtk.ListStore(bool, str, str)
        self.treeview_users.set_model(self.treeview_users_store)   

        for user in self.users.entries:
            self.treeview_users_store.append((user[0] in self.users_active , user[0], user[0]))         
        
        
    def init_vhost_properties(self):

        # Get glade file XML
        f = open( os.path.join(self.path, "basic_auth.glade") ,"r")
        self.glade_vhost_xml =  f.read()
        f.close()

        wtree = gtk.glade.xml_new_from_buffer(self.glade_vhost_xml, len(self.glade_vhost_xml), "hbox_auth_basic")
        hbox_auth_basic = wtree.get_widget("hbox_auth_basic") 
        
        self.checkbutton_enable_auth_basic = wtree.get_widget("checkbutton_enable_auth_basic") 
        self.entry_warning_message = wtree.get_widget("entry_warning_message") 
        self.treeview_users = wtree.get_widget("treeview_users") 
        self.entry_location = wtree.get_widget("entry_location")      
        
        signals = {
            "on_toolbutton_user_add_clicked"    : self.on_toolbutton_user_add_clicked,
            "on_toolbutton_user_edit_clicked"   : self.on_toolbutton_user_edit_clicked,
            "on_toolbutton_user_delete_clicked" : self.on_toolbutton_user_delete_clicked,
            "on_treeview_users_row_activated"   : self.on_treeview_users_row_activated,
            "on_button_location_clear_clicked"  : self.on_button_location_clear_clicked
        }

# 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

    def update_users(self):
        self.treeview_users_store = gtk.ListStore(bool, str, str)
        self.treeview_users.set_model(self.treeview_users_store)   

        for user in self.users.entries:
            self.treeview_users_store.append((user[0] in self.users_active , user[0], user[0]))         
        
        
    def init_vhost_properties(self):

        # Get glade file XML
        f = open( os.path.join(self.path, "basic_auth.glade") ,"r")
        self.glade_vhost_xml =  f.read()
        f.close()

        wtree = gtk.glade.xml_new_from_buffer(self.glade_vhost_xml, len(self.glade_vhost_xml), "hbox_auth_basic")
        hbox_auth_basic = wtree.get_widget("hbox_auth_basic") 
        
        self.checkbutton_enable_auth_basic = wtree.get_widget("checkbutton_enable_auth_basic") 
        self.entry_warning_message = wtree.get_widget("entry_warning_message") 
        self.treeview_users = wtree.get_widget("treeview_users") 
        self.entry_location = wtree.get_widget("entry_location")      
        
        signals = {
            "on_toolbutton_user_add_clicked"    : self.on_toolbutton_user_add_clicked,
            "on_toolbutton_user_edit_clicked"   : self.on_toolbutton_user_edit_clicked,
            "on_toolbutton_user_delete_clicked" : self.on_toolbutton_user_delete_clicked,
            "on_treeview_users_row_activated"   : self.on_treeview_users_row_activated,
            "on_button_location_clear_clicked"  : self.on_button_location_clear_clicked
        }

        wtree.signal_autoconnect(signals)  