Commit 36413fae authored by Rachele Grasshopper's avatar Rachele Grasshopper

added pending requests script

parent 00d42399
<?php
/* Rude script for managing pending registration requests
*/
$sql_servername = "YER-SERVERNAME-OR-IP-HERE";
$sql_username = "USERNAME-HERE";
$sql_password = "PASSWORD-HERE";
$sql_dbname = "DATABASE-NAME-HERE";
$conn = new mysqli($sql_servername, $sql_username, $sql_password, $sql_dbname);
echo "Connection to database... ";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "Connected succeessfully to database.\n\n";
}
$repeat = 1;
while ( $repeat == 1 ) {
$sql_query = sprintf("SELECT * FROM users WHERE status=0" );
$result = $conn->query($sql_query);
if ($result->num_rows > 0) {
echo "PENDING REQUEST\n---------------------------\n"; // output data of each row
$i = 1;
$user_dic;
while( $row = $result->fetch_assoc() ) {
$how_old_is = date_diff( date_create( $row["date"] ), date_create(date("Y-m-d")) );
$user_dic[$i] = $row["username"];
$user_pass[$i] = $row["password"];
echo "(" . $i . ") " . $row["username"]. " registered " . $how_old_is->format("%d day") . " ago\n";
$i+=1;
}
echo "\n\nSelect the user. Press q to quit. [Default: 1]\n>> ";
fscanf(STDIN, "%c\n", $number);
if ( $number == '' ) $number='1';
if ( $number == 'q' ) {
$repeat = 0;
$number2 = 0;
} else {
echo "\n\nYou have selected " . $user_dic[(int) $number] . "\nPress 1 to approve, 2 to deny, 0 to quit.\n>> ";
fscanf(STDIN, "%d\n", $number2);
}
if ($number2 == 1) {
system("prosodyctl register $user_dic[$number] eigenlab.org $user_pass[$number]", $status);
if ($status!=0) die ("prosody scazza");
$sql_query = sprintf("UPDATE users SET status=1 WHERE username='%s'",$user_dic[$number]);
if( $conn->query($sql_query) == TRUE ){
echo "The join request for the user " . $user_dic[$number] . " has been approved\n";
}
else{
echo "Can't approve user\n";
}
}
elseif ($number2 == 2) {
$sql_query = sprintf("UPDATE users SET status=-1 WHERE username='%s'",$user_dic[$number]);
if( $conn->query($sql_query) == TRUE ){
echo "The join request for the user " . $user_dic[$number] . " has been denied\n";
}
else{
echo "Can't deny user\n";
}
}
elseif ($number2 == 0) {
$repeat=0;
}
}
else {
echo "No new registrations\n";
$repeat=0;
}
}
$conn->close();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment