Example #1
0
 /**
  * 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');
 }
 /**
  * Validate a friend
  *
  * Do network hit to the friend's url and validate it's request
  *
  * @return true if validation was succesful, false otherwise
  */
 public function validateFriend()
 {
     $signature = Encryption::i()->privateEncrypt(HERISSON_LOCAL_URL);
     $postData = array('url' => HERISSON_LOCAL_URL, 'signature' => $signature);
     $network = new Network();
     try {
         $content = $network->download($this->url . "/validate", $postData);
         if ($content['data'] === "1") {
             $this->b_wantsyou = 0;
             $this->is_active = 1;
             $this->save();
             return true;
         } else {
             return false;
         }
     } catch (Network\Exception $e) {
         Message::i()->addError($e->getMessage());
         return false;
     }
 }
 /**
  * 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]));
 }
Example #4
0
 /**
  * Display import and maintenance options page
  *
  * This is the default Action
  *
  * @return void
  */
 function indexAction()
 {
     $correctFormats = array();
     $formats = Format::getList();
     // Check for problems in format list
     foreach ($formats as $format) {
         try {
             $format->check();
             if (!array_key_exists($format->keyword, $correctFormats)) {
                 $correctFormats[$format->keyword] = $format;
             } else {
                 $format1 = $correctFormats[$format->keyword];
                 Message::i()->addError(sprintf(__('Format « %s » defined in « %s » already exists in format « %s ». It will be ignored.', HERISSON_TD), $format->keyword, $format->name, $format1->name));
             }
         } catch (Format\Exception $e) {
             Message::i()->addError($e->getMessage());
         }
     }
     $this->view->formatList = $correctFormats;
 }
Example #5
0
 /**
  * Action to edit a friend
  *
  * If POST method used, update the given friend with the POST parameters,
  * otherwise just display the friend properties
  *
  * @return void
  */
 function editAction()
 {
     $id = intval(param('id'));
     if (!$id) {
         $id = 0;
     }
     if (sizeof($_POST)) {
         $url = post('url');
         $alias = post('alias');
         $new = $id == 0 ? true : false;
         if ($new) {
             $friend = new WpHerissonFriends();
             $friend->is_active = 0;
         } else {
             $friend = WpHerissonFriendsTable::get($id);
         }
         $friend->alias = $alias;
         $friend->url = $url;
         if ($new) {
             $friend->getInfo();
             $friend->askForFriend();
         }
         $friend->save();
         if ($new) {
             if ($new && $friend->is_active) {
                 Message::i()->addSucces(__("Friend has been added and automatically validated"));
             } else {
                 Message::i()->addSucces(__("Friend has been added, but needs to be validated by its owner"));
             }
             // Return to list after creating new friend.
             $this->indexAction();
             $this->setView('index');
             return;
         } else {
             Message::i()->addSucces(__("Friend saved"));
         }
     }
     if ($id == 0) {
         $this->view->existing = new WpHerissonFriends();
     } else {
         $this->view->existing = WpHerissonFriendsTable::get($id);
     }
     $this->view->id = $id;
 }
Example #6
0
 /**
  * Download a backup from friend
  *
  * @return void
  */
 private function _retrieve()
 {
     $friend = WpHerissonFriendsTable::get(get('id'));
     if (!$friend->id) {
         Message::i()->addError(__("Friend could not be found", HERISSON_TD));
         $this->indexAction();
         $this->setView('index');
         return;
     }
     return $friend->downloadBackup();
 }
 /**
  * Create the bookmark dir of the bookmark files
  *
  * @return boolean true if the directory was succesfully created, false otherwise
  */
 public function createDir()
 {
     if (!file_exists($this->getDir())) {
         // Create dir recursively
         mkdir($this->getDir(), 0775, true);
         return true;
     } else {
         if (file_exists($this->getDir()) && !is_dir($this->getDir())) {
             Message::i()->addError(__("Can't create directory " . $this->getDir() . ". A file already exists", HERISSON_TD));
             return false;
         } else {
             if (!is_writeable($this->getDir())) {
                 Message::i()->addError(__("Directory " . $this->getDir() . " exists, but is not writable.", HERISSON_TD));
                 return false;
             }
         }
     }
     return true;
 }