Exemple #1
0
 public function checkUrl()
 {
     if ($this->url == self::URL_EXAMPLE) {
         $this->url = '';
     }
     if (!$this->url && !$this->uploadedfile && !$this->content) {
         $this->addError('url', Yii::t('swu', 'If you don\'t upload a file or input some text, you must provide a URL.'));
         return;
     }
     if ($this->url) {
         if (Helpers::getYiiParam('checkURL')) {
             try {
                 $array = @get_headers($this->url);
             } catch (Exception $e) {
                 $this->addError('url', Yii::t('swu', 'The URL provided is invalid.'));
                 return;
             }
             $string = $array[0];
             if (strpos($string, "200") === false) {
                 $this->addError('url', 'The URL provided does not seem to work.');
                 return;
             }
         } else {
             $valid_schemes = array('http', 'https', 'ftp');
             $scheme = @parse_url($this->url, PHP_URL_SCHEME);
             if (!in_array($scheme, $valid_schemes)) {
                 $this->addError('url', 'The URL provided does not validate. Valid schemes are: ' . implode(', ', $valid_schemes) . '.');
                 return;
             }
         }
     }
 }
Exemple #2
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $users = Helpers::getYiiParam('admins');
     if (!isset($users[$this->username])) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif (crypt($this->password, $users[$this->username]) != $users[$this->username]) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } else {
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }
Exemple #3
0
 public function sendCodes($controller)
 {
     if (!($student = Student::model()->findByAttributes(array('email' => $this->email)))) {
         return false;
     }
     $exercises = Exercise::model()->with('assignment')->sortByDuedate()->findAllByAttributes(array('student_id' => $student->id));
     foreach ($exercises as $exercise) {
         $exercise->link = Yii::app()->controller->createAbsoluteSslUrl('exercise/info', array('k' => $exercise->generateAckKey()));
     }
     $options = array();
     if (Helpers::getYiiParam('addOriginatingIP')) {
         $options['originating_IP'] = sprintf('[%s]', Yii::app()->request->userHostAddress);
     }
     return MailTemplate::model()->mailFromTemplate('send_codes', array($student->email => $student->name), array('student' => $student, 'exercises' => $exercises), $options);
 }
Exemple #4
0
 /**
  * Displays the contact page
  */
 public function actionContact($name = '', $subject = '', $body = '')
 {
     $model = new ContactForm();
     $model->name = $name;
     $model->subject = $subject;
     $model->body = $body;
     if (isset($_POST['ContactForm'])) {
         $model->attributes = $_POST['ContactForm'];
         if ($model->validate()) {
             MailTemplate::model()->mailFromTemplate('contact_form', Helpers::getYiiParam('adminEmail'), array('subject' => $model->subject, 'name' => $model->name, 'email' => $model->email, 'body' => $model->body), array('replyto' => $model->email));
             Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
             $this->refresh();
         }
     }
     $this->render('contact', array('model' => $model));
 }
Exemple #5
0
 protected function preFilter($filterChain)
 {
     if (!Helpers::getYiiParam('sslServerName')) {
         return true;
     }
     if (!isset($_SERVER['HTTP_X_FORWARDED_HOST']) || isset($_SERVER['HTTP_X_FORWARDED_HOST']) && $_SERVER['HTTP_X_FORWARDED_HOST'] != Helpers::getYiiParam('sslServerName')) {
         /*
          *      if ( !Yii::app()->getRequest()->isSecureConnection ) {
          *      This was the original check -- but it doesn't work with altervista...
          */
         # Redirect to the secure version of the page.
         $url = 'https://' . Helpers::getYiiParam('sslServerName') . Yii::app()->getRequest()->requestUri;
         // die("Not a secure connection, redirecting to: " . $url);
         Yii::app()->request->redirect($url);
         return false;
     }
     return true;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id = null)
 {
     $model = new Assignment();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Assignment'])) {
         $model->attributes = $_POST['Assignment'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     if ($id) {
         $cloned = $this->loadModel($id);
         Helpers::object2object($cloned, $model, array('subject', 'title', 'description', 'checklist', 'url', 'duedate', 'grace', 'language', 'status', 'notification', 'shown_since'));
     } else {
         $model->grace = Helpers::getYiiParam('defaultGrace');
         $model->duedate = date('Y-m-d') . ' 23:59:00';
         $model->shown_since = date('Y-m-d H:i:s');
         $model->language = Yii::app()->language;
         $model->status = Helpers::getYiiParam('defaultAssignmentStatus');
         $cloned = null;
     }
     $this->render('create', array('model' => $model, 'cloned' => $cloned));
 }
Exemple #7
0
 public function findTemplateAndMakeReplacements($code, $replacements)
 {
     $lang = Yii::app()->language;
     if (!($this->_template = MailTemplate::findByAttributes(array('code' => $code, 'lang' => $lang)))) {
         $lang = 'en';
         // as a fallback, we look for a template in English
         if (!($this->_template = MailTemplate::findByAttributes(array('code' => $code, 'lang' => $lang)))) {
             throw new Exception("Could not find mail template {$code} (language: {$lang})");
         }
     }
     $twig = new Twig();
     foreach (array('subject', 'plaintext_body', 'html_body') as $field) {
         $this->_template->{$field} = $twig->render($this->_template->{$field}, array_merge(array('site_url' => Helpers::getYiiParam('siteUrl'), 'site_name' => Yii::app()->name, 'lang' => $lang, 'now' => date('Y-m-d H:i:s')), $replacements));
     }
 }
Exemple #8
0
    echo Yii::app()->user->getFlash('flash-error');
    ?>
    </div>
  <?php 
}
?>

  <?php 
