public function archiveFile()
 {
     if (!class_exists('CommonUtilities')) {
         include 'src/utilities.php';
     }
     $util = new CommonUtilities();
     $origFile = "data/search.json";
     $origFile2 = "data/search_full.json";
     $newFileName = "data/archive/search-" . $util->getDateTimeNow() . ".json";
     $newFileName2 = "data/archive/search_full-" . $util->getDateTimeNow() . ".json";
     file_put_contents($newFileName, file_get_contents($origFile), FILE_APPEND);
     file_put_contents($newFileName2, file_get_contents($origFile2), FILE_APPEND);
     file_put_contents($origFile, "");
     file_put_contents($origFile2, "");
 }
 /**
  * Verify if the user is already logged in. If not, redirect to the home page.
  */
 public static function verify_login()
 {
     if (CommonUtilities::id_in_session()) {
         return true;
     } else {
         CommonUtilities::print_error_message('User is not logged in!');
         return false;
     }
 }
 public function saveJSONFiles($resultsFull)
 {
     $util = new CommonUtilities();
     $this->appendFile("data/search_full.json", $resultsFull);
     $resultsConvert = json_decode(json_encode($resultsFull), true);
     $resultsSnippet = array();
     //Removing the headers and saving the juicy bits
     foreach ($resultsConvert['results'] as $aSnip) {
         $jobtitle = $aSnip['jobtitle'];
         $jobkey = $aSnip['jobkey'];
         $company = $aSnip['company'];
         $date = $aSnip['date'];
         $url = $aSnip['url'];
         $deleted = (bool) false;
         $applied = (bool) false;
         $querydate = $util->getDateTimeNow();
         $toapply = array("jobtitle" => $jobtitle, "jobkey" => $jobkey, "company" => $company, "date" => $date, "url" => $url, "deleted" => $deleted, "applied" => $applied, "querydate" => $querydate);
         $resultsSnippet[] = $toapply;
     }
     $this->appendFile("data/search.json", $resultsSnippet);
 }
 public function convertJSONtoCSV($jsonFilename)
 {
     if (!class_exists('CommonUtilities')) {
         include 'src/utilities.php';
     }
     $util = new CommonUtilities();
     $csvFilename = "csv/" . $util->getDateTimeNow() . "_search.csv";
     $json = file_get_contents($jsonFilename);
     $array = json_decode($json, true);
     $f = fopen($csvFilename, 'w');
     $firstLineKeys = false;
     foreach ($array as $line) {
         if (empty($firstLineKeys)) {
             $firstLineKeys = array_keys($line);
             fputcsv($f, $firstLineKeys);
             $firstLineKeys = array_flip($firstLineKeys);
         }
         // Using array_merge is important to maintain the order of keys acording to the first element
         fputcsv($f, array_merge($firstLineKeys, $line));
     }
 }
 public function loginSubmit()
 {
     if (CommonUtilities::form_submitted()) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         try {
             if (WSIS::authenticate($username, $password)) {
                 if (in_array(Config::get('pga_config.wsis')['admin-role-name'], (array) WSIS::getUserRoles($username))) {
                     Session::put("admin", true);
                 }
                 CommonUtilities::store_id_in_session($username);
                 CommonUtilities::print_success_message('Login successful! You will be redirected to your home page shortly.');
                 Session::put("gateway_id", Config::get('pga_config.wsis')['gateway-id']);
                 //TODO::If this option is not safe, have to find a better method to send credentials to identity server on every connection.
                 Session::put("password", $_POST["password"]);
                 return Redirect::to("home");
             } else {
                 return Redirect::to("login")->with("invalid-credentials", true);
             }
         } catch (Exception $ex) {
             return Redirect::to("login")->with("invalid-credentials", true);
         }
     }
 }
<?php

