Current File : //etc/zpanel/panel/modules/pgusers/module.zpm
<style>
#register .short{
font-weight:bold;
color:#FF0000;
font-size:larger;
}
#register .weak{
font-weight:bold;
color:orange;
font-size:larger;
}
#register .good{
font-weight:bold;
color:#2D98F3;
font-size:larger;
}
#register .strong{
font-weight:bold;
color: limegreen;
font-size:larger;
}

</style>

<div class="zmodule_content panel" id="zmodule_header_<@ ModuleName @>">
    <div class="panel-heading">
        <img src="<@ ModuleIcon @>" width="35" height="35" border="0" alt="<@ ModuleName @>">

        <div class="zmodule_title">
            <@ ModuleName @>
        </div>

        <div class="zmodule_desc" id="zmodule_desc_<@ ModuleName @>"><@ ModuleDesc @></div>

    </div>

    <@ Result @>

    <% if isDeleteUser %>
    <div class="zform_wrapper alert alert-danger">
        <h2><: Delete User :>: <@ EditCurrentUserName @> ?</h2>
        <p><: Please confirm that you want to delete this PostgreSQL user. :></p>
        <form action="./?module=pgusers&action=ConfirmDeleteUser" method="post">
            <table class="none" cellpadding="0" cellspacing="0">
                <tr>
                    <td colspan="2" align="right">
                        <input type="hidden" name="inDelete" value="<@ EditCurrentUserID @>">
                        <button class="button-loader delete btn btn-danger" type="submit" ><: Delete :></button>
                        <button class="button-loader btn btn-default" type="button" onclick="window.location.href='./?module=pgusers';return false;"><: Cancel :></button>
                    </td>
                </tr>
            </table>
            <@ CSFR_Tag @>
        </form>
    </div>
    <% endif %>

    <% if isEditUser %>
    <div class="zgrid_wrapper">
        <h2><: Databases for user :>: <@ EditCurrentUserName @></h2>
        <% if UserDatabaseList %>
        <form action="./?module=pgusers&action=RemoveDB" method="post">
            <table class="table table-striped">
                <tr>
                    <th><: Database name :></th>
                    <th><: Remove from user :></th>
                </tr>
                <% loop UserDatabaseList %>
                <tr>
                    <td><& mmdbname &></td>
                    <td><button class="button-loader delete btn btn-danger" type="submit" name="inRemove_<& mmid &>" id="inRemove_<& mmid &>" value="<& mmid &>"><: Remove database :></button></td>
                </tr>
                <% endloop %>
                <input type="hidden" name="inUser" value="<@ EditCurrentUserID @>">
            </table>
            <@ CSFR_Tag @>
        </form>
        <% else %>
        <: This user currently has no databases. Assign a database using the form below. :>
        <% endif %>

        <p>&nbsp;</p>

        <h2><: Add Database :></h2>
        <form action="./?module=pgusers&action=AddDB" method="post">
            <table class="table table-striped">
                <tr>
                    <th nowrap="nowrap"><: Database :>:</th>
                    <td width="150px">
                        <select name="inDatabase" id="inDatabase">
                            <option value="" selected="selected">-- Select a database --</option>
                            <% if DatabaseList %>
                            <% loop DatabaseList %>
                            <option value="<& mysqlid &>"><& mysqlname &></option>
                            <% endloop %>
                            <% endif %>
                        </select>
                    </td>
                    <td>
                        <input type="hidden" name="inUser" value="<@ EditCurrentUserID @>">
                        <button class="button-loader btn btn-primary" type="submit" ><: Add Database :></button>
                    </td>
                </tr>
            </table>
            <@ CSFR_Tag @>
        </form>

        <p>&nbsp;</p>

        <h2><: Reset Password :></h2>
        <form action="./?module=pgusers&action=ResetPW" method="post" id="register">
            <table class="zform">
                <tr>
                    <th nowrap="nowrap"><: Password :>:</th>
                    <td width="150px">
                        <input type="text" name="inResetPW" id="input-password" value="">
                    </td>
                    <td>
                        <input type="hidden" name="inUser" value="<@ EditCurrentUserID @>"> 
                        
                        <button class="button-loader btn btn-primary" id="pwdstr" type="submit" ><: Save :></button></td>
                        
                       <td> <button class="button-loader btn btn-default" type="button" onclick="window.location.href='./?module=pgusers';return false;"><: Cancel :></button>
                    </td>
                </tr>
                <tr>
                    <th></th>
                    <td><span id="result"></span></td>
                    <td><a href="#" class="link-password" id="generate"><: Generate Password :></a></td>
                    <td></td>
                </tr>
            </table>
            <@ CSFR_Tag @>
        </form>

    </div>
    <% endif %>

    <div class="zgrid_wrapper">
        <h2><: Current Postgre&reg; Users :></h2>
        <% if UserList %>
        <form action="./?module=pgusers&action=EditUser" method="post">
            <table class="table table-striped">
				<tr>
					<th><: User name :></th>
                    <th><: Access :></th>
                    <th><: Databases :></th>
                    <th><: Password :></th>
                    <th></th>
                </tr>
                <% loop UserList %>
                <tr>
                    <td><& username &></td>
                    <td><& accesshtml &></td>
                    <td><& totaldb &></td>
                    <td><& dbpassword &></td>
                    <td>
                        <button class="button-loader btn btn-default" type="submit" name="inEdit_<& userid &>" id="inEdit_<& userid &>" value="<& userid &>"><: Edit :></button></td>
                       <td> <button class="button-loader delete btn btn-danger" type="submit" name="inDelete_<& userid &>" id="inDelete_<& userid &>" value="<& userid &>"><: Delete :></button>
                    </td>
                </tr>
                <% endloop %>
            </table>
            <@ CSFR_Tag @>
        </form>
        <% else %>
        <: You have no Postgre&reg; users at this time. Create a user using the form below. :>
        <% endif %>
    </div>

    <% if isCreateUser %>
    <div class="zform_wrapper">
        <table class="none" width="100%" cellborder="0" cellspacing="0">
            <tr valign="top">
                <td>
                    <h2><: Create a new PostgreSQL&reg; User :></h2>
                    <form action="./?module=pgusers&action=CreateUser" method="post">
                        <table class="table table-striped">
                            <tr>
                                <th nowrap="nowrap"><: User name :>:</th>
                                <td nowrap="nowrap"><input type="text" size="30" name="inUserName" id="inUserName" /></td>
                            </tr>
                            <tr>
                                <th nowrap="nowrap"><: Map Database :>:</th>
                                <td>
                                    <select name="inDatabase" id="inDatabase">
                                        <option value="" selected="selected">-- Select a database --</option>
                                        <% if DatabaseList %>
                                        <% loop DatabaseList %>
                                        <option value="<& mysqlid &>"><& mysqlname &></option>
                                        <% endloop %>
                                        <% endif %>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>&nbsp;</th>
                                <td>
                                    <div id="showaccess" style="display:none;">
                                        <input type="text" size="30" name="inAccessIP" id="inAccessIP" />
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th colspan="2" align="right">
                                    <button class="button-loader btn btn-primary" type="submit" ><: Create :></button></th>
                            </tr>
                        </table>
                        <@ CSFR_Tag @>
                    </form>
                </td>
                <td align="right"><@ MysqlUsagepChart @></td>
            </tr></table>
    </div>
    <% endif %>

