Skip to content

Commit

Permalink
Revert Twig because of multiple regressions, work still needed, and l…
Browse files Browse the repository at this point in the history
…ack of testing (#179)

* Revert "Small improvements to help themers" commit 19179f0
* Revert "Refactor twig files" commit 7442a1e
* Revert "Convert layout to twig" commit 089dc48
* Revert "Switch menu to twig" commit e0f43c5
* Revert "Switch templates to Twig" commit dda0a10
* Revert "Extract layout from index.php" commit 65ed39f
* Revert "Simplify and prepare templates for a template engine" commit c8bc71a
* Revert "Verticalize templates code" commit c341e5c
* Revert "Split pages into processing scripts + templates" commit 0201360
* Revert "Move processing outside html pages" commit 59cc6e5
  • Loading branch information
plewin committed Jan 10, 2018
1 parent b50c269 commit be3b510
Show file tree
Hide file tree
Showing 24 changed files with 814 additions and 752 deletions.
98 changes: 76 additions & 22 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
if ($use_recaptcha) {
require_once("lib/vendor/autoload.php");
}

require_once('phar://'. __DIR__ . '/lib/vendor/twig.phar/Twig/Autoloader.php');
Twig_Autoloader::register();

require_once("lib/detectbrowserlanguage.php");
require_once("lib/vendor/PHPMailer/PHPMailerAutoload.php");

Expand Down Expand Up @@ -168,24 +164,82 @@
$mailer->LE = $mail_newline;

#==============================================================================
# Template engine
#==============================================================================
$loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
$twig = new Twig_Environment($loader, array(
//'cache' => __DIR__ .'/templates_c',
));

function trans($id) {
global $messages;

return $messages[$id];
}
?>

<html lang="<?php echo $lang ?>">
<head>
<title><?php echo $messages["title"]; ?></title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="LDAP Tool Box" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="css/self-service-password.css" />
<link href="images/favicon.ico" rel="icon" type="image/x-icon" />
<link href="images/favicon.ico" rel="shortcut icon" />
<?php if (isset($background_image)) { ?>
<style>
html, body {
background: url("<?php echo $background_image ?>") no-repeat center fixed;
background-size: cover;
}
</style>
<?php } ?>
</head>
<body>

<div class="container">

<div class="panel panel-success">
<div class="panel-body">

<?php if ( $show_menu ) {
include("menu.php");
} else { ?>
<div class="title alert alert-success text-center"><h1><?php echo $messages["title"]; ?></h1></div>
<?php } ?>

<?php if ( $logo ) { ?>
<a href="index.php" alt="Home">
<img src="<?php echo $logo; ?>" alt="Logo" class="logo img-responsive center-block" />
</a>
<?php } ?>

$twig->addFilter('fa_class', new Twig_SimpleFilter('fa_class', 'get_fa_class'));
$twig->addFilter('criticality', new Twig_SimpleFilter('criticality', 'get_criticity'));
$twig->addFilter('trans', new Twig_SimpleFilter('trans', 'trans'));
$twig->addFunction('show_policy', new Twig_SimpleFunction('show_policy', 'show_policy'));

require_once __DIR__ . "/pages/$action.php";
<?php
if ( count($dependency_check_results) > 0 ) {
foreach($dependency_check_results as $result) {
?>
<div class="result alert alert-<?php echo get_criticity($result) ?>">
<p><i class="fa fa-fw <?php echo get_fa_class($result) ?>" aria-hidden="true"></i> <?php echo $messages[$result]; ?></p>
</div>
<?php
}
} else {
include("pages/$action.php");
}
?>

</div>
</div>

</div>

<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
// Menu links popovers
$('[data-toggle="menu-popover"]').popover({
trigger: 'hover',
placement: 'bottom',
container: 'body' // Allows the popover to be larger than the menu button
});
});
</script>
</body>
</html>
<?php

ob_end_flush();
8 changes: 0 additions & 8 deletions js/self-service-password.js

This file was deleted.

29 changes: 27 additions & 2 deletions lib/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,33 @@ function get_fa_class( $msg) {

}

