<?php
/*
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/ # 函数规定报告哪个错误,该函数设置当前脚本的错误报告级别
# 该函数返回旧的错误报告级别
error_reporting(E_ALL); # 加载那些需要的函数
require("helper_functions.php"); $i = ;
$lock_string = "";
$currently_locked = false; $var = read_desktop_file(); # 加载json对象 if($var==null)
{
echo "Json.txt file is empty or doesn't exist.";
return;
} $submenu = isset($_GET["submenu"]) == true ? $_GET["submenu"] : "main_menu" ; # $link = "run_script.php?&submenu=".urlencode($submenu)."&app=".urlencode($app_title);
# 获取对应的app
$found_app = get_application($var,$submenu,$_GET["app"]); # 查看当前的json.txt文件,其中的Lock字段的内容都是-
# 所以这一部分的其中很多内容可以不分析
$lock_list = $found_app["Lock"]; //Verify that there is a lock specified for this application
# 应用有锁
if($lock_list != - )
{
//Convert the string into an array.
//This might be backwards*********CHECKOUT********
# explode(): 把字符串分割为数组
$lock_list_array = explode($lock_list," "); //Check if the lock list only has one lock. If so add to the array
//Since index 0 will be empty
if(count($lock_list_array) == )
$lock_list_array[] = $lock_list; //Check to see if any of the locks exist.
for($x = ;$x<count($lock_list_array);$x++)
{
# 这里貌似是锁文件,是否存在的意思
if(file_exists ("lock/".$lock_list_array[$x])==true)
{
$currently_locked = true;
break;
}
}
}
else
$lock_list = ""; # 就当前的json.txt文件而言,都是采用这种方式 if($currently_locked==false)
{
$script_link = $found_app["Exec"]; # strval(): 用于获取变量对应的字符串值
# rand(): 返回随机整数
$random_string = strval(rand());
$random_string .= strval(rand()); # addslashes(): 在指定的预定义字符前添加反斜杠
$script_command = "./execute_command.sh \"".addslashes($script_link). "\" ".$random_string.".txt ".$lock_list; # 获取系统执行结果最后一行
# system()第二个参数:如果提供的return_var参数,则外部命令执行后的
# 返回状态将会被设置到此变量中
$last_line = system($script_command." > /dev/null 2>/dev/null & ", $retval);
} # 菜单标题采用app的名字
$menu_title = $found_app["Name"];
?> <!-- 这里需要区分web的程序还是gui程序 -->
<!-- 这里是没有锁,并且是程序类型不是web,也就是说gui程序会走接下来的这种方式 -->
<?php if($currently_locked==false && $found_app["ProgramType"]!="web"){ ?>
<!-- 加入菜单 -->
<?php include "menubar.php"; ?>
<div id="container"></div> <script>
<?php echo "var uri_link = \"$random_string\";"; ?> // 仅仅是一个随机数 var fail_count = ; // 这个函数的主要功能好像是,获取app的输出内容显示到网页上来,
// 但这个函数是有时间限制的,如果在规定的时间内不能获取到相应的数据,
// 那么就会提示出错了
function update()
{
//This is a fix for IE browsers. IE likes to cache Ajax results. Therefore, adding a random string will prevent the browser from caching the Ajax request.
// 防止浏览器缓存页面导致不访问web服务器
var uri = "tmp/"+uri_link+".txt?rand="+Math.round((Math.random()*))+Math.round((Math.random()*))+Math.round((Math.random()*)); $.get(uri, function(data)
{
fail_count = ;
data = jQuery.trim(data); //The execute_command script adds the text "_?!!MATRIX_SCRIPT_COMPLETED!!?_" to the end of the file to mark that the command is done executing
// 获取系统返回的数据,并查找字符串
var script_complete = data.indexOf("_?!!MATRIX_SCRIPT_COMPLETED!!?_");
if(script_complete != -)
{
//Just replace the end of file text to Script Complete which
data = data.replace("_?!!MATRIX_SCRIPT_COMPLETED!!?_", "Script Complete");
} <?php
//GUI applications shouldn't have any output that needs to be displayed. Therefore, don't include the code that will update the HTML container
//with the program's output. This prevents some flickering problems that occur in some GUI applications even if the HTML container is being passed no information.
// GUI程序没有任何输出需要显示,所以不需要将程序输出显示出来,
// 这里主要是为了防止一些无输出的问题
if($found_app["ProgramType"]!="gui"){ ?>
$('#container').html("<pre>"+data+"</pre>");
$('#container').scrollTop(document.getElementById("container").scrollHeight);
<?php } ?> if(script_complete != -)
{
//Display the exit and back button.
$('#main_menu_link').removeClass("hide_link");
$('#back_link').removeClass("hide_link"); <?php if($found_app["ProgramType"]=="gui"){ ?>
$('#back_link').click(); // 这里为什么会需要自动点击返回?
<?php } ?>
}
else
setTimeout("update()",); })
//If a file cant be read or some other error related to trying to retrieve this file then JQuery executes the error function.
//This sometimes occurs when the browser tries to read the output file before output file is even created.
.error(function()
{
//This function will attempt to read the file 3 times with an increase delay for each attempt. If the file still hasn't
//been able to be read then an error is displayed and the Exit and Back Link is enabled. fail_count++;
if(fail_count==)
{
$('#container').html("Failed to read output file");
$('#main_menu_link').removeClass("hide_link");
$('#back_link').removeClass("hide_link");
}
else
{
//Every time it fails wait a signifcantly longer amount of time
setTimeout("update()",fail_count*);
}
}); } //Wait 500ms before trying to read the application output
// 从这里开始开始调用前面的update()函数
setTimeout("update()",);
</script>
<?php }if($currently_locked==false && $found_app["ProgramType"]=="web"){ ?>
<?php include "menubar.php"; ?> <script>
$('#main_menu_link').removeClass("hide_link");
$('#back_link').removeClass("hide_link"); $("#menubar").outerHeight(true)
$("#menubar").outerWidth(true) // 在后面给调用
function scrollbarWidth() {
var $inner = jQuery('<div style="width: 100%; height:200px;">test</div>'),
$outer = jQuery('<div style="width:200px;height:150px; position: absolute; top: 0; left: 0; visibility: hidden; overflow:hidden;"></div>').append($inner),
inner = $inner[],
outer = $outer[]; jQuery('body').append(outer);
var width1 = inner.offsetWidth;
$outer.css('overflow', 'scroll');
var width2 = outer.clientWidth;
$outer.remove(); return (width1 - width2);
} $("#html5-frame").width($("#menubar").width()-scrollbarWidth());
$("#html5-frame").height($(window).height() - $("#menubar").outerHeight(true)-scrollbarWidth()) </script>
<!-- 用一个框架来显示一些东西 -->
<iframe id = "html5-frame" src = "<?php echo $found_app["Exec"]; ?>"scrolling = "auto" style = "padding:5px;"> <!-- 就目前的json.txt文本内容而言,currently_locked一直都是等于false -->
<?php }if($currently_locked==true){?>
<?php include "menubar.php"; ?>
This program can't run since a program is already running that contains a lock that this program is trying to use
<script>
//Display the back and exit button since the application couldn't run
$('#main_menu_link').removeClass("hide_link");
$('#back_link').removeClass("hide_link");
</script> <?php } ?>

Texas Instruments matrix-gui-2.0 hacking -- run_script.php的更多相关文章

  1. Texas Instruments matrix-gui-2.0 hacking -- app_description.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  2. Texas Instruments matrix-gui-2.0 hacking -- submenu.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  3. Texas Instruments matrix-gui-2.0 hacking -- index.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  4. Texas Instruments matrix-gui-2.0 hacking -- execute_command.sh

    #!/bin/sh #Copyright (C) Texas Instruments Incorporated - http://www.ti.com/ # # # Redistribution an ...

  5. Texas Instruments matrix-gui-2.0 hacking -- menubar.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  6. Texas Instruments matrix-gui-2.0 hacking -- generate.php

    <?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...

  7. 【LeetCode每天一题】Set Matrix Zeroes(设置0矩阵)

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Exampl ...

  8. Texas Instruments matrix-gui-2.0 hacking -- json.txt

    { "main_menu": { "apps": [ { "Name":"Profiling", ", &qu ...

  9. Texas Instruments matrix-gui-2.0 hacking -- helper_functions.php

    <?php # PHP_SELF: 但前正在执行脚本的文件名,与document root相关 # QUERY_STRING: 查询(query)的字符串 $cachefile = " ...

随机推荐

  1. 《F4+2团队项目系统设计改进》

    项目软件系统设计改进 1引言 1.1编写目的 本阶段完成系统的大致设计并明确系统的数据结构与软件结构.本概要设计说明书的目的就是进一步细化软件设计阶段得出的软件概貌,把它加工成在程序细节上非常接近与源 ...

  2. Eclipse打JAR包,插件FatJar安装与使用

    下载fatJar插件,解压缩后是一个.../plugins/(net...)把plugins下面的(net..)文件夹拷贝到eclipse 的plugins下,重新启动Eclipse3.1,Windo ...

  3. URAL 1513 Lemon Tale

    URAL 1513 思路: dp+高精度 状态:dp[i][j]表示长度为i末尾连续j个L的方案数 初始状态:dp[0][0]=1 状态转移:dp[i][j]=dp[i-1][j-1](0<=j ...

  4. (转)关于C# 中的Attribute 特性

    摘要:纠结地说,这应该算是一篇关于Attribute 的笔记,其中的一些思路和代码借鉴了他人的文笔(见本文底部链接).但是,由于此文对Attribute 的讲解实在是叫好(自夸一下 ^_^),所以公之 ...

  5. 雷林鹏分享:C# 反射(Reflection)

    C# 反射(Reflection) 反射(Reflection) 对象用于在运行时获取类型信息.该类位于 System.Reflection 命名空间中,可访问一个正在运行的程序的元数据. Syste ...

  6. 广播 (Broadcast)

    广播 :在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制.我们拿广播电台来做个比方.我们平常使用收音机收音是这样的:许许多多不同的广播电台通过特定的频率来发送他们的内 ...

  7. splice的多种用法

    (一)splice的多种用法: splice(n,m) 从索引n开始删除m个.返回删除项组成新数组 splice(n) 从索引n开始删除到末尾 splice(n,m,x) 从索引n开始删除m个,并且把 ...

  8. iterator not dereferencable问题

    STL中的迭代器总是出现各种问题,这个是我在打表达式求值时碰到的... 综合网上的答案,一般来说有两种情况: 第一:访问了非法位置. 一般来说可能在queue为空时取front(),rear(),或者 ...

  9. Oracle11g温习-第一章:Oracle 体系架构

    2013年4月27日 星期六 10:20 1.oracle 网络架构及应用环境 1. ORACLE 实例——包括内存结构与后台进程 2. ORACLE 数据库——物理操作系统文件的集合 3. 了解内存 ...

  10. OAF多语言的实现

    在之前的文章中转载了一篇关于多语言实现的文章. OAF中多语言的实现(转) 现在我来讲讲另外一种情况. 在建立工程项目没有特别选择语言,所以所有的PG或RN页面都是英文的,在页面原文件中可看到如下内容 ...