This repository has been archived by the owner on Mar 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
class.php
216 lines (201 loc) · 4.8 KB
/
class.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
* Class written by Svenskunganka
*
* Website: http://tjservers.org
* Facepunch: http://facepunch.com/member.php?u=445369
*/
class SQLiteToMySQL {
/**
* Points to the file to convert
*
* @access private
* @var string
*/
private $file = "";
/**
* The DarkRP MySQL/SQlite Tables
*
* @access private
* @var array
*/
private $darkrp_tables = array(
"FADMIN_GROUPS",
"FADMIN_MOTD",
"FADMIN_PRIVILEGES",
"FADMIN_RESTRICTEDENTS",
"FAdminBans",
"FAdmin_PlayerGroup",
"FAdmin_ServerSettings",
"FAdmin_Immunity",
"FPP_ANTISPAM1",
"FPP_BLOCKED1",
"FPP_BLOCKEDMODELS1",
"FPP_BLOCKEDMODELSETTINGS1",
"FPP_ENTITYDAMAGE1",
"FPP_GLOBALSETTINGS1",
"FPP_GRAVGUN1",
"FPP_GROUPMEMBERS1",
"FPP_GROUPS3",
"FPP_GROUPTOOL",
"FPP_PHYSGUN1",
"FPP_TOOLADMINONLY",
"FPP_TOOLGUN1",
"FPP_TOOLRESTRICTPERSON1",
"FPP_TOOLTEAMRESTRICT",
"darkrp_cvar",
"darkrp_door",
"darkrp_doorgroups",
"darkrp_jobown",
"darkrp_jobspawn",
"darkrp_player",
"darkrp_position",
"playerinformation",
);
/**
* Checks if file is of the correct MIME-type
*
* @return boolean
*/
public function checkMime () {
$mime = explode(".", $this->file);
if($mime[1] == "db") {
return true;
}
else {
return false;
}
}
/**
* Checks if the sqlite3 package is installed.
*
* @return boolean
*/
public function checkSQLite3 () {
if(exec("sqlite3 --version")) {
return true;
}
else {
return false;
}
}
/**
* Extracts the sv.db to a .sql file to the directory of the script
*
* @return boolean
*/
public function extractSQL () {
if($this->checkMime() && $this->checkSQLite3()) {
$newpath = __DIR__ . "/db.sql";
passthru("sqlite3 " . $this->file . " .dump > " . $newpath ."");
$this->file = $newpath;
return true;
}
else {
return false;
}
}
/**
* Pastes the converted SQL to Pastebin and send the user to the paste.
*
* @param string
*/
public function pastebin ($code) {
$url = "http://pastebin.com/api/api_post.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=paste&api_user_key=&api_paste_private='.PB_PRIVATE.'&api_paste_name='.PB_NAME.'&api_paste_expire_date='.PB_EXPIRE_DATE.'&api_paste_format=SQL&api_dev_key='.PB_DEV_KEY.'&api_paste_code='.$code.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
$response = curl_exec($ch);
if(!strpos($response, "Bad API")) {
header("Location: ".$response);
}
else {
die($response);
}
}
/**
* Puts the converted content into a SQL file.
*
* @param string $code
*/
public function download ($code) {
file_put_contents("converted.sql", $code);
echo "<script>window.location='converted.sql'</script>";
}
/**
* Converts SQLite INSERT values to MySQL values.
*
* @param string $type
* @param string $method
* @param string $file
* @return boolean
*/
public function convert ($type, $method, $file) {
$this->file = __DIR__ . "/" . $file;
if ($this->extractSQL()) {
$content = file_get_contents($this->file);
$eachline = explode(";", $content);
foreach($eachline as $key => &$value) {
if($type == "pointshop") {
if(strpos($value, 'INSERT INTO "playerpdata"') !== false && strpos($value, '[PS_Points]') !== false) {
$templine = explode(",", $eachline[$key+1]);
$var = ",";
foreach($templine as $key2 => $value2) {
if ($key2 > 0) {
$var = $var.$value2;
}
}
unset($eachline[$key+1]);
$value = str_replace('"playerpdata"', "`pointshop_data`", $value);
$value = str_replace("[PS_Points]", "", $value);
$value = str_replace(")",$var,$value);
}
else {
unset($eachline[$key]);
}
}
elseif($type == "darkrp") {
foreach($this->darkrp_tables as $table) {
if(strpos($value, 'INSERT INTO "'.$table.'"') !== false) {
$value = str_replace('"'.$table.'"', '`'.$table.'`', $value);
}
else {
$templine = explode("(", $value);
$blacklist = array (
'INSERT',
'INTO',
'VALUES',
'"',
'`'
);
$templine[0] = trim(str_replace($blacklist, "", $templine[0]));
if(!in_array($templine[0], $this->darkrp_tables)) {
unset($eachline[$key]);
}
}
}
}
elseif($type == "utime") {
var_dump($value);
if(strpos($value, 'INSERT INTO "utime"') !== false) {
$value = str_replace('"utime"', '`utime`', $value);
}
else {
unset($eachline[$key]);
}
}
}
$code = implode(";", $eachline);
$code .= ";";
unlink($this->file);
if ($type == "pastebin" && ENABLE_PASTEBIN) {$this->pastebin($code);} else {$this->download($code);}
}
else {
return false;
}
}
}
?>