1) {
$checkbit="";
$updword='Update';
}
if (isset($argc)) {
$fn=$argv[0];
$swis=file_get_contents($fn);
} else {
$fn=dirname(__FILE__) . "/sass_watchdog.php";
$swis=file_get_contents($fn);
if (strpos($swis,'" ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' "') !== false) {
$swis=str_replace('" ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' "', '"http://' . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "" . explode("#", explode("?", $_SERVER['REQUEST_URI'])[0])[0] . '"', $swis);
$curlurl[0]='http://' . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "" . explode("#", explode("?", $_SERVER['REQUEST_URI'])[0])[0];
$upd=true;
}
if (strpos($swis,'" ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' "') !== false) {
if (PHP_OS=='WINNT' || PHP_OS=='WIN32' || PHP_OS=='Windows') {
$swis=str_replace('" ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' "', '"' . dirname(__FILE__) . substr("\\",0,1) . 'sass_watchdog.php' . '"', $swis);
$phppath[0]=dirname(__FILE__) . substr("\\",0,1) . 'sass_watchdog.php';
} else {
$swis=str_replace('" ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' ' . ' "', '"' . dirname(__FILE__) . '/sass_watchdog.php' . '"', $swis);
$phppath[0]=dirname(__FILE__) . '/sass_watchdog.php';
}
$upd=true;
}
}
// Thanks to https://gist.github.com/lsauer/6476476
// # www.lsauer.com, 2012 lo sauer
// # desc: kill a process on Linux, MacOS, Windows without a process-control library
// # in the php setup or environment
$kill = function($pid){ return stripos(php_uname('s'), 'win')>-1
? exec("taskkill /F /PID $pid") : exec("kill -9 $pid");
};
//e.g.
//echo $kill(19008);
//> "Successfully terminated...."
//array_map($kill, [19008,23012,1802,930]);
//killall: without using array_map and a boolean return value
$killall = function($pids){ $os=stripos(php_uname('s'), 'win')>-1;
($_=implode($os?' /PID ':' ',$pids)) or ($_=$pids);
return preg_match('/success|close/',
$os ? exec("taskkill /F /PID $_") : exec("kill -9 $_"));
};
//if( $killall([19008,23012,1802,930]) and $killall(19280)){
// echo "successfully killed all processes"
//}
// /usr/local/Cellar/sass/1.22.12/bin/sass --watch /Applications/MAMP/htdocs/sass/base.scss /Applications/MAMP/htdocs/sass/build/test.css >> /Applications/MAMP/htdocs/sass/sass_watch.ok 2>> /Applications/MAMP/htdocs/sass/sass_watch.notok &
function ourrealpath($inid) {
if (realpath($inid) != $inid && realpath($inid) != '') {
return realpath($inid);
}
return $inid;
}
//Note for windows users:
//You cannot redirect stdout/stderr to nul in the following manner:
//startBackgroundProcess('ping yandex.com', null, 'nul', 'nul');
//However, you can do this:
//startBackgroundProcess('ping yandex.com >nul 2>&1');
function startBackgroundProcess(
$commandin,
$stdin = null,
$redirectStdout = null,
$redirectStderr = null,
$cwd = null,
$env = null,
$other_options = null
) { // thanks to https://stackoverflow.com/questions/45953/php-execute-a-background-process
global $incssfiles, $outcssfiles, $logfiles, $errlogfiles,$amrunning,$sasexe, $swis, $fn, $upd;
$command=str_replace(" " . " "," ",str_replace(" " . " " . " "," ",$commandin));
$four=4;
$trunning = false;
$proc = null;
$isthere = true;
$cwords=explode(' ', str_replace(" " . " "," ",str_replace(" " . " " . " "," ",$commandin)));
if (sizeof($cwords) > 1) {
if (substr($cwords[1],0,1) != '-') { $four=3; }
}
if (sizeof($cwords) >= $four) {
if ($four == 4) {
$command=$cwords[0] . ' ' . $cwords[1] . ' ' . ourrealpath($cwords[2]) . ' ' . ourrealpath($cwords[3]);
} else {
$command=$cwords[0] . ' ' . ourrealpath($cwords[1]) . ' ' . ourrealpath($cwords[2]);
}
for ($ii=$four; $ii ' . str_replace("sass_watchdog.php", "swjunk.jnk", $fn));
if (file_exists(str_replace("sass_watchdog.php", "swjunk.jnk", $fn))) {
$tlout=file_get_contents(str_replace("sass_watchdog.php", "swjunk.jnk", $fn));
unlink(str_replace("sass_watchdog.php", "swjunk.jnk", $fn));
if (strpos($tlout, ' ' . $tpid . ' ') !== false) {
$trunning = true;
}
}
} else {
$trunning = posix_kill($tpid,0);
}
if ($trunning) {
return null;
} else {
$swis=str_replace("," . $tpid . "|" . str_replace(" ",";",explode($sasswitch[0], $command)[1]), '', $swis);
$upd=true;
}
}
$cwords=explode(' ', $command);
if (sizeof($cwords) >= $four) {
if (!file_exists($cwords[-2 + $four])) { // not good
$isthere=false;
}
} else {
$isthere=false;
}
$descriptorspec = array(
1 => is_string($redirectStdout) ? array('file', $redirectStdout, 'w') : array('pipe', 'w'),
2 => is_string($redirectStderr) ? array('file', $redirectStderr, 'w') : array('pipe', 'w'),
);
if (is_string($stdin)) {
$descriptorspec[0] = array('pipe', 'r');
}
if ($isthere) {
$proc = proc_open($command, $descriptorspec, $pipes, $cwd, $env, $other_options);
}
if (!is_resource($proc)) {
//throw new \Exception("Failed to start background process by command: $command");
$proc=null;
} else {
$etat=proc_get_status($proc);
if ($etat['running'] == FALSE) {
proc_close($proc);
$proc=null;
return null;
} else {
$swis=str_replace("," . ",", "," . $etat['pid'] . "|" . $cwords[-2 + $four] . ";" . $cwords[-1 + $four] . "," . ",", $swis);
$upd=true;
$swis=str_replace('["' . ' ' . ' ' . '"]', '["' . $cwords[-2 + $four] . '","' . ' ' . ' ' . '"]', str_replace(',"' . ' ' . ' ' . '"]', ',"' . $cwords[-2 + $four] . '","' . ' ' . ' ' . '"]', $swis));
$swis=str_replace('["' . ' ' . ' ' . ' ' . '"]', '["' . $cwords[-1 + $four] . '","' . ' ' . ' ' . ' ' . '"]', str_replace(',"' . ' ' . ' ' . ' ' . '"]', ',"' . $cwords[-1 + $four] . '","' . ' ' . ' ' . ' ' . '"]', $swis));
}
}
if (is_string($stdin)) {
fwrite($pipes[0], $stdin);
fclose($pipes[0]);
}
if (!is_string($redirectStdout)) {
fclose($pipes[1]);
}
if (!is_string($redirectStderr)) {
fclose($pipes[2]);
}
return $proc;
}
if (!function_exists("readline")) { // thanks to https://stackoverflow.com/questions/23238378/call-to-undefined-function-readline
function readline($prompt = null) {
if ($prompt) {
echo $prompt;
}
$fp = fopen("php://stdin","r");
$line = rtrim(fgets($fp, 1024));
return $line;
}
}
if (!isset($argc)) { // surfing the net
if (isset($_POST['check']) && isset($_POST['in1out1'])) {
while (isset($_POST['in' . $preone . 'out' . $preone])) {
if ($prerest == '') {
$prerest=str_replace('+',' ',urldecode($_POST['in' . $preone . 'out' . $preone]));
$preone++;
} else {
$rest.=" |
";
$preone++;
}
}
if ($prerest != '') {
$rest.=" |
";
}
}
if (isset($_GET['check'])) {
} else if (isset($_GET['in1']) && isset($_GET['out1'])) {
} else if (isset($_POST['in1out1']) && !isset($_POST['check'])) {
$scrbit=
$cmds='/usr/local/Cellar/sass/1.22.12/bin/sass';
if (isset($_POST['sasexe'])) {
if (strlen(trim($_POST['sasexe'])) != 0) {
if (realpath(str_replace('+',' ',urldecode($_POST['sasexe']))) != '') {
$cmds=realpath(str_replace('+',' ',urldecode($_POST['sasexe'])));
} else {
$cmds=str_replace('+',' ',urldecode($_POST['sasexe']));
}
} else {
$cmds="sass";
}
}
$cmdsw=' --watch ';
if (isset($_POST['sasswitch'])) {
if (strlen(trim($_POST['sasswitch'])) != 0) {
$cmdsw=str_replace('+',' ',urldecode($_POST['sasswitch']));
}
}
if (PHP_OS=='WINNT' || PHP_OS=='WIN32' || PHP_OS=='Windows') {
$lfil='nul';
$errlfil='&1';
} else {
$lfil='/dev/null';
$errlfil='/dev/null';
}
if (isset($_POST['errlogfiles'])) {
if (strlen(trim($_POST['errlogfiles'])) != 0) {
if (ourrealpath(str_replace('+',' ',urldecode($_POST['errlogfiles']))) == '') {
$errlfil=str_replace('+',' ',urldecode($_POST['errlogfiles']));
} else {
$errlfil=ourrealpath(str_replace('+',' ',urldecode($_POST['errlogfiles'])));
}
}
}
if (isset($_POST['logfiles'])) {
if (strlen(trim($_POST['logfiles'])) != 0) {
if (ourrealpath(str_replace('+',' ',urldecode($_POST['logfiles']))) == '') {
$lfil=str_replace('+',' ',urldecode($_POST['logfiles']));
} else {
$lfil=ourrealpath(str_replace('+',' ',urldecode($_POST['logfiles'])));
}
}
}
$one=$preone;
while (isset($_POST['in' . $one . 'out' . $one])) {
if (strlen($_POST['in' . $one . 'out' . $one]) > 0) {
//if (sizeof($incssfiles) > $one) {
if (PHP_OS=='WINNT' || PHP_OS=='WIN32' || PHP_OS=='Windows') {
if (strpos($_SERVER['SERVER_NAME'], "rjmprogramming.com.au") === false) {
if (!startBackgroundProcess($cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil)) {
echo str_replace("\n","
",str_replace(">",">",str_replace("<","<","Errors calling ... startBackgroundProcess('" . $cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil . "');\n")));
} else {
echo str_replace("\n","
",str_replace(">",">",str_replace("<","<","Successfully called ... startBackgroundProcess('" . $cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil . "');\n")));
}
} else {
echo str_replace("\n","
",str_replace(">",">",str_replace("<","<","Would have tried to call ... startBackgroundProcess('" . $cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil . "');\n")));
}
} else {
if (strpos($_SERVER['SERVER_NAME'], "rjmprogramming.com.au") === false) {
if (!startBackgroundProcess($cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil)) {
echo str_replace("\n","
",str_replace(">",">",str_replace("<","<","Errors calling ... startBackgroundProcess('" . $cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil . "');\n")));
} else {
echo str_replace("\n","
",str_replace(">",">",str_replace("<","<","Successfully called ... startBackgroundProcess('" . $cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil . "');\n")));
}
} else {
echo str_replace("\n","
",str_replace(">",">",str_replace("<","<","Would have tried to call ... startBackgroundProcess('" . $cmds . ' ' . $cmdsw . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[0] . ' ' . explode(' ',str_replace(';', ' ',str_replace('+',' ',urldecode($_POST['in' . $one . 'out' . $one]))))[1] . ' >> ' . $lfil . ' 2>> ' . $errlfil . "');\n")));
}
}
//}
}
$one++;
}
if ($upd) { file_put_contents($fn, $swis); }
} else {
echo "
Sass 'sass --watch [inputSassSCSS] [outputCSS]' Supervisor and Watchdog
RJM Programming
September, 2019
";
}
} else { // command line
$swis=$swis;
}
// Logging information below
// ,,
?>