Remove old v2ray module
This commit is contained in:
244
v2ray.php
244
v2ray.php
@@ -1,244 +0,0 @@
|
||||
<?php
|
||||
require_once '/opt/DragonCore/config.php';
|
||||
|
||||
|
||||
function createv2table()
|
||||
{
|
||||
global $db_host, $db_port, $db_name, $db_user, $db_pass;
|
||||
|
||||
|
||||
$conn = pg_connect("host=localhost dbname=dragoncore user=$db_user password=$db_pass");
|
||||
|
||||
if (!$conn) {
|
||||
echo "Failed to connect to PostgreSQL";
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "CREATE TABLE IF NOT EXISTS v2ray (
|
||||
ID SERIAL PRIMARY KEY,
|
||||
UUID TEXT,
|
||||
nck TEXT,
|
||||
vlc TEXT
|
||||
)";
|
||||
|
||||
$result = pg_query($conn, $query);
|
||||
|
||||
if (!$result) {
|
||||
echo "Error creating table: " . pg_last_error($conn);
|
||||
}
|
||||
|
||||
pg_close($conn);
|
||||
}
|
||||
|
||||
|
||||
function v2users()
|
||||
{
|
||||
global $db_host, $db_port, $db_name, $db_user, $db_pass;
|
||||
|
||||
|
||||
$conn = pg_connect("host=localhost dbname=dragoncore user=$db_user password=$db_pass");
|
||||
if (!$conn) {
|
||||
die("Connection failed: " . pg_last_error());
|
||||
}
|
||||
$query = "SELECT * FROM v2ray";
|
||||
$result = pg_query($conn, $query);
|
||||
if (!$result) {
|
||||
die("Query execution failed: " . pg_last_error());
|
||||
}
|
||||
while ($row = pg_fetch_assoc($result)) {
|
||||
$ID = $row['id'];
|
||||
$UUID = $row['uuid'];
|
||||
$nick = $row['nck'];
|
||||
echo "ID: " . $ID . " | " . "NOME: " . $nick . " | " . "UUID: " . $UUID . "\n";
|
||||
}
|
||||
pg_close($conn);
|
||||
}
|
||||
|
||||
|
||||
function v2uid($id)
|
||||
{
|
||||
global $db_host, $db_port, $db_name, $db_user, $db_pass;
|
||||
|
||||
|
||||
$conn = pg_connect("host=localhost dbname=dragoncore user=$db_user password=$db_pass");
|
||||
if (!$conn) {
|
||||
die("Connection failed: " . pg_last_error());
|
||||
}
|
||||
$query = "SELECT uuid FROM v2ray WHERE id=$id";
|
||||
$result = pg_query($conn, $query);
|
||||
if (!$result) {
|
||||
die("Query execution failed: " . pg_last_error());
|
||||
}
|
||||
while ($row = pg_fetch_assoc($result)) {
|
||||
$UUID = $row['uuid'];
|
||||
echo $UUID;
|
||||
}
|
||||
pg_close($conn);
|
||||
}
|
||||
|
||||
|
||||
function inv2($uuid, $nick, $valid)
|
||||
{
|
||||
global $db_host, $db_port, $db_name, $db_user, $db_pass;
|
||||
|
||||
|
||||
$conn = pg_connect("host=localhost dbname=dragoncore user=$db_user password=$db_pass");
|
||||
if (!$conn) {
|
||||
die("Connection failed: " . pg_last_error());
|
||||
}
|
||||
$query = "INSERT INTO v2ray (UUID, nck, vlc) VALUES ($1, $2, $3)";
|
||||
$result = pg_prepare($conn, "", $query);
|
||||
if (!$result) {
|
||||
die("Statement preparation failed: " . pg_last_error());
|
||||
}
|
||||
$result = pg_execute($conn, "", array($uuid, $nick, $valid));
|
||||
if (!$result) {
|
||||
die("Execution failed: " . pg_last_error());
|
||||
}
|
||||
pg_close($conn);
|
||||
}
|
||||
|
||||
|
||||
function intallv2()
|
||||
{
|
||||
$filePath = '/bin/v2ray';
|
||||
if (file_exists($filePath)) {
|
||||
echo "/opt/DragonCore/v2ray --remove";
|
||||
} else {
|
||||
echo "apt install python3-pip -y" . "\n" . "/opt/DragonCore/v2ray";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function v2protocol()
|
||||
{
|
||||
echo "v2ray stream";
|
||||
}
|
||||
|
||||
|
||||
function v2tls()
|
||||
{
|
||||
echo "v2ray tls";
|
||||
}
|
||||
|
||||
|
||||
function v2port()
|
||||
{
|
||||
echo "v2ray port";
|
||||
}
|
||||
|
||||
|
||||
function v2stats()
|
||||
{
|
||||
echo "v2ray stats";
|
||||
}
|
||||
|
||||
|
||||
function removev2()
|
||||
{
|
||||
echo "/opt/DragonCore/v2ray --remove";
|
||||
}
|
||||
|
||||
|
||||
function v2info()
|
||||
{
|
||||
echo "v2ray info";
|
||||
}
|
||||
|
||||
|
||||
function uuidgen()
|
||||
{
|
||||
return shell_exec('uuidgen');
|
||||
}
|
||||
|
||||
|
||||
function addv2user($nick)
|
||||
{
|
||||
$valid = date("Y-m-d", strtotime("+31 days"));
|
||||
$MAILITO = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
|
||||
$UUID = uuidgen();
|
||||
$UUID2 = str_replace(array("\r", "\n"), '', $UUID);
|
||||
$configPath = "/etc/v2ray/config.json";
|
||||
$newClient = [
|
||||
'{
|
||||
"alterId": 0,',
|
||||
' "id": "' . $UUID2 . '",',
|
||||
' "email": "' . $MAILITO . '@gmail.com"}'
|
||||
];
|
||||
$config = file_get_contents($configPath);
|
||||
$pos = strpos($config, '"clients": [');
|
||||
if ($pos !== false) {
|
||||
$config = substr_replace($config, implode("\n", $newClient) . ',', $pos + strlen('"clients": ['), 0);
|
||||
file_put_contents($configPath, $config);
|
||||
inv2($UUID, $nick, $valid);
|
||||
system("v2ray restart > /dev/null 2>&1");
|
||||
echo "UUID Criado: " . $UUID2 . "\n\n" . extractVmessUrlByUUID($UUID2);
|
||||
} else {
|
||||
echo "Error: Unable to find 'clients' array in the config file.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function delv2($uuidel)
|
||||
{
|
||||
$lineP = shell_exec("sed -n '/'" . $uuidel . "'/=' /etc/v2ray/config.json");
|
||||
$numl1 = 2;
|
||||
$resta = $lineP - $numl1;
|
||||
shell_exec("sed -i \"" . $resta . "d\" /etc/v2ray/config.json");
|
||||
shell_exec("sed -i \"" . $resta . "d\" /etc/v2ray/config.json");
|
||||
shell_exec("sed -i \"" . $resta . "d\" /etc/v2ray/config.json");
|
||||
shell_exec("sed -i \"" . $resta . "d\" /etc/v2ray/config.json");
|
||||
shell_exec("sed -i \"" . $resta . "d\" /etc/v2ray/config.json");
|
||||
shell_exec("v2ray restart > /dev/null 2>&1");
|
||||
|
||||
}
|
||||
|
||||
|
||||
function dlv2($id)
|
||||
{
|
||||
global $db_host, $db_port, $db_name, $db_user, $db_pass;
|
||||
|
||||
|
||||
$conn = pg_connect("host=localhost dbname=dragoncore user=$db_user password=$db_pass");
|
||||
if (!$conn) {
|
||||
die("Connection failed: " . pg_last_error());
|
||||
}
|
||||
$query = "DELETE FROM v2ray WHERE id = $1";
|
||||
$result = pg_prepare($conn, "", $query);
|
||||
if (!$result) {
|
||||
die("Statement preparation failed: " . pg_last_error());
|
||||
}
|
||||
$result = pg_execute($conn, "", array($id));
|
||||
if (!$result) {
|
||||
die("Execution failed: " . pg_last_error());
|
||||
}
|
||||
pg_close($conn);
|
||||
}
|
||||
|
||||
|
||||
function v2cho()
|
||||
{
|
||||
$filePath = '/bin/v2ray';
|
||||
if (file_exists($filePath)) {
|
||||
return "Remover";
|
||||
} else {
|
||||
return "Instalar";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function extractVmessUrlByUUID($uuid)
|
||||
{
|
||||
$v2link = shell_exec("v2ray info | grep -A4 \"UUID: $uuid\" | tail -n1 | grep -o 'vmess://.*'");
|
||||
if (str_contains($v2link, "vmess")) {
|
||||
return "$v2link";
|
||||
} else {
|
||||
$v2link2 = shell_exec("v2ray info | grep -A4 \"ID: $uuid\" | tail -n1 | grep -o 'vless://.*'");
|
||||
if (str_contains($v2link2, "vless")) {
|
||||
return "$v2link2";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user