This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
manageftp.php
126 lines (110 loc) · 4.26 KB
/
manageftp.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
<?php
/*
* @author: Scottish Borders Design
* @script: SBD SHOUTcast Manager
* @function: FTP Management and Creation
* @website: http://scottishbordersdesign.co.uk/
*/
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
session_start();
require('include/functions.inc.php');
if(!isset($_SESSION['username'])){
echo "<center>Please <a href=\"login.php\">LOGIN</a></center>";
} else {
$db = dbConnect();
$config = settings();
$uid = getuid($_SESSION['username']);
$myid = getuid($_SESSION['username']);
$port = $_GET['server'];
$myserver = getserverbyportbase($port);
if ($myserver['owner'] != $myid ) {
die("You do not own this server.");
exit();
}
if (isset($_GET['server']) && isset($_GET['action']) && $_GET['action'] == 'fetchFTP') {
die(getFTPAccounts($_GET['server']));
exit;
}
if (isset($_GET['server']) && isset($_GET['action']) && $_GET['action'] == 'generateFTP') {
$subject = $config['media_path'];
$search = $config['cpanel_homedir'];
$trim_home = str_replace($search, '', $subject);
$passwordForFTP = generatePassword(10,false,'lud');
$usernameForFTP = generatePassword(10,false,'ld');
$return = cpanel_api('add_ftp', $myserver['servername'].'-'.$usernameForFTP, $passwordForFTP, '/' . $trim_home . '/' . $myserver['PortBase'] . '/', $myserver['autodj_max_space'], '.' . $config['cpanel_hostname']);
if (strpos($return, 'No Valid Command Given') !== false) {
die("Something went wrong, please try again.");
} else {
$insert = array(
"username" => $myserver['servername'].'-'.$usernameForFTP,
"password" => $passwordForFTP,
"PortBase" => $myserver['PortBase']
);
$db->insert("ftp", $insert);
}
exit();
}
if (isset($_GET['server']) && isset($_GET['action']) && $_GET['action'] == 'deleteFTP') {
/* Get */
$db->where("id", $_GET['delID']);
$db->where("PortBase", $myserver['PortBase']);
$ftpRow = $db->getOne("ftp");
/* delete from cPanel */
cpanel_api( 'del_ftp', $ftpRow['username'], null, null, null, null, 0 );
/* remove from db */
$db->where("id", $_GET['delID']);
$db->where("PortBase", $myserver['PortBase']);
$deleteFTPID = $db->delete("ftp");
}
?>
<div class="box box-primary">
<div class="box-body">
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<thead>
<tr>
<th>Host</th>
<th>Username</th>
<th>Password</th>
<th>Port</th>
<th> </th>
</tr>
</thead>
<tbody id="ftprows">
<tr id="noFTPWarning">
<td colspan="5" style="text-align:center;">No FTP Accounts</td>
</tr>
</tbody>
</table>
</div>
</div><!-- /.box-body -->
<div class="box-footer clearfix no-border">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="FTPactionButton" onClick="createFTP(); return false;" type="button" name="createftpButton" class="btn btn-default pull-right">Create FTP</button>
</div>
</div>
<script>
function removeFTP(ftpID){
$('#ftprows').html("<tr><td colspan='5' style='text-align:center;''><span class=\"loader-inner ball-pulse\"><div></div><div></div><div></div></span></td></tr>");
$('#ftprows').load('manageftp.php?server=<?php echo $port;?>&action=deleteFTP&delID='+ftpID, function(){
// getFTPAccounts();
});
}
function getFTPAccounts(){
$('#ftprows').load('manageftp.php?server=<?php echo $port;?>&action=fetchFTP');
}
function createFTP(){
$('#ftprows').html("<tr><td colspan='5' style='text-align:center;''><span class=\"loader-inner ball-pulse\"><div></div><div></div><div></div></span></td></tr>");
$('#FTPactionButton').attr("disabled", "true");
$('#ftprows').load('manageftp.php?server=<?php echo $port;?>&action=generateFTP', function(){
$('#FTPactionButton').removeAttr("disabled");
getFTPAccounts();
});
}
$('#ftprows').load('manageftp.php?server=<?php echo $port;?>&action=fetchFTP');
</script>
<?php
} // end of sign in detection
?>