-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.php
More file actions
79 lines (74 loc) · 3.71 KB
/
auth.php
File metadata and controls
79 lines (74 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
session_start();
if(!isset($_SESSION['login']) || $_SESSION['login'] != true)
{
header("location: login.php");
exit;
}
$username = $username1 = $passphrase = $passphrase1 = $passphrase2 = "";
$errmsg = $okmsg = "";
if(isset($_POST['button']))
{
$username = escapeshellarg(trim($_POST['username']));
$username1 = escapeshellarg(trim($_POST['username1']));
$passphrase = escapeshellarg(trim($_POST['passphrase']));
$passphrase1 = escapeshellarg(trim($_POST['passphrase1']));
$passphrase2 = escapeshellarg(trim($_POST['passphrase2']));
exec("sudo /var/www/html/chkpasswd $username $passphrase", $output, $ret);
if($ret != 0)
{
$errmsg = "Invalid username or password";
} else {
if($passphrase1 != $passphrase2 || strlen($passphrase1) < 10)
{
$errmsg = "New passphrases must be identical and at least 8 characters long.";
} else {
if($username != $username1 && strlen($username1) > 2)
{
$do = `sudo userdel -f -r $username`;
$do = `sudo useradd -m -G "adm,sudo,audio,video,plugdev,input,ssh" -s "/bin/bash" $username1`;
$username = $username1;
}
$cmd = "echo '".substr($username, 1, -1).":".substr($passphrase1, 1, -1)."' | sudo chpasswd";
$do = `$cmd`;
$okmsg = "Username and/or passphrases have been updated.";
}
}
}
$userinfo = posix_getpwuid(1000);
$page = 6;
$pageTitle = "User Settings";
include_once("header.php");
?>
<div id="page-wrapper">
<div id="page-inner">
<div class="row" style="padding-right:15px;padding-left:15px;">
<div class="col-md-12">
<h2><?=$pageTitle?></h2>
</div>
</div>
<hr />
<div class="row" style="padding-right:15px;padding-left:15px;">
<?php if($errmsg != "") { ?>
<p><div class="alert alert-warning alert-dismissable"><?=$errmsg?><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button></div></p>
<?php } ?>
<?php if($okmsg != "") { ?>
<p><div class="alert alert-success alert-dismissable"><?=$okmsg?><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button></div></p>
<?php } ?>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<div style="width:140px;float:left">Existing Username:</div>
<input type="text" style="width:200px;float:left;margin-left:20px;" class="form-control" name="username" value="<?=$userinfo['name']?>" placeholder="Existing Username" /><br style="clear:left;"/>
<div style="width:140px;float:left">New Username:</div>
<input type="text" style="width:200px;float:left;margin-left:20px;" class="form-control" name="username1" value="<?=substr($username1, 1, -1)?>" placeholder="Enter New Username" /><br style="clear:left;"/>
<div style="width:140px;float:left">Existing Passphrase:</div>
<input type="password" style="width:200px;float:left;margin-left:20px;" class="form-control" name="passphrase" placeholder="Enter the current Passphrase" /><br style="clear:left;"/>
<div style="width:140px;float:left">New Passphrase:</div>
<input type="password" style="width:200px;float:left;margin-left:20px;" class="form-control" name="passphrase1" placeholder="Enter a New Passphrase" /><br style="clear:left;"/>
<div style="width:140px;float:left">Redo Passphrase:</div>
<input type="password" style="width:200px;float:left;margin-left:20px;" class="form-control" name="passphrase2" placeholder="Re-enter your Passphrase" /><br style="clear:left;"/>
<input type="submit" class="btn btn-primary" name="button" value="Update User" />
</form>
</div>
</div>
</div>
<?php include_once("footer.php"); ?>