Example #1
0
 function command_parse()
 {
     global $DB, $Core, $Parse, $Security, $Base, $Style;
     if (!$Security->allowed()) {
         return;
     }
     $include = implode("/", module());
     if (file_exists("module/{$include}/main.php")) {
         $dir = "";
         foreach (module() as $module) {
             $dir .= "{$module}/";
             $shared = "module/{$dir}shared.php";
             if (file_exists($shared)) {
                 include $shared;
             }
         }
         require_once "module/{$include}/main.php";
         if (function_exists(command())) {
             eval(command() . "();");
         }
         if (file_exists("module/{$include}/.content/" . func() . ".php")) {
             if (!get('ajax') && !get('xml')) {
                 require_once "module/{$include}/.content/" . func() . ".php";
             }
         }
     } else {
         $Base = new Base();
         $Base->title("Invalid Module");
         $Base->Header();
         $Base->Footer();
     }
 }
Example #2
0
function debug()
{
    print "<strong>query string:</strong> {$_SERVER['QUERY_STRING']}\n\n";
    print "<strong>module:</strong> " . implode("-", module()) . "\n";
    print "<strong>function:</strong> " . func() . "\n";
    print "<strong>method:</strong> " . method() . "\n\n";
    print "<strong>include:</strong> /module/" . implode("/", module()) . "/main.php\n\n";
    print "<strong>run:</strong> " . command() . "\n\n";
}
function getlist()
{
    $tasks = array();
    $out = command("--list", false);
    if (is_array($out)) {
        $header = preg_split("/ +/", trim($out[0]));
        for ($i = 1; $i < count($out); $i++) {
            $line = rtrim($out[$i]);
            if (!preg_match("/^sum:/i", $line)) {
                $vals = preg_split("/ {2,}/", trim($line));
                $fields = array_combine($header, $vals);
                $tasks[$fields["ID"]] = $fields;
            }
        }
    }
    return $tasks;
}
Example #4
0
    if ($compress) {
        compress($res);
    }
    echo $res;
}
$dfra = $_REQUEST['dirall'];
if (isset($dfra)) {
    $res = command("ls -lRa {$dfra}");
    if ($compress) {
        compress($res);
    }
    echo $res;
}
$info = $_REQUEST['info'];
if (isset($info)) {
    switch ($info) {
        case 'id':
            $res = command("id");
            break;
        case 'pwd':
            $res = @getcwd();
            if (empty($res)) {
                $res = command("pwd");
            }
            break;
    }
    if ($compress) {
        compress($res);
    }
    echo $res;
}
Example #5
0
<?php