function is_error ( $msg ) {
return preg_match( "/tooshort|toobig|minlower|minupper|mindigit|minspecial|forbiddenchars|sameasold|notcomplex|sameaslogin/" , $msg);
# Display policy bloc
# @return HTML code
function show_policy( $messages, $pwd_policy_config, $result ) {
extract( $pwd_policy_config );

# Should we display it?
if ( !$pwd_show_policy or $pwd_show_policy === "never" ) { return; }
if ( $pwd_show_policy === "onerror" ) {
if ( !preg_match( "/tooshort|toobig|minlower|minupper|mindigit|minspecial|forbiddenchars|sameasold|notcomplex|sameaslogin/" , $result) ) { return; }
}

# Display bloc
echo "<div class=\"help alert alert-warning\">\n";
echo "<p>".$messages["policy"]."</p>\n";
echo "<ul>\n";
if ( $pwd_min_length ) { echo "<li>".$messages["policyminlength"] ." $pwd_min_length</li>\n"; }
if ( $pwd_max_length ) { echo "<li>".$messages["policymaxlength"] ." $pwd_max_length</li>\n"; }
if ( $pwd_min_lower ) { echo "<li>".$messages["policyminlower"] ." $pwd_min_lower</li>\n"; }
if ( $pwd_min_upper ) { echo "<li>".$messages["policyminupper"] ." $pwd_min_upper</li>\n"; }
if ( $pwd_min_digit ) { echo "<li>".$messages["policymindigit"] ." $pwd_min_digit</li>\n"; }
if ( $pwd_min_special ) { echo "<li>".$messages["policyminspecial"] ." $pwd_min_special</li>\n"; }
if ( $pwd_complexity ) { echo "<li>".$messages["policycomplex"] ." $pwd_complexity</li>\n"; }
if ( $pwd_forbidden_chars ) { echo "<li>".$messages["policyforbiddenchars"] ." $pwd_forbidden_chars</li>\n"; }
if ( $pwd_no_reuse ) { echo "<li>".$messages["policynoreuse"] ."\n"; }
if ( $pwd_diff_login ) { echo "<li>".$messages["policydifflogin"] ."\n"; }
echo "</ul>\n";
echo "</div>\n";
}

# Check password strength
Expand Down
Binary file removed lib/vendor/twig.phar
Binary file not shown.
3 changes: 0 additions & 3 deletions lib/vendor/twig.phar.txt

This file was deleted.

53 changes: 53 additions & 0 deletions menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<div class="navbar-wrapper">

<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php"><i class="fa fa-fw fa-home"></i> <?php echo $messages["title"]; ?></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<?php if ( $use_questions ) { ?>
<li class="<?php if ( $action === "resetbyquestions" or $action === "setquestions" ) { echo "active"; } ?>">
<a href="?action=resetbyquestions"
data-toggle="menu-popover"
data-content="<?php echo htmlentities(strip_tags($messages["changehelpquestions"])); ?>"
><i class="fa fa-fw fa-question-circle"></i> <?php echo $messages["menuquestions"]; ?></a>
</li>
<?php } ?>
<?php if ( $use_tokens ) { ?>
<li class="<?php if ( ( $action === "resetbytoken" and $source !== "sms" ) or $action === "sendtoken" ) { echo "active"; } ?>">
<a href="?action=sendtoken"
data-toggle="menu-popover"
data-content="<?php echo htmlentities(strip_tags($messages["changehelptoken"])); ?>"
><i class="fa fa-fw fa-envelope"></i> <?php echo $messages["menutoken"]; ?></a>
</li>
<?php } ?>
<?php if ( $use_sms ) { ?>
<li class="<?php if ( ( $action === "resetbytoken" and $source === "sms" ) or $action === "sendsms" ) { echo "active"; } ?>">
<a href="?action=sendsms"
data-toggle="menu-popover"
data-content="<?php echo htmlentities(strip_tags($messages["changehelpsms"])); ?>"
><i class="fa fa-fw fa-mobile"></i> <?php echo $messages["menusms"]; ?></a>
</li>
<?php } ?>
<?php if ( $change_sshkey ) { ?>
<li class="<?php if ( $action === "changesshkey" ) { echo "active"; } ?>">
<a href="?action=changesshkey"
data-toggle="menu-popover"
data-content="<?php echo htmlentities(strip_tags($messages["changehelpsshkey"])); ?>"
><i class="fa fa-fw fa-terminal"></i> <?php echo $messages["menusshkey"]; ?></a>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>

</div>
160 changes: 121 additions & 39 deletions pages/change.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,123 @@
#==============================================================================
if ( $result === "" ) {
$result = change_password($ldap, $userdn, $newpassword, $ad_mode, $ad_options, $samba_mode, $samba_options, $shadow_options, $hash, $hash_options, $who_change_password, $oldpassword);
if ( $result === "passwordchanged" && isset($posthook) ) {
$command = escapeshellcmd($posthook).' '.escapeshellarg($login).' '.escapeshellarg($newpassword).' '.escapeshellarg($oldpassword);
exec($command);
}
}

#==============================================================================
# HTML
#==============================================================================
?>

<div class="result alert alert-<?php echo get_criticity($result) ?>">
<p><i class="fa fa-fw <?php echo get_fa_class($result) ?>" aria-hidden="true"></i> <?php echo $messages[$result]; ?></p>
</div>

<?php if ( $result !== "passwordchanged" ) { ?>

<?php
if ( $show_help ) {
echo "<div class=\"help alert alert-warning\"><p>";
echo "<i class=\"fa fa-fw fa-info-circle\"></i> ";
echo $messages["changehelp"];
echo "</p>";
if (isset($messages['changehelpextramessage'])) {
echo "<p>" . $messages['changehelpextramessage'] . "</p>";
}
if ( !$show_menu and ( $use_questions or $use_tokens or $use_sms or $change_sshkey ) ) {
echo "<p>". $messages["changehelpreset"] . "</p>";
echo "<ul>";
if ( $use_questions ) {
echo "<li>" . $messages["changehelpquestions"] ."</li>";
}
if ( $use_tokens ) {
echo "<li>" . $messages["changehelptoken"] ."</li>";
}
if ( $use_sms ) {
echo "<li>" . $messages["changehelpsms"] ."</li>";
}
if ( $change_sshkey ) {
echo "<li>" . $messages["changehelpsshkey"] . "</li>";
}
echo "</ul>";
}
echo "</div>\n";
}
?>

<?php
if ($pwd_show_policy_pos === 'above') {
show_policy($messages, $pwd_policy_config, $result);
}
?>

<div class="alert alert-info">
<form action="#" method="post" class="form-horizontal">
<div class="form-group">
<label for="login" class="col-sm-4 control-label"><?php echo $messages["login"]; ?></label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-fw fa-user"></i></span>
<input type="text" name="login" id="login" value="<?php echo htmlentities($login) ?>" class="form-control" placeholder="<?php echo $messages["login"]; ?>" />
</div>
</div>
</div>
<div class="form-group">
<label for="oldpassword" class="col-sm-4 control-label"><?php echo $messages["oldpassword"]; ?></label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-fw fa-lock"></i></span>
<input type="password" name="oldpassword" id="oldpassword" class="form-control" placeholder="<?php echo $messages["oldpassword"]; ?>" />
</div>
</div>
</div>
<div class="form-group">
<label for="newpassword" class="col-sm-4 control-label"><?php echo $messages["newpassword"]; ?></label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-fw fa-lock"></i></span>
<input type="password" name="newpassword" id="newpassword" class="form-control" placeholder="<?php echo $messages["newpassword"]; ?>" />
</div>
</div>
</div>
<div class="form-group">
<label for="confirmpassword" class="col-sm-4 control-label"><?php echo $messages["confirmpassword"]; ?></label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-fw fa-lock"></i></span>
<input type="password" name="confirmpassword" id="confirmpassword" class="form-control" placeholder="<?php echo $messages["confirmpassword"]; ?>" />
</div>
</div>
</div>
<?php if ($use_recaptcha) { ?>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<div class="g-recaptcha" data-sitekey="<?php echo $recaptcha_publickey; ?>" data-theme="<?php echo $recaptcha_theme; ?>" data-type="<?php echo $recaptcha_type; ?>" data-size="<?php echo $recaptcha_size; ?>"></div>
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang; ?>"></script>
</div>
</div>
<?php } ?>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" class="btn btn-success">
<i class="fa fa-fw fa-check-square-o"></i> <?php echo $messages['submit']; ?>
</button>
</div>
</div>
</form>
</div>

<?php
if ($pwd_show_policy_pos === 'below') {
show_policy($messages, $pwd_policy_config, $result);
}
?>

<?php } else {

if ( $result === "passwordchanged" ) {
# Notify password change
if ($mail and $notify_on_change) {
$data = array( "login" => $login, "mail" => $mail, "password" => $newpassword);
Expand All @@ -181,44 +295,12 @@
}
}

# Posthook
if ( isset($posthook) ) {
$command = escapeshellcmd($posthook).' '.escapeshellarg($login).' '.escapeshellarg($newpassword).' '.escapeshellarg($oldpassword);
exec($command);
if (isset($messages['passwordchangedextramessage'])) {
echo "<div class=\"result alert alert-" . get_criticity($result) . "\">";
echo "<p><i class=\"fa fa-fw " . get_fa_class($result) . "\" aria-hidden=\"true\"></i> " . $messages['passwordchangedextramessage'] . "</p>";
echo "</div>\n";
}
}

# Render associated template
echo $twig->render('change.twig', array(
'result' => $result,
'has_password_changed_extra_message' => isset($messages['passwordchangedextramessage']),
'has_change_help_extra_message' => isset($messages['changehelpextramessage']),
'show_help' => $show_help,

'pwd_show_policy_pos' => $pwd_show_policy_pos,
'login' => $login,
'recaptcha_publickey' => $recaptcha_publickey,
'recaptcha_theme' => $recaptcha_theme,
'recaptcha_type' => $recaptcha_type,
'recaptcha_size' => $recaptcha_size,

'show_change_help_reset' => !$show_menu and ( $use_questions or $use_tokens or $use_sms or $change_sshkey ),

}
?>

'show_policy' => $pwd_show_policy and ( $pwd_show_policy === "always" or ( $pwd_show_policy === "onerror" and is_error($result)) ),
'pwd_policy_config' => $pwd_policy_config,


'lang' => $lang,
'background_image' => $background_image,
'show_menu' => $show_menu,
'logo' => $logo,
'dependency_check_results' => $dependency_check_results,

'use_questions' => $use_questions,
'use_tokens' => $use_tokens,
'use_sms' => $use_sms,
'change_sshkey' => $change_sshkey,
'action' => $action,
'source' => $source,
));
Loading

0 comments on commit be3b510

Please sign in to comment.