HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux dev1 5.15.83-1-pve #1 SMP PVE 5.15.83-1 (2022-12-15T00:00Z) x86_64
User: safarimaris (1000)
PHP: 7.2.34-54+ubuntu22.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /home/safarimaris/home/safarimaris/console/controllers/SystemController.php
<?php
namespace console\controllers;

use common\components\UserRole;
use common\models\User;
use Yii;
use yii\console\Controller;
use yii\imagine\Image;

class SystemController extends Controller
{

    public function actionCheck301()
    {
        $xml = simplexml_load_file('http://safarimaris.com/sitemap.xml');
        foreach ($xml as $x) {
            $oldUrl = (string)$x->loc;
            if (strpos($oldUrl, 'http://safarimaris.com/yachts/') !== 0) {
                continue;
            }
            $redirectUrl = $this->get_web_page(str_replace('.com', '.lof', $oldUrl));

            //echo $oldUrl."\n".$redirectUrl."\n";

            if ($oldUrl == str_replace('.lof', '.com', $redirectUrl)) {
                echo $redirectUrl."\n";
                //exit;
            }


        }
    }

    protected function get_web_page( $url )
    {
        $options = array(
            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => true,    // return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_USERAGENT      => "spider", // who am i
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
            CURLOPT_TIMEOUT        => 120,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects

        );

        $ch      = curl_init( $url );
        curl_setopt_array( $ch, $options );
        $content = curl_exec( $ch );
        $err     = curl_errno( $ch );
        $errmsg  = curl_error( $ch );
        $header  = curl_getinfo( $ch, CURLINFO_EFFECTIVE_URL );
        //curl_getinfo($ch,CURLINFO_EFFECTIVE_URL )
        curl_close( $ch );

        //$header['errno']   = $err;
        //$header['errmsg']  = $errmsg;
        //$header['content'] = $content;

        return $header;
    }

    public function actionImg60()
    {
        $this->img60(Yii::getAlias('@web').'/images/country/');
        $this->img60(Yii::getAlias('@web').'/images/entity/');
        $this->img60(Yii::getAlias('@web').'/images/entity_boat/');
        $this->img60(Yii::getAlias('@web').'/images/product/');
        $this->img60(Yii::getAlias('@web').'/images/site/');
    }

    function img60($dir)
    {
        echo $dir."\n";
        if($handler = opendir($dir)) {
            $i = 0;
            while (($sub = readdir($handler)) !== FALSE) {
                if ($sub != "." && $sub != ".." && $sub != "Thumb.db") {
                    if(is_file($dir."/".$sub)) {
                        Image::getImagine()->open($dir."/".$sub)->save($dir."/".$sub, ['quality' => 60]);
                    }elseif(is_dir($dir."/".$sub)){
                        $this->img60($dir."/".$sub);
                    }
                }
                $i++;
                echo "$i\r";
            }
            closedir($handler);
        }
    }

    public function actionRegInstructor()
    {
        if (($handle = fopen(Yii::$app->basePath.'/data/instructor.csv', "r")) !== FALSE) {
            $list = fgetcsv($handle, 10000, ";");

            fclose($handle);
            $fp = fopen(Yii::$app->basePath.'/data/instructor_password.csv', 'w');

            $return = [];
            $i = 1;
            foreach ($list as $email) {
                $i++;
                echo $i." of ".sizeof($list)."\r";

                $pwd = bin2hex(openssl_random_pseudo_bytes(4));

                $user = User::findByUsername($email);
                if (!$user) {
                    $user = new User();
                }
                $user->username = $email;
                $user->email = $email;
                $user->role = UserRole::INSTRUCTOR;
                $user->setPassword($pwd);
                $user->generateAuthKey();
                $user->save();
                fputcsv($fp, [$email, $pwd], ';');
                array_push($return, [$email, $pwd]);
            }

            fclose($fp);
        }
    }
}