Skip to content

Commit

Permalink
1.1.4
Browse files Browse the repository at this point in the history
   - Plugin: restart - now escapes from parent process
   - Plugin: server - now escapes from parent process
   - fixed repeated messages on join event
  • Loading branch information
S3x0r committed Dec 26, 2020
1 parent a784104 commit 2c5fb88
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 102 deletions.
119 changes: 60 additions & 59 deletions BOT.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,73 +20,74 @@
'Visit <a href="https://github.com/S3x0r/MINION/">this page</a> for more information.') : false;
//---------------------------------------------------------------------------------------------------------

/* PHP_EOL shortcuts */
define('N', PHP_EOL);
define('NN', PHP_EOL.N);
/* PHP_EOL shortcuts */
define('N', PHP_EOL);
define('NN', PHP_EOL.N);

/* check if the bot was launched from the attached php */
dirname($_SERVER['PHP_SELF']) == '../..' ? chdir('../../') : false;
/* check if the bot was launched from the attached php */
dirname($_SERVER['PHP_SELF']) == '../..' ? chdir('../../') : false;

/* simple os check */
/* PHP 7.2.0 we have PHP_OS_FAMILY */
strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' ? $GLOBALS['OS'] = 'Linux' : false;
/* simple os check */
/* PHP 7.2.0 we have PHP_OS_FAMILY */
strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' ? $GLOBALS['OS'] = 'Linux' : false;

/* hide prompt */
echo "\e[?25l";
/* hide prompt */
echo "\e[?25l";

/* needed files */
$botCoreFiles = ['cli.php',
'misc.php',
'config.php',
'core_commands.php',
'debug.php',
'define.php',
'events.php',
'logo.php',
'logs.php',
'plugins.php',
'socket.php',
'timers.php',
'web.php',
'ctcp.php'
];
/* needed files */
$botCoreFiles = ['cli.php',
'misc.php',
'config.php',
'core_commands.php',
'debug.php',
'define.php',
'events.php',
'logo.php',
'logs.php',
'plugins.php',
'socket.php',
'timers.php',
'web.php',
'ctcp.php'
];

/* check if we got all files */
foreach ($botCoreFiles as $botCoreFile) {
if (is_file("src/{$botCoreFile}")) {
require_once("src/{$botCoreFile}");
} else {
echo N;
echo " I need a file '{$botCoreFile}' to work!".NN,
' You can download missing files from:'.N,
' https://github.com/S3x0r/MINION/releases'.NN,
' Terminating program after 10 seconds.'.NN;
!isset($GLOBALS['os']) ? sleep(10) : false;
exit;
}
}
/* check if we got all files */
foreach ($botCoreFiles as $botCoreFile) {
if (is_file("src/{$botCoreFile}")) {
require_once("src/{$botCoreFile}");
} else {
echo N;
echo " I need a file '{$botCoreFile}' to work!".NN,
' You can download missing files from:'.N,
' https://github.com/S3x0r/MINION/releases'.NN,
' Terminating program after 10 seconds.'.NN;
!isset($GLOBALS['os']) ? sleep(10) : false;
exit;
}
}

/* if we cannnot write */
if (!is_writable('BOT.php')) {
echo "\n Bot has no permissions to save files, Check your permissions! Exiting.";
WinSleep(7);
exit;
} else {
!is_dir(LOGSDIR) ? mkdir(LOGSDIR) : false;
!is_dir(DATADIR) ? mkdir(DATADIR) : false;
}
/* if we cannnot write */
if (!is_writable('BOT.php')) {
echo "\n Bot has no permissions to save files, Check your permissions! Exiting.";
WinSleep(7);
exit;
} else {
!is_dir(LOGSDIR) ? mkdir(LOGSDIR) : false;
!is_dir(DATADIR) ? mkdir(DATADIR) : false;
}
//---------------------------------------------------------------------------------------------------------
/* Check if we got cli args */
CheckCliArgs();

/* Check if we got cli args */
CheckCliArgs();

/* Load config */
LoadConfig();
/* Load config */
LoadConfig();

/* Logging init */
LogsInit();
/* Logging init */
LogsInit();

/* Load plugins */
LoadPlugins();
/* Load plugins */
LoadPlugins();

/* Time to connect */
Connect();
/* Time to connect */
Connect();
2 changes: 1 addition & 1 deletion CONFIG.INI
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ command_prefix = '!'
ctcp_response = 'yes'

; ctcp version response (please do not change it:)
ctcp_version = 'MINION (1.1.3) powered by minions!'
ctcp_version = 'MINION (1.1.4) powered by minions!'

; ctcf finger response
ctcp_finger = 'MINION'
Expand Down
5 changes: 5 additions & 0 deletions DOCS/CHANGELOG.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

v1.1.4 changes (26.12.2020):
- Plugin: restart - now escapes from parent process
- Plugin: server - now escapes from parent process
- fixed repeated messages on join event

v1.1.3 changes (21.12.2020):
- registration to bot bug fixed
Expand Down
12 changes: 6 additions & 6 deletions PLUGINS/OWNER/restart.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
$plugin_description = "Restarts Bot: {$GLOBALS['CONFIG_CMD_PREFIX']}restart";
$plugin_command = 'restart';

/* TODO:
- escape from parent process
*/

