Example #1
0
 /**
  * @param Sag $sag An instantiated copy of Sag that you want this class to
  * use. If you don't specify a database (empty($sag->currentDatabase())) then
  * it will be set to '_users'.
  *
  * @return SagUserUtils
  */
 public function __construct($sag)
 {
     if (!$sag instanceof Sag) {
         throw new SagException('Tried to call setSag() with a non-Sag implementation.');
     }
     //Use the database if they pre-selected it, else default to Couch's default.
     $db = $sag->currentDatabase();
     if (empty($db)) {
         $sag->setDatabase('_users');
     }
     $this->sag = $sag;
 }
//We need to pull in the Sag PHP library. SAG is an open API used to connect to the Cloudant database.
//We only need to do this once!
require 'vendor/autoload.php';
//Get Connection Variables from VCAPS_SERVICES. We first need to pull in our Cloudant database
//connection variables from the VCAPS_SERVICES environment variable. This environment variable
//will be put in your project by Bluemix once you add the Cloudant database to your Bluemix
//application.
// vcap_services Extraction
$services_json = json_decode(getenv('VCAP_SERVICES'), true);
$VcapSvs = $services_json["cloudantNoSQLDB"][0]["credentials"];
// Extract the VCAP_SERVICES variables for Cloudant connection.
$myUsername = $VcapSvs["username"];
$myPassword = $VcapSvs["password"];
try {
    // Let's login to the database.
    $sag = new Sag($myUsername . ".cloudant.com");
    $sag->login($myUsername, $myPassword);
    // Now that we are logged in, we can create a database to use
    //$sag->createDatabase("ttpfeedback");
    $sag->setDatabase("ttpfeedback");
    /****feedback document starts ****/
    $namee = $_POST["name"];
    $com = $_POST["com"];
    $tweet = $_POST["tweet"];
    $acc = $_POST["service"];
    $sw = $_POST["topic"];
    $text = $_POST["text"];
    $rating = $_POST["rating"];
    /**test starts**/
    $ch = curl_init();
    $customer = array('EmailID' => $tweet, 'Organization' => $com, 'Rating' => $rating, 'Service' => $acc, 'Topics' => $sw, 'comments' => $text);
Example #3
0
     $auth->login();
 }
 if (!isset($auth) || empty($auth)) {
     $auth = new $authType($config);
 }
 if (!$auth->isLoggedIn()) {
     $auth->login();
 }
 if ($groupShare) {
     $groups = new $groupType($config, $auth);
 } else {
     $groups = NULL;
 }
 $action = getRequest('action', FALSE, 'showFiles');
 $useRest = getRequest('useRest', FALSE, FALSE);
 $storage = new Sag();
 $storage->setDatabase($dbName);
 if ($action === "logout") {
     $auth->logout($_SERVER["SCRIPT_NAME"]);
     exit(0);
 }
 if (!in_array($action, array('downloadFile', 'fileInfo', 'fileUpload', 'legacyFileUpload', 'getCacheObject', 'handleUpload', 'handleLegacyUpload', 'showFiles', 'rawFileInfo', 'updateFileInfo'), TRUE)) {
     throw new Exception("unregistered action called");
 }
 if ($useRest) {
     $f = new Files($config, $storage, $auth, $groups, NULL);
     $f->setRest(TRUE);
     $content = $f->{$action}();
     header("Content-Type: application/json;charset=UTF-8");
     header('Content-Disposition: attachment; filename="response.json"');
     die($content);
Example #4
0
<?php

/*
 * A real quick example to get and update a doc.
 */
require_once './src/Sag.php';
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$school = $_POST['school'];
$discipline = $_POST['discipline'];
$sag = new Sag('127.0.0.1', '5984');
// Select the database that holds our blog's data.
$sag->setDatabase('sakib');
try {
    //Get a blog post (a StdClass)...
    $post = $sag->get('postID')->body;
    //...update its info...
    $post->views++;
    //..and send it back to the couch.
    if (!$sag->put($post->_id, $post)->body->ok) {
        error_log('Unable to log a view to CouchDB.');
    }
} catch (SagCouchException $e) {
    //The requested post doesn't exist - oh no!
    if ($e->getCode() == "404") {
        $e = new Exception("That post doesn't exist.");
    }
    throw $e;
} catch (SagException $e) {
    //We sent something to Sag that it didn't expect.
    error_log('Programmer error: ' . $e->getMessage());
 public static function makeCouchDBLibrary()
 {
     $sag = new Sag('205.186.144.58');
     $sag->setDatabase('plugins');
     return $sag;
 }
require 'vendor/autoload.php';
//Get Connection Variables from VCAPS_SERVICES. We first need to pull in our Cloudant database
//connection variables from the VCAPS_SERVICES environment variable. This environment variable
//will be put in your project by Bluemix once you add the Cloudant database to your Bluemix
//application.
// vcap_services Extraction
$services_json = json_decode(getenv('VCAP_SERVICES'), true);
$VcapSvs = $services_json["cloudantNoSQLDB"][0]["credentials"];
//Debug: If you want to see all the variables returned you can use this line of code.
//var_dump($services_json);
// Extract the VCAP_SERVICES variables for Cloudant connection.
$myUsername = $VcapSvs["username"];
$myPassword = $VcapSvs["password"];
try {
    // Let's login to the database.
    $sag = new Sag($myUsername . ".cloudant.com");
    $sag->login($myUsername, $myPassword);
    // Now that we are logged in, we can create a database to use
    $sag->createDatabase("mydatabase");
    $sag->setDatabase("mydatabase");
    if (!$sag->put("myId", '{"myKey":"Hello World from Cloudant!"}')->body->ok) {
        error_log('Unable to post a document to Cloudant.');
    } else {
        // We are now going to read a document from our cloudant database. We are going
        // to retrieve the value associated with myKey from the body of the document.
        //The SAG PHP library takes care of all the gory details and only retrieves the value.
        $resp = $sag->get('myId')->body->myKey;
        echo $resp;
    }
    // Assuming everything above was executed without error, we now are connected to the
    // database and have retrieved the value.
Example #7
0
 public function test_connectionFailure()
 {
     $badCouch = new Sag('example.com');
     $badCouch->setOpenTimeout(1);
     try {
         $badCouch->setDatabase('bwah');
         $badCouch->get('/asdf');
         $this->assertTrue(false);
         //shouldn't reach this line
     } catch (SagException $e) {
         $this->assertTrue(true);
     }
 }
Example #8
0
<?php

header('Content-Type:text/plain');
require_once 'check_and_start_session.php';
require_once 'Sag/Sag.php';
$s = new Sag();
$s->setDatabase('slouchin_test');
// requires login, but we've got a cookie!
$s->setAuthSession(session_id());
$doc = new stdClass();
$doc->test = 'doc';
$doc->used_session_id = $s->authSession;
try {
    $res = $s->put(uniqid(), $doc);
    print_r($res);
} catch (SagCouchException $e) {
    print_r($e->getCode());
    print_r($e->getMessage());
}
Example #9
0
File: run.php Project: hyla/sag
$_SESSION['time'] = time();

var_dump($_SESSION);
    </pre>

    <hr/>

    <p>
      <strong>Here are the results:</strong>

    <div>
      <?php 
ini_set('display_errors', true);
require 'CouchSessionStore.php';
require_once '../../src/Sag.php';
$sag = new Sag();
$sag->login('admin', 'password');
CouchSessionStore::setSag($sag);
session_start();
var_dump($_SESSION);
echo "<br/>";
if (!$_SESSION['userID']) {
    //Get user's info from the database ... or just hardcode it.
    $_SESSION['userID'] = 100;
    $_SESSION['firstName'] = "Sam";
}
printf("Welcome back %s (#%s)!<br/>\n", $_SESSION['firstName'], $_SESSION['userID']);
$_SESSION['time'] = time();
var_dump($_SESSION);
?>
    </div>
Example #10
0
<?php

/*
 * A sample script illustrating one way to insert a user into the 
 *  CloudKnock database
 */
require 'classes/user.php';
require 'path/to/Sag.php';
$user = new User(null, null, null, null, "5551112222", null, "15551112222", null);
$user->setName("Your Name");
$sag = new Sag('your-db.couchone.com', '5984');
$sag->setDatabase('cloudknock');
$sag->post(sprintf($user));
<?php

// Include required classes.
require 'classes/tropo.class.php';
require 'classes/sag/sag.php';
// Grab the raw JSON sent from Tropo.
$json = file_get_contents("php://input");
// Create a new Session object and obtain the session ID value.
$session = new Session($json);
$session_id = $session->getId();
// Insert the Session object into a CouchDB database called sessions.
try {
    $sag = new Sag();
    $sag->setDatabase("sessions");
    $sag->put($session_id, $json);
} catch (SagCouchException $ex) {
    die("*** " . $ex->getMessage() . " ***");
}
// Create a new Tropo object.
$tropo = new Tropo();
// Set options for an Ask.
$options = array("attempts" => 20, "bargein" => true, "choices" => "[5 DIGITS]", "name" => "zip", "timeout" => 5, "allowSignals" => array("tooLong", "farTooLong"));
$tropo->ask("Please enter your 5 digit zip code.", $options);
// Set event handlers
$tropo->on(array("event" => "continue", "next" => "get_zip_code.php?uri=end", "say" => "Please hold."));
$tropo->on(array("event" => "tooLong", "next" => "get_zip_code.php?uri=end&tooLong=true", "say" => "Please hold on."));
$tropo->on(array("event" => "farTooLong", "next" => "get_zip_code.php?uri=end&farTooLong=true", "say" => "Please hold on for dear life."));
// Render JSON for Tropo to consume.
$tropo->renderJSON();
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once 'config.php';
require_once 'utils.php';
$videoHeight = 360;
if (!isset($config) || !is_array($config)) {
    die("broken or missing configuration file?");
}
date_default_timezone_set(getConfig($config, 'time_zone', FALSE, 'Europe/Amsterdam'));
$dbName = getConfig($config, 'db_name', TRUE);
require_once "ext/sag/src/Sag.php";
$storage = new Sag();
$storage->setDatabase($dbName);
do {
    $toTranscode = $storage->get("_design/files/_view/get_media_status?limit=1&startkey=[\"WAITING\"]&endkey=[\"WAITING\",{}]")->body->rows;
    if (!empty($toTranscode)) {
        $t = $toTranscode[0];
        $id = $t->id;
        $info = $storage->get($id)->body;
        $info->transcodeStatus = 'PROGRESS';
        $storage->put($id, $info);
        $fileOwner = $info->fileOwner;
        $fileName = getConfig($config, 'file_storage_dir', TRUE) . DIRECTORY_SEPARATOR . base64_encode($fileOwner) . DIRECTORY_SEPARATOR . $info->fileName;
        if (isset($info->video)) {
            $transcodeFileName = getConfig($config, 'cache_dir', TRUE) . DIRECTORY_SEPARATOR . $info->video->transcode->{$videoHeight}->file;
            $newSize = $info->video->transcode->{$videoHeight}->width . "x" . $info->video->transcode->{$videoHeight}->height;
            // -vf transpose=1   (for rotating clockwise 90 degrees)
Example #13
0
if (count($_POST) == 0) {
    if (is_array($_SESSION['slouchin'])) {
        header('Location: private.php');
        exit;
    }
    header('Location: index.html');
    exit;
}
require_once 'Sag/Sag.php';
/*$username="******"; // Mysql username
$password="******"; // Mysql password
print_r($_POST);*/
// Define $myusername and $mypassword
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$s = new Sag();
/* cookie auth */
try {
    $res = $s->login($myusername, $mypassword, Sag::$AUTH_COOKIE);
    //$me = $s->get('org.couchdb.user:'******'username'])->body;
    if ($res->body->ok) {
        session_name('SlouchIn');
        session_id($res->cookies->AuthSession);
        session_start();
        $_SESSION['slouchin'] = array('name' => $myusername);
        header("Location: private.php");
        exit;
    }
} catch (SagCouchException $e) {
    echo 'Wrong Username or Password. <a href="index.html">Try Again?</a>';
}
   the data/files directory by linking them to users, analyzing
   their type, extracting some meta-data and other useful 
   information. 

   WARNING: custom added metadata and sharing properties will be 
   overwritten! 
*/
$fileStorageDir = getConfig($config, 'file_storage_dir', TRUE);
$cachePath = getConfig($config, 'cache_dir', TRUE);
/* each user has their own data directory, easy to link files
   to users in case the index breaks, so at least the files 
   themselves are not lost, only the metadata added by the user and
   sharing groups.
 */
$dbName = getConfig($config, 'db_name', TRUE);
$s = new Sag();
$dbs = $s->getAllDatabases()->body;
/* if db already exists, delete it */
if (in_array($dbName, $dbs)) {
    $s->deleteDatabase($dbName);
}
$s->createDatabase($dbName);
$s->setDatabase($dbName);
/* load all the map/reduce js functions from mapReduce directory */
$views = array();
foreach (glob("docs/mapReduce/*") as $mrFiles) {
    list($name, $type) = explode(".", basename($mrFiles));
    $views[$name][$type] = file_get_contents($mrFiles);
}
$view = array("_id" => "_design/files", "type" => "view", "language" => "javascript", "views" => $views);
// Add the view
Example #15
0
File: index.php Project: xwiz/sag
<?php

require_once '../../src/Sag.php';
session_start();
try {
    // We are going to get our page's content from Sag.
    $sag = new Sag('sbisbee.com');
    $sag->setDatabase('outlook');
    if ($_POST['login']) {
        echo '<p>Using login()';
        $_SESSION['AuthSession'] = $sag->login($_POST['username'], $_POST['password'], $sag::$AUTH_COOKIE);
    } else {
        if ($_SESSION['AuthSession']) {
            echo '<p>Using setCookie()';
            $sag->setCookie('AuthSession', $_SESSION['AuthSession']);
        }
    }
    $result = $sag->get('/');
} catch (Exception $e) {
    $error = $e->getMessage();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>proxyCookie example</title>
  </head>
  <body>
    <?php