echo $content;
?>

  <div class="clear"></div>

  <div id="footer">
    <?php 
echo Helpers::getYiiParam('tagline');
?>
<br />
    This website is based on the application <a href="<?php 
echo SWU::WEBSITE;
?>
">SWU</a> (release <?php 
echo SWU::RELEASE;
?>
), available under <a href="<?php 
echo SWU::LICENSE_URL;
?>
">GNU Affero General Public License</a>.<br/>
    <?php 
echo Yii::powered();
?>
Exemple #9
0
    public static function mail($to, $subject, $plaintext_body, $html_body = '', $options = array())
    {
        if (!Helpers::getYiiParam('sendEmails')) {
            return true;
            // we won't send emails if it is not enabled, but we won't fail!
        }
        $from = Helpers::getOption('from', $options, Helpers::getYiiParam('botEmail'));
        if ($from == Helpers::getYiiParam('botEmail')) {
            $sender = Yii::app()->name;
        } else {
            $sender = $from;
        }
        $replyto = Helpers::getOption('replyto', $options, $from);
        $title = $subject;
        $subject = self::b64($subject);
        if (is_array($to)) {
            // we expect an array to be like array('*****@*****.**'=>'John Doe')
            $address = array_pop(array_keys($to));
            $name = $to[$address];
        } else {
            $name = $address = $to;
        }
        $addressee = self::b64($name) . " <" . $address . ">";
        $headers = array('From: ' . self::b64($sender) . " <{$from}>", "Reply-To: {$replyto}", 'MIME-Version: 1.0', "X-SWU-Version: " . SWU::RELEASE);
        foreach (array('message_id' => 'Message', 'originating_IP' => 'Originating-IP') as $key => $value) {
            if ($info = Helpers::getOption($key, $options, false)) {
                $headers[] = 'X-SWU-' . $value . ': ' . $info;
            }
        }
        $ack = Helpers::getOption('ack', $options, false);
        $ack_link = $ack ? Yii::app()->getController()->createAbsoluteSslUrl('message/ack', array('k' => Helpers::generateAckKey($ack['message_id']))) : false;
        $ack_image = Yii::app()->getController()->createAbsoluteSslUrl('site/image', array('name' => 'swu', 'k' => Helpers::generateAckKey(Helpers::getOption('message_id', $options))));
        $htt = new MailTemplate();
        $htt->findTemplateAndMakeReplacements('standard_head', array('title' => $subject, 'ack_link' => $ack_link, 'ack_image' => $ack_image));
        list($plaintext_head, $html_head) = array($htt->getSubtemplateField('plaintext_body'), $htt->getSubtemplateField('html_body'));
        $htt->findTemplateAndMakeReplacements('standard_tail', array('ack_link' => $ack_link, 'ack_image' => $ack_image));
        list($plaintext_tail, $html_tail) = array($htt->getSubtemplateField('plaintext_body'), $htt->getSubtemplateField('html_body'));
        if ($html_body) {
            //create a boundary string. It must be unique
            //so we use the MD5 algorithm to generate a random hash
            $random_hash = md5(date('r', time()));
            //add boundary string and mime type specification
            $headers[] = "Content-Type: multipart/mixed; boundary=\"PHP-mixed-{$random_hash}\"";
            $html = quoted_printable_encode($html_head . $html_body . $html_tail);
        }
        $plaintext_body = quoted_printable_encode($plaintext_body);
        if ($html_body) {
            $body = <<<EOT
--PHP-mixed-{$random_hash}  
Content-Type: multipart/alternative; boundary="PHP-alt-{$random_hash}" 

--PHP-alt-{$random_hash}  
Content-Type: text/plain; charset="UTF-8" 
Content-Transfer-Encoding: quoted-printable

{$plaintext_body}

--PHP-alt-{$random_hash}  
Content-Type: text/html; charset="UTF-8" 
Content-Transfer-Encoding: quoted-printable

{$html} 

EOT;
        } else {
            $headers[] = "Content-type: text/plain; charset=UTF-8";
            $headers[] = "Content-Transfer-Encoding: quoted-printable";
            $body = $plaintext_body;
        }
        Yii::log('sending message to ' . $addressee, 'info', 'components.Mailer');
        try {
            if (mail($addressee, $subject, $body, implode("\r\n", array_merge($headers, Helpers::getYiiParam('customMailHeaders'))) . "\r\n")) {
                return true;
            }
        } catch (Exception $e) {
            Yii::log('failed sending message to ' . $addressee . ' ' . $e->getMessage(), 'error', 'components.Mailer');
            return false;
        }
        return false;
    }