</div>


<script type="text/javascript">
    <!--
    function show_div(id) {
        var e = document.getElementById(id);
        if(e.style.display == 'none')
            e.style.display = 'block';
    }
    //-->
</script>
<script type="text/javascript">
    <!--
    function hide_div(id) {
        var e = document.getElementById(id);
        if(e.style.display == 'block')
            e.style.display = 'none';
    }
    //-->
</script>
<script type="text/JavaScript">
    $.extend({
        password: function (length, special) {
            var iteration = 0;
            var password = "";
            var randomNumber;
            if(special == undefined){
                var special = false;
            }
            while(iteration < length){
                randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
                if(!special){
                    if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
                    if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
                    if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
                    if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
                }
                iteration++;
                password += String.fromCharCode(randomNumber);
            }
            return password;
        }

    });
    $(document).ready(function() {
        
    });
</script>

<script>
/*
	jQuery document ready.
*/
$(document).ready(function()
{
	/*

		assigning keyup event to password field

		so everytime user type code will execute

	*/

	$('.link-password').click(function(e){
            linkId = $(this).attr('id');
            if (linkId == 'generate'){
                password = $.password(9,false);
                $('#input-password').val(password);
          	$('#result').html(checkStrength($('#input-password').val()));
            }

            e.preventDefault();
        });	

        if($('#input-password').val().length ==0){

               $('#pwdstr').attr('disabled', 'disabled');
        	}
	$('#input-password').keyup(function()
	{
            
              $('#result').html(checkStrength($('#input-password').val()))
		

	})	
		
        
	/*
		checkStrength is function which will do the 

		main password strength checking for us

	*/
	
	function checkStrength(password)
	{
		//initial strength
		var strength = 0
		
		//if the password length is less than 6, return message.
		if (password.length < 6) { 
			$('#result').removeClass();
			$('#result').addClass('short');
			$('#pwdstr').attr('disabled','disabled');
			return 'Too short'; 
		}
		
		//length is ok, lets continue.
		
		//if length is 8 characters or more, increase strength value
		if (password.length > 7) strength += 1
		
		//if password contains both lower and uppercase characters, increase strength value
		if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  strength += 1
		
		//if it has numbers and characters, increase strength value
		if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  strength += 1 
		
		//if it has one special character, increase strength value
		if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/))  strength += 1
		
		//if it has two special characters, increase strength value
		if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1
		
		//now we have calculated strength value, we can return messages
		
		//if value is less than 2
		if (strength <2 )
		{
			$('#result').removeClass();
			$('#result').addClass('weak');
			$('#pwdstr').attr('disabled','disabled');			
                        return 'Weak'			
		}
		else if (strength == 2 )
		{
			$('#result').removeClass();
			$('#result').addClass('good');
                        // $("#pwdstr").show();	
                        $('#pwdstr').removeAttr('disabled');	
			return 'Good'		
		}
		else
		{
			$('#result').removeClass();
			$('#result').addClass('strong');
                        // $("#pwdstr").show();
                        $('#pwdstr').removeAttr('disabled');	
			return 'Strong'
		}
	}
});
</script>