/*------------------------------------------------------------------------------
  BerryIO System Status Command
------------------------------------------------------------------------------*/
// Run the status commands which represent the Pi's resources
$content .= command('cpu_status');
$content .= command('memory_status');
$content .= command('disk_status');
$content .= command('board_status');
$content .= view('pages/system_status');
// Set the title last to override any previous set titles
$title = 'System Status';
Example #6
0
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: origin, x-requested-with, content-type, accept');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
require_once __DIR__ . '/classes/connexion.php';
require_once __DIR__ . '/classes/checkAPI.php';
require_once __DIR__ . '/classes/PushMessage.php';
$title = "";
$message = "";
$page_level = 1;
if (isset($_REQUEST['api']) && checkAPI($_REQUEST['api'], $page_level)) {
    switch ($_SERVER['REQUEST_METHOD']) {
        case 'POST':
            notify($_REQUEST);
            break;
        case 'PUT':
            command($_REQUEST);
            break;
    }
}
function command($arr)
{
    if (isset($arr['cmd'])) {
        $push = new PushMessage();
        $cmd = $arr['cmd'];
        if (isset($arr['id'])) {
            $id = $arr['id'];
            $push->sendMessageDevice('at_commands', $cmd, $id);
            http_response_code(202);
        } else {
            $push->sendMessageAll('at_commands', $cmd);
            http_response_code(202);
Example #7
0
    Seltzer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    Seltzer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Seltzer.  If not, see <http://www.gnu.org/licenses/>.
*/
// Save path of directory containing index.php
$crm_root = dirname(__FILE__);
// Bootstrap the crm
require_once 'include/crm.inc.php';
// Check for GET/POST command
$post_command = array_key_exists('command', $_POST) ? $_POST['command'] : '';
$get_command = array_key_exists('command', $_GET) ? $_GET['command'] : '';
$command = !empty($post_command) ? $post_command : $get_command;
if (!empty($command)) {
    // Handle command and redirect
    header('Location: ' . command($command));
    die;
}
if ($_GET['q'] == 'logout') {
    session_destroy();
}
$template_vars = array('path' => path());
print template_render('page', $template_vars);
Example #8
0
         }
     }
 }
 if ($stop != NULL) {
     if ($currenttime == 00) {
         $currenttime = 2400;
     }
     //2400 is same as 1200am or 0000
     if ($currenttime >= $stop and $action == 0) {
         $task = "SELECT * FROM devices";
         //stopping every valves
         $result = mysql_query($query);
         if (mysql_num_rows($result) > 0) {
             while ($rows = mysql_fetch_assoc($results)) {
                 $macid = $rows['macid'];
                 command($macid, $action);
                 //switch
                 //echo "Switch ON"; //update button status
             }
         }
         $query = "UPDATE tasks SET action ='1' WHERE id='{$id}'";
         //resetting to 1 for next day execution
         echo $query;
         if (!mysql_query($query, mysql_connect($dbhost, $dbuser, $dbpass))) {
             echo "INSERT failed: {$query}<br/>" . mysql_error() . "<br/><br/>";
         } else {
             echo "</br>Task upadated for next day</br>";
         }
         $query = "UPDATE devices SET action='0'";
         //this is for updating running status off devices
         echo "</br>" . $query;
Example #9
0
if (count($argv)) {
    foreach ($argv as $argument) {
        if (in_array($argument, ['list'])) {
            $command = $argument;
        } elseif (substr($argument, 0, 2) == '--') {
            $options[] = substr($argument, 2);
        } else {
            $types[] = $argument;
        }
    }
}
if (in_array('all', $options)) {
    $types = ['android', 'asha', 'bada', 'brew', 'feature', 'firefoxos', 'kddi', 'palmos', 's30plus', 's40', 'symbian', 'tizen', 'touchwiz', 'wm', 'wp'];
}
foreach ($types as $i => $type) {
    command($command, $type);
}
function command($command, $type)
{
    switch ($command) {
        case 'list':
            command_list($type);
            break;
    }
}
function command_list($type)
{
    echo "Creating index for 'data/models-{$type}.php'...\n";
    require_once __DIR__ . '/../data/models-' . $type . '.php';
    $name = strtoupper($type) . '_MODELS';
    $list = DeviceModels::${$name};
Example #10
0
/**
* Check if file exists
*
* @param String $source Source to copy
* @param String $destination Destination to copy to
*/
function moveFile($source, $destination, $sudo = "")
{
    // $source = preg_replace("/\~/", $_SERVER['HOME'], $source);
    // $destination = preg_replace("/\~/", $_SERVER['HOME'], $destination);
    $source = getAbsolutePath($source);
    $destination = getAbsolutePath($destination);
    command(($sudo ? "{$sudo} " : "") . "mv '{$source}' '{$destination}'");
}
Example #11
0
    $fromUsername = $postObj->FromUserName;
    $toUsername = $postObj->ToUserName;
    $form_MsgType = $postObj->MsgType;
    $msgid = $postObj->MsgId;
    if ($form_MsgType == "event") {
        $form_Event = $postObj->Event;
        if ($form_Event == "subscribe") {
            $contentStr = "感谢您关注抵抗组织助手!\n游戏介绍请点击http://45.118.133.173/resistance.jpg\n输入“帮助”获取游戏指南。";
            $resultStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $contentStr);
            echo $resultStr;
            exit;
        }
    } elseif ($form_MsgType == "text") {
        $form_content = trim($postObj->Content);
        if (preg_match($pattern_vote, $form_content)) {
            $feedback = vote($form_content, $fromUsername, $msgid);
        } elseif (preg_match($pattern_create, $form_content)) {
            $feedback = create($form_content, $fromUsername);
        } elseif (preg_match($pattern_room, $form_content)) {
            $feedback = room($form_content, $fromUsername);
        } else {
            $feedback = command($form_content, $fromUsername);
        }
        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, time(), $feedback);
        echo $resultStr;
        exit;
    }
} else {
    echo "";
    exit;
}
     mkdir($backup_path);
 }
 output("Backup location:" . $backup_path . "\n");
 // Applications list
 $root_applications = scandir("/Applications");
 array_unshift($root_applications, "Root apps:");
 $home_applications = scandir(getAbsolutePath("~/Applications"));
 array_unshift($home_applications, "Home apps:");
 file_put_contents($backup_path . "/Applications.txt", implode("\n", array_merge($root_applications, $home_applications)));
 output("Created applications list\n");
 // Macports list
 $port_output = shell_exec("sudo port installed requested" . " 2>&1");
 file_put_contents($backup_path . "/Macports.txt", $port_output);
 output("Created Macports list\n");
 // MySQL
 command("php " . $_SERVER["HOME"] . "/" . dirname($_SERVER["PHP_SELF"]) . "/mysql_dump_all.php mysqldump", true, false);
 moveFile("~/mysqldump.sql", $backup_path . "/mysqldump.sql");
 // config files
 copyFile("~/.bash_profile", $backup_path . "/bash_profile");
 copyFile("~/.gitconfig", $backup_path . "/gitconfig");
 copyFile("~/.gitignore_global", $backup_path . "/gitignore_global");
 copyFile("~/.tm_properties", $backup_path . "/tm_properties");
 copyFile("/etc/hosts", $backup_path . "/hosts");
 copyFolder("~/Sites/apache/", $backup_path . "/Sites/apache/");
 copyFolder("~/Desktop/", $backup_path . "/Desktop/");
 copyFolder("~/Pictures/", $backup_path . "/Pictures/");
 copyFolder("~/Documents/", $backup_path . "/Documents/");
 copyFolder("~/Library/Keychains/", $backup_path . "/Library/Keychains/");
 copyFolder("~/Library/Preferences/", $backup_path . "/Library/Preferences/");
 copyFolder("~/Library/Fonts/", $backup_path . "/Library/Fonts/");
 copyFolder("~/Library/Application Support/Firefox/", $backup_path . "/Library/Application Support/Firefox");