Exemple #10
0
<p class="note"><?php 
echo Yii::t('swu', 'Here you can upload a file choosing it from your computer.');
?>
 <?php 
echo Yii::t('swu', 'Please note that the maximum allowed size is %number% KiB.', array('%number%' => Helpers::getYiiParam('uploadMaxSize')));
?>
 <?php 
echo Yii::t('swu', 'If your file is bigger, you can either zip it or use the URL tab.');
?>
</p>

<div class="row">
  <?php 
echo $form->labelEx($model, 'uploadedfile');
?>
  <?php 
echo $form->fileField($model, 'uploadedfile');
?>
  <?php 
echo $form->error($model, 'uploadedfile');
?>
</div>
Exemple #11
0
 private function _replaceSchemaAndHost($url)
 {
     $redirection = Helpers::getYiiParam('redirection_url_replace');
     return str_replace($redirection['from'], $redirection['to'], $url);
 }
Exemple #12
0
 public static function getHostName()
 {
     if ($name = self::getYiiParam('sslServerName')) {
         return $name;
     }
     return 'http://' . Helpers::getYiiParam('siteUrl');
 }
 /**
  * Specifies the access control rules.
  * This method is used by the 'accessControl' filter.
  * @return array access control rules
  */
 public function accessRules()
 {
     return array(array('allow', 'actions' => array('ack'), 'users' => array('*')), array('allow', 'actions' => array('index', 'view', 'create', 'update', 'admin', 'delete', 'confirm', 'email', 'send', 'do', 'activation', 'toggle'), 'users' => array_keys(Helpers::getYiiParam('admins'))), array('deny', 'users' => array('*')));
 }
 /**
  * Specifies the access control rules.
  * This method is used by the 'accessControl' filter.
  * @return array access control rules
  */
 public function accessRules()
 {
     return array(array('allow', 'actions' => array('none'), 'users' => array('*')), array('allow', 'actions' => array('password'), 'users' => array_keys(Helpers::getYiiParam('admins'))), array('deny', 'users' => array('*')));
 }
 /**
  * Specifies the access control rules.
  * This method is used by the 'accessControl' filter.
  * @return array access control rules
  */
 public function accessRules()
 {
     return array(array('allow', 'actions' => array('info'), 'users' => array('*')), array('allow', 'actions' => array(), 'users' => array('@')), array('allow', 'actions' => array('create', 'update', 'index', 'view', 'admin', 'delete'), 'users' => array_keys(Helpers::getYiiParam('admins'))), array('deny', 'users' => array('*')));
 }
Exemple #16
0
    ?>
  <div class="label">
    <p>
    <span class="student"><?php 
    echo $exercise->student;
    ?>
</span> <?php 
    if (!$exercise->student->email) {
        echo $this->createIcon('email_edit', 'Missing email', array('width' => 16, 'height' => 16));
    }
    ?>
<br />
    <span class="assignment"><?php 
    echo $exercise->assignment->title;
    ?>
</span><br />
    <span class="url"><?php 
    echo Helpers::getYiiParam('siteUrl');
    ?>
