| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php namespace helper;
- function execBackground($command)
- {
- exec("echo \"{$command}\" | /usr/bin/at now", $var);
- return $var;
- }
- function checkDependency($dependencyName)
- {
- exec("/usr/bin/which $dependencyName", $output);
- return !(trim($output[0]) === "");
- }
- function isSDAvailable()
- {
- $output = exec('/bin/mount | /bin/grep "on /sd" -c');
- return $output >= 1;
- }
- function sdReaderPresent() {
- return file_exists('/sd');
- }
- function sdCardPresent() {
- return !file_exists('/sd/NO_SD');
- }
- function checkRunning($processName)
- {
- $processName = escapeshellarg($processName);
- exec("/usr/bin/pgrep {$processName}", $output);
- return count($output) > 0;
- }
- function checkRunningFull($processString) {
- $processString = escapeshellarg($processString);
- exec("/usr/bin/pgrep -f {$processString}", $output);
- return count($output) > 0;
- }
- function udsSend($path, $message)
- {
- $sock = stream_socket_client("unix://{$path}", $errno, $errstr);
- fwrite($sock, $message);
- fclose($sock);
- return true;
- }
- function dgramUdsSend($path, $message)
- {
- $sock = NULL;
- if(!($sock = socket_create(AF_UNIX, SOCK_DGRAM, 0))) {
- return false;
- }
- socket_sendto($sock, $message, strlen($message), 0, $path);
- return true;
- }
- function uciGet($uciString, $autoBool = true)
- {
- $uciString = escapeshellarg($uciString);
- $result = exec("uci get {$uciString}");
- if ($autoBool && ($result === "0" || $result === "1")) {
- return $result === "1";
- }
- return $result;
- }
- function uciSet($settingString, $value)
- {
- $settingString = escapeshellarg($settingString);
- if (!empty($value)) {
- $value = escapeshellarg($value);
- }
- if ($value === "''" || $value === "") {
- $value = "'0'";
- }
- exec("uci set {$settingString}={$value}");
- exec("uci commit {$settingString}");
- }
- function uciAddList($settingString, $value)
- {
- $settingString = escapeshellarg($settingString);
- if (!empty($value)) {
- $value = escapeshellarg($value);
- }
- if ($value === "''") {
- $value = "'0'";
- }
- exec("uci add_list {$settingString}={$value}");
- exec("uci commit {$settingString}");
- }
- function downloadFile($file)
- {
- $token = hash('sha256', $file . time());
- require_once('DatabaseConnection.php');
- $database = new \pineapple\DatabaseConnection("/etc/pineapple/pineapple.db");
- $database->exec("CREATE TABLE IF NOT EXISTS downloads (token VARCHAR NOT NULL, file VARCHAR NOT NULL, time timestamp default (strftime('%s', 'now')));");
- $database->exec("INSERT INTO downloads (token, file) VALUES ('%s', '%s')", $token, $file);
- return $token;
- }
- function getFirmwareVersion()
- {
- return trim(file_get_contents('/etc/pineapple/pineapple_version'));
- }
- function getDevice()
- {
- $data = file_get_contents('/proc/cpuinfo');
- if (preg_match('/NANO/', $data)) {
- return 'nano';
- } elseif (preg_match('/TETRA/', $data)) {
- return 'tetra';
- }
- return 'unknown';
- }
- function getMacFromInterface($interface)
- {
- $interface = escapeshellarg($interface);
- return trim(exec("ifconfig {$interface} | grep HWaddr | awk '{print $5}'"));
- }
- function getBoard()
- {
- $data = @file_get_contents('/tmp/sysinfo/board_name');
- if (!empty($data)) {
- $parts = explode(',', $data);
- return isset($parts[1]) ? $parts[1] : $parts[0];
- }
- return false;
- }
|