Esempio n. 1
0
 public function __construct($collection)
 {
     $this->_mongo = new MongoConnection();
     $this->_mongo->getCredentialsFromConfig(ConfigUtil::getConfig());
     $this->_mongo->open();
     $this->_mongo->setCollection($collection);
 }
Esempio n. 2
0
 /**
  * Indicate that the table needs to be created.
  *
  * @return bool
  */
 public function create()
 {
     $collection = $this->collection->getName();
     $db = $this->connection->getMongoDB();
     // Ensure the collection is created.
     $db->createCollection($collection);
 }
Esempio n. 3
0
 public static function selectCollection($collection_name)
 {
     try {
         $collection = MongoConnection::$mongo_db->selectCollection($collection_name);
     } catch (Exception $mongoException) {
         //Output error details
         Error::halt(503, 'service unavailable', 'Temporarily unable to process request. Failed to select the MongoDB collection. Please retry.');
     }
     if (empty($collection)) {
         //Output error details
         Error::halt(503, 'service unavailable', 'Temporarily unable to process request. Failed to select the MongoDB collection. Please retry.');
     }
     MongoConnection::$mongo_collection = $collection;
 }
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/
$_SERVER['SCRIPT_NAME'] !== "/controller.php" ? require_once __DIR__ . "/classes/Requires.php" : (Links::$pretty = true);
Functions::check_required_parameters(array($_GET['param1']));
//Get execution history record
$execution_history = null;
MongoConnection::connect();
MongoConnection::select_collection("executions");
$results = MongoConnection::find(array("_id" => new MongoId($_GET['param1'])));
MongoConnection::close();
foreach ($results as $result) {
    $result['executed'] = date(DATE_FORMAT, $result['executed']->sec + Functions::timezone_offset_in_seconds());
    $execution_history = $result;
}
if (empty($execution_history)) {
    Error::halt(404, 'not found', 'Execution history ID \'' . $_GET['param1'] . '\' does not exist.');
}
$execution_history_json = @json_encode($execution_history, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
header("Content-Type: application/json");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"" . $execution_history['_id'] . ".json\"");
header("Content-Transfer-Encoding: quoted-printable");
header("Content-Length: " . strlen($execution_history_json));
echo $execution_history_json;
?>
Esempio n. 5
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/
$_SERVER['SCRIPT_NAME'] !== "/controller.php" ? require_once __DIR__ . "/classes/Requires.php" : (Links::$pretty = true);
//Make sure we can connect and select the executions collection in MongoDB
MongoConnection::connect();
MongoConnection::selectCollection("executions");
//Get groups
$groups = array();
$result = MySQLQueries::get_groups();
while ($row = MySQLConnection::fetch_object($result)) {
    $groups[] = $row;
}
//Get the servers in the default group
$servers_in_default_group = array();
$result = MySQLQueries::get_servers_by_groups(array());
while ($row = MySQLConnection::fetch_object($result)) {
    $servers_in_default_group[] = $row;
}
//Get recipes
$recipes = array();
$result = MySQLQueries::get_recipes();
Esempio n. 6
0
        $ex = json_decode($ex->getMessage());
        $returned_results[] = array("server" => $server->id, "server_label" => $server->label, "stream" => "error", "result" => $ex->error->message);
        continue;
    }
    ////
    // Build the correct interpreter and command
    ////
    switch ($recipe->interpreter) {
        case "shell":
            $command = $recipe->content;
            break;
        case "bash":
            $command = "echo \$'" . str_replace("'", "\\'", $recipe->content) . "' | bash";
            break;
        case "perl":
            $command = "echo \$'" . str_replace("'", "\\'", $recipe->content) . "' | perl";
            break;
        case "python":
            $command = "echo \$'" . str_replace("'", "\\'", $recipe->content) . "' | python";
            break;
        case "node.js":
            $command = "echo \$'" . str_replace("'", "\\'", $recipe->content) . "' | node";
            break;
    }
    $result = $ssh->execute($command);
    $returned_results[] = array("server" => $server->id, "server_label" => $server->label, "stream" => $result->stream, "result" => $result->result);
}
MongoConnection::connect();
MongoConnection::selectCollection("executions");
MongoConnection::insert(Functions::build_execution_history_object($_POST['notes'], $_POST['groups'], $recipe, $servers, $returned_results));
echo json_encode($returned_results);
Esempio n. 7
0
 public static function grid_fs()
 {
     MongoConnection::$mongo_grid_fs = MongoConnection::$mongo_db->getGridFS();
 }
Esempio n. 8
0
 /**
  * MongoBehavior::getDbName()
  *
  * @param mixed $connectionId
  * @return
  */
 public function setDbName($dbName, $connectionId = null)
 {
     $this->setConnectionId($connectionId);
     if (!empty($dbName) && $this->getDbName() != $dbName) {
         MongoConnection::instance($this->getConnectionId())->dbName = $dbName;
     }
 }
 /**
  * Returns edmsMongo connection instance if not exists will create new
  *
  * @return edmsMongo
  * @throws EMongoException
  * @since v1.0
  */
 public function getMongo()
 {
     if (!isset(self::$_mongo)) {
         try {
             if (empty($this->dbName)) {
                 throw new YMongoException('No database configured');
             }
             //remove keys with null values
             $options = array();
             foreach ($this->options as $key => $value) {
                 if (isset($value)) {
                     $options[$key] = $value;
                 }
             }
             if (!isset($this->server)) {
                 $this->server = 'mongodb://localhost:27017';
             }
             self::$_mongo = new Mongo($this->server, $options);
         } catch (MongoConnectionException $e) {
             throw new YMongoException('Failed to create class edmsMongo: ' . $e->getMessage());
         }
     }
     return self::$_mongo;
 }