if (isset($expContainer))
{
if (sizeof($expContainer) == 0)
{
    if (isset($pageNo) && $pageNo == 1) {
        CommonUtilities::print_warning_message('No results found. Please try again.');
    } else {
        CommonUtilities::print_warning_message('No more results found.');
    }
}
else
{
?>

<div id="re" class="table-responsive">
    <table class="table">
        <tr>
            <th>Name</th>
            <th>Application</th>
            <th>Description</th>
            <!--<th>Resource</th>-->
            <th>Creation Time</th>
            <th>Status</th>
            <!--                    <select class="form-control select-status">-->
            <!--                        <option value="ALL">Status</option>-->
            <!--                    @foreach( $expStates as $index => $state)-->
            <!--                        <option value="{{ $state }}">{{ $state }}</option>-->
            <!--                    @endforeach-->
            <!--                    </select>-->
 /**
  * Get a list of compute resources available for the given application ID
  * @param $id
  * @return null
  */
 public static function get_available_app_interface_compute_resources($id)
 {
     $computeResources = null;
     try {
         $computeResources = Airavata::getAvailableAppInterfaceComputeResources(Session::get('authz-token'), $id);
     } catch (InvalidRequestException $ire) {
         CommonUtilities::print_error_message('<p>There was a problem getting compute resources.
         Please try again later or submit a bug report using the link in the Help menu.</p>' . '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
     } catch (AiravataClientException $ace) {
         CommonUtilities::print_error_message('<p>There was a problem getting compute resources.
         Please try again later or submit a bug report using the link in the Help menu.</p>' . '<p>Airavata Client Exception: ' . $ace->getMessage() . '</p>');
     } catch (AiravataSystemException $ase) {
         CommonUtilities::print_error_message('<p>There was a problem getting compute resources.
         Please try again later or submit a bug report using the link in the Help menu.</p>' . '<p>Airavata System Exception: ' . $ase->getMessage() . '</p>');
     }
     return $computeResources;
 }
                </p>
                <p><a href="https://github.com/apache/airavata-php-gateway"
                        target="_blank">See the code <span class="glyphicon glyphicon-new-window"></span></a></p>
                <p><a href="https://cwiki.apache.org/confluence/display/AIRAVATA/XSEDE+2014+Tutorial"
                    target="_blank">View the XSEDE 2014 tutorial documentation <span class="glyphicon glyphicon-new-window"></span></a></p>
            ';
}
?>
    </div>
</div>

<div class="container">

    <div class="row">
        <?php 
if (CommonUtilities::id_in_session()) {
    echo '
                <div class="col-md-4">
                    <h2>PHP Gateway with Airavata</h2>
                    <p>
                        PGA is a science gateway built with the Airavata API. You can reference PGA as you integrate
                        Airavata into your own gateway, or you can create your gateway on top of PGA by cloning it at
                        the link below. PGA is known to work well in the Chrome, Firefox, and Internet Explorer browsers.
                    </p>
                    <p><a href="https://github.com/apache/airavata-php-gateway/"
                        target="_blank">See the code <span class="glyphicon glyphicon-new-window"></span></a></p>
                    <p><a href="https://cwiki.apache.org/confluence/display/AIRAVATA/XSEDE+2014+Tutorial"
                        target="_blank">View the XSEDE 2014 tutorial documentation <span class="glyphicon glyphicon-new-window"></span></a></p>
                </div>
            ';
}
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
    if (Session::token() != Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
Route::filter('verifylogin', function () {
    if (!CommonUtilities::verify_login()) {
        return Redirect::to("home")->with("login-alert", true);
    }
});
Route::filter('verifyadmin', function () {
    if (CommonUtilities::verify_login()) {
        if (!(Session::has("admin") || Session::has("admin-read-only"))) {
            return Redirect::to("home")->with("admin-alert", true);
        }
    } else {
        return Redirect::to("home")->with("login-alert", true);
    }
});
Route::filter('verifyeditadmin', function () {
    if (CommonUtilities::verify_login()) {
        if (!Session::has("admin")) {
            return Redirect::to("home")->with("admin-alert", true);
        }
    } else {
        return Redirect::to("home")->with("login-alert", true);
    }
});
 /**
  * Get results of the user's all experiments with pagination.
  * Results are ordered creation time DESC
  * @return array|null
  */
 public static function get_all_user_experiments_with_pagination($limit, $offset)
 {
     $experiments = array();
     try {
         $experiments = Airavata::getUserExperiments(Session::get('authz-token'), Session::get('gateway_id'), Session::get('username'), $limit, $offset);
     } catch (InvalidRequestException $ire) {
         CommonUtilities::print_error_message('InvalidRequestException!<br><br>' . $ire->getMessage());
     } catch (AiravataClientException $ace) {
         CommonUtilities::print_error_message('AiravataClientException!<br><br>' . $ace->getMessage());
     } catch (AiravataSystemException $ase) {
         if ($ase->airavataErrorType == 2) {
             CommonUtilities::print_info_message('<p>You have not created any experiments yet, so no results will be returned!</p>
                             <p>Click <a href="create_experiment.php">here</a> to create an experiment, or
                             <a href="create_project.php">here</a> to create a new project.</p>');
         } else {
             CommonUtilities::print_error_message('There was a problem with Airavata. Please try again later or report a bug using the link in the Help menu.');
             //print_error_message('AiravataSystemException!<br><br>' . $ase->airavataErrorType . ': ' . $ase->getMessage());
         }
     } catch (TTransportException $tte) {
         CommonUtilities::print_error_message('TTransportException!<br><br>' . $tte->getMessage());
     }
     //get values of all experiments
     $expContainer = array();
     $expNum = 0;
     foreach ($experiments as $experiment) {
         $expValue = ExperimentUtilities::get_experiment_summary_values($experiment, true);
         $expContainer[$expNum]['experiment'] = $experiment;
         if ($expValue["experimentStatusString"] == "FAILED") {
             $expValue["editable"] = false;
         }
         $expContainer[$expNum]['expValue'] = $expValue;
         $expNum++;
     }
     return $expContainer;
 }
 public static function remove_ssh_token($token)
 {
     try {
         return Airavata::deleteSSHPubKey(Session::get('authz-token'), $token, Session::get("gateway_id"));
     } catch (InvalidRequestException $ire) {
         CommonUtilities::print_error_message('p>Error in creating SSH Handshake. You might have to enable TLS in pga_config. </p>' . '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
     } catch (AiravataClientException $ace) {
         CommonUtilities::print_error_message('<p>Error in creating SSH Handshake. You might have to enable TLS in pga_config.  </p>' . '<p>Airavata Client Exception: ' . $ace->getMessage() . '</p>');
     } catch (AiravataSystemException $ase) {
         CommonUtilities::print_error_message('p>Error in creating SSH Handshake. You might have to enable TLS in pga_config.  </p>' . '<p>Airavata System Exception: ' . $ase->getMessage() . '</p>');
     }
 }
<body>

<?php 
CommonUtilities::create_nav_bar();
?>

<?php 
// Alerts if guests users try to go to the link without signing in.
if (Session::has("login-alert")) {
    CommonUtilities::print_error_message("You need to login to use this service.");
    Session::forget("login-alert");
}
// if signed in user is not an admin.
if (Session::has("admin-alert")) {
    CommonUtilities::print_error_message("You need to be an admin to use this service.");
    Session::forget("admin-alert");
}
?>

@show

@yield('content')

</body>
@section('scripts')
<!-- Jira Issue Collector - Report Issue -->
<script type="text/javascript"
        src="https://gateways.atlassian.net/s/31280375aecc888d5140f63e1dc78a93-T/en_USmlc07/6328/46/1.4.13/_/download/batch/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector.js?locale=en-US&collectorId=b1572922"></script>

<!-- Jira Issue Collector - Request Feature -->
 public function resetPasswordSubmit()
 {
     $rules = array("new_password" => "required|min:6", "confirm_new_password" => "required|same:new_password");
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to("reset-password")->withInput(Input::except('new_password', 'confirm)new_password'))->withErrors($validator);
     }
     $key = $_POST['key'];
     $username = $_POST['username'];
     $new_password = $_POST['new_password'];
     try {
         $result = WSIS::resetPassword($username, $new_password, $key);
         if ($result) {
             CommonUtilities::print_success_message("User password was reset successfully");
             return View::make("account/login");
         } else {
             CommonUtilities::print_error_message("Resetting user password operation failed");
             return View::make("account/home");
         }
     } catch (Exception $e) {
         CommonUtilities::print_error_message("Resetting user password operation failed");
         return View::make("account/home");
     }
 }
 /**
  * Get a list of the outputs for the application with the given ID
  * @param $id
  * @return null
  */
 public static function get_application_outputs($id)
 {
     $outputs = null;
     try {
         $outputs = Airavata::getApplicationOutputs(Session::get('authz-token'), $id);
     } catch (InvalidRequestException $ire) {
         CommonUtilities::print_error_message('<p>There was a problem getting application outputs.
         Please try again later or submit a bug report using the link in the Help menu.</p>' . '<p>InvalidRequestException: ' . $ire->getMessage() . '</p>');
     } catch (AiravataClientException $ace) {
         CommonUtilities::print_error_message('<p>There was a problem getting application outputs.
         Please try again later or submit a bug report using the link in the Help menu.</p>' . '<p>Airavata Client Exception: ' . $ace->getMessage() . '</p>');
     } catch (AiravataSystemException $ase) {
         CommonUtilities::print_error_message('<p>There was a problem getting application outputs.
         Please try again later or submit a bug report using the link in the Help menu.</p>' . '<p>Airavata System Exception: ' . $ase->getMessage() . '</p>');
     }
     return $outputs;
 }
 public static function get_projsearch_results($searchKey, $searchValue)
 {
     $projects = array();
     try {
         switch ($searchKey) {
             case 'project-name':
                 $projects = Airavata::searchProjectsByProjectName(Session::get('authz-token'), Session::get("gateway_id"), Session::get("username"), $searchValue);
                 break;
             case 'project-description':
                 $projects = Airavata::searchProjectsByProjectDesc(Session::get('authz-token'), Session::get("gateway_id"), Session::get("username"), $searchValue);
                 break;
         }
     } catch (InvalidRequestException $ire) {
         CommonUtilities::print_error_message('InvalidRequestException!<br><br>' . $ire->getMessage());
     } catch (AiravataClientException $ace) {
         CommonUtilities::print_error_message('AiravataClientException!<br><br>' . $ace->getMessage());
     } catch (AiravataSystemException $ase) {
         if ($ase->airavataErrorType == 2) {
             CommonUtilities::print_info_message('<p>You have not created any projects yet, so no results will be returned!</p>
                             <p>Click <a href="create_project.php">here</a> to create a new project.</p>');
         } else {
             CommonUtilities::print_error_message('There was a problem with Airavata. Please try again later, or report a bug using the link in the Help menu.');
             //print_error_message('AiravataSystemException!<br><br>' . $ase->airavataErrorType . ': ' . $ase->getMessage());
         }
     } catch (TTransportException $tte) {
         CommonUtilities::print_error_message('TTransportException!<br><br>' . $tte->getMessage());
     }
     return $projects;
 }