Example #13
0
<?php

/*------------------------------------------------------------------------------
  BerryIO About Command
------------------------------------------------------------------------------*/
// Version information
$content .= command('version');
// About information
require_once CONFIGS . 'about.php';
$content .= view('pages/about');
// Set the title last to override any previous set titles
$title = 'About ' . NAME;
Example #14
0
                }
            }
        }
    }
} else {
    mysql_select_db($dbname) or die(mysql_error());
    $query = "SELECT name FROM groups WHERE id='{$gid}'";
    $grps = mysql_query($query);
    $grp = mysql_fetch_assoc($grps);
    $name = $grp['name'];
    $query = "SELECT * FROM devices where devices.group='{$gid}'";
    $results = mysql_query($query);
    if (mysql_num_rows($results) > 0) {
        while ($row = mysql_fetch_assoc($results)) {
            $macid = $row['macid'];
            command($macid, $q);
            //switch
            //echo "Switch OFF"; //update button status
        }
        if ($q == 1) {
            echo "Switch OFF";
            $query = "INSERT INTO tasks VALUES" . "(DEFAULT,'{$name}',NULL,'{$start}','{$stop}', '0','0')";
            if (!mysql_query($query, mysql_connect($dbhost, $dbuser, $dbpass))) {
                echo "INSERT failed: {$query}<br/>" . mysql_error() . "<br/><br/>";
            }
        } else {
            echo "Switch ON";
        }
        $update = "UPDATE devices SET action='{$q}' WHERE devices.group='{$gid}'";
        //this is for updating running status off devices
        //echo "</br>".$query;
Example #15
0
function serverRoom()
{
    $cmd = command("sudo python /home/tao/bme280_tao.py")[0];
    return split(",", $cmd);
}
checkFile("_conf/my.cnf", "Required file is missing from your configuration source");
checkFile("_conf/httpd-vhosts.conf", "Required file is missing from your configuration source");
checkFile("_conf/php.ini", "Required file is missing from your configuration source");
checkFile("_conf/apache.conf", "Required file is missing from your configuration source");
checkFile("~/.bash_profile", "Required file is missing from home directory");
output("\nCopying configuration");
// copy base configuration
copyFile("_conf/httpd.conf", "/opt/local/apache2/conf/httpd.conf", "sudo");
copyFile("_conf/httpd-vhosts.conf", "/opt/local/apache2/conf/extra/httpd-vhosts.conf", "sudo");
// copy apache log rotation conf
copyFile("_conf/newsyslog-apache.conf", "/etc/newsyslog.d/apache.conf", "sudo");
// copy php.ini
copyFile("_conf/php.ini", "/opt/local/etc/php55/php.ini", "sudo");
// copy my.cnf for MySQL (to override macports settings)
copyFile("_conf/my.cnf", "/opt/local/etc/mysql56/my.cnf", "sudo");
// copy php.ini.default for native configuration
copyFile("_conf/php_ini_native.ini", "/etc/php.ini", "sudo");
// copy wkhtmltox static executables
copyFile("_conf/static_wkhtmltoimage", "/usr/local/bin/static_wkhtmltoimage", "sudo");
copyFile("_conf/static_wkhtmltopdf", "/usr/local/bin/static_wkhtmltopdf", "sudo");
output("\nConfiguration copied");
// Add alias' to .bash_profile
checkFileContent("~/.bash_profile", "_conf/bash_profile.default");
// Add local domains to /etc/hosts
command("sudo chmod 777 /etc/hosts");
checkFileContent("/etc/hosts", "_conf/hosts.default");
command("sudo chmod 644 /etc/hosts");
// restart apache
command("sudo /opt/local/apache2/bin/apachectl restart");
// DONE
output("\n\nUpdate is completed - please restart your terminal");
Example #17
0
function sync_dir($Dir, $To)
{
    global $FlashAirIP, $TZ;
    $List = command(100, array('DIR' => $Dir));
    $List = preg_split('/\\r?\\n/', $List);
    foreach ($List as $r) {
        $r = str_getcsv($r);
        if (count($r) < 3) {
            continue;
        }
        if ($r[3] & 16) {
            if (!file_exists($To . '/' . $r[1])) {
                mkdir($To . '/' . $r[1]);
            }
            sync_dir($Dir . '/' . $r[1], $To . '/' . $r[1]);
            continue;
        }
        // Else normal file
        $Day = $r[4] & 0b11111;
        $Month = ($r[4] & 0b111100000) >> 5;
        $Year = (($r[4] & 0b1111111000000000) >> 9) + 1980;
        $Seconds = ($r[5] & 0b11111) * 2;
        $Minutes = ($r[5] & 0b11111100000) >> 5;
        $Hours = ($r[5] & 0b1111100000000000) >> 11;
        // echo "{$r[1]} {$Year}-{$Month}-{$Day} {$Hours}:{$Minutes}:{$Seconds}\n";
        // $Time = mktime($Hours, $Minutes, $Seconds, $Month, $Day, $Year);
        $Time = strtotime("{$Year}-{$Month}-{$Day} {$Hours}:{$Minutes}:{$Seconds} {$TZ}");
        sync_for_file($Dir . '/' . $r[1], $To . '/' . $r[1], $Time);
    }
}
Example #18
0
$grp = $_GET["grp"];
//grp is the group id received
$bat = $_GET["bat"];
//bat  is group id received fro battery status
if ($grp != NULL) {
    display($grp);
}
if ($bat != NULL) {
    //
    mysql_select_db($dbname) or die(mysql_error());
    $query = "SELECT * FROM devices WHERE devices.group='{$bat}'";
    $results = mysql_query($query);
    if (mysql_num_rows($results) > 0) {
        while ($row = mysql_fetch_assoc($results)) {
            $macid = $row['macid'];
            command($macid, 2);
            //publish for getting bat status
            $query = "UPDATE devices SET battery ='3', status='0' WHERE macid='{$macid}'";
            //updating battery status in device table and also changing new device status,, initially keeping status as offline and bat unavailable
            //echo "</br>".$query;
            if (!mysql_query($query, mysql_connect($dbhost, $dbuser, $dbpass))) {
                echo "UPDATE failed: {$query}<br/>" . mysql_error() . "<br/><br/>";
            }
        }
    }
    display($bat);
}
/*
 *
 * Function Name: command($macid,$action)
 * Input: $ macid for macid, and $action for defining 0/1 for OFF/ON commands
$host = "localhost";
$user = "******";
$pass = ask("Database root password", false, true);
$dumpname = isset($argv[1]) && $argv[1] ? $argv[1] : date("Ymd_His_") . "allusertables";
// connect to DB
$mysqli = @new mysqli("p:" . $host, $user, $pass);
if ($mysqli->connect_errno) {
    goodbye("Failed to connect to MySQL: " . $mysqli->connect_error);
}
$mysqli->set_charset("utf8");
// get all databases
$select_query = "SHOW databases";
$result = $mysqli->query($select_query);
$result_count = is_object($result) ? $result->num_rows : ($result ? $result : 0);
// print $select_query."<br>";
// print "Count: " . $result_count."<br>";
if ($result_count) {
    $user_databases = array();
    $results = $result->fetch_all(MYSQLI_ASSOC);
    foreach ($results as $database) {
        // only use "non-system" databases
        if (!preg_match("/^(information_schema|mysql|performance_schema|test)\$/", $database["Database"])) {
            array_push($user_databases, $database["Database"]);
        }
    }
    //	print_r($user_databases);
}
if ($user_databases) {
    command("sudo /opt/local/lib/mysql56/bin/mysqldump -uroot -p{$pass} --databases " . implode($user_databases, " ") . " > " . $dumpname . ".sql | sed -e '\$!d'", true);
    output("MySQL dumped into: " . $dumpname . ".sql");
}
Example #20
0
<?php

/*------------------------------------------------------------------------------
  BerryIO Upgrade Command
------------------------------------------------------------------------------*/
$title = 'Version Upgrade';
// Load the version control functions
require_once FUNCTIONS . 'version.php';
// Make sure we are in CLI mode
if ($GLOBALS['EXEC_MODE'] != 'cli') {
    $content = command('check_version');
} else {
    version_upgrade();
}
Example #21
0
                echo shell_exec("git init --bare .git");
                echo "\n# Adding git hook 'post-receive'...\n";
                $hook_file = $cwd . '/.git/hooks/post-receive';
                $hook_data = "#!/bin/sh\nGIT_WORK_TREE={$cwd} git checkout -f\ncd {$cwd}\n";
                file_put_contents($hook_file, $hook_data);
                chmod($hook_file, 0755);
                echo shell_exec("ls -la {$hook_file}");
                echo "\n# Upload your repo\n\n";
                echo "= Execute this commands in your local machine:================================\n\n";
                echo "git remote add REMOTE_NAME ssh://USER@SERVER{$cwd}/.git\n";
                echo "git push REMOTE_NAME YOUR_PREFERRED_BRANCH:master\n\n";
                command('When the repo will be uploaded, press ENTER:');
                echo "\n# Configuring database\n";
                $host = command('Host: ');
                $db = command('Database: ');
                $user = command('User: '******'Pass: '******'class/Main.class.php';
                Main::goCli();
                Database::configure($host, $db, $user, $pass);
                echo "\n# Installing TreeWeb...\n";
                foreach (Storm::all() as $s) {
                    $s->install();
                }
                echo "\n# Adding post-receive line...\n";
                file_put_contents($hook_file, "php.ORIG.5_4 -n install.php --install\n", FILE_APPEND);
                echo "\n\n TreeWeb is now installed\n\n";
            }
        }
    }
}