Skip to content

Commit a156cea

Browse files
committed
Fixed colors in console;
More sophisticated autoloader; Error message changes.
1 parent d1352b5 commit a156cea

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

scripts/roscon.bat

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ REM 2. "php" from %cd% with one of %pathext% extensions.
55
REM 3. "php" from a %path% path with one of %pathext% extensions.
66
REM 4. Whatever %PHP_PEAR_PHP_BIN% points to.
77
REM
8-
REM Once a binary is found, a file is looked for at the %PHPFILE% environment
9-
REM variable (not intendend to be overriden).
10-
REM Fallbacks to a file with the same name as this one.
8+
REM Once a binary is found, a file is looked for that has the same name as
9+
REM this batch file.
1110
REM Prefered extensions are ".php" and then no extension.
12-
REM
1311
goto SET_BIN
1412
:PHP_ERR
1513
echo PHP interpreter not found. Please set the %%PHPBIN%% or %%PHP_PEAR_PHP_BIN%% environment variable to one, or add one to your %%PATH%%.
16-
goto DONE
14+
goto :eof
1715
:FILE_ERR
1816
echo The file to be ran was not found. It should be at either "%~d0%~p0%~n0.php" or "%~d0%~p0%~n0".
19-
goto DONE
17+
endlocal
18+
goto :eof
2019
:SET_BIN
2120
if "%PHPBIN%" == "" set PHPBIN=php
2221
where /q %PHPBIN%
@@ -26,10 +25,12 @@ where /q "%PHP_PEAR_PHP_BIN%"
2625
if %ERRORLEVEL% neq 0 goto PHP_ERR
2726
set PHPBIN=%PHP_PEAR_PHP_BIN%
2827
:SET_FILE
29-
if "%PHPFILE%" == "" set PHPFILE=%~d0%~p0%~n0.php
28+
setlocal
29+
set PHPFILE=%~d0%~p0%~n0.php
3030
if exist "%PHPFILE%" goto RUN
3131
set PHPFILE=%~d0%~p0%~n0
32-
if not exist "%PHPFILE%" goto FILE_ERR
32+
if exist "%PHPFILE%" goto RUN
33+
goto FILE_ERR
3334
:RUN
3435
"%PHPBIN%" "%PHPFILE%" %*
35-
:DONE
36+
endlocal

scripts/roscon.php

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,29 @@
4949

5050
//If there's no appropriate autoloader, add one
5151
if (!class_exists('PEAR2\Net\RouterOS\Communicator', true)) {
52-
include_once 'PEAR2/Autoload.php';
53-
chdir(__DIR__);
54-
Autoload::initialize(realpath('../src'));
55-
Autoload::initialize(realpath('../../Net_Transmitter.git/src'));
56-
Autoload::initialize(realpath('../../Console_Color.git/src'));
52+
$autoloader = stream_resolve_include_path('../vendor/autoload.php');
53+
if (false !== $autoloader) {
54+
include_once $autoloader;
55+
} else {
56+
$autoloader = stream_resolve_include_path('PEAR2/Autoload.php');
57+
if (false !== $autoloader) {
58+
include_once $autoloader;
59+
Autoload::initialize(realpath('../src'));
60+
Autoload::initialize(realpath('../../Net_Transmitter.git/src'));
61+
Autoload::initialize(realpath('../../Cache_SHM.git/src'));
62+
} else {
63+
fwrite(
64+
STDERR,
65+
<<<HEREDOC
66+
No recognized autoloader is available.
67+
Please install this package with Pyrus, PEAR or Composer.
68+
Alternatively, install PEAR2_Autoload, and/or add it to your include_path.
69+
HEREDOC
70+
);
71+
exit(10);
72+
}
73+
}
74+
unset($autoloader);
5775
}
5876

5977
// Locate the data dir, in preference as:
@@ -72,7 +90,7 @@
7290
STDERR,
7391
'Unable to find data dir.'
7492
);
75-
exit(10);
93+
exit(11);
7694
}
7795
$consoleDefFile = realpath($dataDir . '/roscon.xml');
7896
if (false === $consoleDefFile) {
@@ -84,7 +102,7 @@
84102
{$dataDir}
85103
HEREDOC
86104
);
87-
exit(11);
105+
exit(12);
88106
}
89107

90108
$cmdParser = CommandLine::fromXmlFile($consoleDefFile);
@@ -95,7 +113,7 @@
95113
STDERR,
96114
'Error when parsing command line: ' . $e->getMessage() . "\n"
97115
);
98-
$cmdParser->displayUsage(12);
116+
$cmdParser->displayUsage(13);
99117
}
100118

101119
$c_colors = array(
@@ -126,6 +144,10 @@
126144
Color\Backgrounds::YELLOW
127145
);
128146
$c_colors[''] = new Color();
147+
148+
foreach ($c_colors as $mode => $color) {
149+
$c_colors[$mode] = ((string)$color) . "\033[K";
150+
}
129151
}
130152

131153
$cmd->options['size'] = $cmd->options['size'] ?: 80;
@@ -188,12 +210,18 @@
188210
<<<HEREDOC
189211
Login refused. Possible reasons:
190212
1. No such username.
191-
3. The user does not have the "api" privilege. Check the username's group, and
192-
it's permissions at "/user groups".
193-
2. Mistyped password. If the password contains non-ASCII characters, be careful
194-
of your locale settings - either they must match those of the terminal you
195-
set your password on, or you must type the equivalent code points in your
196-
locale, which may display as different characters.
213+
Make sure you have spelled it correctly.
214+
2. The user does not have the "api" privilege.
215+
Check the permissions of the user's group at "/user group".
216+
3. The user is not allowed to access the router from your web server's IP.
217+
Make sure your web server's IP address is within the subnets the user is
218+
allowed to log in from. You can check them at the "address" property
219+
of the user in the "/user" menu.
220+
4. Mistyped password.
221+
If the password contains non-ASCII characters, be careful of your locale.
222+
It must match that of the terminal you set your password on, or you must
223+
type the equivalent code points in your current locale, which may display as
224+
different characters.
197225
198226
HEREDOC
199227
);

stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
117117
1. You haven't enabled the API service at RouterOS or you've enabled it on a
118118
different TCP port. Make sure that the "api" service at "/ip service" is
119-
enabled, and with that same TCP port (8728 by default).
119+
enabled, and with that same TCP port (8728 by default or 8729 for "api-ssl").
120120
121121
2. You've mistyped the IP and/or port. Check the IP and port you've specified
122122
are the ones you intended.

0 commit comments

Comments
 (0)