</span><br />
    <?php 
    echo Yii::t('swu', 'code: %code%', array('%code%' => $exercise->code));
    ?>
<br />
    </p>
  </div>
<?php 
}
?>
<div class="page-break"></div>
Exemple #17
0
/* @var $model Message */
$this->breadcrumbs = array('Messages' => array('index'), 'Send');
if (Yii::app()->user->getState('sending') == 'true') {
    Yii::app()->clientScript->registerScript('stats', "\n\n    (function worker() {\n      \$.ajax({\n        url: 'index.php?r=message/do', \n        success: function(data) {\n          \$('#status').html(data);\n        },\n        complete: function() {\n          // Schedule the next request when the current one's complete\n          setTimeout(worker, 5000);\n        }\n      });\n    })();\n    ");
}
?>

<h1>Send Messages</h1>

<?php 
if (Yii::app()->user->getState('sending') != 'true') {
    ?>
  <p>Mailing is not currently active.
  
  <?php 
    if (Helpers::getYiiParam('sendEmails')) {
        ?>
    <?php 
        echo CHtml::link('Activate it now', $url = CHtml::normalizeUrl(array('message/activation', 'active' => 'true')), array('submit' => $url, 'title' => 'Activate mailing'));
        ?>
.
  <?php 
    } else {
        ?>
    This web site does not allow sending emails, though (check configuration).
  <?php 
    }
    ?>
  </p>
<?php 
} else {
Exemple #18
0
<!DOCTYPE html>
<html  lang="<?php 
echo Yii::app()->language;
?>
">
<head>
    <meta charset="utf-8">
    <title><?php 
echo CHtml::encode($this->pageTitle);
?>
</title>
    <link rel="icon" href="<?php 
echo Yii::app()->request->baseUrl;
?>
/images/printer.png" type="image/png" />
    <style>
    <?php 
echo Helpers::getYiiParam('labelsStyle');
?>
    </style>

</head>
<body>
<?php 
echo $content;
?>
</body>
</html>
Exemple #19
0
 /**
  * Allows the upload of a file.
  */
 public function actionUpload($code = '')
 {
     $model = new UploadForm();
     if (!Yii::app()->user->isGuest) {
         $model->byteacher = true;
     }
     $model->code = $code;
     $model->setUrlExample();
     if (isset($_POST['UploadForm'])) {
         $model->uploadedfile = CUploadedFile::getInstance($model, 'uploadedfile');
         $model->attributes = $_POST['UploadForm'];
         if ($model->validate()) {
             if ($file = $model->saveData(Yii::app()->basePath . DIRECTORY_SEPARATOR . Helpers::getYiiParam('uploadDirectory'))) {
                 if (!$model->byteacher) {
                     if ($file->exercise->assignment->notification) {
                         MailTemplate::model()->mailFromTemplate('new_work_notification', Helpers::getYiiParam('adminEmail'), array('student' => $model->exercise->student, 'file' => $file, 'url' => $this->createAbsoluteSslUrl('file/view', array('id' => $file->id, 'hash' => $file->md5))));
                     }
                     if ($model->exercise->student->email) {
                         MailTemplate::model()->mailFromTemplate('new_work_acknowledgement', array($model->exercise->student->email => $model->exercise->student), array('student' => $model->exercise->student, 'file' => $file, 'url' => $this->createAbsoluteSslUrl('file/view', array('id' => $file->id, 'hash' => $file->md5))));
                         Yii::app()->getUser()->setFlash('success', 'Work correctly uploaded / saved. An email has been sent to your address.');
                     }
                 } else {
                     Yii::app()->getUser()->setFlash('success', 'Work correctly uploaded / saved.');
                 }
                 $this->redirect(array('file/view', 'id' => $file->id, 'hash' => $file->md5, 'status' => 1));
             } else {
                 Yii::app()->getUser()->setFlash('error', 'The work could not be saved.');
             }
         }
     }
     $this->render('upload', array('model' => $model));
 }
 /**
  * Specifies the access control rules.
  * This method is used by the 'accessControl' filter.
  * @return array access control rules
  */
 public function accessRules()
 {
     return array(array('allow', 'actions' => array('sendcodes'), 'users' => array('*')), array('allow', 'actions' => array('view', 'create', 'admin', 'delete', 'update', 'emailaddresses', 'message', 'email', 'report', 'import'), 'users' => array_keys(Helpers::getYiiParam('admins'))), array('deny', 'users' => array('*')));
 }