コード例 #1
0
ファイル: Option.php プロジェクト: Wilkins/herisson-wordpress
 /**
  * Creates the options admin page and manages the update of options.
  * 
  * This is the default Action
  *
  * @return void
  */
 function indexAction()
 {
     if (post('action') == 'index') {
         $options = get_option('HerissonOptions');
         $new_options = array();
         foreach ($this->allowedoptions as $option) {
             $new_options[$option] = post($option);
         }
         $complete_options = array_merge($options, $new_options);
         if (!array_key_exists('privateKey', $complete_options)) {
             $encryption = Encryption::i()->generateKeyPairs();
             $complete_options['publicKey'] = $encryption->public;
             $complete_options['privateKey'] = $encryption->private;
             Message::i()->addError("<b>Warning</b> : public/private keys have been regenerated");
         }
         update_option('HerissonOptions', $complete_options);
     }
     // Check binaries paths
     $binaryTools = array('convert', 'wget', 'du', 'mv', 'uname');
     sort($binaryTools);
     $this->view->binaries = array();
     foreach ($binaryTools as $binary) {
         $this->view->binaries[$binary] = Shell::getPath($binary);
     }
     $this->view->platform = Shell::shellExec('uname', '-a');
     $this->view->screenshots = WpHerissonScreenshotsTable::getAll();
     $this->view->options = get_option('HerissonOptions');
 }
コード例 #2
0
ファイル: Index.php プロジェクト: Wilkins/herisson-wordpress
 /**
  * Action to handle validation of a pending request for friendship.
  *
  * Handled via HTTP Response code
  *
  * @return void
  */
 function validateAction()
 {
     $signature = post('signature');
     $url = post('url');
     $f = WpHerissonFriendsTable::getOneWhere("url=? AND b_youwant=1", array($url));
     try {
         if (Encryption::i()->publicDecrypt($signature, $f->public_key) == $url) {
             $f->b_youwant = 0;
             $f->is_active = 1;
             $f->save();
             Network::reply(200);
             echo "1";
             exit;
         } else {
             Network::reply(417, HERISSON_EXIT);
         }
     } catch (Encryption\Exception $e) {
         Network::reply(417, HERISSON_EXIT);
     }
 }
コード例 #3
0
 /**
  * Download backup data from this friend
  *
  * Do network hit to the friend's url
  * We decipher our bookmarks data with our private key, because only we can read our bookmarks
  *
  * @return true if backup was succesful, false otherwise
  */
 public function downloadBackup()
 {
     $signature = Encryption::i()->privateEncrypt(HERISSON_LOCAL_URL);
     $postData = array('url' => HERISSON_LOCAL_URL, 'signature' => $signature);
     $network = new Network();
     try {
         $content = $network->download($this->url . "/downloadbackup", $postData);
         // FIXME We should not have to use stripslashes here !!
         $encryptionData = unserialize(stripslashes($content['data']));
         $data = Encryption::i()->privateDecryptLongData($encryptionData['data'], $encryptionData['hash'], $encryptionData['iv']);
         return $data;
     } catch (Network\Exception $e) {
         switch ($e->getCode()) {
             case 417:
                 return 0;
                 break;
         }
         return $e->getCode();
     }
 }
コード例 #4
0
 /**
  * Test validating a friend with the wrong key
  *
  * @return void
  */
 public function testValidateFriendWaitingError()
 {
     // create a fake request from sample site
     $f = new WpHerissonFriends();
     $e = Encryption::i();
     $e->generateKeyPairs();
     $f->public_key = $e->public;
     $f->url = $this->herissonUrl;
     //$f->setUrl($this->herissonUrl);
     $f->b_wantsyou = 1;
     $f->save();
     // Check the request is pending
     $friends = WpHerissonFriendsTable::getWhere('url=? and b_wantsyou=? and is_active=?', array($f->url, 1, 0));
     $this->assertEquals(1, sizeof($friends));
     $friend = $friends[0];
     $friend->validateFriend();
     $msgs = Message::i()->getErrors();
     $msgs = array_reverse($msgs);
     $this->assertEquals(1, preg_match("/417/", $msgs[0]));
 }