Example #1
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $userString = $pl->getParameterValue("userString");
     if ($userString == null || $userString == '') {
         throw new ProcessException(_("Error processing the request."), "no_user_string");
     }
     // check if userString match the IP pattern
     if (preg_match('/^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+(\\|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)?$/', $userString) !== 1) {
         throw new ProcessException(_("Error processing the request."), "bad_user_string");
     }
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     // which to use which not.
     $ips = explode('|', $userString);
     $flagged = true;
     $valid1 = false;
     foreach ($ips as $ip) {
         // check if private
         if (false && preg_match("/^(10\\..*)|(172\\.16\\..*)|(192\\.168\\..*)|(127\\..*)|(169\\.254\\..*)/", $ip) != 0) {
             continue;
         }
         $valid1 = true;
         $c = new Criteria();
         $c->add("address", $ip);
         $c->add("user_id", $user->getUserId());
         $flag = DB_AnonymousAbuseFlagPeer::instance()->selectOne($c);
         if ($flag) {
             $flagged = $flagged && true;
         } else {
             $flagged = false;
         }
     }
     if (!$valid1) {
         throw new ProcessException(_("IP address of the user belongs to a private subnet. Sorry, such an address can not be flagged."));
     }
     if ($flagged) {
         $runData->contextAdd("flagged", true);
     }
     $runData->contextAdd("userString", $userString);
     list($ip, $proxy) = explode("|", $userString);
     $runData->contextAdd("ip", $ip);
     $runData->contextAdd("proxy", $proxy);
 }
Example #2
0
 public function flagAnonymousEvent($runData)
 {
     $pl = $runData->getParameterList();
     $toFlag = $pl->getParameterValue("flag");
     $userString = $pl->getParameterValue("userString");
     if ($userString == null || $userString == '') {
         throw new ProcessException(_("Error processing the request."), "no_user_string");
     }
     // check if userString match the IP pattern
     if (preg_match('/^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+(\\|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)?$/', $userString) !== 1) {
         throw new ProcessException(_("Error processing the request."), "bad_user_string");
     }
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $db = Database::connection();
     $db->begin();
     $ips = explode('|', $userString);
     if ($toFlag) {
         $i = 0;
         foreach ($ips as $ip) {
             $i++;
             if (false && preg_match("/^(10\\..*)|(172\\.16\\..*)|(192\\.168\\..*)|(127\\..*)|(169\\.254\\..*)/", $ip) != 0) {
                 continue;
             }
             // flag the IP
             // check if not flagged already
             $c = new Criteria();
             $c->add("user_id", $user->getUserId());
             $c->add("address", $ip);
             $flag = DB_AnonymousAbuseFlagPeer::instance()->selectOne($c);
             if ($flag == null) {
                 $siteId = $site->getSiteId();
                 $flag = new DB_AnonymousAbuseFlag();
                 $flag->setUserId($user->getUserId());
                 $flag->setSiteId($siteId);
                 $flag->setAddress($ip);
                 if ($i == 2) {
                     $flag->setProxy(true);
                 }
                 $flag->save();
             }
         }
         EventLogger::instance()->logFlagAnonymous($userString);
     } else {
         foreach ($ips as $ip) {
             // 	unflag
             $c = new Criteria();
             $c->add("user_id", $user->getUserId());
             $c->add("address", $ip);
             DB_AnonymousAbuseFlagPeer::instance()->delete($c);
         }
         EventLogger::instance()->logUnflagAnonymous($userString);
     }
     $db->commit();
 }
Example #3
0
 /**
  * Marks the site as "deleted" and invalidates all the cache related to the site.
  *
  * @param unknown_type $runData
  */
 public function deleteSiteEvent($runData)
 {
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("site_id", $site->getSiteId());
     $c->add("founder", true);
     $rel = DB_AdminPeer::instance()->selectOne($c);
     if (!$rel) {
         throw new ProcessException(_("Sorry, you have no permissions to delete this site."));
     }
     $db = Database::connection();
     $db->begin();
     $oldUnixName = $site->getUnixName();
     $site->setDeleted(true);
     // remove some data.
     $c = new Criteria();
     $c->add('site_id', $site->getSiteId());
     DB_AnonymousAbuseFlagPeer::instance()->delete($c);
     DB_DomainRedirectPeer::instance()->delete($c);
     DB_EmailInvitationPeer::instance()->delete($c);
     DB_MemberApplicationPeer::instance()->delete($c);
     DB_MemberInvitationPeer::instance()->delete($c);
     // now clear cache!
     $keys = array();
     $keys[] = 'site..' . $site->getUnixName();
     $keys[] = 'site_cd..' . $site->getCustomDomain();
     $mc = OZONE::$memcache;
     foreach ($keys as $k) {
         $mc->delete($k);
     }
     $outdater = new Outdater();
     $outdater->siteEvent('delete', $site);
     $outdater->siteEvent('sitewide_change', $site);
     // change site name!!!
     $site->setUnixName($site->getUnixName() . '..del..' . time());
     $site->save();
     // remove custom domain link
     // rename the files
     @rename(WIKIDOT_ROOT . '/web/files--sites/' . $oldUnixName, WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName());
     // delete custom domain link
     if ($site->getCustomDomain()) {
         @unlink(WIKIDOT_ROOT . '/web/custom--domains/' . $site->getCustomDomain());
         $site->setCustomDomain(null);
     }
     $db->commit();
 }