-
Notifications
You must be signed in to change notification settings - Fork 48
/
ajax_adduser.php
125 lines (119 loc) · 5.36 KB
/
ajax_adduser.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
<?php
//require_once 'settings.php';
use PEAR2\Net\RouterOS;
require_once 'PEAR2/Autoload.php';
require_once 'config.php';
$util = new RouterOS\Util($client = new RouterOS\Client("$host", "$user", "$pass"));
if (isset($_GET['name'])) $username = $_GET['name'];
if (isset($_GET['psd'])) $password = $_GET['psd'];
if (isset($_GET['limit_uptime'])) $limit_uptime = $_GET['limit_uptime'];
if (isset($_GET['limit_bytes'])) $limit_bytes = $_GET['limit_bytes'];
if (isset($_GET['profile'])) $profile = $_GET['profile'];
if ( !isset($_SESSION) ) session_start();
$util->setMenu('/ip hotspot user');
$iv = count($util);
if ((!empty($username)) and (!empty($password)) and (!empty($profile))) {
if (intval($limit_bytes) != 0) {
$limit_bytes_total = (intval($limit_bytes) * 1024 * 1024 * 1024 );
$util->add(
array(
'name' => "$username",
'password' => "$password",
'disabled' => "no",
'limit-uptime' => "$limit_uptime",
'limit-bytes-total' => "$limit_bytes_total",
'profile' => "$profile",
'comment' => "Zetozone",
)
);
}
else
{
$util->add(
array(
'name' => "$username",
'password' => "$password",
'disabled' => "no",
'limit-uptime' => "$limit_uptime",
'profile' => "$profile",
'comment' => "Zetozone",
)
);
$limit_bytes = 0; // For Adding it to Local database
}
if ($iv != count($util)) {
include('dbconfig.php');
$stmt = $DB_con->prepare("SELECT booking_id from hotspot_vouchers ORDER BY booking_id DESC LIMIT 1");
$stmt->execute(array());
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$booking_id = $row['booking_id'];
$booking_id++;
$uid = $booking_id.'-1-'.date('dmY');
//$creator = $_SESSION['username'].'['.$_SESSION['id'].']';
$stmt = $DB_con->prepare("UPDATE hotspot_vouchers set status=:status WHERE 1");
$stmt->execute(array(':status' => 'Over'));
$stmt = $DB_con->prepare("insert into hotspot_vouchers (created_on, created_by, creator, user_name, password, printed_times,
printed_last, status, group_of, booking_id, limit_uptime, limit_bytes, profile, uid)
values(NOW(), :created_by, :creator, :user_name, :password, :printed_times, :printed_last, :status, :group_of,
:booking_id, :limit_uptime, :limit_bytes, :profile, :uid)");
$stmt->execute(array(':created_by' => $_SESSION['username'], ':creator' => $_SESSION['id'], ':user_name' => $username, ':password' => $password,
':printed_times' => 0, ':printed_last' => '', ':status' => 'Active', ':group_of' => 1,
':booking_id' => $booking_id, ':limit_uptime' => $limit_uptime, ':limit_bytes' => $limit_bytes,
':profile' => $profile, ':uid' => $uid));
// here starts Echo String
$echo_text ='
<div class="container">
<div class="row" style="padding-top:20px;">
<div class="col-sm-12 col-md-12">
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="text-center">Hotspot User Voucher</h3></div>
<div class="panel-body">
<form id="userForm" class="form-horizontal" method="GET" action="" enctype="multipart/form-data">
<div class="col-sm-12 col-md-12">
<table cellpadding="0" cellspacing="0" border="0" class="table table-bordered" id="example">
<thead>
<tr>
<th width="10%"></th>
<th colspan="2">Username</th>
<th colspan="2">Password</th>
</tr>
</thead>
<tbody>';
$echo_text .= '<tr>
<td width="10%" style="margin:0px; border: 0px; padding: 2px;"><img src="images/logo.png" width="250" height="50"></td>
<td colspan="2"><input type="text" name="username" class="form-control" value="Username : '.$username.'" placeholder="User Name" readonly></td>
<td colspan="2"><input type="text" name="password" class="form-control" value="Password : '.$password.'" placeholder="Password" readonly></td>
</tr>
<tr>';
if (intval($limit_bytes) != 0) {
$echo_text .= '<td colspan="5">Validity : '.$limit_uptime.'ays; Counts from First login; Data usage Maximum : '.$limit_bytes_total.' Bytes; Bandwidth : '.$profile.'; HAPPY BROWSING...</td>';
}
else
{
$echo_text .= '<td colspan="5">Validity : '.$limit_uptime.'ays; Counts from First login; Bandwidth/Profile : '.$profile.'; HAPPY BROWSING...</td>';
}
$echo_text .= '
</tr>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
<div class="col-sm-3 col-sm-offset-5">
<button onclick="window.print();" class="btn btn-primary" ><i class="icon-save icon-large"></i></a> PRINT</button>
<button onclick="document.getElementById("single").style.display="none !important;" type="reset" class="btn btn-danger"><i class="icon-save icon-large"></i></a> Reset</button>
<button data-dismiss="modal" class="btn btn-info" ><i class="icon-save icon-large"></i></a> BACK</button>
</div>
</div>
</div>';
echo $echo_text;
}
else
{
echo '<script>cmodalOkCancel("ERROR/DUPLICATE", " Username '.$username.' is not added, Found as Duplicate. Try some other name", "error");</script>';
}
}
//End Adding a Guest User
?>