Added password generating JS
[PHPCredLocker.git] / views / Creds / edit.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/** Edit Credential
*
* Copyright (C) 2012 B Tasker
* Released under GNU GPL V2
* See LICENSE
*
*/ 
 
defined('_CREDLOCK') or die;
 
 
global $notifications;
$creds = new CredDB;
$id = BTMain::getVar('id');
 
 
 
$notifications->setPageTitle("Edit " .Lang::_('Credential'));
 
 
if (BTMain::getVar('editCredSubmitted')){
 
$id = BTMain::getVar('id');
$credtype = BTMain::getVar('FrmCredType');
$cred = BTMain::getVar('frmCredential');
$clicky = BTMain::getVar('frmClicky');
$group = BTMain::getVar('frmGroup');
$address = BTMain::getVar('frmAddress');
$uname = BTMain::getVar('frmUser');
$group = BTMain::getVar('frmGroup');
  
  if (!BTMain::getConnTypeSSL()){
            $crypt = new Crypto;
            $tlskey = BTMain::getsessVar('tls');
            $cred = $crypt->xordstring(base64_decode($cred),$tlskey);
            $address = $crypt->xordstring(base64_decode($address),$tlskey);
            $uname = $crypt->xordstring(base64_decode($uname),$tlskey);
         }
 
 
 
if ($id == "NOCHANGE"){ $id = false; }
if ($cred == "NOCHANGE"){ $cred = false; }
if ($credtype == "NOCHANGE"){ $credtype = false; }
if ($clicky == "NOCHANGE"){ $clicky = false; }
if ($group == "NOCHANGE"){ $group = false; }
if ($address == "NOCHANGE"){ $address = false; }
if ($uname == "NOCHANGE"){ $uname = false; }
 
 
  // Add the cred to the db
  if ($creds->editCred($id,$credtype,$cred,$clicky,$group,$address,$uname)){
  // Success
  $notifications->setNotification("addCredSuccess");
  }else{
  $notifications->setNotification("addCredFail");
  }
 
 
 
 
 
}
 
$cred = $creds->FetchCredential($id);
$preselect = $cred->Group;
 
  if (!$cred){
  // Invalid credential
  $notifications->setNotification("NoSuchCustomer");
  return;
 
  }
 
 
 
 
 
$path = array(array('name'=>Lang::_("Credentials"),'url'=>'#'),array('name'=>'Edit','url'=>'index.php?option=editCred&id='.$id));
 
$notifications->setBreadcrumb($path);
 
 
$credtype = $cred->CredType;
 
$auth = new AuthDB;
$credtypes = $creds->getCredTypes();
 
 
 
 
$cust = BTMain::getVar('cust');
$custs = new CustDB;
$customers = $custs->getAllCustomers();
 
$crypt = new Crypto;
$crypt->safety = 0;
 
 
?>
<h1>Edit <?php echo Lang::_("Credential");?></h1>
 
<i>Leave a field blank to delete the <?php echo Lang::_("Credential");?> element</i>
 
<form method="POST" onsubmit="return checkEditCred();">
 
<input type="hidden" name="option" value="editCred">
<input type="hidden" name="editCredSubmitted" value="1">
<input type="hidden" name="frmClicky" id="frmClicky" value="NOCHANGE">
<input type="hidden" name="id" value="<?php echo $id; ?>">
 
 
 
<label for='FrmCredType'><?php echo Lang::_("Credential Type");?></label><select id="FrmCredType" name="FrmCredType" readonly='readonly'>
<?php 
foreach ($credtypes as $cred){
 
?>
<option value="<?php echo $cred->id;?>" 
<?php if ($credtype == $cred->id):?>
selected
<?php endif; ?>
><?php echo htmlspecialchars($crypt->decrypt($cred->Name,'CredType'));?></option>
<?php
 
}
unset($crypt);
?>
</select>
 
<label for="frmUser"><?php echo Lang::_("User");?></label><input type="text" name="frmUser" id="frmUser" value="NOCHANGE">
 
<label for="frmCredential"><?php echo Lang::_("Password");?></label><textarea id="frmCredential" name="frmCredential">NOCHANGE</textarea>
<a href="javascript: genPwd('frmCredential',10);">Generate Password</a>
<label for="frmAddress"><?php echo Lang::_("Address");?></label><input type="text" name="frmAddress" id="frmAddress" value="NOCHANGE">
 
 
 
<?php include 'lib/includes/groupSelection.php'; ?>
 
<input type="submit" class="btn btn-primary" value="Edit <?php echo Lang::_("Credential");?>">
</form>