Ejemplo n.º 1
0
function savePluginConfig($ecuId, $name, $appConfig_id)
{
    global $wpdb;
    $table_name = "PluginConfig";
    $wpdb->show_errors();
    $vin = getVIN();
    $result = $wpdb->query($wpdb->prepare("\n\t\tINSERT INTO {$table_name}\n\t\t(ecuId, name, appConfig_id) \n\t\tVALUES(%d, %s, %d)\n\t", $ecuId, $name, $appConfig_id));
    return $result;
}
Ejemplo n.º 2
0
function addInstalledApp($appId)
{
    global $wpdb;
    $table_name = "Vehicle";
    $wpdb->show_errors();
    $vin = getVIN();
    $myvalue = $wpdb->get_var($wpdb->prepare("select INSTALLED_APPS from Vehicle where VIN = %s", $vin));
    if ($myvalue == NULL || $myvalue == "") {
        $wpdb->query($wpdb->prepare("\r\n\t\t\t\tUPDATE {$table_name} SET INSTALLED_APPS = {$appId} WHERE VIN = %s\r\n\t\t\t", $vin));
    } else {
        $apps = $myvalue . "," . $appId;
        $wpdb->query($wpdb->prepare("\r\n\t\t\tUPDATE {$table_name} SET INSTALLED_APPS = {$apps} WHERE VIN = %s\r\n\t\t", $vin));
    }
    return true;
}
Ejemplo n.º 3
0
function invoke_uninstall_webservice($app_id)
{
    global $client;
    try {
        $vin = getVIN();
        $ret = $client->uninstallApp($vin, $app_id);
        $ret = json_decode($ret);
        if ($ret->error) {
            $e = $ret->message;
            echo "<font color='red'>Uninstallation failed: {$e}</font>";
            return;
        }
        return $ret;
    } catch (SoapFault $exception) {
        print $exception;
        return false;
    }
}
Ejemplo n.º 4
0
/**
 * Invoke the app installation web service
 *
 * @param $app_id 		- app id, as stored in the MOPED database
 * @param $jvm			- type of JVM (e.g. JDK or Squawk)
 */