function plugin_restart()
{
/* give op before restart */
Expand All @@ -41,8 +37,12 @@ function plugin_restart()
/* send cli messages */
cliLog('Restarting BOT...');

/* execute batch script */
!isset($GLOBALS['OS']) ? system('START_BOT.BAT') : system('php -f BOT.php');
if (!isset($GLOBALS['OS'])) {
chdir('src/php');
runProgram('start php.exe ../../BOT.php');
} else {
runProgram('php -f BOT.php');
}

exit;
}
10 changes: 9 additions & 1 deletion PLUGINS/OWNER/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ function plugin_server()

toServer("QUIT :Changing server...");

!isset($GLOBALS['OS']) ? system('cd src & cd php & php.exe ../../BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']) : system('php BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']);
if (!isset($GLOBALS['OS'])) {
chdir('src/php');
runProgram('start php.exe ../../BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']);
exit;
} else {
runProgram('php BOT.php -o '.$GLOBALS['piece1'].' '.$GLOBALS['piece2']);
exit;
}

} elseif (empty($GLOBALS['args'])) {
response('You need to specify server address.');
} elseif (empty($GLOBALS['piece2'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/define.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
exit('This script can\'t be run from a web browser. Use CLI terminal to run it<br>'.
'Visit <a href="https://github.com/S3x0r/MINION/">this page</a> for more information.') : false;
//---------------------------------------------------------------------------------------------------------
define('VER', '1.1.3');
define('VER', '1.1.4');
//---------------------------------------------------------------------------------------------------------
define('START_TIME', time());
define('PHP_VER', phpversion());
Expand Down
61 changes: 28 additions & 33 deletions src/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ function on_mode() /* on MODE event */
//---------------------------------------------------------------------------------------------------------
function on_join()
{
/* if bot joined */
if ($GLOBALS['USER'] == getBotNickname()) {
/* 1. set channel from 353 */
$GLOBALS['BOT_CHANNEL'] = str_replace(':', '', $GLOBALS['rawDataArray'][2]);

cliLog("[bot] Joined channel: ".getBotChannel());

/* 1.check channel modes for cli message */
toServer("MODE ".getBotChannel());

/* FIX: save data for web panel */
}

/* if user joined channel */
if ($GLOBALS['USER'] != getBotNickname()) {
cliLog("[".getBotChannel()."] * {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']}) has joined");
Expand Down Expand Up @@ -156,23 +169,11 @@ function on_join()
//---------------------------------------------------------------------------------------------------------
function on_353() /* on channel join info */
{
/* when we got confirmation that bot joined channel */
if (isset($GLOBALS['rawDataArray'][2]) && $GLOBALS['rawDataArray'][2] == getBotNickname()) {
/* 1. set channel from 353 */
$GLOBALS['BOT_CHANNEL'] = $GLOBALS['rawDataArray'][4]; /* FIX: we can set channel name faster after JOIN event */

cliLog("[bot] Joined channel: ".getBotChannel());

/* FIX: save data for web panel */

/* if bot got op */
if (isset($GLOBALS['rawDataArray'][5]) && $GLOBALS['rawDataArray'][5] == ':@'.getBotNickname()) {
/* on bot opped event */
on_bot_opped();
}

/* check channel modes */
toServer("MODE ".getBotChannel());
$nick = str_replace(':', '', $GLOBALS['rawDataArray'][5]);

/* if bot opped */
if ($nick == '@'.getBotNickname()) {
on_bot_opped();
}
}
//---------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -393,22 +394,16 @@ function setChannelModesAndBans()
}

/* set channel modes from config */
if ($GLOBALS['CONFIG_KEEPCHAN_MODES'] == 'yes') {
toServer('MODE '.getBotChannel());

if (BotOpped() == true) {
if (isset($GLOBALS['CHANNEL_MODES']) && $GLOBALS['CHANNEL_MODES'] != $GLOBALS['CONFIG_CHANNEL_MODES']) {
sleep(1);
toServer("MODE ".getBotChannel()." -{$GLOBALS['CHANNEL_MODES']}");
sleep(1);
toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}");
}
if (empty($GLOBALS['CHANNEL_MODES'])) {
if (!empty($GLOBALS['CONFIG_CHANNEL_MODES'])) {
sleep(1);
toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}");
}
}
if ($GLOBALS['CONFIG_KEEPCHAN_MODES'] == 'yes' && BotOpped() == true) { //FIX: keep modes
if (isset($GLOBALS['CHANNEL_MODES']) && $GLOBALS['CHANNEL_MODES'] != $GLOBALS['CONFIG_CHANNEL_MODES']) {
sleep(1);
toServer("MODE ".getBotChannel()." -{$GLOBALS['CHANNEL_MODES']}");
sleep(1);
toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}");
}
if (empty($GLOBALS['CHANNEL_MODES']) && !empty($GLOBALS['CONFIG_CHANNEL_MODES'])) {
sleep(1);
toServer("MODE ".getBotChannel()." +{$GLOBALS['CONFIG_CHANNEL_MODES']}");
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,15 @@ function in_array_r($needle, $haystack, $strict = false) {
function pluginUsageCli($pluginName)
{
cliLog("[PLUGIN: {$pluginName}] Used by: {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']}), channel: ".getBotChannel());
}
}
//---------------------------------------------------------------------------------------------------------
function runProgram($command)
{
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);

$process = proc_open($command, $descriptorspec, $pipes);
}

0 comments on commit 2c5fb88

Please sign in to comment.