function ws_install($app_id, $jvm)
{
    global $client;
    try {
        $vin = getVIN();
        $client->__soapCall("install", array('vin' => $vin, 'appID' => $app_id, 'jvm' => $jvm));
        //TODO: This could probably be done in another way...
        for ($i = 0; $i < 30; $i++) {
            $ret = $client->__soapCall("get_ack_status", array('vin' => $vin, 'appId' => $app_id));
            if ($ret) {
                echo "<font color='green'>Installation complete</font><br/>";
                break;
            } else {
                sleep(1);
            }
        }
        //TODO: ... up to here
        if (!$ret) {
            echo "<font color='red'>Installation failed</font>";
        }
        return $ret;
    } catch (SoapFault $exception) {
        print $exception;
        return false;
    }
}
Ejemplo n.º 5
0
function apps_display_form()
{
    global $client;
    // we should look at the error value, too
    $apps = $client->listApplications();
    $apps = json_decode($apps);
    $apps = $apps->result;
    $username = wp_get_current_user()->user_login;
    $myvin = getVIN();
    if (!$username) {
        print "<font color='red'>You are not logged in</font>";
    } else {
        if (!$myvin) {
            print "<font color='red'>No active vehicle</font>";
        } else {
            print "Active vehicle: {$myvin}";
        }
    }
    $car = $client->infoVehicle($myvin);
    $car = json_decode($car);
    $car = $car->result;
    $iapps = $client->listInstalledApps();
    $iapps = json_decode($iapps);
    $iapps = $iapps->result;
    $ia = array();
    $istatea = array();
    $ecua = array();
    foreach ($iapps as $iapp) {
        $nam = $iapp->name;
        $vin = $iapp->vin;
        if ($iapp->vin == $myvin) {
            $ia[$nam] = 1;
            $istatea[$nam] = $iapp->installationState;
            $ecua[$nam] = "ecu" . $iapp->ecu;
        }
    }
    ?>
		
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
		<thead>
			<tr>
				<th width="18%">Application</th>
				<th width="15%">Publisher</th>
				<th width="13%">Version</th>
				<th width="10%">Type</th>
				<th width="12%">Install</th>
				<th width="17%">Info</th>
				<th width="15%">Uninstall</th>
			</tr>
		</thead>
		<tbody>
			<?php 
    $app_nr = 0;
    foreach ($apps as $app) {
        echo "<tr>\r\n";
        echo "<td>{$app->name}</td>\r\n";
        echo "<td>{$app->publisher}</td>\r\n";
        echo "<td>{$app->version}</td>\r\n";
        echo "<td>{$app->vehicleConfig}</td>\r\n";
        echo "<td><form method=\"post\"><input type='hidden' name='app_row' value='{$app_nr}'/><input type='hidden' name='app_id' value='{$app->id}'/><input name='Jdk_install' type='image' src='wordpress/custom/images/install.png' alt='Install'/></form></td>\r\n";
        $i = $ia[$app->name];
        if (!$i) {
            if ($app->vehicleConfig == $car->type) {
                $i = 0;
            }
        }
        $id = $app->id;
        $state = $app->state;
        $istate = $istatea[$app->name];
        $ecus = "";
        foreach ($app->ecuList as $ecu) {
            $ecus = $ecus . " ecu{$ecu}";
        }
        echo "<td>{$i} {$id} {$state} {$istate} {$ecus}</td>\r\n";
        echo "<td><form method=\"post\"><input type='hidden' name='app_row' value='{$app_nr}'/><input type='hidden' name='app_id' value='{$app->id}'/><input name='Jdk_uninstall' type='image' src='wordpress/custom/images/uninstall.png' alt='Uninstall'/></form></td>\r\n";
        echo "</tr>\r\n";
        $app_nr++;
    }
    ?>
	<!-- 		<tr> -->
	<!-- 			<td colspan=\"6\" class=\"dataTables_empty\">Loading data from server...</td> -->
	<!-- 		</tr> -->
		</tbody>
		<tfoot>
			<tr>
				<th>Application</th>
				<th>Publisher</th>
				<th>Version</th>
				<th>Type</th>
				<th>Install</th>
				<th>Info</th>
				<th>Uninstall</th>
			</tr>
		</tfoot>
	</table>
	<div id="feedback"></div>
	
	<?php 
    if (isset($_POST['Jdk_uninstall_x'])) {
        $myvin = getVIN();
        if (!$myvin) {
            print "<font color='red'>No active vehicle: add one to your list of cars, and mark it as active</font>";
        } else {
            $ret = invoke_uninstall_webservice($_POST['app_id']);
        }
    }
    if (isset($_POST['Jdk_install_x'])) {
        $myvin = getVIN();
        if (!$myvin) {
            print "<font color='red'>No active vehicle: add one to your list of cars, and mark it as active</font>";
        } else {
            $ret = invoke_install_webservice($_POST['app_id']);
        }
    }
}
Ejemplo n.º 6
0
function restore_configuration($id)
{
    // invoke webservice of restore ecu
    // Invoke Web Services
    $webServiceAddress = getWebServiceAddress();
    ini_set("soap.wsdl_cache_enabled", "0");
    $client = new SoapClient($webServiceAddress, array('encoding' => 'UTF-8'));
    try {
        $vin = getVIN();
        $param = array('arg0' => $vin, 'arg1' => $id);
        $ret = $client->restoreEcu($param);
        if ($ret->return == true) {
            return "<br/><font color='red'>Success to restore ECU {$id}</font><br />";
        } else {
            return "<br/><font color='red'>Error. Fail to restore ECU {$id}</font><br />";
        }
        //print_r($ret);
    } catch (SoapFault $exception) {
        print $exception;
    }
}
Ejemplo n.º 7
0
function restore_configuration($id)
{
    // invoke webservice of restore ecu
    // Invoke Web Services
    global $client;
    try {
        $vin = getVIN();
        $param = array('arg0' => $vin, 'arg1' => $id);
        $ret = $client->restoreEcu($param);
        if ($ret->return == true) {
            return "<br/><font color='red'>Success to restore ECU {$id}</font><br />";
        } else {
            return "<br/><font color='red'>Error. Fail to restore ECU {$id}</font><br />";
        }
        //print_r($ret);
    } catch (SoapFault $exception) {
        print $exception;
    }
}
function unintall_app_by_app_id($app_id)
{
    // Invoke Web Services
    $webServiceAddress = getWebServiceAddress();
    ini_set("soap.wsdl_cache_enabled", "0");
    $client = new SoapClient($webServiceAddress, array('encoding' => 'UTF-8'));
    try {
        $vin = getVIN();
        $param = array('arg0' => $vin, 'arg1' => $app_id);
        $ret = $client->uninstall($param);
        //print_r($ret);
        if ($ret->return) {
            echo "<font color='green'>Application is uninstalling...</font>";
        } else {
            echo "<font color='red'>Application failed uninstallation</font>";
        }
    } catch (SoapFault $exception) {
        print $exception;
    }
    // Synchronize DB
    //$field_name = "INSTALLED_APPS";
    //$apps = get_cimyFieldValue(getVIN(), $field_name);
    /*	$apps = getInstalledApps(getVIN());
    	if (strpos($apps, ',') !== false) {
    		$apps_array = explode(',', $apps);
    	} else {
    		$apps_array = array($apps);
    	}
    	$removed_array = array_diff($apps_array, array($app_id));
    	$size = count($removed_array);
    	if($size == 0) {
    		$result = "";
    	} else if ($size == 1) {
    		$result = $removed_array[0];
    	} else {
    		$result = implode(',', $removed_array);
    	}
    	removeInstalledApp($result);
    	*/
}